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 745a80c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 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

0 comments on commit 745a80c

Please sign in to comment.