From cb19e502766d44545566c5b512ed207f4cfecdc1 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 6 Dec 2023 15:10:36 -0300 Subject: [PATCH] Revert "feat: add `Predicate.getTransferTxId` helper (#1467)" This reverts commit 70233c1e579e607bdc2714b9b8039ea0eaac40a9. --- ...nd-and-spend-funds-from-predicates.test.ts | 21 ++----------- .../send-and-spend-funds-from-predicates.md | 6 ---- packages/predicate/package.json | 1 - packages/predicate/src/predicate.ts | 30 +------------------ packages/wallet/src/account.ts | 25 +--------------- pnpm-lock.yaml | 7 +++-- 6 files changed, 8 insertions(+), 82 deletions(-) diff --git a/apps/docs-snippets/src/guide/predicates/send-and-spend-funds-from-predicates.test.ts b/apps/docs-snippets/src/guide/predicates/send-and-spend-funds-from-predicates.test.ts index 7b60cd28f26..4ad9e9b0ae3 100644 --- a/apps/docs-snippets/src/guide/predicates/send-and-spend-funds-from-predicates.test.ts +++ b/apps/docs-snippets/src/guide/predicates/send-and-spend-funds-from-predicates.test.ts @@ -9,10 +9,7 @@ import { BaseAssetId, } from 'fuels'; -import { - DocSnippetProjectsEnum, - getDocsSnippetsForcProject, -} from '../../../test/fixtures/forc-projects'; +import { DocSnippetProjectsEnum, getDocsSnippetsForcProject } from '../../../test/fixtures/forc-projects'; import { getTestWallet } from '../../utils'; describe(__filename, () => { @@ -54,22 +51,11 @@ describe(__filename, () => { predicate.setData(inputAddress); // #endregion send-and-spend-funds-from-predicates-4 + // #region send-and-spend-funds-from-predicates-5 const receiverWallet = WalletUnlocked.generate({ provider, }); - // #region send-and-spend-funds-from-predicates-8 - const txId = await predicate.getTransferTxId( - receiverWallet.address, - amountToPredicate - 150_000, - BaseAssetId, - { - gasPrice, - } - ); - // #endregion send-and-spend-funds-from-predicates-8 - - // #region send-and-spend-funds-from-predicates-5 const tx2 = await predicate.transfer( receiverWallet.address, amountToPredicate - 150_000, @@ -82,9 +68,6 @@ describe(__filename, () => { await tx2.waitForResult(); // #endregion send-and-spend-funds-from-predicates-5 - const txIdFromExecutedTx = tx2.id; - - expect(txId).toEqual(txIdFromExecutedTx); }); it('should fail when trying to spend predicates entire amount', async () => { diff --git a/apps/docs/src/guide/predicates/send-and-spend-funds-from-predicates.md b/apps/docs/src/guide/predicates/send-and-spend-funds-from-predicates.md index 68c8695edd3..337b0d79d8c 100644 --- a/apps/docs/src/guide/predicates/send-and-spend-funds-from-predicates.md +++ b/apps/docs/src/guide/predicates/send-and-spend-funds-from-predicates.md @@ -38,12 +38,6 @@ Note the method transfer has two parameters: the recipient's address and the int Once the predicate resolves with a return value `true` based on its predefined condition, our predicate successfully spends its funds by means of a transfer to a desired wallet. ---- - -You can also use the `getTransferTxId` helper to obtain the transaction ID of the transfer beforehand, without actually executing it. - -<<< @/../../docs-snippets/src/guide/predicates/send-and-spend-funds-from-predicates.test.ts#send-and-spend-funds-from-predicates-8{ts:line-numbers} - ## Spending Entire Predicate Held Amount Trying to forward the entire amount held by the predicate results in an error because no funds are left to cover the transaction fees. Attempting this will result in an error message like: diff --git a/packages/predicate/package.json b/packages/predicate/package.json index 37d2a112144..a2fa199ec53 100644 --- a/packages/predicate/package.json +++ b/packages/predicate/package.json @@ -28,7 +28,6 @@ "@fuel-ts/abi-coder": "workspace:*", "@fuel-ts/address": "workspace:*", "@fuel-ts/interfaces": "workspace:*", - "@fuel-ts/math": "workspace:*", "@fuel-ts/merkle": "workspace:*", "@fuel-ts/providers": "workspace:*", "@fuel-ts/transactions": "workspace:*", diff --git a/packages/predicate/src/predicate.ts b/packages/predicate/src/predicate.ts index 3bd87618b22..fe61b61a9e2 100644 --- a/packages/predicate/src/predicate.ts +++ b/packages/predicate/src/predicate.ts @@ -7,11 +7,8 @@ import { SCRIPT_FIXED_SIZE, } from '@fuel-ts/abi-coder'; import { Address } from '@fuel-ts/address'; -import { BaseAssetId } from '@fuel-ts/address/configs'; import { ErrorCode, FuelError } from '@fuel-ts/errors'; -import { hashTransaction } from '@fuel-ts/hasher'; -import type { AbstractAddress, AbstractPredicate } from '@fuel-ts/interfaces'; -import type { BigNumberish } from '@fuel-ts/math'; +import type { AbstractPredicate } from '@fuel-ts/interfaces'; import type { CallResult, Provider, @@ -20,7 +17,6 @@ import type { } from '@fuel-ts/providers'; import { transactionRequestify, BaseTransactionRequest } from '@fuel-ts/providers'; import { ByteArrayCoder, InputType } from '@fuel-ts/transactions'; -import type { TxParamsType } from '@fuel-ts/wallet'; import { Account } from '@fuel-ts/wallet'; import type { BytesLike } from 'ethers'; import { getBytesCopy, hexlify } from 'ethers'; @@ -98,30 +94,6 @@ export class Predicate extends Account implements Abs return super.sendTransaction(transactionRequest); } - /** - * Returns the transaction ID for a transfer transaction, without sending it. - * - * @param destination - The address of the destination. - * @param amount - The amount of coins to transfer. - * @param assetId - The asset ID of the coins to transfer. - * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity). - * @returns A promise that resolves to the transaction ID. - */ - async getTransferTxId( - /** Address of the destination */ - destination: AbstractAddress, - /** Amount of coins */ - amount: BigNumberish, - /** Asset ID of coins */ - assetId: BytesLike = BaseAssetId, - /** Tx Params */ - txParams: TxParamsType = {} - ): Promise { - const request = await super.prepareTransferTxRequest(destination, amount, assetId, txParams); - const populatedRequest = this.populateTransactionPredicateData(request); - return hashTransaction(populatedRequest, this.provider.getChainId()); - } - /** * Simulates a transaction with the populated predicate data. * diff --git a/packages/wallet/src/account.ts b/packages/wallet/src/account.ts index c2cc5370143..d6d10f9be65 100644 --- a/packages/wallet/src/account.ts +++ b/packages/wallet/src/account.ts @@ -243,29 +243,6 @@ export class Account extends AbstractAccount { /** Tx Params */ txParams: TxParamsType = {} ): Promise { - const request = await this.prepareTransferTxRequest(destination, amount, assetId, txParams); - return this.sendTransaction(request); - } - - /** - * A helper that prepares a transaction request for calculating the transaction ID. - * - * @param destination - The address of the destination. - * @param amount - The amount of coins to transfer. - * @param assetId - The asset ID of the coins to transfer. - * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity). - * @returns A promise that resolves to the prepared transaction request. - */ - protected async prepareTransferTxRequest( - /** Address of the destination */ - destination: AbstractAddress, - /** Amount of coins */ - amount: BigNumberish, - /** Asset ID of coins */ - assetId: BytesLike = BaseAssetId, - /** Tx Params */ - txParams: TxParamsType = {} - ): Promise { const { minGasPrice } = this.provider.getGasConfig(); const params = { gasPrice: minGasPrice, ...txParams }; @@ -278,7 +255,7 @@ export class Account extends AbstractAccount { await this.fund(request, requiredQuantities, maxFee); - return request; + return this.sendTransaction(request); } /** diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a0299795792..972198c807d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -873,9 +873,6 @@ importers: '@fuel-ts/interfaces': specifier: workspace:* version: link:../interfaces - '@fuel-ts/math': - specifier: workspace:* - version: link:../math '@fuel-ts/merkle': specifier: workspace:* version: link:../merkle @@ -897,6 +894,10 @@ importers: ethers: specifier: ^6.7.1 version: 6.7.1 + devDependencies: + '@fuel-ts/math': + specifier: workspace:* + version: link:../math packages/program: dependencies: