diff --git a/CHANGELOG.md b/CHANGELOG.md index 873afc8c4ea..2f0d422eef6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2455,6 +2455,7 @@ If there are any bugs, improvements, optimizations or any new feature proposal f #### web3-eth - `defaultReturnFormat` was added to all methods that have `ReturnType` param. (#6947) +- `getTransactionFromOrToAttr`, `waitForTransactionReceipt`, `trySendTransaction`, `SendTxHelper` was exported (#7000) #### web3-eth-contract @@ -2473,8 +2474,23 @@ If there are any bugs, improvements, optimizations or any new feature proposal f - Added `signature` to type `AbiFunctionFragment` (#6922) - update type `Withdrawals`, `block` and `BlockHeaderOutput` to include properties of eip 4844, 4895, 4788 (#6933) +#### web3-utils + + ### Fixed +#### web3-utils + + #### web3-validator -- The JSON schema conversion process now correctly assigns an id when the `abi.name` is not available, for example, in the case of public mappings. (#6981) \ No newline at end of file + +### Changed + +#### web3-eth + +- Added parameter `customTransactionReceiptSchema` into methods `emitConfirmation`, `waitForTransactionReceipt`, `watchTransactionByPolling`, `watchTransactionBySubscription`, `watchTransactionForConfirmations` (#7000) + +#### web3-rpc-methods + +- Change `estimateGas` method to add possibility pass Transaction type (#7000) diff --git a/packages/web3-eth/CHANGELOG.md b/packages/web3-eth/CHANGELOG.md index ba7ee38a443..5fb80eef663 100644 --- a/packages/web3-eth/CHANGELOG.md +++ b/packages/web3-eth/CHANGELOG.md @@ -237,3 +237,8 @@ Documentation: ### Added - `defaultReturnFormat` was added to all methods that have `ReturnType` param. (#6947) +- `getTransactionFromOrToAttr`, `waitForTransactionReceipt`, `trySendTransaction`, `SendTxHelper` was exported (#7000) + +### Changed + +- Added parameter `customTransactionReceiptSchema` into methods `emitConfirmation`, `waitForTransactionReceipt`, `watchTransactionByPolling`, `watchTransactionBySubscription`, `watchTransactionForConfirmations` (#7000) diff --git a/packages/web3-eth/src/index.ts b/packages/web3-eth/src/index.ts index d1f1d326832..5e1c4297ffa 100644 --- a/packages/web3-eth/src/index.ts +++ b/packages/web3-eth/src/index.ts @@ -63,6 +63,9 @@ export * from './utils/format_transaction.js'; export * from './utils/prepare_transaction_for_signing.js'; export * from './web3_subscriptions.js'; export { detectTransactionType } from './utils/detect_transaction_type.js'; -export { transactionBuilder } from './utils/transaction_builder.js'; +export { transactionBuilder, getTransactionFromOrToAttr } from './utils/transaction_builder.js'; +export { waitForTransactionReceipt } from './utils/wait_for_transaction_receipt.js'; +export { trySendTransaction } from './utils/try_send_transaction.js'; +export { SendTxHelper } from './utils/send_tx_helper.js'; export default Web3Eth; diff --git a/packages/web3-eth/src/utils/send_tx_helper.ts b/packages/web3-eth/src/utils/send_tx_helper.ts index 2e3385d5d1c..282e778e519 100644 --- a/packages/web3-eth/src/utils/send_tx_helper.ts +++ b/packages/web3-eth/src/utils/send_tx_helper.ts @@ -33,7 +33,7 @@ import { ContractAbiWithSignature, } from 'web3-types'; import { Web3Context, Web3EventEmitter, Web3PromiEvent } from 'web3-core'; -import { isNullish } from 'web3-validator'; +import { isNullish, JsonSchema } from 'web3-validator'; import { ContractExecutionError, InvalidResponseError, @@ -257,9 +257,11 @@ export class SendTxHelper< public emitConfirmation({ receipt, transactionHash, + customTransactionReceiptSchema, }: { receipt: ResolveType; transactionHash: TransactionHash; + customTransactionReceiptSchema?: JsonSchema; }) { if (this.promiEvent.listenerCount('confirmation') > 0) { watchTransactionForConfirmations< @@ -272,6 +274,7 @@ export class SendTxHelper< receipt as unknown as TransactionReceipt, transactionHash, this.returnFormat, + customTransactionReceiptSchema, ); } } diff --git a/packages/web3-eth/src/utils/wait_for_transaction_receipt.ts b/packages/web3-eth/src/utils/wait_for_transaction_receipt.ts index d335683391e..e422b6307a2 100644 --- a/packages/web3-eth/src/utils/wait_for_transaction_receipt.ts +++ b/packages/web3-eth/src/utils/wait_for_transaction_receipt.ts @@ -30,19 +30,30 @@ export async function waitForTransactionReceipt web3Context: Web3Context, transactionHash: Bytes, returnFormat: ReturnFormat, + customGetTransactionReceipt?: ( + web3Context: Web3Context, + transactionHash: Bytes, + returnFormat: ReturnFormat, + ) => Promise, ): Promise { - const pollingInterval = web3Context.transactionReceiptPollingInterval ?? web3Context.transactionPollingInterval; - const [awaitableTransactionReceipt, IntervalId] = pollTillDefinedAndReturnIntervalId(async () => { - try { - return getTransactionReceipt(web3Context, transactionHash, returnFormat); - } catch (error) { - console.warn('An error happen while trying to get the transaction receipt', error); - return undefined; - } - }, pollingInterval); + const [awaitableTransactionReceipt, IntervalId] = pollTillDefinedAndReturnIntervalId( + async () => { + try { + return (customGetTransactionReceipt ?? getTransactionReceipt)( + web3Context, + transactionHash, + returnFormat, + ); + } catch (error) { + console.warn('An error happen while trying to get the transaction receipt', error); + return undefined; + } + }, + pollingInterval, + ); const [timeoutId, rejectOnTimeout] = rejectIfTimeout( web3Context.transactionPollingTimeout, @@ -65,10 +76,8 @@ export async function waitForTransactionReceipt rejectOnBlockTimeout, // this will throw an error on Transaction Block Timeout ]); } finally { - if(timeoutId) - clearTimeout(timeoutId); - if(IntervalId) - clearInterval(IntervalId); + if (timeoutId) clearTimeout(timeoutId); + if (IntervalId) clearInterval(IntervalId); blockTimeoutResourceCleaner.clean(); } } diff --git a/packages/web3-eth/src/utils/watch_transaction_by_polling.ts b/packages/web3-eth/src/utils/watch_transaction_by_polling.ts index 6be3c572742..34e01581422 100644 --- a/packages/web3-eth/src/utils/watch_transaction_by_polling.ts +++ b/packages/web3-eth/src/utils/watch_transaction_by_polling.ts @@ -20,6 +20,7 @@ import { format, numberToHex } from 'web3-utils'; import { ethRpcMethods } from 'web3-rpc-methods'; import { DataFormat } from 'web3-types'; +import { JsonSchema } from 'web3-validator'; import { SendSignedTransactionEvents, SendTransactionEvents } from '../types.js'; import { transactionReceiptSchema } from '../schemas.js'; @@ -30,6 +31,7 @@ export type Web3PromiEventEventTypeBase = export type WaitProps = { web3Context: Web3Context; transactionReceipt: TransactionReceipt; + customTransactionReceiptSchema?: JsonSchema; transactionPromiEvent: Web3PromiEvent>; returnFormat: ReturnFormat; }; @@ -46,6 +48,7 @@ export const watchTransactionByPolling = < web3Context, transactionReceipt, transactionPromiEvent, + customTransactionReceiptSchema, returnFormat, }: WaitProps) => { // Having a transactionReceipt means that the transaction has already been included @@ -67,7 +70,11 @@ export const watchTransactionByPolling = < transactionPromiEvent.emit('confirmation', { confirmations: format({ format: 'uint' }, confirmations, returnFormat), - receipt: format(transactionReceiptSchema, transactionReceipt, returnFormat), + receipt: format( + customTransactionReceiptSchema ?? transactionReceiptSchema, + transactionReceipt, + returnFormat, + ), latestBlockHash: format( { format: 'bytes32' }, nextBlock.hash as Bytes, diff --git a/packages/web3-eth/src/utils/watch_transaction_by_subscription.ts b/packages/web3-eth/src/utils/watch_transaction_by_subscription.ts index d68c39da95d..e7e68adc529 100644 --- a/packages/web3-eth/src/utils/watch_transaction_by_subscription.ts +++ b/packages/web3-eth/src/utils/watch_transaction_by_subscription.ts @@ -21,7 +21,6 @@ import { DataFormat } from 'web3-types'; import { NewHeadsSubscription } from '../web3_subscriptions.js'; import { transactionReceiptSchema } from '../schemas.js'; import { WaitProps, watchTransactionByPolling } from './watch_transaction_by_polling.js'; - /** * This function watches a Transaction by subscribing to new heads. * It is used by `watchTransactionForConfirmations`, in case the provider supports subscription. @@ -33,6 +32,7 @@ export const watchTransactionBySubscription = < web3Context, transactionReceipt, transactionPromiEvent, + customTransactionReceiptSchema, returnFormat, }: WaitProps) => { // The following variable will stay true except if the data arrived, @@ -66,7 +66,11 @@ export const watchTransactionBySubscription = < confirmations as Numbers, returnFormat, ), - receipt: format(transactionReceiptSchema, transactionReceipt, returnFormat), + receipt: format( + customTransactionReceiptSchema ?? transactionReceiptSchema, + transactionReceipt, + returnFormat, + ), latestBlockHash: format( { format: 'bytes32' }, newBlockHeader.parentHash as Bytes, @@ -85,6 +89,7 @@ export const watchTransactionBySubscription = < web3Context, transactionReceipt, transactionPromiEvent, + customTransactionReceiptSchema, returnFormat, }); }); @@ -94,6 +99,7 @@ export const watchTransactionBySubscription = < watchTransactionByPolling({ web3Context, transactionReceipt, + customTransactionReceiptSchema, transactionPromiEvent, returnFormat, }); diff --git a/packages/web3-eth/src/utils/watch_transaction_for_confirmations.ts b/packages/web3-eth/src/utils/watch_transaction_for_confirmations.ts index 60489d59c50..01ca39f8894 100644 --- a/packages/web3-eth/src/utils/watch_transaction_for_confirmations.ts +++ b/packages/web3-eth/src/utils/watch_transaction_for_confirmations.ts @@ -17,7 +17,7 @@ along with web3.js. If not, see . import { Bytes, EthExecutionAPI, Web3BaseProvider, TransactionReceipt } from 'web3-types'; import { Web3Context, Web3PromiEvent } from 'web3-core'; import { format } from 'web3-utils'; -import { isNullish } from 'web3-validator'; +import { isNullish, JsonSchema } from 'web3-validator'; import { TransactionMissingReceiptOrBlockHashError, @@ -41,6 +41,7 @@ export function watchTransactionForConfirmations< transactionReceipt: TransactionReceipt, transactionHash: Bytes, returnFormat: ReturnFormat, + customTransactionReceiptSchema?: JsonSchema, ) { if (isNullish(transactionReceipt) || isNullish(transactionReceipt.blockHash)) throw new TransactionMissingReceiptOrBlockHashError({ @@ -55,7 +56,11 @@ export function watchTransactionForConfirmations< // As we have the receipt, it's the first confirmation that tx is accepted. transactionPromiEvent.emit('confirmation', { confirmations: format({ format: 'uint' }, 1, returnFormat), - receipt: format(transactionReceiptSchema, transactionReceipt, returnFormat), + receipt: format( + customTransactionReceiptSchema ?? transactionReceiptSchema, + transactionReceipt, + returnFormat, + ), latestBlockHash: format({ format: 'bytes32' }, transactionReceipt.blockHash, returnFormat), }); @@ -66,6 +71,7 @@ export function watchTransactionForConfirmations< web3Context, transactionReceipt, transactionPromiEvent, + customTransactionReceiptSchema, returnFormat, }); } else { @@ -73,6 +79,7 @@ export function watchTransactionForConfirmations< web3Context, transactionReceipt, transactionPromiEvent, + customTransactionReceiptSchema, returnFormat, }); } diff --git a/packages/web3-eth/test/unit/rpc_method_wrappers/send_signed_transaction.test.ts b/packages/web3-eth/test/unit/rpc_method_wrappers/send_signed_transaction.test.ts index 4a741c46646..c5a461c7372 100644 --- a/packages/web3-eth/test/unit/rpc_method_wrappers/send_signed_transaction.test.ts +++ b/packages/web3-eth/test/unit/rpc_method_wrappers/send_signed_transaction.test.ts @@ -53,7 +53,7 @@ describe('sendTransaction', () => { WaitForTransactionReceipt.waitForTransactionReceipt as jest.Mock ).mockResolvedValueOnce(expectedTransactionReceipt); - const checkRevertBeforeSendingSpy = jest.fn().mockImplementation((transaction) => { + const checkRevertBeforeSendingSpy = jest.fn().mockImplementation(transaction => { expect(transaction).toBeDefined(); // verify signature part is removed before sending to revert check function @@ -78,7 +78,6 @@ describe('sendTransaction', () => { ); expect(checkRevertBeforeSendingSpy).toHaveBeenCalledTimes(1); - }, ); @@ -300,6 +299,7 @@ describe('sendTransaction', () => { formattedTransactionReceipt, expectedTransactionHash, DEFAULT_RETURN_FORMAT, + undefined, ); }, ); diff --git a/packages/web3-eth/test/unit/rpc_method_wrappers/send_transaction.test.ts b/packages/web3-eth/test/unit/rpc_method_wrappers/send_transaction.test.ts index 3be8182cd33..e9b60f97e74 100644 --- a/packages/web3-eth/test/unit/rpc_method_wrappers/send_transaction.test.ts +++ b/packages/web3-eth/test/unit/rpc_method_wrappers/send_transaction.test.ts @@ -299,6 +299,7 @@ describe('sendTransaction', () => { formattedTransactionReceipt, expectedTransactionHash, DEFAULT_RETURN_FORMAT, + undefined, ); }, ); diff --git a/packages/web3-rpc-methods/CHANGELOG.md b/packages/web3-rpc-methods/CHANGELOG.md index c2385435cac..c57997c5ddc 100644 --- a/packages/web3-rpc-methods/CHANGELOG.md +++ b/packages/web3-rpc-methods/CHANGELOG.md @@ -138,4 +138,8 @@ Documentation: - Added `getMaxPriorityFeePerGas` method (#6748) -## [Unreleased] \ No newline at end of file +## [Unreleased] + +### Changed + +- Change `estimateGas` method to add possibility pass Transaction type (#7000) diff --git a/packages/web3-rpc-methods/src/eth_rpc_methods.ts b/packages/web3-rpc-methods/src/eth_rpc_methods.ts index b33857d7d80..f86240ddccb 100644 --- a/packages/web3-rpc-methods/src/eth_rpc_methods.ts +++ b/packages/web3-rpc-methods/src/eth_rpc_methods.ts @@ -264,9 +264,9 @@ export async function call( } // TODO Not sure how to best validate Partial -export async function estimateGas( +export async function estimateGas( requestManager: Web3RequestManager, - transaction: Partial, + transaction: Partial, blockNumber: BlockNumberOrTag, ) { validator.validate(['blockNumberOrTag'], [blockNumber]);