Skip to content

Commit

Permalink
add contractName and pending tx status
Browse files Browse the repository at this point in the history
  • Loading branch information
zoeyTM committed Oct 21, 2024
1 parent d541c74 commit 1fb7c0f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
50 changes: 37 additions & 13 deletions packages/core/src/list-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
});
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions packages/core/src/types/list-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum TransactionStatus {
SUCCESS = "SUCCESS",
FAILURE = "FAILURE",
DROPPED = "DROPPED",
PENDING = "PENDING",
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/list-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe("listTransactions", () => {
txHash:
"0xb7b49d16087ab6351e26b2358ae211e5dac335441f323a28c6c26f0bc0c3a0a3",
status: TransactionStatus.SUCCESS,
name: "basicFunction",
name: "BasicContract#basicFunction",
to: "0x74e720c9B362ae3A65fF356ad62866511486BBBc",
params: [40],
value: 0n,
Expand Down

0 comments on commit 1fb7c0f

Please sign in to comment.