Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: transaction revert error #2896

Merged
merged 8 commits into from
Aug 12, 2024
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
petertonysmith94 marked this conversation as resolved.
Show resolved Hide resolved
---

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
Loading