From 568b4b23075d21d4f96b84a74b28b647ec845211 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Fri, 4 Mar 2022 15:54:23 +0500 Subject: [PATCH] Update `web3-eth-contract` to use `web3-eth` methods (#4806) * Add @ethereumjs/tx dependency * Update Web3BaseProvider to SupportedProviders for Web3Eth constructor * WIP eth-tx * Add support for undefined values for convertToValidType * Remove unused Web3BaseProvider * WIP eth-tx utils * Export privateKeyToAddress * Add web3-eth-accounts dependency * WIP web3-eth-tx util methods * Replace inline errors with error constructors * Change types for transaction r and s properties. Correct hardforks in detectTransactionType * Init formatTransaction tests and fixture * Init detectTransactionType and fixture * Add more descriptive error messages * Logic fixes for validateTransactionForSigning * Init validateTransactionForSigning tests and fixtures * Add esModuleInterop: true to tsconfig * Small bug fixes and added TODOs * Add parent describe to detect_transaction_type test * Add parent describe to format_transaction test * Add web3-providers-http as dev dependency for tests * Init populate_transaction tests * Move types from eth_tx.ts to types.ts * Remove TODOs * Add missing , * Remove TODO * Remove TODO * Fix transaction type import issues * Update convertToValidType test data for undefined * Update override method tests * Update packages/web3-eth/src/eth_tx.ts Co-authored-by: jdevcs <86780488+jdevcs@users.noreply.github.com> * Move getBlock to after type check for populateTransaction * Replace N/A with name of error for error.msg * Assign formattedTransaction type Transaction * convertToValidType now throws error for value === undefined * NumberType extends Numbers * Transaction type related changes * Refactor DesiredType logic * Convert to deep copy for formatTransaction method * skip override method test - needs to be refactored. General formatting * Skip override method test - needs to be refactored. Set input.type > 0x7f * Refactor formatTransaction * Add error codes to web3-eth errors * Refactor validateGate if statements into readable consts * Update comment * Add link to error message from 1.x * Fix bug with is gas consts in validateGas * Init InvalidConvertibleValueError * Replace error with InvalidConvertibleValueError * Update tests for formatting undefined * Update expected errors for validateGas tests * No longer default tx.type if undefined * Refactor detectTransactionType * Fix type error for return in detectTransactionType * Init rpc_method_wrappers.ts * Remove Web3Eth import * Refactor use of web3Context.defaults * Restore Formatted transaction types * Init web3_rpc_method_wrappers tests * Refactor web3_eth_methods_with_parameters test * Replace if X === undefined checks with ? * Un-export consts that aren't used * Add defaultTransactionType and defaultMaxPriorityFeePerGas * Update defaults for chain and hardfork to mainnet and london * Update to use web3Context.default chain and hardfork. Init tests for defaults * Update test to account for added defaults * Refactor validateGas to use helper methods * remove TODO * Init error TransactionGasMismatchError * Fix tests and refactor transaction validator helper methods * Move validation methods to validation.ts * Add input to Transaction type * Add @ethereumjs/common dependency * yarn format * Remove null for defaultTransactionType * Add default for defaultTransactionType * Update default for defaultTransactionType * Bug fixes, refactors, and init prepareTransactionForSigning and tests * Remove unused test code * revert transaction data and value to default to 0x * Fix failing populate_transaction tests * Add defaultNetworkId to web3_config * Add TODO for failing prepare_transaction_for_signing test * Remove TODO * Init TransactionDataAndInputError * Add else if to populateTransaction - data * Refactor populateTransaction - chainId * Comment out unused ifs * Remove populateTransaction - gas * Remove populateTransaction - hexTxType * Replace use of ValidReturnTypes[ValidTypes.HexString] with HexString * Remove toHex import * Remove | null for Web3ConfigOptions defaultChain and defaultHardfork * Refactor getEthereumjsTransactionOptions * Remove no longer needed populateTransaction - gas test * Update packages/web3-eth/src/validation.ts * Remove unnecessary rpc method wrappers * Web3Eth now extends Web3Context instead of instantiating it * Init getPendingTransactions * Init requestAccounts * Add EIP-1102 as a comment for requestAccounts * Init getChainId * Init getProof * Init Web3EthExecutionAPI * Fix imports for AccountObject in fixtures * Add formatting to getPendingTransactions. Move formatTransaction to seperate file * Add TODO to investigate transaction.data * Add formatting to getChainId response * Init getNodeInfo * Revert esModuleInterop change * Combine networkId and chainId if statements * yarn format * Add Partial to type of transaction for eth_sendTransaction * Init transactionReceiptPollingInterval and transactionConfirmationPollingInterval * Add TODO and Partial to transaction type for sendTransaction * WIP sendTransaction and PromiEvent integration * Add eslint-disable-next-line * Add eslint-disable-next-line * Move TransactionEvents * eslint fixes * Update sendSignedTransaction to use PromiEvent * Init signTransaction * Refactor TransactionCall * Comment out validation for call * Init TransactionCall type for web3-eth types * Remove as BaseTransaction from isTransactionCall * Implement call for rpc_method_wrappers * Uncomment sendTransaction, signTransaction, and call * :sparkles: Update estimate gas method to use web3-eth * :art: Update contract mehtod send to use web3-eth utility functions * :art: Update contract method call to use web3-eth utilities * :art: Fix code introduced in merge conflicts Co-authored-by: Wyatt Barnes Co-authored-by: jdevcs <86780488+jdevcs@users.noreply.github.com> --- CHANGELOG.md | 2 + .../web3-common/src/web3_event_emitter.ts | 12 ++ packages/web3-eth-contract/package.json | 3 +- packages/web3-eth-contract/src/contract.ts | 151 ++++++++---------- packages/web3-eth-contract/src/types.ts | 55 ++----- packages/web3-eth-contract/src/utils.ts | 9 +- packages/web3-eth/src/rpc_method_wrappers.ts | 130 +++++++++------ yarn.lock | 23 +-- 8 files changed, 192 insertions(+), 193 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53a982b0221..752575a3b64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -357,6 +357,7 @@ Released with 1.0.0-beta.37 code base. 4. `recover` function's last param is boolean `hashed`, it is used to indicate if data provided is already hashed or not. By default this function will assume data is not hashed. 5. The `Wallet` no more supports address/number indexing. Have to use `wallet.get` instead. 6. `Wallet.create` function doesn't accepts `entropy` param +7. `contract.method.send()` will resolve to transaction receipt instead of `transactionHash`. User can use `receipt.transactionHash` instead. #### web3-net @@ -368,3 +369,4 @@ Released with 1.0.0-beta.37 code base. 2. `setContent` is not supported in web3-eth-ens 4.x as its deprecated in ENS public resolver (https://github.com/ensdomains/resolvers/blob/master/contracts/PublicResolver.sol) 3. `getContent` is not supported in web3-eth-ens 4.x as its deprecated in ENS public resolver. 4. `getMultihash` is not supported in web3-eth-ens 4.x as its deprecated in ENS public resolver. + diff --git a/packages/web3-common/src/web3_event_emitter.ts b/packages/web3-common/src/web3_event_emitter.ts index 9fab7e82916..ffba425135c 100644 --- a/packages/web3-common/src/web3_event_emitter.ts +++ b/packages/web3-common/src/web3_event_emitter.ts @@ -31,4 +31,16 @@ export class Web3EventEmitter implements Web3Emitter public emit>(eventName: K, params: T[K]) { this._emitter.emit(eventName, params); } + + public listenerCount>(eventName: K) { + return this._emitter.listenerCount(eventName); + } + + public listeners>(eventName: K) { + return this._emitter.listeners(eventName); + } + + public eventNames() { + return this._emitter.eventNames(); + } } diff --git a/packages/web3-eth-contract/package.json b/packages/web3-eth-contract/package.json index 312f1aecdd6..e20076ed6cd 100644 --- a/packages/web3-eth-contract/package.json +++ b/packages/web3-eth-contract/package.json @@ -29,7 +29,8 @@ "web3-core": "4.0.0-alpha.0", "web3-eth-abi": "4.0.0-alpha.0", "web3-utils": "4.0.0-alpha.1", - "web3-validator": "0.1.0-alpha.0" + "web3-validator": "0.1.0-alpha.0", + "web3-eth": "4.0.0-alpha.1" }, "devDependencies": { "@humeris/espresso-shot": "^4.0.0", diff --git a/packages/web3-eth-contract/src/contract.ts b/packages/web3-eth-contract/src/contract.ts index 77486dad3da..e8da1bc5bcc 100644 --- a/packages/web3-eth-contract/src/contract.ts +++ b/packages/web3-eth-contract/src/contract.ts @@ -14,13 +14,14 @@ import { isAbiFunctionFragment, jsonInterfaceMethodToString, } from 'web3-eth-abi'; +import { estimateGas, sendTransaction, call } from 'web3-eth/src/rpc_method_wrappers'; import { Address, BlockNumberOrTag, BlockTags, - hexToNumber, - toChecksumAddress, HexString, + toChecksumAddress, + ValidTypes, } from 'web3-utils'; import { validator } from 'web3-validator'; import { decodeMethodReturn, encodeEventABI, encodeMethodABI } from './encoding'; @@ -164,47 +165,38 @@ export class Contract return { arguments: args, - // TODO: Use `web3-eth-tx` package to return `PromiEvent` instead. send: async (options?: PayableCallOptions) => { const modifiedOptions = { ...options }; delete modifiedOptions.to; - const txHash = await this._contractMethodSend( + const promiEvent = this._contractMethodSend( abi as AbiFunctionFragment, args, modifiedOptions, contractOptions, ); - return txHash; - - // TODO: Use eth-tx functions to - // - // 1. Get the transaction receipt from the above txHash - // 2. Extract the contract address from the receipt - // 3. Get the code from eth_getCode for the contract address - // 4. Return the contract instance with the new address and the code - // - // return new Contract(this._jsonInterface, contractAddress as HexString, { - // gas: this.options.gas, - // gasPrice: this.options.gasPrice, - // gasLimit: this.options.gasLimit, - // from: this.options.from, - // data: this.options.data, - // provider: this.currentProvider, - // }); + // eslint-disable-next-line no-void + void promiEvent.then(res => { + this._address = res.contractAddress; + }); + + return promiEvent; }, - estimateGas: async (options?: PayableCallOptions, block?: BlockNumberOrTag) => { + estimateGas: async ( + options?: PayableCallOptions, + returnType?: ReturnType, + ) => { const modifiedOptions = { ...options }; delete modifiedOptions.to; - return this._contractMethodEstimateGas( - abi as AbiFunctionFragment, - args, - modifiedOptions, - block, + return this._contractMethodEstimateGas({ + abi: abi as AbiFunctionFragment, + params: args, + returnType, + options: modifiedOptions, contractOptions, - ); + }); }, encodeABI: () => encodeMethodABI(abi as AbiFunctionFragment, args, data), }; @@ -296,11 +288,12 @@ export class Contract arguments: params, call: async (options?: PayableCallOptions, block?: BlockNumberOrTag) => this._contractMethodCall(abi, params, options, block), - // TODO: Use `web3-eth-tx` package to return `PromiEvent` instead. - send: async (options?: PayableCallOptions) => + send: (options?: PayableCallOptions) => this._contractMethodSend(abi, params, options), - estimateGas: async (options?: PayableCallOptions, block?: BlockNumberOrTag) => - this._contractMethodEstimateGas(abi, params, options, block), + estimateGas: async ( + options?: PayableCallOptions, + returnType?: ReturnType, + ) => this._contractMethodEstimateGas({ abi, params, returnType, options }), encodeABI: () => encodeMethodABI(abi, params), } as unknown as PayableMethodObject< ContractMethod['Inputs'], @@ -312,10 +305,12 @@ export class Contract arguments: params, call: async (options?: NonPayableCallOptions, block?: BlockNumberOrTag) => this._contractMethodCall(abi, params, options, block), - send: async (options?: NonPayableCallOptions) => + send: (options?: NonPayableCallOptions) => this._contractMethodSend(abi, params, options), - estimateGas: async (options?: NonPayableCallOptions, block?: BlockNumberOrTag) => - this._contractMethodEstimateGas(abi, params, options, block), + estimateGas: async ( + options?: NonPayableCallOptions, + returnType?: ReturnType, + ) => this._contractMethodEstimateGas({ abi, params, returnType, options }), encodeABI: () => encodeMethodABI(abi, params), } as unknown as NonPayableMethodObject< ContractMethod['Inputs'], @@ -330,68 +325,56 @@ export class Contract options?: Options, block?: BlockNumberOrTag, ) { - return decodeMethodReturn( + const tx = getEthTxCallParams({ abi, - await this.requestManager.send({ - method: 'eth_call', - params: [ - getEthTxCallParams({ - abi, - params, - options, - contractOptions: this.options, - }), - block ?? BlockTags.LATEST, - ], - }), - ); + params, + options, + contractOptions: this.options, + }); + + return decodeMethodReturn(abi, await call(this, tx, block)); } - private async _contractMethodSend( + private _contractMethodSend( abi: AbiFunctionFragment, params: unknown[], options?: Options, contractOptions?: ContractOptions, ) { - return decodeMethodReturn( + const tx = getSendTxParams({ abi, - await this.requestManager.send({ - method: 'eth_sendTransaction', - params: [ - getSendTxParams({ - abi, - params, - options, - contractOptions: contractOptions ?? this.options, - }), - ], - }), - ); + params, + options, + contractOptions: contractOptions ?? this.options, + }); + + return sendTransaction(this, tx); } private async _contractMethodEstimateGas< Options extends PayableCallOptions | NonPayableCallOptions, - >( - abi: AbiFunctionFragment, - params: unknown[], - options?: Options, - block?: BlockNumberOrTag, - contractOptions?: ContractOptions, - ) { - return hexToNumber( - await this.requestManager.send({ - method: 'eth_estimateGas', - params: [ - getEstimateGasParams({ - abi, - params, - options, - contractOptions: contractOptions ?? this.options, - }), - block ?? BlockTags.LATEST, - ], - }), - ); + ReturnType extends ValidTypes = ValidTypes.HexString, + >({ + abi, + params, + returnType, + options, + contractOptions, + }: { + abi: AbiFunctionFragment; + params: unknown[]; + returnType?: ReturnType; + options?: Options; + contractOptions?: ContractOptions; + }) { + const tx = getEstimateGasParams({ + abi, + params, + options, + contractOptions: contractOptions ?? this.options, + }); + + return estimateGas(this, tx, BlockTags.LATEST, returnType); } // eslint-disable-next-line class-methods-use-this diff --git a/packages/web3-eth-contract/src/types.ts b/packages/web3-eth-contract/src/types.ts index 8b7eaf634ba..82eb56d6286 100644 --- a/packages/web3-eth-contract/src/types.ts +++ b/packages/web3-eth-contract/src/types.ts @@ -1,7 +1,8 @@ -import { EthExecutionAPI, PromiEvent, ReceiptInfo } from 'web3-common'; +import { EthExecutionAPI, ReceiptInfo } from 'web3-common'; import { SupportedProviders } from 'web3-core'; import { ContractAbi } from 'web3-eth-abi'; -import { Address, BlockNumberOrTag, Bytes, Filter, HexString, Numbers, Uint } from 'web3-utils'; +import { sendTransaction } from 'web3-eth/src/rpc_method_wrappers'; +import { Address, BlockNumberOrTag, Bytes, Filter, HexString, Uint, ValidTypes } from 'web3-utils'; export interface EventLog { event: string; @@ -43,14 +44,14 @@ export interface ContractInitOptions { export type TransactionReceipt = ReceiptInfo; export interface NonPayableCallOptions { - nonce?: Numbers; - chainId?: Numbers; + nonce?: HexString; + chainId?: HexString; from?: Address; to?: Address; data?: HexString; gas?: string; - maxPriorityFeePerGas?: Numbers; - maxFeePerGas?: Numbers; + maxPriorityFeePerGas?: HexString; + maxFeePerGas?: HexString; gasPrice?: string; } @@ -61,43 +62,21 @@ export interface PayableCallOptions extends NonPayableCallOptions { export interface NonPayableMethodObject { arguments: Inputs; call(tx?: NonPayableCallOptions, block?: BlockNumberOrTag): Promise; - send(tx?: NonPayableCallOptions): PromiEvent< - TransactionReceipt, - { - sending: object; - sent: object; - transactionHash: string; - receipt: TransactionReceipt; - confirmation: { - confirmations: number; - receipt: TransactionReceipt; - latestBlockHash: HexString; - }; - error: Error; - } - >; - estimateGas(tx?: NonPayableCallOptions): Promise; + send(tx?: NonPayableCallOptions): ReturnType; + estimateGas( + options?: NonPayableCallOptions, + returnType?: ReturnType, + ): Promise; encodeABI(): string; } export interface PayableMethodObject { arguments: Inputs; call(tx?: PayableCallOptions, block?: BlockNumberOrTag): Promise; - send(tx?: PayableCallOptions): PromiEvent< - TransactionReceipt, - { - sending: object; - sent: object; - transactionHash: string; - receipt: TransactionReceipt; - confirmation: { - confirmations: number; - receipt: TransactionReceipt; - latestBlockHash: HexString; - }; - error: Error; - } - >; - estimateGas(tx?: PayableCallOptions): Promise; + send(tx?: PayableCallOptions): ReturnType; + estimateGas( + options?: PayableCallOptions, + returnType?: ReturnType, + ): Promise; encodeABI(): HexString; } diff --git a/packages/web3-eth-contract/src/utils.ts b/packages/web3-eth-contract/src/utils.ts index 53f969f165a..e5bcc3faca7 100644 --- a/packages/web3-eth-contract/src/utils.ts +++ b/packages/web3-eth-contract/src/utils.ts @@ -1,6 +1,7 @@ -import { TransactionCall, TransactionWithSender } from 'web3-common'; +import { TransactionWithSender } from 'web3-common'; import { AbiFunctionFragment } from 'web3-eth-abi'; import { mergeDeep } from 'web3-utils'; +import { TransactionCall } from 'web3-eth/src/types'; import { encodeMethodABI } from './encoding'; import { Web3ContractError } from './errors'; import { NonPayableCallOptions, PayableCallOptions, ContractOptions } from './types'; @@ -15,7 +16,7 @@ export const getSendTxParams = ({ params: unknown[]; options?: PayableCallOptions | NonPayableCallOptions; contractOptions: ContractOptions; -}): TransactionWithSender & { data: string } => { +}): TransactionCall => { if (!options?.to && !contractOptions.address) { throw new Web3ContractError('Contract address not specified'); } @@ -33,7 +34,7 @@ export const getSendTxParams = ({ data: contractOptions.data, }, options as unknown as Record, - ) as unknown as TransactionWithSender & { data: string }; + ) as unknown as TransactionCall; if (!txParams.data) { txParams = { @@ -114,5 +115,5 @@ export const getEstimateGasParams = ({ }; } - return txParams; + return txParams as TransactionWithSender; }; diff --git a/packages/web3-eth/src/rpc_method_wrappers.ts b/packages/web3-eth/src/rpc_method_wrappers.ts index fb9b55136e2..4b881328716 100644 --- a/packages/web3-eth/src/rpc_method_wrappers.ts +++ b/packages/web3-eth/src/rpc_method_wrappers.ts @@ -11,12 +11,14 @@ import { HexString, HexString32Bytes, HexStringBytes, + hexToNumber, + numberToHex, Uint, Uint256, ValidReturnTypes, ValidTypes, } from 'web3-utils'; -import { validator, isHexString32Bytes } from 'web3-validator'; +import { validator, isHexString32Bytes, isBlockTag } from 'web3-validator'; import { convertibleBlockProperties, convertibleFeeHistoryResultProperties, @@ -116,7 +118,9 @@ export const getCode = async ( ) => rpcMethods.getCode(web3Context.requestManager, address, blockNumber); export async function getBlock( - web3Context: Web3Context, + // A context can have any subscriptions + // eslint-disable-next-line @typescript-eslint/no-explicit-any + web3Context: Web3Context, block: HexString32Bytes | BlockNumberOrTag = web3Context.defaultBlock, hydrated = false, returnType?: ReturnType, @@ -292,7 +296,9 @@ export async function getPendingTransactions, + // A context can have any subscriptions + // eslint-disable-next-line @typescript-eslint/no-explicit-any + web3Context: Web3Context, transactionHash: HexString32Bytes, ): Promise => new Promise(resolve => { @@ -327,7 +333,9 @@ const waitForTransactionReceipt = async ( function watchTransactionForConfirmations< PromiEventEventType extends SendTransactionEvents | SendSignedTransactionEvents, >( - web3Context: Web3Context, + // A context can have any subscriptions + // eslint-disable-next-line @typescript-eslint/no-explicit-any + web3Context: Web3Context, transactionPromiEvent: PromiEvent, transactionReceipt: ReceiptInfo, ) { @@ -359,8 +367,9 @@ function watchTransactionForConfirmations< const nextBlock = await getBlock( web3Context, - // TODO - Refactor after input formatting is added to getBlock - (BigInt(transactionReceipt.blockNumber) + BigInt(confirmationNumber)).toString(16), + numberToHex( + BigInt(hexToNumber(transactionReceipt.blockNumber)) + BigInt(confirmationNumber), + ), false, ValidTypes.Number, ); @@ -373,57 +382,68 @@ function watchTransactionForConfirmations< latestBlockHash: nextBlock.hash, }); } - }, web3Context.transactionConfirmationPollingInterval ?? web3Context.transactionPollingInterval); + }, web3Context.transactionReceiptPollingInterval ?? web3Context.transactionPollingInterval); } -export async function sendTransaction( - web3Context: Web3Context, +export function sendTransaction( + // caller can have different subscriptions + web3Context: Web3Context, transaction: Transaction, -) { +): PromiEvent { const formattedTransaction = formatTransaction(transaction, ValidTypes.HexString); - // TODO - Promise returned in function argument where a void return was expected - // eslint-disable-next-line @typescript-eslint/no-misused-promises - const promiEvent = new PromiEvent(async resolve => { - // TODO - Populate potentially missing gas fields - // if ( - // transaction.gasPrice === undefined && - // (transaction.maxPriorityFeePerGas === undefined || - // transaction.maxFeePerGas === undefined) - // ) { - // Determine transaction type and fill in required gas properties - // } - - promiEvent.emit('sending', formattedTransaction); - - // TODO - If an account is available in wallet, sign transaction and call sendRawTransaction - // https://github.com/ChainSafe/web3.js/blob/b32555cfeedde128c657dabbba201102f691f955/packages/web3-core-method/src/index.js#L720 - - const transactionHash = await rpcMethods.sendTransaction( - web3Context.requestManager, - formattedTransaction, - ); + const promiEvent = new PromiEvent(resolve => { + // eslint-disable-next-line @typescript-eslint/no-misused-promises + setImmediate(async () => { + // TODO - Populate potentially missing gas fields + // if ( + // transaction.gasPrice === undefined && + // (transaction.maxPriorityFeePerGas === undefined || + // transaction.maxFeePerGas === undefined) + // ) { + // Determine transaction type and fill in required gas properties + // } + + if (promiEvent.listenerCount('sending') > 0) { + promiEvent.emit('sending', formattedTransaction); + } - promiEvent.emit('sent', formattedTransaction); - promiEvent.emit('transactionHash', transactionHash); + // TODO - If an account is available in wallet, sign transaction and call sendRawTransaction + // https://github.com/ChainSafe/web3.js/blob/b32555cfeedde128c657dabbba201102f691f955/packages/web3-core-method/src/index.js#L720 - let transactionReceipt = await rpcMethods.getTransactionReceipt( - web3Context.requestManager, - transactionHash, - ); + const transactionHash = await rpcMethods.sendTransaction( + web3Context.requestManager, + formattedTransaction, + ); - // Transaction hasn't been included in a block yet - if (transactionReceipt === null) - transactionReceipt = await waitForTransactionReceipt(web3Context, transactionHash); + if (promiEvent.listenerCount('sent') > 0) { + promiEvent.emit('sent', formattedTransaction); + } - promiEvent.emit('receipt', transactionReceipt); - // TODO - Format receipt - resolve(transactionReceipt); + if (promiEvent.listenerCount('transactionHash') > 0) { + promiEvent.emit('transactionHash', transactionHash); + } - watchTransactionForConfirmations( - web3Context, - promiEvent, - transactionReceipt, - ); + let transactionReceipt = await rpcMethods.getTransactionReceipt( + web3Context.requestManager, + transactionHash, + ); + + // Transaction hasn't been included in a block yet + if (transactionReceipt === null) + transactionReceipt = await waitForTransactionReceipt(web3Context, transactionHash); + + promiEvent.emit('receipt', transactionReceipt); + // TODO - Format receipt + resolve(transactionReceipt); + + if (promiEvent.listenerCount('confirmation') > 0) { + watchTransactionForConfirmations( + web3Context, + promiEvent, + transactionReceipt, + ); + } + }); }); return promiEvent; @@ -486,22 +506,30 @@ export const signTransaction = async ( formatTransaction(transaction, ValidTypes.HexString), ); +// TODO Decide what to do with transaction.to +// https://github.com/ChainSafe/web3.js/pull/4525#issuecomment-982330076 export const call = async ( - web3Context: Web3Context, + // A context can have any subscriptions + // eslint-disable-next-line @typescript-eslint/no-explicit-any + web3Context: Web3Context, transaction: TransactionCall, blockNumber: BlockNumberOrTag = web3Context.defaultBlock, ) => { validator.validate(['address'], [transaction.to]); + return rpcMethods.call( web3Context.requestManager, formatTransaction(transaction, ValidTypes.HexString) as TransactionCall, - convertToValidType(blockNumber, ValidTypes.HexString) as HexString, + isBlockTag(blockNumber) + ? blockNumber + : (convertToValidType(blockNumber, ValidTypes.HexString) as HexString), ); }; // TODO Missing param export async function estimateGas( - web3Context: Web3Context, + // The context can have different subscriptions + web3Context: Web3Context, transaction: Partial, blockNumber: BlockNumberOrTag = web3Context.defaultBlock, returnType?: ReturnType, diff --git a/yarn.lock b/yarn.lock index 170a5197f13..772f0b47b7f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3425,10 +3425,10 @@ ethereum-cryptography@^0.2.1: "@noble/secp256k1" "^1.3.3" micro-base "^0.10.0" -ethereumjs-util@^7.0.10, ethereumjs-util@^7.1.4: - version "7.1.4" - resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-7.1.4.tgz#a6885bcdd92045b06f596c7626c3e89ab3312458" - integrity sha512-p6KmuPCX4mZIqsQzXfmSx9Y0l2hqf+VkAiwSisW3UKUFdk8ZkAt+AYaor83z2nSi6CU2zSsXMlD80hAbNEGM0A== +ethereumjs-util@^7.1.3: + version "7.1.3" + resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-7.1.3.tgz#b55d7b64dde3e3e45749e4c41288238edec32d23" + integrity sha512-y+82tEbyASO0K0X1/SRhbJJoAlfcvq8JbrG4a5cjrOks7HS/36efU/0j2flxCPOUM++HFahk33kr/ZxyC4vNuw== dependencies: "@types/bn.js" "^5.1.0" bn.js "^5.1.2" @@ -3436,10 +3436,10 @@ ethereumjs-util@^7.0.10, ethereumjs-util@^7.1.4: ethereum-cryptography "^0.1.3" rlp "^2.2.4" -ethereumjs-util@^7.1.3: - version "7.1.3" - resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-7.1.3.tgz#b55d7b64dde3e3e45749e4c41288238edec32d23" - integrity sha512-y+82tEbyASO0K0X1/SRhbJJoAlfcvq8JbrG4a5cjrOks7HS/36efU/0j2flxCPOUM++HFahk33kr/ZxyC4vNuw== +ethereumjs-util@^7.1.4: + version "7.1.4" + resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-7.1.4.tgz#a6885bcdd92045b06f596c7626c3e89ab3312458" + integrity sha512-p6KmuPCX4mZIqsQzXfmSx9Y0l2hqf+VkAiwSisW3UKUFdk8ZkAt+AYaor83z2nSi6CU2zSsXMlD80hAbNEGM0A== dependencies: "@types/bn.js" "^5.1.0" bn.js "^5.1.2" @@ -7565,13 +7565,6 @@ wcwidth@^1.0.0: dependencies: defaults "^1.0.3" -web3-utils@4.0.0-alpha.0: - version "4.0.0-alpha.0" - resolved "https://registry.yarnpkg.com/web3-utils/-/web3-utils-4.0.0-alpha.0.tgz#ca71c3601c33e3a733d5221ebc4ab57c790f6c58" - integrity sha512-mywnauBZR3Xi7e7RYLUQN9EN5x8jylEz8Qb/fZAJnJtzSEcgXEZ+kuTHIyIJxpDKWoHwlpqnZL4WGsuG+4NiCA== - dependencies: - ethereumjs-util "^7.0.10" - webidl-conversions@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"