From 1fb7c0f46d1d4e854a6fd41484726e61d2a98219 Mon Sep 17 00:00:00 2001 From: zoeyTM Date: Sun, 20 Oct 2024 23:49:05 -0400 Subject: [PATCH] add contractName and pending tx status --- packages/core/src/list-transactions.ts | 50 +++++++++++++++----- packages/core/src/types/list-transactions.ts | 1 + packages/core/test/list-transactions.ts | 2 +- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/packages/core/src/list-transactions.ts b/packages/core/src/list-transactions.ts index 3ceafe8ee..a2e3fe903 100644 --- a/packages/core/src/list-transactions.ts +++ b/packages/core/src/list-transactions.ts @@ -64,14 +64,20 @@ export async function listTransactions( "Expected network interaction to be an onchain interaction" ); - for (const transaction of networkInteraction.transactions) { + for (const [ + index, + transaction, + ] of networkInteraction.transactions.entries()) { switch (exState.type) { case ExecutionSateType.DEPLOYMENT_EXECUTION_STATE: { transactions.push({ type: exState.type, from: exState.from, txHash: transaction.hash, - status: getTransactionStatus(transaction), + status: getTransactionStatus( + transaction, + index === networkInteraction.transactions.length - 1 + ), name: exState.contractName, address: transaction.receipt?.status === TransactionReceiptStatus.SUCCESS @@ -86,12 +92,19 @@ export async function listTransactions( break; } case ExecutionSateType.CALL_EXECUTION_STATE: { + const artifact = await deploymentLoader.loadArtifact( + exState.artifactId + ); + transactions.push({ type: exState.type, from: exState.from, txHash: transaction.hash, - status: getTransactionStatus(transaction), - name: exState.functionName, + status: getTransactionStatus( + transaction, + index === networkInteraction.transactions.length - 1 + ), + name: `${artifact.contractName}#${exState.functionName}`, to: networkInteraction.to, params: exState.args, value: networkInteraction.value, @@ -104,7 +117,10 @@ export async function listTransactions( type: exState.type, from: exState.from, txHash: transaction.hash, - status: getTransactionStatus(transaction), + status: getTransactionStatus( + transaction, + index === networkInteraction.transactions.length - 1 + ), to: networkInteraction.to, value: networkInteraction.value, }); @@ -132,13 +148,21 @@ function doesSendTransactions( ); } -function getTransactionStatus(transaction: Transaction): TransactionStatus { - const status = - transaction.receipt === undefined - ? TransactionStatus.DROPPED - : transaction.receipt.status === TransactionReceiptStatus.SUCCESS - ? TransactionStatus.SUCCESS - : TransactionStatus.FAILURE; +function getTransactionStatus( + transaction: Transaction, + isFinalTransaction: boolean +): TransactionStatus { + if (transaction.receipt === undefined) { + if (isFinalTransaction) { + return TransactionStatus.PENDING; + } + + return TransactionStatus.DROPPED; + } + + if (transaction.receipt.status === TransactionReceiptStatus.SUCCESS) { + return TransactionStatus.SUCCESS; + } - return status; + return TransactionStatus.FAILURE; } diff --git a/packages/core/src/types/list-transactions.ts b/packages/core/src/types/list-transactions.ts index 567ae5236..81aafa37a 100644 --- a/packages/core/src/types/list-transactions.ts +++ b/packages/core/src/types/list-transactions.ts @@ -9,6 +9,7 @@ export enum TransactionStatus { SUCCESS = "SUCCESS", FAILURE = "FAILURE", DROPPED = "DROPPED", + PENDING = "PENDING", } /** diff --git a/packages/core/test/list-transactions.ts b/packages/core/test/list-transactions.ts index 14e8fbb25..796cf0611 100644 --- a/packages/core/test/list-transactions.ts +++ b/packages/core/test/list-transactions.ts @@ -51,7 +51,7 @@ describe("listTransactions", () => { txHash: "0xb7b49d16087ab6351e26b2358ae211e5dac335441f323a28c6c26f0bc0c3a0a3", status: TransactionStatus.SUCCESS, - name: "basicFunction", + name: "BasicContract#basicFunction", to: "0x74e720c9B362ae3A65fF356ad62866511486BBBc", params: [40], value: 0n,