Skip to content

Commit 43fef09

Browse files
authored
Fix: Deploy Published Contract Flow (#499)
* Updated Deploy Published Contract Flow + ProcessTx * removed commented lines * Updates
1 parent f2f2e40 commit 43fef09

File tree

6 files changed

+53
-21
lines changed

6 files changed

+53
-21
lines changed

src/db/transactions/queueTx.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ export const queueTx = async ({
6060
return queueId;
6161
} else {
6262
const fromAddress = await tx.getSignerAddress();
63-
const toAddress = tx.getTarget();
63+
const toAddress =
64+
tx.getTarget() === "0x0000000000000000000000000000000000000000" &&
65+
txData.functionName === "deploy" &&
66+
extension === "deploy-published"
67+
? null
68+
: tx.getTarget();
6469

6570
const { id: queueId } = await queueTxRaw({
6671
pgtx,

src/db/transactions/updateTx.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type UpdateTxData =
2424
res: ethers.providers.TransactionRequest;
2525
sentAtBlockNumber: number;
2626
retryCount?: number;
27+
deployedContractAddress?: string;
2728
}
2829
| {
2930
status: TransactionStatus.UserOpSent;
@@ -84,6 +85,7 @@ export const updateTx = async ({ pgtx, queueId, data }: UpdateTxParams) => {
8485
maxFeePerGas: data.res?.maxFeePerGas?.toString(),
8586
maxPriorityFeePerGas: data.res?.maxPriorityFeePerGas?.toString(),
8687
value: data.res?.value?.toString(),
88+
deployedContractAddress: data.deployedContractAddress,
8789
},
8890
});
8991
break;

src/server/middleware/logs.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ import { logger } from "../../utils/logger";
44
export const withRequestLogs = async (server: FastifyInstance) => {
55
server.addHook("onRequest", async (request, reply) => {
66
if (
7-
!request.routerPath?.includes("static") &&
8-
!request.routerPath?.includes("json") &&
7+
!request.routeOptions.url?.includes("static") &&
8+
!request.routeOptions.url?.includes("json") &&
99
request.method !== "OPTIONS"
1010
) {
1111
logger({
1212
service: "server",
1313
level: "info",
14-
message: `Request received - ${request.method} - ${request.routerPath}`,
14+
message: `Request received - ${request.method} - ${request.routeOptions.url}`,
1515
});
1616
}
1717

1818
if (process.env.NODE_ENV === "production") {
19-
if (request.routerPath?.includes("static")) {
19+
if (request.routeOptions.url?.includes("static")) {
2020
return reply.status(404).send({
2121
statusCode: 404,
2222
error: "Not Found",
@@ -28,16 +28,16 @@ export const withRequestLogs = async (server: FastifyInstance) => {
2828

2929
server.addHook("preHandler", async (request, reply) => {
3030
if (
31-
!request.routerPath?.includes("static") &&
32-
!request.routerPath?.includes("json") &&
33-
!request.routerPath?.includes("/backend-wallet/import") &&
31+
!request.routeOptions.url?.includes("static") &&
32+
!request.routeOptions.url?.includes("json") &&
33+
!request.routeOptions.url?.includes("/backend-wallet/import") &&
3434
request.method !== "OPTIONS"
3535
) {
3636
if (request.body && Object.keys(request.body).length > 0) {
3737
logger({
3838
service: "server",
3939
level: "info",
40-
message: `Request body - ${request.method} - ${request.routerPath}`,
40+
message: `Request body - ${request.method} - ${request.routeOptions.url}`,
4141
data: request.body,
4242
});
4343
}
@@ -55,7 +55,7 @@ export const withRequestLogs = async (server: FastifyInstance) => {
5555
logger({
5656
service: "server",
5757
level: "info",
58-
message: `Request querystring - ${request.method} - ${request.routerPath}`,
58+
message: `Request querystring - ${request.method} - ${request.routeOptions.url}`,
5959
data: request.query,
6060
});
6161
}
@@ -64,18 +64,18 @@ export const withRequestLogs = async (server: FastifyInstance) => {
6464

6565
server.addHook("onResponse", (request, reply, done) => {
6666
if (
67-
!request.routerPath?.includes("static") &&
68-
!request.routerPath?.includes("json") &&
67+
!request.routeOptions.url?.includes("static") &&
68+
!request.routeOptions.url?.includes("json") &&
6969
request.method !== "OPTIONS"
7070
) {
7171
logger({
7272
service: "server",
7373
level: "info",
7474
message: `Request completed - ${request.method} - ${
75-
reply.request.routerPath
76-
} - status code: ${reply.statusCode} - Response time: ${reply
77-
.getResponseTime()
78-
.toFixed(2)}ms`,
75+
reply.request.routeOptions.url
76+
} - status code: ${
77+
reply.statusCode
78+
} - Response time: ${reply.elapsedTime.toFixed(2)}ms`,
7979
});
8080
}
8181

src/server/routes/deploy/published.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import { txOverrides } from "../../schemas/txOverrides";
1111
import { walletHeaderSchema } from "../../schemas/wallet";
1212
import { getChainIdFromChain } from "../../utils/chain";
13+
import { isAddress } from "thirdweb";
1314

1415
// INPUTS
1516
const requestSchema = publishedDeployParamSchema;
@@ -35,7 +36,12 @@ requestBodySchema.examples = [
3536
// OUTPUT
3637
const responseSchema = Type.Object({
3738
queueId: Type.Optional(Type.String()),
38-
deployedAddress: Type.Optional(Type.String()),
39+
deployedAddress: Type.Optional(
40+
Type.String({
41+
description: "Not all contracts return a deployed address.",
42+
}),
43+
),
44+
message: Type.Optional(Type.String()),
3945
});
4046

4147
export async function deployPublished(fastify: FastifyInstance) {
@@ -76,7 +82,10 @@ export async function deployPublished(fastify: FastifyInstance) {
7682
constructorParams,
7783
version,
7884
);
79-
const deployedAddress = await tx.simulate();
85+
const _deployedAddress = await tx.simulate();
86+
const deployedAddress = isAddress(_deployedAddress)
87+
? _deployedAddress
88+
: undefined;
8089

8190
const queueId = await queueTx({
8291
tx,
@@ -90,6 +99,9 @@ export async function deployPublished(fastify: FastifyInstance) {
9099
reply.status(StatusCodes.OK).send({
91100
deployedAddress,
92101
queueId,
102+
message: !deployedAddress
103+
? `To retrieve the deployed contract address, use the endpoint '/transaction/status/${queueId}' and check the value of the 'deployedContractAddress' field`
104+
: undefined,
93105
});
94106
},
95107
});

src/utils/usage.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ export const withServerUsageReporting = (server: FastifyInstance) => {
8080

8181
server.addHook("onResponse", async (request, reply) => {
8282
if (
83-
URLS_LIST_TO_NOT_REPORT_USAGE.has(reply.request.routerPath) ||
83+
reply.request.routeOptions.url === undefined ||
84+
URLS_LIST_TO_NOT_REPORT_USAGE.has(reply.request.routeOptions.url) ||
8485
reply.request.method === "OPTIONS"
8586
) {
8687
return;
@@ -100,12 +101,12 @@ export const withServerUsageReporting = (server: FastifyInstance) => {
100101
source: "engine",
101102
action: UsageEventTxActionEnum.APIRequest,
102103
clientId: thirdwebClientId,
103-
pathname: reply.request.routerPath,
104+
pathname: reply.request.routeOptions.url,
104105
chainId: chainId || undefined,
105106
walletAddress: requestParams.walletAddress || undefined,
106107
contractAddress: requestParams.contractAddress || undefined,
107108
httpStatusCode: reply.statusCode,
108-
msTotalDuration: Math.ceil(reply.getResponseTime()),
109+
msTotalDuration: Math.ceil(reply.elapsedTime),
109110
};
110111

111112
fetch(env.CLIENT_ANALYTICS_URL, {

src/worker/tasks/processTx.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
} from "../../utils/webhook";
3636
import { randomNonce } from "../utils/nonce";
3737
import { getWithdrawValue } from "../utils/withdraw";
38+
import { getContractAddress } from "ethers/lib/utils";
3839

3940
type RpcResponseData = {
4041
tx: Transactions;
@@ -288,6 +289,16 @@ export const processTx = async () => {
288289
if (rpcResponse.result) {
289290
// Transaction was successful.
290291
const transactionHash = rpcResponse.result;
292+
let contractAddress: string | undefined;
293+
if (
294+
tx.extension === "deploy-published" &&
295+
tx.functionName === "deploy"
296+
) {
297+
contractAddress = getContractAddress({
298+
from: txRequest.from!,
299+
nonce: BigNumber.from(txRequest.nonce!),
300+
});
301+
}
291302
await updateTx({
292303
pgtx,
293304
queueId: tx.id,
@@ -297,6 +308,7 @@ export const processTx = async () => {
297308
res: txRequest,
298309
sentAt: new Date(),
299310
sentAtBlockNumber: sentAtBlockNumber!,
311+
deployedContractAddress: contractAddress,
300312
},
301313
});
302314
reportUsageForQueueIds.push({

0 commit comments

Comments
 (0)