Skip to content

Commit 989ac6b

Browse files
authored
Add updated transaction receipt (#317)
1 parent c33ed20 commit 989ac6b

File tree

3 files changed

+47
-14
lines changed

3 files changed

+47
-14
lines changed

src/db/transactions/updateTx.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ type UpdateTxData =
2222
}
2323
| {
2424
status: TransactionStatusEnum.Submitted;
25-
res: ethers.providers.TransactionResponse;
25+
transactionHash: string;
26+
res: ethers.providers.TransactionResponse | null;
2627
sentAtBlockNumber: number;
2728
retryCount?: number;
2829
}
@@ -41,6 +42,7 @@ type UpdateTxData =
4142
gasLimit?: string;
4243
maxFeePerGas?: string;
4344
maxPriorityFeePerGas?: string;
45+
nonce?: number;
4446
};
4547

4648
export const updateTx = async ({ pgtx, queueId, data }: UpdateTxParams) => {
@@ -83,15 +85,15 @@ export const updateTx = async ({ pgtx, queueId, data }: UpdateTxParams) => {
8385
},
8486
data: {
8587
sentAt: new Date(),
86-
nonce: data.res.nonce,
87-
transactionHash: data.res.hash,
88-
transactionType: data.res.type || undefined,
89-
gasPrice: data.res.gasPrice?.toString(),
90-
gasLimit: data.res.gasLimit?.toString(),
91-
maxFeePerGas: data.res.maxFeePerGas?.toString(),
92-
maxPriorityFeePerGas: data.res.maxPriorityFeePerGas?.toString(),
88+
transactionHash: data.transactionHash,
9389
sentAtBlockNumber: data.sentAtBlockNumber,
9490
retryCount: data.retryCount,
91+
nonce: data.res?.nonce,
92+
transactionType: data.res?.type || undefined,
93+
gasPrice: data.res?.gasPrice?.toString(),
94+
gasLimit: data.res?.gasLimit?.toString(),
95+
maxFeePerGas: data.res?.maxFeePerGas?.toString(),
96+
maxPriorityFeePerGas: data.res?.maxPriorityFeePerGas?.toString(),
9597
},
9698
});
9799
break;
@@ -113,14 +115,15 @@ export const updateTx = async ({ pgtx, queueId, data }: UpdateTxParams) => {
113115
},
114116
data: {
115117
minedAt: data.minedAt,
116-
gasPrice: data.gasPrice,
117118
blockNumber: data.blockNumber,
118119
onChainTxStatus: data.onChainTxStatus,
119120
transactionHash: data.transactionHash,
120121
transactionType: data.transactionType,
122+
gasPrice: data.gasPrice,
121123
gasLimit: data.gasLimit,
122124
maxFeePerGas: data.maxFeePerGas,
123125
maxPriorityFeePerGas: data.maxPriorityFeePerGas,
126+
nonce: data.nonce,
124127
},
125128
});
126129
break;

src/worker/tasks/processTx.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ import { randomNonce } from "../utils/nonce";
2626

2727
type SentTxStatus =
2828
| {
29+
transactionHash: string;
2930
status: TransactionStatusEnum.Submitted;
3031
queueId: string;
31-
res: ethers.providers.TransactionResponse;
32+
res: ethers.providers.TransactionResponse | null;
3233
sentAtBlockNumber: number;
3334
}
3435
| {
@@ -233,11 +234,23 @@ export const processTx = async () => {
233234
const tx = txsToSend[i];
234235
if (rpcRes.result) {
235236
const txHash = rpcRes.result;
236-
const txRes = await provider.getTransaction(txHash);
237+
238+
const txRes = (await provider.getTransaction(
239+
txHash,
240+
)) as ethers.providers.TransactionResponse | null;
241+
237242
logger.worker.info(
238-
`[Transaction] [${tx.queueId}] Sent tx ${txHash}, with Nonce ${txRes.nonce}`,
243+
`[Transaction] [${tx.queueId}] Sent transaction with hash ${txHash}`,
239244
);
245+
246+
if (!!txRes) {
247+
logger.worker.debug(
248+
`[Transaction] [${tx.queueId}] Using nonce ${txRes.nonce}`,
249+
);
250+
}
251+
240252
return {
253+
transactionHash: txHash,
241254
status: TransactionStatusEnum.Submitted,
242255
queueId: tx.queueId!,
243256
res: txRes,
@@ -274,6 +287,7 @@ export const processTx = async () => {
274287
queueId: tx.queueId,
275288
data: {
276289
status: TransactionStatusEnum.Submitted,
290+
transactionHash: tx.transactionHash,
277291
res: tx.res,
278292
sentAtBlockNumber: await provider.getBlockNumber(),
279293
},

src/worker/tasks/updateMinedTx.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ export const updateMinedTx = async () => {
3434
return undefined;
3535
}
3636

37+
const response = (await sdk
38+
.getProvider()
39+
.getTransaction(
40+
tx.transactionHash!,
41+
)) as ethers.providers.TransactionResponse | null;
42+
3743
// Get the timestamp when the transaction was mined
3844
const minedAt = new Date(
3945
(
@@ -47,6 +53,7 @@ export const updateMinedTx = async () => {
4753
return {
4854
tx,
4955
receipt,
56+
response,
5057
minedAt,
5158
};
5259
}),
@@ -57,6 +64,7 @@ export const updateMinedTx = async () => {
5764
}) as {
5865
tx: Transactions;
5966
receipt: ethers.providers.TransactionReceipt;
67+
response: ethers.providers.TransactionResponse;
6068
minedAt: Date;
6169
}[];
6270

@@ -68,12 +76,20 @@ export const updateMinedTx = async () => {
6876
queueId: txWithReceipt.tx.id,
6977
data: {
7078
status: TransactionStatusEnum.Mined,
71-
gasPrice: txWithReceipt.receipt.effectiveGasPrice.toString(),
72-
blockNumber: txWithReceipt.receipt.blockNumber,
7379
minedAt: txWithReceipt.minedAt,
80+
blockNumber: txWithReceipt.receipt.blockNumber,
7481
onChainTxStatus: txWithReceipt.receipt.status,
82+
transactionHash: txWithReceipt.receipt.transactionHash,
83+
transactionType: txWithReceipt.receipt.type,
84+
gasPrice: txWithReceipt.receipt.effectiveGasPrice.toString(),
85+
gasLimit: txWithReceipt.response?.gasLimit?.toString(),
86+
maxFeePerGas: txWithReceipt.response?.maxFeePerGas?.toString(),
87+
maxPriorityFeePerGas:
88+
txWithReceipt.response?.maxPriorityFeePerGas?.toString(),
89+
nonce: txWithReceipt.response?.nonce,
7590
},
7691
});
92+
7793
logger.worker.info(
7894
`[Transaction] [${txWithReceipt.tx.id}] Updated with receipt`,
7995
);

0 commit comments

Comments
 (0)