viem 1.4.1 → 1.5.0
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/README.md +6 -0
- package/dist/cjs/accounts/index.js +1 -1
- package/dist/cjs/accounts/index.js.map +1 -1
- package/dist/cjs/accounts/utils/signMessage.js +1 -1
- package/dist/cjs/accounts/utils/signMessage.js.map +1 -1
- package/dist/cjs/accounts/utils/signTypedData.js +1 -1
- package/dist/cjs/accounts/utils/signTypedData.js.map +1 -1
- package/dist/cjs/actions/index.js.map +1 -1
- package/dist/cjs/actions/public/createContractEventFilter.js.map +1 -1
- package/dist/cjs/actions/public/createEventFilter.js +16 -8
- package/dist/cjs/actions/public/createEventFilter.js.map +1 -1
- package/dist/cjs/actions/public/getBlock.js +3 -1
- package/dist/cjs/actions/public/getBlock.js.map +1 -1
- package/dist/cjs/actions/public/getBlockNumber.js +2 -2
- package/dist/cjs/actions/public/getBlockNumber.js.map +1 -1
- package/dist/cjs/actions/public/getFilterChanges.js.map +1 -1
- package/dist/cjs/actions/public/getFilterLogs.js +1 -1
- package/dist/cjs/actions/public/getFilterLogs.js.map +1 -1
- package/dist/cjs/actions/public/getLogs.js +16 -10
- package/dist/cjs/actions/public/getLogs.js.map +1 -1
- package/dist/cjs/actions/public/getTransaction.js +2 -1
- package/dist/cjs/actions/public/getTransaction.js.map +1 -1
- package/dist/cjs/actions/public/watchBlockNumber.js +1 -1
- package/dist/cjs/actions/public/watchBlockNumber.js.map +1 -1
- package/dist/cjs/actions/public/watchBlocks.js +2 -1
- package/dist/cjs/actions/public/watchBlocks.js.map +1 -1
- package/dist/cjs/actions/public/watchContractEvent.js.map +1 -1
- package/dist/cjs/actions/public/watchEvent.js +4 -2
- package/dist/cjs/actions/public/watchEvent.js.map +1 -1
- package/dist/cjs/clients/createClient.js +2 -1
- package/dist/cjs/clients/createClient.js.map +1 -1
- package/dist/cjs/clients/createPublicClient.js.map +1 -1
- package/dist/cjs/clients/createTestClient.js.map +1 -1
- package/dist/cjs/clients/createWalletClient.js.map +1 -1
- package/dist/cjs/clients/decorators/public.js.map +1 -1
- package/dist/cjs/constants/number.js +101 -0
- package/dist/cjs/constants/number.js.map +1 -0
- package/dist/cjs/contract.js.map +1 -1
- package/dist/cjs/errors/abi.js +8 -1
- package/dist/cjs/errors/abi.js.map +1 -1
- package/dist/cjs/errors/contract.js +56 -32
- package/dist/cjs/errors/contract.js.map +1 -1
- package/dist/cjs/errors/version.js +1 -1
- package/dist/cjs/index.js +110 -7
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/public.js.map +1 -1
- package/dist/cjs/utils/formatters/block.js.map +1 -1
- package/dist/cjs/utils/formatters/formatter.js +1 -0
- package/dist/cjs/utils/formatters/formatter.js.map +1 -1
- package/dist/cjs/utils/formatters/transaction.js.map +1 -1
- package/dist/cjs/utils/promise/withCache.js +3 -3
- package/dist/cjs/utils/promise/withCache.js.map +1 -1
- package/dist/cjs/utils/signature/hexToSignature.js +12 -0
- package/dist/cjs/utils/signature/hexToSignature.js.map +1 -0
- package/dist/cjs/utils/signature/signatureToHex.js.map +1 -0
- package/dist/esm/accounts/index.js +1 -1
- package/dist/esm/accounts/index.js.map +1 -1
- package/dist/esm/accounts/utils/signMessage.js +1 -1
- package/dist/esm/accounts/utils/signMessage.js.map +1 -1
- package/dist/esm/accounts/utils/signTypedData.js +1 -1
- package/dist/esm/accounts/utils/signTypedData.js.map +1 -1
- package/dist/esm/actions/index.js.map +1 -1
- package/dist/esm/actions/public/createContractEventFilter.js.map +1 -1
- package/dist/esm/actions/public/createEventFilter.js +16 -8
- package/dist/esm/actions/public/createEventFilter.js.map +1 -1
- package/dist/esm/actions/public/getBlock.js +3 -1
- package/dist/esm/actions/public/getBlock.js.map +1 -1
- package/dist/esm/actions/public/getBlockNumber.js +2 -2
- package/dist/esm/actions/public/getBlockNumber.js.map +1 -1
- package/dist/esm/actions/public/getFilterChanges.js.map +1 -1
- package/dist/esm/actions/public/getFilterLogs.js +1 -1
- package/dist/esm/actions/public/getFilterLogs.js.map +1 -1
- package/dist/esm/actions/public/getLogs.js +16 -10
- package/dist/esm/actions/public/getLogs.js.map +1 -1
- package/dist/esm/actions/public/getTransaction.js +2 -1
- package/dist/esm/actions/public/getTransaction.js.map +1 -1
- package/dist/esm/actions/public/watchBlockNumber.js +1 -1
- package/dist/esm/actions/public/watchBlockNumber.js.map +1 -1
- package/dist/esm/actions/public/watchBlocks.js +2 -1
- package/dist/esm/actions/public/watchBlocks.js.map +1 -1
- package/dist/esm/actions/public/watchContractEvent.js.map +1 -1
- package/dist/esm/actions/public/watchEvent.js +4 -2
- package/dist/esm/actions/public/watchEvent.js.map +1 -1
- package/dist/esm/clients/createClient.js +2 -1
- package/dist/esm/clients/createClient.js.map +1 -1
- package/dist/esm/clients/createPublicClient.js.map +1 -1
- package/dist/esm/clients/createTestClient.js.map +1 -1
- package/dist/esm/clients/createWalletClient.js.map +1 -1
- package/dist/esm/clients/decorators/public.js.map +1 -1
- package/dist/esm/constants/number.js +97 -0
- package/dist/esm/constants/number.js.map +1 -0
- package/dist/esm/contract.js.map +1 -1
- package/dist/esm/errors/abi.js +8 -1
- package/dist/esm/errors/abi.js.map +1 -1
- package/dist/esm/errors/contract.js +56 -32
- package/dist/esm/errors/contract.js.map +1 -1
- package/dist/esm/errors/version.js +1 -1
- package/dist/esm/index.js +4 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/public.js.map +1 -1
- package/dist/esm/utils/formatters/block.js.map +1 -1
- package/dist/esm/utils/formatters/formatter.js +1 -0
- package/dist/esm/utils/formatters/formatter.js.map +1 -1
- package/dist/esm/utils/formatters/transaction.js.map +1 -1
- package/dist/esm/utils/promise/withCache.js +3 -3
- package/dist/esm/utils/promise/withCache.js.map +1 -1
- package/dist/esm/utils/signature/hexToSignature.js +18 -0
- package/dist/esm/utils/signature/hexToSignature.js.map +1 -0
- package/dist/esm/utils/signature/signatureToHex.js +21 -0
- package/dist/esm/utils/signature/signatureToHex.js.map +1 -0
- package/dist/types/accounts/index.d.ts +1 -1
- package/dist/types/accounts/index.d.ts.map +1 -1
- package/dist/types/actions/index.d.ts +5 -1
- package/dist/types/actions/index.d.ts.map +1 -1
- package/dist/types/actions/public/createContractEventFilter.d.ts +5 -5
- package/dist/types/actions/public/createContractEventFilter.d.ts.map +1 -1
- package/dist/types/actions/public/createEventFilter.d.ts +20 -7
- package/dist/types/actions/public/createEventFilter.d.ts.map +1 -1
- package/dist/types/actions/public/getBlock.d.ts +5 -5
- package/dist/types/actions/public/getBlock.d.ts.map +1 -1
- package/dist/types/actions/public/getBlockNumber.d.ts +4 -2
- package/dist/types/actions/public/getBlockNumber.d.ts.map +1 -1
- package/dist/types/actions/public/getFilterChanges.d.ts +5 -8
- package/dist/types/actions/public/getFilterChanges.d.ts.map +1 -1
- package/dist/types/actions/public/getFilterLogs.d.ts +5 -4
- package/dist/types/actions/public/getFilterLogs.d.ts.map +1 -1
- package/dist/types/actions/public/getLogs.d.ts +17 -6
- package/dist/types/actions/public/getLogs.d.ts.map +1 -1
- package/dist/types/actions/public/getTransaction.d.ts +4 -4
- package/dist/types/actions/public/getTransaction.d.ts.map +1 -1
- package/dist/types/actions/public/watchBlocks.d.ts +10 -10
- package/dist/types/actions/public/watchBlocks.d.ts.map +1 -1
- package/dist/types/actions/public/watchContractEvent.d.ts +3 -3
- package/dist/types/actions/public/watchContractEvent.d.ts.map +1 -1
- package/dist/types/actions/public/watchEvent.d.ts +19 -8
- package/dist/types/actions/public/watchEvent.d.ts.map +1 -1
- package/dist/types/chains/formatters/celo.d.ts +4 -0
- package/dist/types/chains/formatters/celo.d.ts.map +1 -1
- package/dist/types/chains/formatters/optimism.d.ts +5 -3
- package/dist/types/chains/formatters/optimism.d.ts.map +1 -1
- package/dist/types/chains/index.d.ts +44 -12
- package/dist/types/chains/index.d.ts.map +1 -1
- package/dist/types/clients/createClient.d.ts +7 -0
- package/dist/types/clients/createClient.d.ts.map +1 -1
- package/dist/types/clients/createPublicClient.d.ts +1 -1
- package/dist/types/clients/createPublicClient.d.ts.map +1 -1
- package/dist/types/clients/createTestClient.d.ts +1 -1
- package/dist/types/clients/createTestClient.d.ts.map +1 -1
- package/dist/types/clients/createWalletClient.d.ts +1 -1
- package/dist/types/clients/createWalletClient.d.ts.map +1 -1
- package/dist/types/clients/decorators/public.d.ts +10 -9
- package/dist/types/clients/decorators/public.d.ts.map +1 -1
- package/dist/types/constants/number.d.ts +97 -0
- package/dist/types/constants/number.d.ts.map +1 -0
- package/dist/types/contract.d.ts +5 -1
- package/dist/types/contract.d.ts.map +1 -1
- package/dist/types/errors/abi.d.ts +1 -0
- package/dist/types/errors/abi.d.ts.map +1 -1
- package/dist/types/errors/contract.d.ts +1 -0
- package/dist/types/errors/contract.d.ts.map +1 -1
- package/dist/types/errors/version.d.ts +1 -1
- package/dist/types/index.d.ts +10 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/public.d.ts +5 -1
- package/dist/types/public.d.ts.map +1 -1
- package/dist/types/types/block.d.ts +7 -7
- package/dist/types/types/block.d.ts.map +1 -1
- package/dist/types/types/contract.d.ts +1 -1
- package/dist/types/types/contract.d.ts.map +1 -1
- package/dist/types/types/filter.d.ts +7 -3
- package/dist/types/types/filter.d.ts.map +1 -1
- package/dist/types/types/formatter.d.ts +3 -0
- package/dist/types/types/formatter.d.ts.map +1 -1
- package/dist/types/types/log.d.ts +8 -8
- package/dist/types/types/log.d.ts.map +1 -1
- package/dist/types/types/misc.d.ts.map +1 -1
- package/dist/types/types/rpc.d.ts +3 -3
- package/dist/types/types/rpc.d.ts.map +1 -1
- package/dist/types/types/transaction.d.ts +8 -8
- package/dist/types/types/transaction.d.ts.map +1 -1
- package/dist/types/utils/formatters/block.d.ts +13 -3
- package/dist/types/utils/formatters/block.d.ts.map +1 -1
- package/dist/types/utils/formatters/formatter.d.ts +1 -0
- package/dist/types/utils/formatters/formatter.d.ts.map +1 -1
- package/dist/types/utils/formatters/transaction.d.ts +10 -3
- package/dist/types/utils/formatters/transaction.d.ts.map +1 -1
- package/dist/types/utils/formatters/transactionReceipt.d.ts +1 -0
- package/dist/types/utils/formatters/transactionReceipt.d.ts.map +1 -1
- package/dist/types/utils/formatters/transactionRequest.d.ts +1 -0
- package/dist/types/utils/formatters/transactionRequest.d.ts.map +1 -1
- package/dist/types/utils/promise/withCache.d.ts +3 -3
- package/dist/types/utils/promise/withCache.d.ts.map +1 -1
- package/dist/types/utils/signature/hexToSignature.d.ts +13 -0
- package/dist/types/utils/signature/hexToSignature.d.ts.map +1 -0
- package/dist/types/utils/signature/signatureToHex.d.ts +17 -0
- package/dist/types/utils/signature/signatureToHex.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/accounts/index.ts +1 -1
- package/src/accounts/utils/signMessage.ts +1 -1
- package/src/accounts/utils/signTypedData.ts +1 -1
- package/src/actions/index.ts +6 -2
- package/src/actions/public/createContractEventFilter.ts +30 -7
- package/src/actions/public/createEventFilter.ts +78 -24
- package/src/actions/public/getBlock.ts +18 -8
- package/src/actions/public/getBlockNumber.ts +5 -3
- package/src/actions/public/getFilterChanges.ts +46 -10
- package/src/actions/public/getFilterLogs.ts +26 -10
- package/src/actions/public/getLogs.ts +73 -18
- package/src/actions/public/getTransaction.ts +15 -8
- package/src/actions/public/watchBlockNumber.ts +1 -1
- package/src/actions/public/watchBlocks.ts +37 -18
- package/src/actions/public/watchContractEvent.ts +9 -9
- package/src/actions/public/watchEvent.ts +52 -19
- package/src/clients/createClient.ts +9 -0
- package/src/clients/createPublicClient.ts +7 -1
- package/src/clients/createTestClient.ts +7 -1
- package/src/clients/createWalletClient.ts +7 -1
- package/src/clients/decorators/public.ts +114 -25
- package/src/constants/number.ts +98 -0
- package/src/contract.ts +6 -2
- package/src/errors/abi.ts +5 -1
- package/src/errors/contract.ts +52 -31
- package/src/errors/version.ts +1 -1
- package/src/index.ts +108 -3
- package/src/public.ts +6 -2
- package/src/types/block.ts +25 -10
- package/src/types/contract.ts +7 -3
- package/src/types/filter.ts +32 -26
- package/src/types/formatter.ts +9 -0
- package/src/types/log.ts +13 -8
- package/src/types/misc.ts +3 -0
- package/src/types/rpc.ts +20 -6
- package/src/types/transaction.ts +22 -11
- package/src/utils/formatters/block.ts +31 -4
- package/src/utils/formatters/formatter.ts +1 -0
- package/src/utils/formatters/transaction.ts +25 -2
- package/src/utils/promise/withCache.ts +5 -5
- package/src/utils/signature/hexToSignature.ts +20 -0
- package/src/utils/signature/signatureToHex.ts +26 -0
- package/dist/cjs/accounts/utils/signatureToHex.js.map +0 -1
- package/dist/esm/accounts/utils/signatureToHex.js +0 -7
- package/dist/esm/accounts/utils/signatureToHex.js.map +0 -1
- package/dist/types/accounts/utils/signatureToHex.d.ts +0 -3
- package/dist/types/accounts/utils/signatureToHex.d.ts.map +0 -1
- package/src/accounts/utils/signatureToHex.ts +0 -12
- /package/dist/cjs/{accounts/utils → utils/signature}/signatureToHex.js +0 -0
@@ -11,7 +11,7 @@ import {
|
|
11
11
|
formatTransaction,
|
12
12
|
} from '../../utils/formatters/transaction.js'
|
13
13
|
|
14
|
-
export type GetTransactionParameters =
|
14
|
+
export type GetTransactionParameters<TBlockTag extends BlockTag = 'latest'> =
|
15
15
|
| {
|
16
16
|
/** The block hash */
|
17
17
|
blockHash: Hash
|
@@ -34,7 +34,7 @@ export type GetTransactionParameters =
|
|
34
34
|
blockHash?: never
|
35
35
|
blockNumber?: never
|
36
36
|
/** The block tag. */
|
37
|
-
blockTag: BlockTag
|
37
|
+
blockTag: TBlockTag | BlockTag
|
38
38
|
hash?: never
|
39
39
|
/** The index of the transaction on the block. */
|
40
40
|
index: number
|
@@ -48,8 +48,10 @@ export type GetTransactionParameters =
|
|
48
48
|
index?: number
|
49
49
|
}
|
50
50
|
|
51
|
-
export type GetTransactionReturnType<
|
52
|
-
|
51
|
+
export type GetTransactionReturnType<
|
52
|
+
TChain extends Chain | undefined = Chain,
|
53
|
+
TBlockTag extends BlockTag = 'latest',
|
54
|
+
> = FormattedTransaction<TChain, TBlockTag>
|
53
55
|
|
54
56
|
/**
|
55
57
|
* Returns information about a [Transaction](https://viem.sh/docs/glossary/terms.html#transaction) given a hash or block identifier.
|
@@ -75,16 +77,21 @@ export type GetTransactionReturnType<TChain extends Chain | undefined = Chain> =
|
|
75
77
|
* hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
|
76
78
|
* })
|
77
79
|
*/
|
78
|
-
export async function getTransaction<
|
80
|
+
export async function getTransaction<
|
81
|
+
TChain extends Chain | undefined,
|
82
|
+
TBlockTag extends BlockTag = 'latest',
|
83
|
+
>(
|
79
84
|
client: Client<Transport, TChain>,
|
80
85
|
{
|
81
86
|
blockHash,
|
82
87
|
blockNumber,
|
83
|
-
blockTag
|
88
|
+
blockTag: blockTag_,
|
84
89
|
hash,
|
85
90
|
index,
|
86
|
-
}: GetTransactionParameters
|
87
|
-
): Promise<GetTransactionReturnType<TChain>> {
|
91
|
+
}: GetTransactionParameters<TBlockTag>,
|
92
|
+
): Promise<GetTransactionReturnType<TChain, TBlockTag>> {
|
93
|
+
const blockTag = blockTag_ || 'latest'
|
94
|
+
|
88
95
|
const blockNumberHex =
|
89
96
|
blockNumber !== undefined ? numberToHex(blockNumber) : undefined
|
90
97
|
|
@@ -105,7 +105,7 @@ export function watchBlockNumber<
|
|
105
105
|
poll(
|
106
106
|
async () => {
|
107
107
|
try {
|
108
|
-
const blockNumber = await getBlockNumber(client, {
|
108
|
+
const blockNumber = await getBlockNumber(client, { cacheTime: 0 })
|
109
109
|
|
110
110
|
if (prevBlockNumber) {
|
111
111
|
// If the current block number is the same as the previous,
|
@@ -10,23 +10,35 @@ import { stringify } from '../../utils/stringify.js'
|
|
10
10
|
|
11
11
|
import { type GetBlockReturnType, getBlock } from './getBlock.js'
|
12
12
|
|
13
|
-
export type OnBlockParameter<
|
14
|
-
|
13
|
+
export type OnBlockParameter<
|
14
|
+
TChain extends Chain | undefined = Chain,
|
15
|
+
TIncludeTransactions extends boolean = false,
|
16
|
+
TBlockTag extends BlockTag = 'latest',
|
17
|
+
> = GetBlockReturnType<TChain, TIncludeTransactions, TBlockTag>
|
15
18
|
|
16
|
-
export type OnBlock<
|
17
|
-
|
18
|
-
|
19
|
+
export type OnBlock<
|
20
|
+
TChain extends Chain | undefined = Chain,
|
21
|
+
TIncludeTransactions extends boolean = false,
|
22
|
+
TBlockTag extends BlockTag = 'latest',
|
23
|
+
> = (
|
24
|
+
block: OnBlockParameter<TChain, TIncludeTransactions, TBlockTag>,
|
25
|
+
prevBlock:
|
26
|
+
| OnBlockParameter<TChain, TIncludeTransactions, TBlockTag>
|
27
|
+
| undefined,
|
19
28
|
) => void
|
20
29
|
|
21
|
-
type PollOptions
|
30
|
+
type PollOptions<
|
31
|
+
TIncludeTransactions extends boolean = false,
|
32
|
+
TBlockTag extends BlockTag = 'latest',
|
33
|
+
> = {
|
22
34
|
/** The block tag. Defaults to "latest". */
|
23
|
-
blockTag?: BlockTag
|
35
|
+
blockTag?: TBlockTag | BlockTag
|
24
36
|
/** Whether or not to emit the missed blocks to the callback. */
|
25
37
|
emitMissed?: boolean
|
26
38
|
/** Whether or not to emit the block to the callback when the subscription opens. */
|
27
39
|
emitOnBegin?: boolean
|
28
40
|
/** Whether or not to include transaction data in the response. */
|
29
|
-
includeTransactions?:
|
41
|
+
includeTransactions?: TIncludeTransactions
|
30
42
|
/** Polling frequency (in ms). Defaults to the client's pollingInterval config. */
|
31
43
|
pollingInterval?: number
|
32
44
|
}
|
@@ -34,9 +46,11 @@ type PollOptions = {
|
|
34
46
|
export type WatchBlocksParameters<
|
35
47
|
TTransport extends Transport = Transport,
|
36
48
|
TChain extends Chain | undefined = Chain,
|
49
|
+
TIncludeTransactions extends boolean = false,
|
50
|
+
TBlockTag extends BlockTag = 'latest',
|
37
51
|
> = {
|
38
52
|
/** The callback to call when a new block is received. */
|
39
|
-
onBlock: OnBlock<TChain>
|
53
|
+
onBlock: OnBlock<TChain, TIncludeTransactions, TBlockTag>
|
40
54
|
/** The callback to call when an error occurred when trying to get for a new block. */
|
41
55
|
onError?: (error: Error) => void
|
42
56
|
} & (GetTransportConfig<TTransport>['type'] extends 'webSocket'
|
@@ -50,8 +64,8 @@ export type WatchBlocksParameters<
|
|
50
64
|
poll?: false
|
51
65
|
pollingInterval?: never
|
52
66
|
}
|
53
|
-
| (PollOptions & { poll?: true })
|
54
|
-
: PollOptions & { poll?: true })
|
67
|
+
| (PollOptions<TIncludeTransactions, TBlockTag> & { poll?: true })
|
68
|
+
: PollOptions<TIncludeTransactions, TBlockTag> & { poll?: true })
|
55
69
|
|
56
70
|
export type WatchBlocksReturnType = () => void
|
57
71
|
|
@@ -83,6 +97,8 @@ export type WatchBlocksReturnType = () => void
|
|
83
97
|
export function watchBlocks<
|
84
98
|
TTransport extends Transport,
|
85
99
|
TChain extends Chain | undefined,
|
100
|
+
TIncludeTransactions extends boolean = false,
|
101
|
+
TBlockTag extends BlockTag = 'latest',
|
86
102
|
>(
|
87
103
|
client: Client<TTransport, TChain>,
|
88
104
|
{
|
@@ -91,15 +107,18 @@ export function watchBlocks<
|
|
91
107
|
emitOnBegin = false,
|
92
108
|
onBlock,
|
93
109
|
onError,
|
94
|
-
includeTransactions
|
110
|
+
includeTransactions: includeTransactions_,
|
95
111
|
poll: poll_,
|
96
112
|
pollingInterval = client.pollingInterval,
|
97
|
-
}: WatchBlocksParameters<TTransport, TChain>,
|
113
|
+
}: WatchBlocksParameters<TTransport, TChain, TIncludeTransactions, TBlockTag>,
|
98
114
|
): WatchBlocksReturnType {
|
99
115
|
const enablePolling =
|
100
116
|
typeof poll_ !== 'undefined' ? poll_ : client.transport.type !== 'webSocket'
|
117
|
+
const includeTransactions = includeTransactions_ ?? false
|
101
118
|
|
102
|
-
let prevBlock:
|
119
|
+
let prevBlock:
|
120
|
+
| GetBlockReturnType<TChain, false | TIncludeTransactions, 'latest'>
|
121
|
+
| undefined
|
103
122
|
|
104
123
|
const pollBlocks = () => {
|
105
124
|
const observerId = stringify([
|
@@ -132,7 +151,7 @@ export function watchBlocks<
|
|
132
151
|
blockNumber: i,
|
133
152
|
includeTransactions,
|
134
153
|
})
|
135
|
-
emit.onBlock(block, prevBlock)
|
154
|
+
emit.onBlock(block as any, prevBlock as any)
|
136
155
|
prevBlock = block
|
137
156
|
}
|
138
157
|
}
|
@@ -147,8 +166,8 @@ export function watchBlocks<
|
|
147
166
|
// We don't want to emit blocks in the past.
|
148
167
|
(block.number && block.number > prevBlock.number)
|
149
168
|
) {
|
150
|
-
emit.onBlock(block, prevBlock)
|
151
|
-
prevBlock = block
|
169
|
+
emit.onBlock(block as any, prevBlock as any)
|
170
|
+
prevBlock = block as any
|
152
171
|
}
|
153
172
|
} catch (err) {
|
154
173
|
emit.onError?.(err as Error)
|
@@ -174,7 +193,7 @@ export function watchBlocks<
|
|
174
193
|
const format =
|
175
194
|
client.chain?.formatters?.block?.format || formatBlock
|
176
195
|
const block = format(data.result)
|
177
|
-
onBlock(block, prevBlock)
|
196
|
+
onBlock(block, prevBlock as any)
|
178
197
|
prevBlock = block
|
179
198
|
},
|
180
199
|
onError(error: Error) {
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { Abi, Address, ExtractAbiEvent, Narrow } from 'abitype'
|
1
|
+
import type { Abi, AbiEvent, Address, ExtractAbiEvent, Narrow } from 'abitype'
|
2
2
|
|
3
3
|
import type { Client } from '../../clients/createClient.js'
|
4
4
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
@@ -20,21 +20,21 @@ import {
|
|
20
20
|
} from './createContractEventFilter.js'
|
21
21
|
import { getBlockNumber } from './getBlockNumber.js'
|
22
22
|
import { getFilterChanges } from './getFilterChanges.js'
|
23
|
-
import {
|
23
|
+
import { getLogs } from './getLogs.js'
|
24
24
|
import { uninstallFilter } from './uninstallFilter.js'
|
25
25
|
|
26
|
-
export type
|
26
|
+
export type WatchContractEventOnLogsParameter<
|
27
27
|
TAbi extends Abi | readonly unknown[] = readonly unknown[],
|
28
28
|
TEventName extends string = string,
|
29
29
|
TStrict extends boolean | undefined = undefined,
|
30
30
|
> = TAbi extends Abi
|
31
|
-
? Log<bigint, number, ExtractAbiEvent<TAbi, TEventName>, TStrict>[]
|
31
|
+
? Log<bigint, number, false, ExtractAbiEvent<TAbi, TEventName>, TStrict>[]
|
32
32
|
: Log[]
|
33
|
-
export type
|
33
|
+
export type WatchContractEventOnLogsFn<
|
34
34
|
TAbi extends Abi | readonly unknown[] = readonly unknown[],
|
35
35
|
TEventName extends string = string,
|
36
36
|
TStrict extends boolean | undefined = undefined,
|
37
|
-
> = (logs:
|
37
|
+
> = (logs: WatchContractEventOnLogsParameter<TAbi, TEventName, TStrict>) => void
|
38
38
|
|
39
39
|
export type WatchContractEventParameters<
|
40
40
|
TAbi extends Abi | readonly unknown[] = readonly unknown[],
|
@@ -53,7 +53,7 @@ export type WatchContractEventParameters<
|
|
53
53
|
/** The callback to call when an error occurred when trying to get for a new block. */
|
54
54
|
onError?: (error: Error) => void
|
55
55
|
/** The callback to call when new event logs are received. */
|
56
|
-
onLogs:
|
56
|
+
onLogs: WatchContractEventOnLogsFn<TAbi, TEventName, TStrict>
|
57
57
|
/** Polling frequency (in ms). Defaults to Client's pollingInterval config. */
|
58
58
|
pollingInterval?: number
|
59
59
|
/**
|
@@ -173,8 +173,8 @@ export function watchContractEvent<
|
|
173
173
|
event: getAbiItem({
|
174
174
|
abi,
|
175
175
|
name: eventName,
|
176
|
-
} as unknown as GetAbiItemParameters),
|
177
|
-
}
|
176
|
+
} as unknown as GetAbiItemParameters) as AbiEvent,
|
177
|
+
})
|
178
178
|
} else {
|
179
179
|
logs = []
|
180
180
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { AbiEvent, Address } from 'abitype'
|
1
|
+
import type { AbiEvent, Address, Narrow } from 'abitype'
|
2
2
|
|
3
3
|
import type { Client } from '../../clients/createClient.js'
|
4
4
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
@@ -19,24 +19,38 @@ import {
|
|
19
19
|
} from './createEventFilter.js'
|
20
20
|
import { getBlockNumber } from './getBlockNumber.js'
|
21
21
|
import { getFilterChanges } from './getFilterChanges.js'
|
22
|
-
import { getLogs } from './getLogs.js'
|
22
|
+
import { type GetLogsParameters, getLogs } from './getLogs.js'
|
23
23
|
import { uninstallFilter } from './uninstallFilter.js'
|
24
24
|
|
25
|
-
export type
|
25
|
+
export type WatchEventOnLogsParameter<
|
26
26
|
TAbiEvent extends AbiEvent | undefined = undefined,
|
27
|
+
TAbiEvents extends
|
28
|
+
| readonly AbiEvent[]
|
29
|
+
| readonly unknown[]
|
30
|
+
| undefined = TAbiEvent extends AbiEvent ? [TAbiEvent] : undefined,
|
27
31
|
TStrict extends boolean | undefined = undefined,
|
28
32
|
TEventName extends string | undefined = MaybeAbiEventName<TAbiEvent>,
|
29
|
-
> = Log<bigint, number, TAbiEvent, TStrict,
|
30
|
-
export type
|
33
|
+
> = Log<bigint, number, false, TAbiEvent, TStrict, TAbiEvents, TEventName>[]
|
34
|
+
export type WatchEventOnLogsFn<
|
31
35
|
TAbiEvent extends AbiEvent | undefined = undefined,
|
36
|
+
TAbiEvents extends
|
37
|
+
| readonly AbiEvent[]
|
38
|
+
| readonly unknown[]
|
39
|
+
| undefined = TAbiEvent extends AbiEvent ? [TAbiEvent] : undefined,
|
32
40
|
TStrict extends boolean | undefined = undefined,
|
33
|
-
|
34
|
-
> = (
|
41
|
+
_EventName extends string | undefined = MaybeAbiEventName<TAbiEvent>,
|
42
|
+
> = (
|
43
|
+
logs: WatchEventOnLogsParameter<TAbiEvent, TAbiEvents, TStrict, _EventName>,
|
44
|
+
) => void
|
35
45
|
|
36
46
|
export type WatchEventParameters<
|
37
47
|
TAbiEvent extends AbiEvent | undefined = undefined,
|
48
|
+
TAbiEvents extends
|
49
|
+
| readonly AbiEvent[]
|
50
|
+
| readonly unknown[]
|
51
|
+
| undefined = TAbiEvent extends AbiEvent ? [TAbiEvent] : undefined,
|
38
52
|
TStrict extends boolean | undefined = undefined,
|
39
|
-
|
53
|
+
_EventName extends string | undefined = MaybeAbiEventName<TAbiEvent>,
|
40
54
|
> = {
|
41
55
|
/** The address of the contract. */
|
42
56
|
address?: Address | Address[]
|
@@ -48,13 +62,24 @@ export type WatchEventParameters<
|
|
48
62
|
/** The callback to call when an error occurred when trying to get for a new block. */
|
49
63
|
onError?: (error: Error) => void
|
50
64
|
/** The callback to call when new event logs are received. */
|
51
|
-
onLogs:
|
65
|
+
onLogs: WatchEventOnLogsFn<TAbiEvent, TAbiEvents, TStrict, _EventName>
|
52
66
|
/** Polling frequency (in ms). Defaults to Client's pollingInterval config. */
|
53
67
|
pollingInterval?: number
|
54
68
|
} & (
|
55
69
|
| {
|
56
|
-
event: TAbiEvent
|
57
|
-
|
70
|
+
event: Narrow<TAbiEvent>
|
71
|
+
events?: never
|
72
|
+
args?: MaybeExtractEventArgsFromAbi<TAbiEvents, _EventName>
|
73
|
+
/**
|
74
|
+
* Whether or not the logs must match the indexed/non-indexed arguments on `event`.
|
75
|
+
* @default false
|
76
|
+
*/
|
77
|
+
strict?: TStrict
|
78
|
+
}
|
79
|
+
| {
|
80
|
+
event?: never
|
81
|
+
events?: Narrow<TAbiEvents>
|
82
|
+
args?: never
|
58
83
|
/**
|
59
84
|
* Whether or not the logs must match the indexed/non-indexed arguments on `event`.
|
60
85
|
* @default false
|
@@ -63,6 +88,7 @@ export type WatchEventParameters<
|
|
63
88
|
}
|
64
89
|
| {
|
65
90
|
event?: never
|
91
|
+
events?: never
|
66
92
|
args?: never
|
67
93
|
strict?: never
|
68
94
|
}
|
@@ -104,9 +130,13 @@ export type WatchEventReturnType = () => void
|
|
104
130
|
*/
|
105
131
|
export function watchEvent<
|
106
132
|
TChain extends Chain | undefined,
|
107
|
-
TAbiEvent extends AbiEvent | undefined,
|
108
|
-
|
133
|
+
TAbiEvent extends AbiEvent | undefined = undefined,
|
134
|
+
TAbiEvents extends
|
135
|
+
| readonly AbiEvent[]
|
136
|
+
| readonly unknown[]
|
137
|
+
| undefined = TAbiEvent extends AbiEvent ? [TAbiEvent] : undefined,
|
109
138
|
TStrict extends boolean | undefined = undefined,
|
139
|
+
_EventName extends string | undefined = undefined,
|
110
140
|
>(
|
111
141
|
client: Client<Transport, TChain>,
|
112
142
|
{
|
@@ -114,11 +144,12 @@ export function watchEvent<
|
|
114
144
|
args,
|
115
145
|
batch = true,
|
116
146
|
event,
|
147
|
+
events,
|
117
148
|
onError,
|
118
149
|
onLogs,
|
119
150
|
pollingInterval = client.pollingInterval,
|
120
151
|
strict: strict_,
|
121
|
-
}: WatchEventParameters<TAbiEvent, TStrict>,
|
152
|
+
}: WatchEventParameters<TAbiEvent, TAbiEvents, TStrict>,
|
122
153
|
): WatchEventReturnType {
|
123
154
|
const observerId = stringify([
|
124
155
|
'watchEvent',
|
@@ -133,7 +164,7 @@ export function watchEvent<
|
|
133
164
|
|
134
165
|
return observe(observerId, { onLogs, onError }, (emit) => {
|
135
166
|
let previousBlockNumber: bigint
|
136
|
-
let filter: Filter<'event',
|
167
|
+
let filter: Filter<'event', TAbiEvents, _EventName, any>
|
137
168
|
let initialized = false
|
138
169
|
|
139
170
|
const unwatch = poll(
|
@@ -144,11 +175,12 @@ export function watchEvent<
|
|
144
175
|
address,
|
145
176
|
args,
|
146
177
|
event: event!,
|
178
|
+
events,
|
147
179
|
strict,
|
148
180
|
} as unknown as CreateEventFilterParameters)) as unknown as Filter<
|
149
181
|
'event',
|
150
|
-
|
151
|
-
|
182
|
+
TAbiEvents,
|
183
|
+
_EventName
|
152
184
|
>
|
153
185
|
} catch {}
|
154
186
|
initialized = true
|
@@ -173,10 +205,11 @@ export function watchEvent<
|
|
173
205
|
logs = await getLogs(client, {
|
174
206
|
address,
|
175
207
|
args,
|
208
|
+
event: event!,
|
209
|
+
events,
|
176
210
|
fromBlock: previousBlockNumber + 1n,
|
177
211
|
toBlock: blockNumber,
|
178
|
-
|
179
|
-
})
|
212
|
+
} as unknown as GetLogsParameters)
|
180
213
|
} else {
|
181
214
|
logs = []
|
182
215
|
}
|
@@ -29,6 +29,11 @@ export type ClientConfig<
|
|
29
29
|
multicall?: boolean | Prettify<MulticallBatchOptions> | undefined
|
30
30
|
}
|
31
31
|
| undefined
|
32
|
+
/**
|
33
|
+
* Time (in ms) that cached data will remain in memory.
|
34
|
+
* @default 4_000
|
35
|
+
*/
|
36
|
+
cacheTime?: number | undefined
|
32
37
|
/** Chain for the client. */
|
33
38
|
chain?: Chain | undefined | chain
|
34
39
|
/** A key for the client. */
|
@@ -79,6 +84,8 @@ type Client_Base<
|
|
79
84
|
account: account
|
80
85
|
/** Flags for batch settings. */
|
81
86
|
batch?: ClientConfig['batch']
|
87
|
+
/** Time (in ms) that cached data will remain in memory. */
|
88
|
+
cacheTime: number
|
82
89
|
/** Chain for the client. */
|
83
90
|
chain: chain
|
84
91
|
/** A key for the client. */
|
@@ -135,6 +142,7 @@ export function createClient<
|
|
135
142
|
export function createClient(parameters: ClientConfig): Client {
|
136
143
|
const {
|
137
144
|
batch,
|
145
|
+
cacheTime = parameters.pollingInterval ?? 4_000,
|
138
146
|
key = 'base',
|
139
147
|
name = 'Base Client',
|
140
148
|
pollingInterval = 4_000,
|
@@ -154,6 +162,7 @@ export function createClient(parameters: ClientConfig): Client {
|
|
154
162
|
const client = {
|
155
163
|
account,
|
156
164
|
batch,
|
165
|
+
cacheTime,
|
157
166
|
chain,
|
158
167
|
key,
|
159
168
|
name,
|
@@ -11,7 +11,13 @@ export type PublicClientConfig<
|
|
11
11
|
> = Prettify<
|
12
12
|
Pick<
|
13
13
|
ClientConfig<transport, chain>,
|
14
|
-
|
14
|
+
| 'batch'
|
15
|
+
| 'cacheTime'
|
16
|
+
| 'chain'
|
17
|
+
| 'key'
|
18
|
+
| 'name'
|
19
|
+
| 'pollingInterval'
|
20
|
+
| 'transport'
|
15
21
|
>
|
16
22
|
>
|
17
23
|
|
@@ -21,7 +21,13 @@ export type TestClientConfig<
|
|
21
21
|
> = Prettify<
|
22
22
|
Pick<
|
23
23
|
ClientConfig<transport, chain, accountOrAddress>,
|
24
|
-
|
24
|
+
| 'account'
|
25
|
+
| 'cacheTime'
|
26
|
+
| 'chain'
|
27
|
+
| 'key'
|
28
|
+
| 'name'
|
29
|
+
| 'pollingInterval'
|
30
|
+
| 'transport'
|
25
31
|
> & {
|
26
32
|
/** Mode of the test client. */
|
27
33
|
mode: mode | ('anvil' | 'hardhat' | 'ganache') // TODO: Type utility that expands `TestClientMode`
|
@@ -19,7 +19,13 @@ export type WalletClientConfig<
|
|
19
19
|
> = Prettify<
|
20
20
|
Pick<
|
21
21
|
ClientConfig<transport, chain, accountOrAddress>,
|
22
|
-
|
22
|
+
| 'account'
|
23
|
+
| 'cacheTime'
|
24
|
+
| 'chain'
|
25
|
+
| 'key'
|
26
|
+
| 'name'
|
27
|
+
| 'pollingInterval'
|
28
|
+
| 'transport'
|
23
29
|
>
|
24
30
|
>
|
25
31
|
|