From 51fd2e4a1600c6d69bba33ea8a58613868508dad Mon Sep 17 00:00:00 2001 From: Danny Delott Date: Fri, 26 Apr 2024 15:27:29 -0700 Subject: [PATCH] Add `status` to Transaction (#60) * Add status to transaction * Add changeset * Cleanup async keyword --- .changeset/rotten-geese-cheer.md | 7 +++++++ packages/evm-client-ethers/src/network/createNetwork.ts | 4 ++++ packages/evm-client-viem/src/network/createNetwork.ts | 4 ++-- packages/evm-client/src/network/stubs/NetworkStub.ts | 1 + packages/evm-client/src/network/types/Transaction.ts | 3 +++ 5 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 .changeset/rotten-geese-cheer.md diff --git a/.changeset/rotten-geese-cheer.md b/.changeset/rotten-geese-cheer.md new file mode 100644 index 00000000..7e7e13bc --- /dev/null +++ b/.changeset/rotten-geese-cheer.md @@ -0,0 +1,7 @@ +--- +"@delvtech/evm-client-ethers": minor +"@delvtech/evm-client-viem": minor +"@delvtech/evm-client": minor +--- + +Add status field to Transaction diff --git a/packages/evm-client-ethers/src/network/createNetwork.ts b/packages/evm-client-ethers/src/network/createNetwork.ts index d1ac465d..5d081a73 100644 --- a/packages/evm-client-ethers/src/network/createNetwork.ts +++ b/packages/evm-client-ethers/src/network/createNetwork.ts @@ -81,6 +81,9 @@ export function createNetwork(provider: Provider): Network { return; } + // status is either 0 (reverted) or 1 (success) + const status = !transaction.status ? 'reverted' : 'success'; + return { blockHash: transaction.blockHash as `0x${string}`, blockNumber: BigInt(transaction.blockNumber), @@ -92,6 +95,7 @@ export function createNetwork(provider: Provider): Network { transactionHash: transaction.hash as `0x${string}`, transactionIndex: transaction.index, effectiveGasPrice: BigInt(transaction.gasPrice), + status, }; }, }; diff --git a/packages/evm-client-viem/src/network/createNetwork.ts b/packages/evm-client-viem/src/network/createNetwork.ts index d2d73886..ee0a6731 100644 --- a/packages/evm-client-viem/src/network/createNetwork.ts +++ b/packages/evm-client-viem/src/network/createNetwork.ts @@ -72,8 +72,8 @@ export function createNetwork(publicClient: PublicClient): Network { }; }, - async waitForTransaction(hash, options) { - return await publicClient.waitForTransactionReceipt({ + waitForTransaction(hash, options) { + return publicClient.waitForTransactionReceipt({ hash, timeout: options?.timeout, }); diff --git a/packages/evm-client/src/network/stubs/NetworkStub.ts b/packages/evm-client/src/network/stubs/NetworkStub.ts index 0e988a2c..1ca88933 100644 --- a/packages/evm-client/src/network/stubs/NetworkStub.ts +++ b/packages/evm-client/src/network/stubs/NetworkStub.ts @@ -154,6 +154,7 @@ export function transactionToReceipt( transactionHash: transaction.hash!, gasUsed: 0n, logsBloom: '0x', + status: 'success', } : undefined; } diff --git a/packages/evm-client/src/network/types/Transaction.ts b/packages/evm-client/src/network/types/Transaction.ts index 99548899..967c74d7 100644 --- a/packages/evm-client/src/network/types/Transaction.ts +++ b/packages/evm-client/src/network/types/Transaction.ts @@ -45,6 +45,9 @@ export interface TransactionReceipt { logsBloom: `0x${string}`; transactionHash: `0x${string}`; transactionIndex: number; + + status: 'success' | 'reverted'; + /** * The actual value per gas deducted from the sender's account. Before * EIP-1559, this is equal to the transaction's gas price. After, it is equal