From c7104da3a2f8caf92cdad0585dd39f563bdc5bd3 Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Mon, 12 Aug 2024 07:29:01 +0100 Subject: [PATCH] fix: transaction revert error (#2896) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 <30977845+Torres-ssf@users.noreply.github.com> --- .changeset/hungry-cups-rest.md | 5 +++++ .../transaction-response.ts | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 .changeset/hungry-cups-rest.md diff --git a/.changeset/hungry-cups-rest.md b/.changeset/hungry-cups-rest.md new file mode 100644 index 00000000000..264aa94b67a --- /dev/null +++ b/.changeset/hungry-cups-rest.md @@ -0,0 +1,5 @@ +--- +"@fuel-ts/account": patch +--- + +fix: transaction revert error diff --git a/packages/account/src/providers/transaction-response/transaction-response.ts b/packages/account/src/providers/transaction-response/transaction-response.ts index 11840da632d..0e14810b876 100644 --- a/packages/account/src/providers/transaction-response/transaction-response.ts +++ b/packages/account/src/providers/transaction-response/transaction-response.ts @@ -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'; @@ -91,6 +96,8 @@ export class TransactionResponse { gqlTransaction?: GqlTransaction; abis?: JsonAbisFromAllCalls; + /** The expected status from the getTransactionWithReceipts response */ + private expectedStatus?: GqlTransactionStatusesNames; /** * Constructor for `TransactionResponse`. @@ -139,6 +146,7 @@ export class TransactionResponse { for await (const { statusChange } of subscription) { if (statusChange) { + this.expectedStatus = statusChange.type; break; } } @@ -146,6 +154,12 @@ export class TransactionResponse { 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; @@ -235,6 +249,7 @@ export class TransactionResponse { ); } if (statusChange.type !== 'SubmittedStatus') { + this.expectedStatus = statusChange.type; break; } }