Skip to content

Commit

Permalink
fix: transaction revert error (#2896)
Browse files Browse the repository at this point in the history
* fix: transaction `waitForStatusChange` expects the status received from the `statusChange` subscription

* chore: remove unneeded import

* chore: changeset

* chore: addressing comments from PR

* chore: change timeout to 100ms

---------

Co-authored-by: Sérgio Torres <[email protected]>
  • Loading branch information
petertonysmith94 and Torres-ssf authored Aug 12, 2024
1 parent b0c161f commit c7104da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-cups-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/account": patch
---

fix: transaction revert error
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@ import type {
ReceiptBurn,
} from '@fuel-ts/transactions';
import { TransactionCoder } from '@fuel-ts/transactions';
import { arrayify } from '@fuel-ts/utils';
import { arrayify, sleep } from '@fuel-ts/utils';

import type { GqlReceiptFragment } from '../__generated__/operations';
import type Provider from '../provider';
import type { JsonAbisFromAllCalls } from '../transaction-request';
import { assembleTransactionSummary } from '../transaction-summary/assemble-transaction-summary';
import { processGqlReceipt } from '../transaction-summary/receipt';
import type { TransactionSummary, GqlTransaction, AbiMap } from '../transaction-summary/types';
import type {
TransactionSummary,
GqlTransaction,
AbiMap,
GqlTransactionStatusesNames,
} from '../transaction-summary/types';
import { extractTxError } from '../utils';

import { getDecodedLogs } from './getDecodedLogs';
Expand Down Expand Up @@ -91,6 +96,8 @@ export class TransactionResponse {
gqlTransaction?: GqlTransaction;

abis?: JsonAbisFromAllCalls;
/** The expected status from the getTransactionWithReceipts response */
private expectedStatus?: GqlTransactionStatusesNames;

/**
* Constructor for `TransactionResponse`.
Expand Down Expand Up @@ -139,13 +146,20 @@ export class TransactionResponse {

for await (const { statusChange } of subscription) {
if (statusChange) {
this.expectedStatus = statusChange.type;
break;
}
}

return this.fetch();
}

// Refetch if the expected status is not the same as the response status
if (this.expectedStatus && response.transaction.status?.type !== this.expectedStatus) {
await sleep(100);
return this.fetch();
}

this.gqlTransaction = response.transaction;

return response.transaction;
Expand Down Expand Up @@ -235,6 +249,7 @@ export class TransactionResponse {
);
}
if (statusChange.type !== 'SubmittedStatus') {
this.expectedStatus = statusChange.type;
break;
}
}
Expand Down

0 comments on commit c7104da

Please sign in to comment.