viem 2.57.17 → 2.57.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +80 -0
- package/_cjs/account-abstraction/actions/paymaster/getPaymasterData.js +4 -2
- package/_cjs/account-abstraction/actions/paymaster/getPaymasterData.js.map +1 -1
- package/_cjs/account-abstraction/actions/paymaster/getPaymasterStubData.js +6 -2
- package/_cjs/account-abstraction/actions/paymaster/getPaymasterStubData.js.map +1 -1
- package/_cjs/actions/ens/getEnsAddress.js +11 -1
- package/_cjs/actions/ens/getEnsAddress.js.map +1 -1
- package/_cjs/actions/index.js +5 -3
- package/_cjs/actions/index.js.map +1 -1
- package/_cjs/actions/public/call.js +13 -2
- package/_cjs/actions/public/call.js.map +1 -1
- package/_cjs/actions/public/getLogs.js +18 -1
- package/_cjs/actions/public/getLogs.js.map +1 -1
- package/_cjs/actions/public/internal/isRangeError.js +18 -0
- package/_cjs/actions/public/internal/isRangeError.js.map +1 -0
- package/_cjs/actions/public/internal/watchTransport.js +24 -0
- package/_cjs/actions/public/internal/watchTransport.js.map +1 -0
- package/_cjs/actions/public/iterateLogs.js +48 -0
- package/_cjs/actions/public/iterateLogs.js.map +1 -0
- package/_cjs/actions/public/simulateContract.js +4 -4
- package/_cjs/actions/public/simulateContract.js.map +1 -1
- package/_cjs/actions/public/verifyHash.js +72 -39
- package/_cjs/actions/public/verifyHash.js.map +1 -1
- package/_cjs/actions/public/waitForTransactionReceipt.js +18 -1
- package/_cjs/actions/public/waitForTransactionReceipt.js.map +1 -1
- package/_cjs/actions/public/watchBlockHeaders.js +2 -10
- package/_cjs/actions/public/watchBlockHeaders.js.map +1 -1
- package/_cjs/actions/public/watchBlockNumber.js +3 -18
- package/_cjs/actions/public/watchBlockNumber.js.map +1 -1
- package/_cjs/actions/public/watchBlocks.js +3 -18
- package/_cjs/actions/public/watchBlocks.js.map +1 -1
- package/_cjs/actions/public/watchContractEvent.js +5 -33
- package/_cjs/actions/public/watchContractEvent.js.map +1 -1
- package/_cjs/actions/public/watchEvent.js +5 -33
- package/_cjs/actions/public/watchEvent.js.map +1 -1
- package/_cjs/actions/wallet/prepareTransactionRequest.js +16 -3
- package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_cjs/celo/serializers.js +1 -1
- package/_cjs/celo/serializers.js.map +1 -1
- package/_cjs/clients/decorators/public.js +2 -0
- package/_cjs/clients/decorators/public.js.map +1 -1
- package/_cjs/constants/contracts.js +1 -1
- package/_cjs/constants/contracts.js.map +1 -1
- package/_cjs/errors/chain.js +2 -2
- package/_cjs/errors/chain.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/index.js +5 -4
- package/_cjs/index.js.map +1 -1
- package/_cjs/op-stack/actions/buildProveWithdrawal.js +5 -5
- package/_cjs/op-stack/actions/buildProveWithdrawal.js.map +1 -1
- package/_cjs/op-stack/actions/getL2Output.js +13 -9
- package/_cjs/op-stack/actions/getL2Output.js.map +1 -1
- package/_cjs/op-stack/actions/waitToProve.js +1 -0
- package/_cjs/op-stack/actions/waitToProve.js.map +1 -1
- package/_cjs/tempo/Account.js +30 -0
- package/_cjs/tempo/Account.js.map +1 -1
- package/_cjs/tempo/actions/accessKey.js +1 -1
- package/_cjs/tempo/actions/accessKey.js.map +1 -1
- package/_cjs/tempo/actions/accounts.js +5 -5
- package/_cjs/tempo/actions/accounts.js.map +1 -1
- package/_cjs/tempo/actions/earn/deployment.js +1 -1
- package/_cjs/tempo/actions/earn/deployment.js.map +1 -1
- package/_cjs/tempo/actions/earn.js +3 -3
- package/_cjs/tempo/actions/earn.js.map +1 -1
- package/_cjs/tempo/actions/propAmm.js +1 -1
- package/_cjs/tempo/actions/propAmm.js.map +1 -1
- package/_cjs/tempo/actions/token.js +10 -2
- package/_cjs/tempo/actions/token.js.map +1 -1
- package/_cjs/tempo/chainConfig.js +14 -0
- package/_cjs/tempo/chainConfig.js.map +1 -1
- package/_cjs/tempo/internal/preAuthorized.js +214 -0
- package/_cjs/tempo/internal/preAuthorized.js.map +1 -0
- package/_cjs/tempo/internal/relay/feePayer.js +25 -7
- package/_cjs/tempo/internal/relay/feePayer.js.map +1 -1
- package/_cjs/utils/abi/decodeAbiParameters.js +33 -9
- package/_cjs/utils/abi/decodeAbiParameters.js.map +1 -1
- package/_cjs/utils/abi/encodeAbiParameters.js +5 -4
- package/_cjs/utils/abi/encodeAbiParameters.js.map +1 -1
- package/_cjs/utils/abi/encodePacked.js +4 -2
- package/_cjs/utils/abi/encodePacked.js.map +1 -1
- package/_cjs/utils/ccip.js +5 -1
- package/_cjs/utils/ccip.js.map +1 -1
- package/_cjs/utils/chain/getChainContractAddress.js +2 -2
- package/_cjs/utils/chain/getChainContractAddress.js.map +1 -1
- package/_cjs/utils/encoding/toBytes.js +5 -6
- package/_cjs/utils/encoding/toBytes.js.map +1 -1
- package/_cjs/utils/ens/avatar/utils.js +25 -5
- package/_cjs/utils/ens/avatar/utils.js.map +1 -1
- package/_cjs/utils/ens/localBatchGatewayRequest.js +13 -1
- package/_cjs/utils/ens/localBatchGatewayRequest.js.map +1 -1
- package/_cjs/utils/promise/createBatchScheduler.js +1 -1
- package/_cjs/utils/promise/createBatchScheduler.js.map +1 -1
- package/_cjs/utils/siwe/validateSiweMessage.js +5 -0
- package/_cjs/utils/siwe/validateSiweMessage.js.map +1 -1
- package/_cjs/zksync/actions/estimateFee.js +1 -1
- package/_cjs/zksync/actions/estimateFee.js.map +1 -1
- package/_cjs/zksync/actions/estimateGasL1ToL2.js +1 -1
- package/_cjs/zksync/actions/estimateGasL1ToL2.js.map +1 -1
- package/_cjs/zksync/actions/finalizeWithdrawal.js +3 -3
- package/_cjs/zksync/actions/finalizeWithdrawal.js.map +1 -1
- package/_cjs/zksync/actions/sendEip712Transaction.js +10 -2
- package/_cjs/zksync/actions/sendEip712Transaction.js.map +1 -1
- package/_cjs/zksync/actions/signEip712Transaction.js +2 -2
- package/_cjs/zksync/actions/signEip712Transaction.js.map +1 -1
- package/_esm/account-abstraction/actions/paymaster/getPaymasterData.js +4 -2
- package/_esm/account-abstraction/actions/paymaster/getPaymasterData.js.map +1 -1
- package/_esm/account-abstraction/actions/paymaster/getPaymasterStubData.js +6 -2
- package/_esm/account-abstraction/actions/paymaster/getPaymasterStubData.js.map +1 -1
- package/_esm/actions/ens/getEnsAddress.js +12 -1
- package/_esm/actions/ens/getEnsAddress.js.map +1 -1
- package/_esm/actions/index.js +1 -0
- package/_esm/actions/index.js.map +1 -1
- package/_esm/actions/public/call.js +13 -2
- package/_esm/actions/public/call.js.map +1 -1
- package/_esm/actions/public/getLogs.js +18 -1
- package/_esm/actions/public/getLogs.js.map +1 -1
- package/_esm/actions/public/internal/isRangeError.js +19 -0
- package/_esm/actions/public/internal/isRangeError.js.map +1 -0
- package/_esm/actions/public/internal/watchTransport.js +22 -0
- package/_esm/actions/public/internal/watchTransport.js.map +1 -0
- package/_esm/actions/public/iterateLogs.js +84 -0
- package/_esm/actions/public/iterateLogs.js.map +1 -0
- package/_esm/actions/public/simulateContract.js +5 -4
- package/_esm/actions/public/simulateContract.js.map +1 -1
- package/_esm/actions/public/verifyHash.js +77 -40
- package/_esm/actions/public/verifyHash.js.map +1 -1
- package/_esm/actions/public/waitForTransactionReceipt.js +20 -1
- package/_esm/actions/public/waitForTransactionReceipt.js.map +1 -1
- package/_esm/actions/public/watchBlockHeaders.js +2 -10
- package/_esm/actions/public/watchBlockHeaders.js.map +1 -1
- package/_esm/actions/public/watchBlockNumber.js +3 -18
- package/_esm/actions/public/watchBlockNumber.js.map +1 -1
- package/_esm/actions/public/watchBlocks.js +3 -18
- package/_esm/actions/public/watchBlocks.js.map +1 -1
- package/_esm/actions/public/watchContractEvent.js +4 -36
- package/_esm/actions/public/watchContractEvent.js.map +1 -1
- package/_esm/actions/public/watchEvent.js +4 -36
- package/_esm/actions/public/watchEvent.js.map +1 -1
- package/_esm/actions/wallet/prepareTransactionRequest.js +17 -3
- package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_esm/celo/serializers.js +1 -1
- package/_esm/celo/serializers.js.map +1 -1
- package/_esm/clients/decorators/public.js +2 -0
- package/_esm/clients/decorators/public.js.map +1 -1
- package/_esm/constants/contracts.js +1 -1
- package/_esm/constants/contracts.js.map +1 -1
- package/_esm/errors/chain.js +2 -2
- package/_esm/errors/chain.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/index.js +1 -1
- package/_esm/index.js.map +1 -1
- package/_esm/op-stack/actions/buildProveWithdrawal.js +5 -5
- package/_esm/op-stack/actions/buildProveWithdrawal.js.map +1 -1
- package/_esm/op-stack/actions/getL2Output.js +14 -9
- package/_esm/op-stack/actions/getL2Output.js.map +1 -1
- package/_esm/op-stack/actions/waitToProve.js +1 -0
- package/_esm/op-stack/actions/waitToProve.js.map +1 -1
- package/_esm/tempo/Account.js +33 -1
- package/_esm/tempo/Account.js.map +1 -1
- package/_esm/tempo/actions/accessKey.js +1 -1
- package/_esm/tempo/actions/accessKey.js.map +1 -1
- package/_esm/tempo/actions/accounts.js +5 -5
- package/_esm/tempo/actions/accounts.js.map +1 -1
- package/_esm/tempo/actions/earn/deployment.js +1 -1
- package/_esm/tempo/actions/earn/deployment.js.map +1 -1
- package/_esm/tempo/actions/earn.js +3 -3
- package/_esm/tempo/actions/earn.js.map +1 -1
- package/_esm/tempo/actions/propAmm.js +1 -1
- package/_esm/tempo/actions/propAmm.js.map +1 -1
- package/_esm/tempo/actions/token.js +10 -2
- package/_esm/tempo/actions/token.js.map +1 -1
- package/_esm/tempo/chainConfig.js +16 -0
- package/_esm/tempo/chainConfig.js.map +1 -1
- package/_esm/tempo/internal/preAuthorized.js +244 -0
- package/_esm/tempo/internal/preAuthorized.js.map +1 -0
- package/_esm/tempo/internal/relay/feePayer.js +26 -7
- package/_esm/tempo/internal/relay/feePayer.js.map +1 -1
- package/_esm/utils/abi/decodeAbiParameters.js +37 -9
- package/_esm/utils/abi/decodeAbiParameters.js.map +1 -1
- package/_esm/utils/abi/encodeAbiParameters.js +6 -4
- package/_esm/utils/abi/encodeAbiParameters.js.map +1 -1
- package/_esm/utils/abi/encodePacked.js +5 -2
- package/_esm/utils/abi/encodePacked.js.map +1 -1
- package/_esm/utils/ccip.js +8 -3
- package/_esm/utils/ccip.js.map +1 -1
- package/_esm/utils/chain/getChainContractAddress.js +2 -2
- package/_esm/utils/chain/getChainContractAddress.js.map +1 -1
- package/_esm/utils/encoding/toBytes.js +5 -6
- package/_esm/utils/encoding/toBytes.js.map +1 -1
- package/_esm/utils/ens/avatar/utils.js +26 -5
- package/_esm/utils/ens/avatar/utils.js.map +1 -1
- package/_esm/utils/ens/localBatchGatewayRequest.js +17 -1
- package/_esm/utils/ens/localBatchGatewayRequest.js.map +1 -1
- package/_esm/utils/promise/createBatchScheduler.js +2 -1
- package/_esm/utils/promise/createBatchScheduler.js.map +1 -1
- package/_esm/utils/siwe/validateSiweMessage.js +6 -0
- package/_esm/utils/siwe/validateSiweMessage.js.map +1 -1
- package/_esm/zksync/actions/estimateFee.js +1 -1
- package/_esm/zksync/actions/estimateFee.js.map +1 -1
- package/_esm/zksync/actions/estimateGasL1ToL2.js +1 -1
- package/_esm/zksync/actions/estimateGasL1ToL2.js.map +1 -1
- package/_esm/zksync/actions/finalizeWithdrawal.js +3 -3
- package/_esm/zksync/actions/finalizeWithdrawal.js.map +1 -1
- package/_esm/zksync/actions/sendEip712Transaction.js +12 -2
- package/_esm/zksync/actions/sendEip712Transaction.js.map +1 -1
- package/_esm/zksync/actions/signEip712Transaction.js +2 -2
- package/_esm/zksync/actions/signEip712Transaction.js.map +1 -1
- package/_types/account-abstraction/actions/paymaster/getPaymasterData.d.ts.map +1 -1
- package/_types/account-abstraction/actions/paymaster/getPaymasterStubData.d.ts.map +1 -1
- package/_types/actions/ens/getEnsAddress.d.ts +2 -1
- package/_types/actions/ens/getEnsAddress.d.ts.map +1 -1
- package/_types/actions/index.d.ts +1 -0
- package/_types/actions/index.d.ts.map +1 -1
- package/_types/actions/public/call.d.ts.map +1 -1
- package/_types/actions/public/getLogs.d.ts +20 -2
- package/_types/actions/public/getLogs.d.ts.map +1 -1
- package/_types/actions/public/internal/isRangeError.d.ts +3 -0
- package/_types/actions/public/internal/isRangeError.d.ts.map +1 -0
- package/_types/actions/public/internal/watchTransport.d.ts +6 -0
- package/_types/actions/public/internal/watchTransport.d.ts.map +1 -0
- package/_types/actions/public/iterateLogs.d.ts +94 -0
- package/_types/actions/public/iterateLogs.d.ts.map +1 -0
- package/_types/actions/public/simulateContract.d.ts.map +1 -1
- package/_types/actions/public/verifyHash.d.ts +2 -1
- package/_types/actions/public/verifyHash.d.ts.map +1 -1
- package/_types/actions/public/waitForTransactionReceipt.d.ts +7 -2
- package/_types/actions/public/waitForTransactionReceipt.d.ts.map +1 -1
- package/_types/actions/public/watchBlockHeaders.d.ts.map +1 -1
- package/_types/actions/public/watchBlockNumber.d.ts.map +1 -1
- package/_types/actions/public/watchBlocks.d.ts.map +1 -1
- package/_types/actions/public/watchContractEvent.d.ts.map +1 -1
- package/_types/actions/public/watchEvent.d.ts.map +1 -1
- package/_types/actions/wallet/prepareTransactionRequest.d.ts +2 -1
- package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
- package/_types/celo/serializers.d.ts.map +1 -1
- package/_types/clients/decorators/public.d.ts +33 -0
- package/_types/clients/decorators/public.d.ts.map +1 -1
- package/_types/constants/contracts.d.ts +1 -1
- package/_types/constants/contracts.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/index.d.ts +2 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/op-stack/actions/getL2Output.d.ts +6 -0
- package/_types/op-stack/actions/getL2Output.d.ts.map +1 -1
- package/_types/op-stack/actions/waitToProve.d.ts.map +1 -1
- package/_types/tempo/Account.d.ts +5 -1
- package/_types/tempo/Account.d.ts.map +1 -1
- package/_types/tempo/actions/earn/deployment.d.ts.map +1 -1
- package/_types/tempo/actions/propAmm.d.ts.map +1 -1
- package/_types/tempo/actions/token.d.ts.map +1 -1
- package/_types/tempo/chainConfig.d.ts.map +1 -1
- package/_types/tempo/internal/preAuthorized.d.ts +41 -0
- package/_types/tempo/internal/preAuthorized.d.ts.map +1 -0
- package/_types/tempo/internal/relay/feePayer.d.ts.map +1 -1
- package/_types/utils/abi/decodeAbiParameters.d.ts +15 -1
- package/_types/utils/abi/decodeAbiParameters.d.ts.map +1 -1
- package/_types/utils/abi/encodeAbiParameters.d.ts.map +1 -1
- package/_types/utils/ccip.d.ts +4 -3
- package/_types/utils/ccip.d.ts.map +1 -1
- package/_types/utils/encoding/toBytes.d.ts +1 -1
- package/_types/utils/encoding/toBytes.d.ts.map +1 -1
- package/_types/utils/ens/avatar/utils.d.ts +6 -2
- package/_types/utils/ens/avatar/utils.d.ts.map +1 -1
- package/_types/utils/ens/localBatchGatewayRequest.d.ts +6 -1
- package/_types/utils/ens/localBatchGatewayRequest.d.ts.map +1 -1
- package/_types/utils/promise/createBatchScheduler.d.ts.map +1 -1
- package/_types/utils/siwe/validateSiweMessage.d.ts.map +1 -1
- package/_types/zksync/actions/estimateFee.d.ts.map +1 -1
- package/_types/zksync/actions/estimateGasL1ToL2.d.ts.map +1 -1
- package/_types/zksync/actions/finalizeWithdrawal.d.ts.map +1 -1
- package/_types/zksync/actions/sendEip712Transaction.d.ts +1 -1
- package/_types/zksync/actions/sendEip712Transaction.d.ts.map +1 -1
- package/account-abstraction/actions/paymaster/getPaymasterData.ts +23 -16
- package/account-abstraction/actions/paymaster/getPaymasterStubData.ts +27 -16
- package/actions/ens/getEnsAddress.ts +15 -1
- package/actions/index.ts +6 -0
- package/actions/public/call.ts +15 -2
- package/actions/public/getLogs.ts +44 -0
- package/actions/public/internal/isRangeError.ts +18 -0
- package/actions/public/internal/watchTransport.ts +29 -0
- package/actions/public/iterateLogs.ts +209 -0
- package/actions/public/simulateContract.ts +6 -4
- package/actions/public/verifyHash.ts +87 -60
- package/actions/public/waitForTransactionReceipt.ts +31 -1
- package/actions/public/watchBlockHeaders.ts +2 -12
- package/actions/public/watchBlockNumber.ts +6 -24
- package/actions/public/watchBlocks.ts +6 -24
- package/actions/public/watchContractEvent.ts +7 -42
- package/actions/public/watchEvent.ts +7 -42
- package/actions/wallet/prepareTransactionRequest.ts +23 -3
- package/celo/serializers.ts +5 -2
- package/clients/decorators/public.ts +47 -0
- package/constants/contracts.ts +1 -1
- package/errors/chain.ts +2 -2
- package/errors/version.ts +1 -1
- package/index.ts +7 -0
- package/op-stack/actions/buildProveWithdrawal.ts +5 -5
- package/op-stack/actions/getL2Output.ts +24 -11
- package/op-stack/actions/waitToProve.ts +1 -0
- package/package.json +2 -2
- package/tempo/Account.ts +38 -1
- package/tempo/actions/accessKey.ts +1 -1
- package/tempo/actions/accounts.ts +5 -5
- package/tempo/actions/earn/deployment.ts +2 -1
- package/tempo/actions/earn.ts +2 -2
- package/tempo/actions/propAmm.ts +2 -1
- package/tempo/actions/token.ts +10 -2
- package/tempo/chainConfig.ts +20 -0
- package/tempo/internal/preAuthorized.ts +309 -0
- package/tempo/internal/relay/feePayer.ts +33 -11
- package/utils/abi/decodeAbiParameters.ts +60 -9
- package/utils/abi/encodeAbiParameters.ts +6 -4
- package/utils/abi/encodePacked.ts +5 -1
- package/utils/ccip.ts +17 -3
- package/utils/chain/getChainContractAddress.ts +2 -2
- package/utils/encoding/toBytes.ts +4 -6
- package/utils/ens/avatar/utils.ts +38 -4
- package/utils/ens/localBatchGatewayRequest.ts +21 -2
- package/utils/promise/createBatchScheduler.ts +2 -1
- package/utils/siwe/validateSiweMessage.ts +7 -0
- package/zksync/actions/estimateFee.ts +2 -1
- package/zksync/actions/estimateGasL1ToL2.ts +2 -1
- package/zksync/actions/finalizeWithdrawal.ts +4 -3
- package/zksync/actions/sendEip712Transaction.ts +21 -8
- package/zksync/actions/signEip712Transaction.ts +3 -3
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import type { AbiEvent, Address } from 'abitype'
|
|
2
|
+
|
|
3
|
+
import type { Client } from '../../clients/createClient.js'
|
|
4
|
+
import type { Transport } from '../../clients/transports/createTransport.js'
|
|
5
|
+
import { BaseError } from '../../errors/base.js'
|
|
6
|
+
import type { ErrorType } from '../../errors/utils.js'
|
|
7
|
+
import type { BlockTag } from '../../types/block.js'
|
|
8
|
+
import type { Chain } from '../../types/chain.js'
|
|
9
|
+
import type {
|
|
10
|
+
MaybeAbiEventName,
|
|
11
|
+
MaybeExtractEventArgsFromAbi,
|
|
12
|
+
} from '../../types/contract.js'
|
|
13
|
+
import { getAction } from '../../utils/getAction.js'
|
|
14
|
+
import { type GetBlockErrorType, getBlock } from './getBlock.js'
|
|
15
|
+
import {
|
|
16
|
+
type GetLogsErrorType,
|
|
17
|
+
type GetLogsParameters,
|
|
18
|
+
type GetLogsReturnType,
|
|
19
|
+
getLogs,
|
|
20
|
+
} from './getLogs.js'
|
|
21
|
+
import { isRangeError } from './internal/isRangeError.js'
|
|
22
|
+
|
|
23
|
+
export type IterateLogsParameters<
|
|
24
|
+
abiEvent extends AbiEvent | undefined = undefined,
|
|
25
|
+
abiEvents extends
|
|
26
|
+
| readonly AbiEvent[]
|
|
27
|
+
| readonly unknown[]
|
|
28
|
+
| undefined = abiEvent extends AbiEvent ? [abiEvent] : undefined,
|
|
29
|
+
strict extends boolean | undefined = undefined,
|
|
30
|
+
//
|
|
31
|
+
_eventName extends string | undefined = MaybeAbiEventName<abiEvent>,
|
|
32
|
+
> = {
|
|
33
|
+
/** Address or list of addresses from which logs originated */
|
|
34
|
+
address?: Address | Address[] | undefined
|
|
35
|
+
/**
|
|
36
|
+
* Most blocks to request in one `eth_getLogs` call. Must be at least `1n`.
|
|
37
|
+
* @default 1_000n
|
|
38
|
+
*/
|
|
39
|
+
blockRange?: bigint | undefined
|
|
40
|
+
/** First block to include. Inclusive. */
|
|
41
|
+
fromBlock: bigint
|
|
42
|
+
/**
|
|
43
|
+
* Last block to include. Inclusive. A block tag is resolved to a block number once, before the first page.
|
|
44
|
+
* @default 'latest'
|
|
45
|
+
*/
|
|
46
|
+
toBlock?: bigint | Exclude<BlockTag, 'pending'> | undefined
|
|
47
|
+
} & (
|
|
48
|
+
| {
|
|
49
|
+
event: abiEvent
|
|
50
|
+
events?: undefined
|
|
51
|
+
args?: MaybeExtractEventArgsFromAbi<abiEvents, _eventName> | undefined
|
|
52
|
+
/**
|
|
53
|
+
* Whether or not the logs must match the indexed/non-indexed arguments on `event`.
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
56
|
+
strict?: strict | undefined
|
|
57
|
+
}
|
|
58
|
+
| {
|
|
59
|
+
event?: undefined
|
|
60
|
+
events: abiEvents
|
|
61
|
+
args?: undefined
|
|
62
|
+
/**
|
|
63
|
+
* Whether or not the logs must match the indexed/non-indexed arguments on `event`.
|
|
64
|
+
* @default false
|
|
65
|
+
*/
|
|
66
|
+
strict?: strict | undefined
|
|
67
|
+
}
|
|
68
|
+
| {
|
|
69
|
+
event?: undefined
|
|
70
|
+
events?: undefined
|
|
71
|
+
args?: undefined
|
|
72
|
+
strict?: undefined
|
|
73
|
+
}
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
export type IterateLogsReturnType<
|
|
77
|
+
abiEvent extends AbiEvent | undefined = undefined,
|
|
78
|
+
abiEvents extends
|
|
79
|
+
| readonly AbiEvent[]
|
|
80
|
+
| readonly unknown[]
|
|
81
|
+
| undefined = abiEvent extends AbiEvent ? [abiEvent] : undefined,
|
|
82
|
+
strict extends boolean | undefined = undefined,
|
|
83
|
+
> = AsyncGenerator<
|
|
84
|
+
{
|
|
85
|
+
/** Last block of the whole iteration: `toBlock`, or the block number its tag resolved to. */
|
|
86
|
+
endBlock: bigint
|
|
87
|
+
/** First block of the page. */
|
|
88
|
+
fromBlock: bigint
|
|
89
|
+
/** Logs from `fromBlock` to `toBlock`. */
|
|
90
|
+
logs: GetLogsReturnType<abiEvent, abiEvents, strict>
|
|
91
|
+
/** Last block of the page. A resumed iteration starts at `toBlock + 1n`. */
|
|
92
|
+
toBlock: bigint
|
|
93
|
+
},
|
|
94
|
+
void,
|
|
95
|
+
undefined
|
|
96
|
+
>
|
|
97
|
+
|
|
98
|
+
export type IterateLogsErrorType =
|
|
99
|
+
| GetBlockErrorType
|
|
100
|
+
| GetLogsErrorType
|
|
101
|
+
| ErrorType
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Iterates over the event logs in a block range, one page of blocks at a time.
|
|
105
|
+
*
|
|
106
|
+
* - Docs: https://viem.sh/docs/actions/public/iterateLogs
|
|
107
|
+
* - JSON-RPC Methods: [`eth_getLogs`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getlogs)
|
|
108
|
+
*
|
|
109
|
+
* Pages are contiguous and are yielded even when they contain no logs, so a consumer that
|
|
110
|
+
* stores each page's `toBlock` can resume from `toBlock + 1n`. A page is only requested
|
|
111
|
+
* once the consumer asks for it. If a request fails with an error that a smaller block
|
|
112
|
+
* range may avoid (such as an RPC Provider's block range or response size limit), the page
|
|
113
|
+
* is halved and requested again.
|
|
114
|
+
*
|
|
115
|
+
* @param client - Client to use
|
|
116
|
+
* @param parameters - {@link IterateLogsParameters}
|
|
117
|
+
* @returns An async iterator of log pages. {@link IterateLogsReturnType}
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* import { createPublicClient, http, parseAbiItem } from 'viem'
|
|
121
|
+
* import { mainnet } from 'viem/chains'
|
|
122
|
+
* import { iterateLogs } from 'viem/actions'
|
|
123
|
+
*
|
|
124
|
+
* const client = createPublicClient({
|
|
125
|
+
* chain: mainnet,
|
|
126
|
+
* transport: http(),
|
|
127
|
+
* })
|
|
128
|
+
* for await (const page of iterateLogs(client, {
|
|
129
|
+
* event: parseAbiItem('event Transfer(address indexed, address indexed, uint256)'),
|
|
130
|
+
* fromBlock: 16330000n,
|
|
131
|
+
* toBlock: 16340000n,
|
|
132
|
+
* })) {
|
|
133
|
+
* console.log(page.toBlock, page.logs)
|
|
134
|
+
* }
|
|
135
|
+
*/
|
|
136
|
+
export async function* iterateLogs<
|
|
137
|
+
chain extends Chain | undefined,
|
|
138
|
+
const abiEvent extends AbiEvent | undefined = undefined,
|
|
139
|
+
const abiEvents extends
|
|
140
|
+
| readonly AbiEvent[]
|
|
141
|
+
| readonly unknown[]
|
|
142
|
+
| undefined = abiEvent extends AbiEvent ? [abiEvent] : undefined,
|
|
143
|
+
strict extends boolean | undefined = undefined,
|
|
144
|
+
>(
|
|
145
|
+
client: Client<Transport, chain>,
|
|
146
|
+
parameters: IterateLogsParameters<abiEvent, abiEvents, strict>,
|
|
147
|
+
): IterateLogsReturnType<abiEvent, abiEvents, strict> {
|
|
148
|
+
const {
|
|
149
|
+
address,
|
|
150
|
+
args,
|
|
151
|
+
blockRange = 1_000n,
|
|
152
|
+
event,
|
|
153
|
+
events,
|
|
154
|
+
fromBlock,
|
|
155
|
+
strict,
|
|
156
|
+
toBlock = 'latest',
|
|
157
|
+
} = parameters
|
|
158
|
+
|
|
159
|
+
// A range of less than one block never moves past `fromBlock`.
|
|
160
|
+
if (blockRange < 1n)
|
|
161
|
+
throw new BaseError(`\`blockRange\` must be at least 1n.`)
|
|
162
|
+
|
|
163
|
+
// Resolve a block tag once, so the iteration has a fixed end.
|
|
164
|
+
const endBlock =
|
|
165
|
+
typeof toBlock === 'bigint'
|
|
166
|
+
? toBlock
|
|
167
|
+
: (await getAction(client, getBlock, 'getBlock')({ blockTag: toBlock }))
|
|
168
|
+
.number
|
|
169
|
+
|
|
170
|
+
// `size` is the most blocks to request at once. It halves when a request fails
|
|
171
|
+
// and doubles back up to `blockRange` after each page.
|
|
172
|
+
let size = blockRange
|
|
173
|
+
let from = fromBlock
|
|
174
|
+
while (from <= endBlock) {
|
|
175
|
+
const end = from + size - 1n
|
|
176
|
+
const to = end < endBlock ? end : endBlock
|
|
177
|
+
|
|
178
|
+
const logs = await getAction(
|
|
179
|
+
client,
|
|
180
|
+
getLogs,
|
|
181
|
+
'getLogs',
|
|
182
|
+
)({
|
|
183
|
+
address,
|
|
184
|
+
args,
|
|
185
|
+
event,
|
|
186
|
+
events,
|
|
187
|
+
fromBlock: from,
|
|
188
|
+
strict,
|
|
189
|
+
toBlock: to,
|
|
190
|
+
} as GetLogsParameters).catch((error) => {
|
|
191
|
+
// A single block cannot be split, and a smaller range does not
|
|
192
|
+
// help when the RPC Provider is unreachable or rejects the client.
|
|
193
|
+
if (from === to || !isRangeError(error)) throw error
|
|
194
|
+
})
|
|
195
|
+
if (!logs) {
|
|
196
|
+
size = (to - from + 1n) / 2n
|
|
197
|
+
continue
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
yield {
|
|
201
|
+
endBlock,
|
|
202
|
+
fromBlock: from,
|
|
203
|
+
logs: logs as GetLogsReturnType<abiEvent, abiEvents, strict>,
|
|
204
|
+
toBlock: to,
|
|
205
|
+
}
|
|
206
|
+
from = to + 1n
|
|
207
|
+
size = size * 2n < blockRange ? size * 2n : blockRange
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -265,9 +265,10 @@ export async function simulateContract<
|
|
|
265
265
|
...callRequest
|
|
266
266
|
} = parameters as SimulateContractParameters
|
|
267
267
|
|
|
268
|
-
const account =
|
|
269
|
-
|
|
270
|
-
|
|
268
|
+
const account =
|
|
269
|
+
callRequest.account === undefined
|
|
270
|
+
? client.account
|
|
271
|
+
: callRequest.account && parseAccount(callRequest.account)
|
|
271
272
|
const calldata = encodeFunctionData({ abi, args, functionName })
|
|
272
273
|
|
|
273
274
|
try {
|
|
@@ -280,7 +281,8 @@ export async function simulateContract<
|
|
|
280
281
|
data: `${calldata}${dataSuffix ? dataSuffix.replace('0x', '') : ''}`,
|
|
281
282
|
to: address,
|
|
282
283
|
...callRequest,
|
|
283
|
-
|
|
284
|
+
// `call` omits the sender for `null` at runtime, but its parameter type excludes `null`.
|
|
285
|
+
account: account as Account | undefined,
|
|
284
286
|
})
|
|
285
287
|
const result = decodeFunctionResult({
|
|
286
288
|
abi,
|
|
@@ -9,20 +9,19 @@ import {
|
|
|
9
9
|
erc6492SignatureValidatorAbi,
|
|
10
10
|
multicall3Abi,
|
|
11
11
|
} from '../../constants/abis.js'
|
|
12
|
+
import { zeroAddress } from '../../constants/address.js'
|
|
12
13
|
import {
|
|
13
14
|
erc6492SignatureValidatorByteCode,
|
|
14
15
|
multicall3Bytecode,
|
|
15
16
|
} from '../../constants/contracts.js'
|
|
16
|
-
import {
|
|
17
|
-
CallExecutionError,
|
|
18
|
-
ContractFunctionExecutionError,
|
|
19
|
-
} from '../../errors/contract.js'
|
|
17
|
+
import { CallExecutionError } from '../../errors/contract.js'
|
|
20
18
|
import type { InvalidHexBooleanError } from '../../errors/encoding.js'
|
|
21
19
|
import type { ErrorType } from '../../errors/utils.js'
|
|
22
20
|
import type { BlockTag } from '../../types/block.js'
|
|
23
21
|
import type { Chain } from '../../types/chain.js'
|
|
24
22
|
import type { ByteArray, Hash, Hex, Signature } from '../../types/misc.js'
|
|
25
23
|
import type { OneOf } from '../../types/utils.js'
|
|
24
|
+
import { decodeFunctionResult } from '../../utils/abi/decodeFunctionResult.js'
|
|
26
25
|
import {
|
|
27
26
|
type EncodeDeployDataErrorType,
|
|
28
27
|
encodeDeployData,
|
|
@@ -49,7 +48,6 @@ import {
|
|
|
49
48
|
type NumberToHexErrorType,
|
|
50
49
|
numberToHex,
|
|
51
50
|
} from '../../utils/encoding/toHex.js'
|
|
52
|
-
import { getAction } from '../../utils/getAction.js'
|
|
53
51
|
import {
|
|
54
52
|
type RecoverAddressErrorType,
|
|
55
53
|
recoverAddress,
|
|
@@ -60,7 +58,7 @@ import {
|
|
|
60
58
|
} from '../../utils/signature/serializeSignature.js'
|
|
61
59
|
import { type CallErrorType, type CallParameters, call } from './call.js'
|
|
62
60
|
import { type GetCodeErrorType, getCode } from './getCode.js'
|
|
63
|
-
import {
|
|
61
|
+
import type { ReadContractErrorType } from './readContract.js'
|
|
64
62
|
|
|
65
63
|
export type BlockParameters = OneOf<
|
|
66
64
|
| {
|
|
@@ -70,6 +68,7 @@ export type BlockParameters = OneOf<
|
|
|
70
68
|
| {
|
|
71
69
|
/**
|
|
72
70
|
* The block tag to check if the contract was already deployed.
|
|
71
|
+
* Pre-delegated ERC-8010 signatures are verified against `'pending'` when no block is selected.
|
|
73
72
|
* @default 'latest'
|
|
74
73
|
*/
|
|
75
74
|
blockTag?: BlockTag | undefined
|
|
@@ -137,12 +136,26 @@ export async function verifyHash<chain extends Chain | undefined>(
|
|
|
137
136
|
hash,
|
|
138
137
|
erc6492VerifierAddress:
|
|
139
138
|
verifierAddress = parameters.universalSignatureVerifierAddress ??
|
|
140
|
-
|
|
139
|
+
(() => {
|
|
140
|
+
const { blockNumber } = parameters
|
|
141
|
+
const verifier = chain?.contracts?.erc6492Verifier
|
|
142
|
+
// Use the deployless validator for blocks before the verifier was created.
|
|
143
|
+
if (
|
|
144
|
+
blockNumber !== undefined &&
|
|
145
|
+
verifier?.blockCreated &&
|
|
146
|
+
verifier.blockCreated > blockNumber
|
|
147
|
+
)
|
|
148
|
+
return undefined
|
|
149
|
+
return verifier?.address
|
|
150
|
+
})(),
|
|
141
151
|
multicallAddress = parameters.multicallAddress ??
|
|
142
152
|
chain?.contracts?.multicall3?.address,
|
|
143
153
|
mode = 'auto',
|
|
144
154
|
} = parameters
|
|
145
155
|
|
|
156
|
+
// No signature is valid for the zero address.
|
|
157
|
+
if (address === zeroAddress) return false
|
|
158
|
+
|
|
146
159
|
if (chain?.verifyHash) return await chain.verifyHash(client, parameters)
|
|
147
160
|
|
|
148
161
|
const signature = (() => {
|
|
@@ -251,48 +264,51 @@ export async function verifyErc8010(
|
|
|
251
264
|
if (!valid) throw new VerificationError()
|
|
252
265
|
|
|
253
266
|
// Deployless verification.
|
|
254
|
-
const
|
|
255
|
-
client,
|
|
256
|
-
readContract,
|
|
257
|
-
'readContract',
|
|
258
|
-
)({
|
|
267
|
+
const { data: aggregate3Data } = await call({ ...client, ccipRead: false }, {
|
|
259
268
|
...(multicallAddress
|
|
260
|
-
? {
|
|
269
|
+
? { to: multicallAddress }
|
|
261
270
|
: { code: multicall3Bytecode }),
|
|
262
271
|
authorizationList: [authorization],
|
|
263
|
-
abi: multicall3Abi,
|
|
264
272
|
blockHash,
|
|
265
273
|
blockNumber,
|
|
266
|
-
blockTag: 'pending',
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
[
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
274
|
+
blockTag: blockTag ?? 'pending',
|
|
275
|
+
data: encodeFunctionData({
|
|
276
|
+
abi: multicall3Abi,
|
|
277
|
+
functionName: 'aggregate3',
|
|
278
|
+
args: [
|
|
279
|
+
[
|
|
280
|
+
...(initData
|
|
281
|
+
? ([
|
|
282
|
+
{
|
|
283
|
+
allowFailure: true,
|
|
284
|
+
target: to ?? address,
|
|
285
|
+
callData: initData,
|
|
286
|
+
},
|
|
287
|
+
] as const)
|
|
288
|
+
: []),
|
|
289
|
+
{
|
|
290
|
+
allowFailure: true,
|
|
291
|
+
target: address,
|
|
292
|
+
callData: encodeFunctionData({
|
|
293
|
+
abi: erc1271Abi,
|
|
294
|
+
functionName: 'isValidSignature',
|
|
295
|
+
args: [hash, signature],
|
|
296
|
+
}),
|
|
297
|
+
},
|
|
298
|
+
],
|
|
289
299
|
],
|
|
290
|
-
|
|
300
|
+
}),
|
|
301
|
+
requireCanonical,
|
|
302
|
+
} as CallParameters)
|
|
303
|
+
const results = decodeFunctionResult({
|
|
304
|
+
abi: multicall3Abi,
|
|
305
|
+
functionName: 'aggregate3',
|
|
306
|
+
data: aggregate3Data ?? '0x',
|
|
291
307
|
})
|
|
292
308
|
|
|
293
|
-
const
|
|
309
|
+
const result = results[results.length - 1]
|
|
294
310
|
|
|
295
|
-
if (
|
|
311
|
+
if (result?.success && result.returnData.startsWith('0x1626ba7e')) return true
|
|
296
312
|
throw new VerificationError()
|
|
297
313
|
}
|
|
298
314
|
|
|
@@ -344,6 +360,7 @@ async function verifyErc6492(
|
|
|
344
360
|
|
|
345
361
|
const args = verifierAddress
|
|
346
362
|
? ({
|
|
363
|
+
batch: false,
|
|
347
364
|
to: verifierAddress,
|
|
348
365
|
data: encodeFunctionData({
|
|
349
366
|
abi: erc6492SignatureValidatorAbi,
|
|
@@ -361,14 +378,14 @@ async function verifyErc6492(
|
|
|
361
378
|
...rest,
|
|
362
379
|
} as unknown as CallParameters)
|
|
363
380
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
381
|
+
// Verification calls run without CCIP-Read. They use `call` directly
|
|
382
|
+
// because a client's own `call` action keeps its CCIP-Read setting.
|
|
383
|
+
const { data } = await call({ ...client, ccipRead: false }, args).catch(
|
|
384
|
+
(error) => {
|
|
385
|
+
if (error instanceof CallExecutionError) throw new VerificationError()
|
|
386
|
+
throw error
|
|
387
|
+
},
|
|
388
|
+
)
|
|
372
389
|
|
|
373
390
|
if (hexToBool(data ?? '0x0')) return true
|
|
374
391
|
throw new VerificationError()
|
|
@@ -402,25 +419,35 @@ export async function verifyErc1271(
|
|
|
402
419
|
signature,
|
|
403
420
|
} = parameters
|
|
404
421
|
|
|
405
|
-
const
|
|
406
|
-
|
|
407
|
-
readContract,
|
|
408
|
-
'readContract',
|
|
409
|
-
)({
|
|
410
|
-
address,
|
|
411
|
-
abi: erc1271Abi,
|
|
412
|
-
args: [hash, signature],
|
|
422
|
+
const { data } = await call({ ...client, ccipRead: false }, {
|
|
423
|
+
batch: false,
|
|
413
424
|
blockHash,
|
|
414
425
|
blockNumber,
|
|
415
426
|
blockTag,
|
|
416
|
-
|
|
427
|
+
data: encodeFunctionData({
|
|
428
|
+
abi: erc1271Abi,
|
|
429
|
+
functionName: 'isValidSignature',
|
|
430
|
+
args: [hash, signature],
|
|
431
|
+
}),
|
|
417
432
|
requireCanonical,
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
433
|
+
to: address,
|
|
434
|
+
} as CallParameters).catch((error) => {
|
|
435
|
+
if (error instanceof CallExecutionError) throw new VerificationError()
|
|
421
436
|
throw error
|
|
422
437
|
})
|
|
423
438
|
|
|
439
|
+
const result = (() => {
|
|
440
|
+
try {
|
|
441
|
+
return decodeFunctionResult({
|
|
442
|
+
abi: erc1271Abi,
|
|
443
|
+
functionName: 'isValidSignature',
|
|
444
|
+
data: data ?? '0x',
|
|
445
|
+
})
|
|
446
|
+
} catch {
|
|
447
|
+
throw new VerificationError()
|
|
448
|
+
}
|
|
449
|
+
})()
|
|
450
|
+
|
|
424
451
|
if (result.startsWith('0x1626ba7e')) return true
|
|
425
452
|
throw new VerificationError()
|
|
426
453
|
}
|
|
@@ -13,7 +13,11 @@ import {
|
|
|
13
13
|
WaitForTransactionReceiptTimeoutError,
|
|
14
14
|
type WaitForTransactionReceiptTimeoutErrorType,
|
|
15
15
|
} from '../../errors/transaction.js'
|
|
16
|
-
import
|
|
16
|
+
import {
|
|
17
|
+
type AbortErrorType,
|
|
18
|
+
type ErrorType,
|
|
19
|
+
getAbortError,
|
|
20
|
+
} from '../../errors/utils.js'
|
|
17
21
|
import type { Chain } from '../../types/chain.js'
|
|
18
22
|
import type { Hash, Hex } from '../../types/misc.js'
|
|
19
23
|
import type { Transaction } from '../../types/transaction.js'
|
|
@@ -26,6 +30,7 @@ import {
|
|
|
26
30
|
withRetry,
|
|
27
31
|
} from '../../utils/promise/withRetry.js'
|
|
28
32
|
import { stringify } from '../../utils/stringify.js'
|
|
33
|
+
import { uid } from '../../utils/uid.js'
|
|
29
34
|
|
|
30
35
|
import { type GetBlockErrorType, getBlock } from './getBlock.js'
|
|
31
36
|
import {
|
|
@@ -117,6 +122,11 @@ export type WaitForTransactionReceiptParameters<
|
|
|
117
122
|
* @default `({ count }) => ~~(1 << count) * 200` (exponential backoff)
|
|
118
123
|
*/
|
|
119
124
|
retryDelay?: WithRetryParameters['delay'] | undefined
|
|
125
|
+
/**
|
|
126
|
+
* Signal that stops the wait. Aborting rejects with the signal's reason and
|
|
127
|
+
* stops polling and retries. It does not cancel the transaction.
|
|
128
|
+
*/
|
|
129
|
+
signal?: AbortSignal | undefined
|
|
120
130
|
/**
|
|
121
131
|
* Optional timeout (in milliseconds) to wait before stopping polling.
|
|
122
132
|
* @default 180_000
|
|
@@ -125,6 +135,7 @@ export type WaitForTransactionReceiptParameters<
|
|
|
125
135
|
}
|
|
126
136
|
|
|
127
137
|
export type WaitForTransactionReceiptErrorType =
|
|
138
|
+
| AbortErrorType
|
|
128
139
|
| ObserveErrorType
|
|
129
140
|
| GetBlockErrorType
|
|
130
141
|
| GetTransactionErrorType
|
|
@@ -188,9 +199,12 @@ export async function waitForTransactionReceipt<
|
|
|
188
199
|
onReplaced,
|
|
189
200
|
retryCount = 6,
|
|
190
201
|
retryDelay = ({ count }) => ~~(1 << count) * 200, // exponential backoff
|
|
202
|
+
signal,
|
|
191
203
|
timeout = 180_000,
|
|
192
204
|
} = parameters
|
|
193
205
|
|
|
206
|
+
if (signal?.aborted) throw getAbortError(signal)
|
|
207
|
+
|
|
194
208
|
// On chains with their own replacement keys, a sender and nonce do not
|
|
195
209
|
// identify a nonce slot.
|
|
196
210
|
const replacement = client.chain?.transactionReplacement?.getKey
|
|
@@ -221,6 +235,9 @@ export async function waitForTransactionReceipt<
|
|
|
221
235
|
pollingInterval,
|
|
222
236
|
replacement,
|
|
223
237
|
retryCount,
|
|
238
|
+
// A cancellable wait polls on its own, so aborting it cannot stop
|
|
239
|
+
// polling for another caller.
|
|
240
|
+
signal: signal ? uid() : undefined,
|
|
224
241
|
timeout,
|
|
225
242
|
},
|
|
226
243
|
])
|
|
@@ -249,6 +266,14 @@ export async function waitForTransactionReceipt<
|
|
|
249
266
|
}, timeout)
|
|
250
267
|
: undefined
|
|
251
268
|
|
|
269
|
+
const onAbort = () => {
|
|
270
|
+
clearTimeout(timer)
|
|
271
|
+
_unwatch?.()
|
|
272
|
+
_unobserve?.()
|
|
273
|
+
reject(getAbortError(signal))
|
|
274
|
+
}
|
|
275
|
+
signal?.addEventListener('abort', onAbort, { once: true })
|
|
276
|
+
|
|
252
277
|
_unobserve = observe(
|
|
253
278
|
observerId,
|
|
254
279
|
{ onReplaced, resolve, reject },
|
|
@@ -259,6 +284,8 @@ export async function waitForTransactionReceipt<
|
|
|
259
284
|
'getTransactionReceipt',
|
|
260
285
|
)({ hash }).catch(() => undefined)
|
|
261
286
|
|
|
287
|
+
if (signal?.aborted) return
|
|
288
|
+
|
|
262
289
|
if (receipt && confirmations <= 1) {
|
|
263
290
|
clearTimeout(timer)
|
|
264
291
|
emit.resolve(receipt)
|
|
@@ -350,6 +377,7 @@ export async function waitForTransactionReceipt<
|
|
|
350
377
|
{
|
|
351
378
|
delay: retryDelay,
|
|
352
379
|
retryCount,
|
|
380
|
+
signal,
|
|
353
381
|
// A dropped transaction does not reappear, so a known
|
|
354
382
|
// sender and nonce are looked up without the retries.
|
|
355
383
|
shouldRetry: ({ error }) =>
|
|
@@ -498,6 +526,7 @@ export async function waitForTransactionReceipt<
|
|
|
498
526
|
{
|
|
499
527
|
delay: retryDelay,
|
|
500
528
|
retryCount,
|
|
529
|
+
signal,
|
|
501
530
|
shouldRetry: ({ error }) =>
|
|
502
531
|
error instanceof BlockNotFoundError,
|
|
503
532
|
},
|
|
@@ -589,6 +618,7 @@ export async function waitForTransactionReceipt<
|
|
|
589
618
|
// never start polling again. The timer is cleared here as well, since a
|
|
590
619
|
// caller that resolves through another caller's poll never reaches `done`.
|
|
591
620
|
return promise.finally(() => {
|
|
621
|
+
signal?.removeEventListener('abort', onAbort)
|
|
592
622
|
clearTimeout(timer)
|
|
593
623
|
_unobserve?.()
|
|
594
624
|
})
|
|
@@ -8,6 +8,7 @@ import { observe } from '../../utils/observe.js'
|
|
|
8
8
|
import { type StringifyErrorType, stringify } from '../../utils/stringify.js'
|
|
9
9
|
|
|
10
10
|
import type { GetBlockReturnType } from './getBlock.js'
|
|
11
|
+
import { getSubscriptionTransport } from './internal/watchTransport.js'
|
|
11
12
|
|
|
12
13
|
const blockFields = [
|
|
13
14
|
'size',
|
|
@@ -88,18 +89,7 @@ export function watchBlockHeaders<
|
|
|
88
89
|
let unsubscribe = () => (active = false)
|
|
89
90
|
;(async () => {
|
|
90
91
|
try {
|
|
91
|
-
const transport = (
|
|
92
|
-
if (client.transport.type === 'fallback') {
|
|
93
|
-
const transport = client.transport.transports.find(
|
|
94
|
-
(transport: ReturnType<Transport>) =>
|
|
95
|
-
transport.config.type === 'webSocket' ||
|
|
96
|
-
transport.config.type === 'ipc',
|
|
97
|
-
)
|
|
98
|
-
if (!transport) return client.transport
|
|
99
|
-
return transport.value
|
|
100
|
-
}
|
|
101
|
-
return client.transport
|
|
102
|
-
})()
|
|
92
|
+
const transport = getSubscriptionTransport(client)
|
|
103
93
|
|
|
104
94
|
const { unsubscribe: unsubscribe_ } = await transport.subscribe({
|
|
105
95
|
params: ['newHeads'],
|
|
@@ -13,6 +13,10 @@ import {
|
|
|
13
13
|
type GetBlockNumberReturnType,
|
|
14
14
|
getBlockNumber,
|
|
15
15
|
} from './getBlockNumber.js'
|
|
16
|
+
import {
|
|
17
|
+
getSubscriptionTransport,
|
|
18
|
+
shouldPoll,
|
|
19
|
+
} from './internal/watchTransport.js'
|
|
16
20
|
|
|
17
21
|
export type OnBlockNumberParameter = GetBlockNumberReturnType
|
|
18
22
|
export type OnBlockNumberFn = (
|
|
@@ -97,18 +101,7 @@ export function watchBlockNumber<
|
|
|
97
101
|
): WatchBlockNumberReturnType {
|
|
98
102
|
const enablePolling = (() => {
|
|
99
103
|
if (typeof poll_ !== 'undefined') return poll_
|
|
100
|
-
|
|
101
|
-
client.transport.type === 'webSocket' ||
|
|
102
|
-
client.transport.type === 'ipc'
|
|
103
|
-
)
|
|
104
|
-
return false
|
|
105
|
-
if (
|
|
106
|
-
client.transport.type === 'fallback' &&
|
|
107
|
-
(client.transport.transports[0].config.type === 'webSocket' ||
|
|
108
|
-
client.transport.transports[0].config.type === 'ipc')
|
|
109
|
-
)
|
|
110
|
-
return false
|
|
111
|
-
return true
|
|
104
|
+
return shouldPoll(client)
|
|
112
105
|
})()
|
|
113
106
|
// Polling less than twice per block skips blocks, so emit the missed
|
|
114
107
|
// ones unless told otherwise.
|
|
@@ -186,18 +179,7 @@ export function watchBlockNumber<
|
|
|
186
179
|
let unsubscribe = () => (active = false)
|
|
187
180
|
;(async () => {
|
|
188
181
|
try {
|
|
189
|
-
const transport = (
|
|
190
|
-
if (client.transport.type === 'fallback') {
|
|
191
|
-
const transport = client.transport.transports.find(
|
|
192
|
-
(transport: ReturnType<Transport>) =>
|
|
193
|
-
transport.config.type === 'webSocket' ||
|
|
194
|
-
transport.config.type === 'ipc',
|
|
195
|
-
)
|
|
196
|
-
if (!transport) return client.transport
|
|
197
|
-
return transport.value
|
|
198
|
-
}
|
|
199
|
-
return client.transport
|
|
200
|
-
})()
|
|
182
|
+
const transport = getSubscriptionTransport(client)
|
|
201
183
|
|
|
202
184
|
const { unsubscribe: unsubscribe_ } = await transport.subscribe({
|
|
203
185
|
params: ['newHeads'],
|