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

chore!: remove awaitExecution functionality #2820

Merged
merged 6 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/cyan-doors-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@fuel-ts/contract": minor
"@fuel-ts/account": minor
"@fuel-ts/program": minor
---

chore!: remove `awaitExecution` functionality
3 changes: 2 additions & 1 deletion apps/docs-snippets/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export const getTestWallet = async (seedQuantities?: CoinQuantityLike[]) => {
// funding the transaction with the required quantities
await genesisWallet.fund(request, txCost);

await genesisWallet.sendTransaction(request, { awaitExecution: true });
const submit = await genesisWallet.sendTransaction(request);
await submit.waitForResult();

// return the test wallet
return testWallet;
Expand Down
3 changes: 1 addition & 2 deletions packages/account/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ export class Account extends AbstractAccount {
*/
async sendTransaction(
transactionRequestLike: TransactionRequestLike,
{ estimateTxDependencies = true, awaitExecution }: ProviderSendTxParams = {}
{ estimateTxDependencies = true }: ProviderSendTxParams = {}
): Promise<TransactionResponse> {
if (this._connector) {
return this.provider.getTransactionResponse(
Expand All @@ -592,7 +592,6 @@ export class Account extends AbstractAccount {
await this.provider.estimateTxDependencies(transactionRequest);
}
return this.provider.sendTransaction(transactionRequest, {
awaitExecution,
estimateTxDependencies: false,
});
}
Expand Down
33 changes: 2 additions & 31 deletions packages/account/src/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,7 @@ export type ProviderCallParams = UTXOValidationParams & EstimateTransactionParam
/**
* Provider Send transaction params
*/
export type ProviderSendTxParams = EstimateTransactionParams & {
/**
* By default, the promise will resolve immediately after the transaction is submitted.
*
* If set to true, the promise will resolve only when the transaction changes status
* from `SubmittedStatus` to one of `SuccessStatus`, `FailureStatus` or `SqueezedOutStatus`.
*/
awaitExecution?: boolean;
};
export type ProviderSendTxParams = EstimateTransactionParams;

/**
* URL - Consensus Params mapping.
Expand Down Expand Up @@ -706,7 +698,7 @@ Supported fuel-core version: ${supportedVersion}.`
// #region Provider-sendTransaction
async sendTransaction(
transactionRequestLike: TransactionRequestLike,
{ estimateTxDependencies = true, awaitExecution = false }: ProviderSendTxParams = {}
{ estimateTxDependencies = true }: ProviderSendTxParams = {}
): Promise<TransactionResponse> {
const transactionRequest = transactionRequestify(transactionRequestLike);
this.#cacheInputs(transactionRequest.inputs);
Expand All @@ -723,27 +715,6 @@ Supported fuel-core version: ${supportedVersion}.`
abis = transactionRequest.abis;
}

if (awaitExecution) {
const subscription = this.operations.submitAndAwait({ encodedTransaction });
for await (const { submitAndAwait } of subscription) {
if (submitAndAwait.type === 'SqueezedOutStatus') {
throw new FuelError(
ErrorCode.TRANSACTION_SQUEEZED_OUT,
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
);
}

if (submitAndAwait.type !== 'SubmittedStatus') {
break;
}
}

const transactionId = transactionRequest.getTransactionId(this.getChainId());
const response = new TransactionResponse(transactionId, this, abis);
await response.fetch();
return response;
}

const {
submit: { id: transactionId },
} = await this.operations.submit({ encodedTransaction });
Expand Down
3 changes: 2 additions & 1 deletion packages/account/src/test-utils/seedTestWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ export const seedTestWallet = async (

await genesisWallet.fund(request, txCost);

await genesisWallet.sendTransaction(request, { awaitExecution: true });
const submit = await genesisWallet.sendTransaction(request);
await submit.waitForResult();
};
5 changes: 2 additions & 3 deletions packages/account/src/wallet/base-wallet-unlocked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,19 @@ export class BaseWalletUnlocked extends Account {
*
* @param transactionRequestLike - The transaction request to send.
* @param estimateTxDependencies - Whether to estimate the transaction dependencies.
* @param awaitExecution - Whether to wait for the transaction to be executed.
* @returns A promise that resolves to the TransactionResponse object.
*/
async sendTransaction(
transactionRequestLike: TransactionRequestLike,
{ estimateTxDependencies = false, awaitExecution }: ProviderSendTxParams = {}
{ estimateTxDependencies = false }: ProviderSendTxParams = {}
): Promise<TransactionResponse> {
const transactionRequest = transactionRequestify(transactionRequestLike);
if (estimateTxDependencies) {
await this.provider.estimateTxDependencies(transactionRequest);
}
return this.provider.sendTransaction(
await this.populateTransactionWitnessesSignature(transactionRequest),
{ awaitExecution, estimateTxDependencies: false }
{ estimateTxDependencies: false }
);
}

Expand Down
4 changes: 1 addition & 3 deletions packages/contract/src/contract-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ export default class ContractFactory {

const account = this.getAccount();

const transactionResponse = await account.sendTransaction(transactionRequest, {
awaitExecution: false,
});
const transactionResponse = await account.sendTransaction(transactionRequest);

const waitForResult = async () => {
const transactionResult = await transactionResponse.waitForResult<TransactionType.Create>();
Expand Down
3 changes: 2 additions & 1 deletion packages/fuel-gauge/src/await-execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ describe('await-execution', () => {
await genesisWallet.signTransaction(transfer)
);

const response = await provider.sendTransaction(transfer, { awaitExecution: true });
const response = await provider.sendTransaction(transfer);
await response.waitForResult();

expect(response.gqlTransaction?.status?.type).toBe('SuccessStatus');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const fundPredicate = async <T extends InputValue[]>(
request.maxFee = txCost.maxFee;
await wallet.fund(request, txCost);

await wallet.sendTransaction(request, { awaitExecution: true });
const submit = await wallet.sendTransaction(request);
await submit.waitForResult();

return predicate.getBalance();
};
3 changes: 2 additions & 1 deletion packages/fuel-gauge/src/transaction-response.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ describe('TransactionResponse', () => {

await expectToThrowFuelError(
async () => {
await provider.sendTransaction(request, { awaitExecution: true });
const submit = await provider.sendTransaction(request);
await submit.waitForResult();
},
{ code: ErrorCode.TRANSACTION_SQUEEZED_OUT }
);
Expand Down
1 change: 0 additions & 1 deletion packages/program/src/functions/base-invocation-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ export class BaseInvocationScope<TReturn = any> {
const transactionRequest = await this.fundWithRequiredCoins();

const response = (await this.program.account.sendTransaction(transactionRequest, {
awaitExecution: false,
estimateTxDependencies: false,
})) as TransactionResponse;

Expand Down
Loading