viem 1.4.2 → 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/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/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/errors/version.js +1 -1
- package/dist/cjs/index.js +110 -7
- package/dist/cjs/index.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/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/errors/version.js +1 -1
- package/dist/esm/index.js +4 -1
- package/dist/esm/index.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/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 +1 -1
- 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/errors/version.d.ts +1 -1
- package/dist/types/index.d.ts +4 -1
- package/dist/types/index.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/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 +5 -5
- package/src/actions/public/watchEvent.ts +50 -17
- 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/errors/version.ts +1 -1
- package/src/index.ts +101 -1
- 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
@@ -12,9 +12,12 @@ import {
|
|
12
12
|
formatBlock,
|
13
13
|
} from '../../utils/formatters/block.js'
|
14
14
|
|
15
|
-
export type GetBlockParameters
|
15
|
+
export type GetBlockParameters<
|
16
|
+
TIncludeTransactions extends boolean = false,
|
17
|
+
TBlockTag extends BlockTag = 'latest',
|
18
|
+
> = {
|
16
19
|
/** Whether or not to include transaction data in the response. */
|
17
|
-
includeTransactions?:
|
20
|
+
includeTransactions?: TIncludeTransactions
|
18
21
|
} & (
|
19
22
|
| {
|
20
23
|
/** Hash of the block. */
|
@@ -35,13 +38,15 @@ export type GetBlockParameters = {
|
|
35
38
|
* The block tag.
|
36
39
|
* @default 'latest'
|
37
40
|
*/
|
38
|
-
blockTag?: BlockTag
|
41
|
+
blockTag?: TBlockTag | BlockTag
|
39
42
|
}
|
40
43
|
)
|
41
44
|
|
42
45
|
export type GetBlockReturnType<
|
43
46
|
TChain extends Chain | undefined = Chain | undefined,
|
44
|
-
|
47
|
+
TIncludeTransactions extends boolean = false,
|
48
|
+
TBlockTag extends BlockTag = 'latest',
|
49
|
+
> = FormattedBlock<TChain, TIncludeTransactions, TBlockTag>
|
45
50
|
|
46
51
|
/**
|
47
52
|
* Returns information about a block at a block number, hash, or tag.
|
@@ -70,15 +75,20 @@ export type GetBlockReturnType<
|
|
70
75
|
export async function getBlock<
|
71
76
|
TChain extends Chain | undefined,
|
72
77
|
TAccount extends Account | undefined,
|
78
|
+
TIncludeTransactions extends boolean = false,
|
79
|
+
TBlockTag extends BlockTag = 'latest',
|
73
80
|
>(
|
74
81
|
client: Client<Transport, TChain, TAccount>,
|
75
82
|
{
|
76
83
|
blockHash,
|
77
84
|
blockNumber,
|
78
|
-
blockTag
|
79
|
-
includeTransactions
|
80
|
-
}: GetBlockParameters = {},
|
81
|
-
): Promise<GetBlockReturnType<TChain>> {
|
85
|
+
blockTag: blockTag_,
|
86
|
+
includeTransactions: includeTransactions_,
|
87
|
+
}: GetBlockParameters<TIncludeTransactions, TBlockTag> = {},
|
88
|
+
): Promise<GetBlockReturnType<TChain, TIncludeTransactions, TBlockTag>> {
|
89
|
+
const blockTag = blockTag_ ?? 'latest'
|
90
|
+
const includeTransactions = includeTransactions_ ?? false
|
91
|
+
|
82
92
|
const blockNumberHex =
|
83
93
|
blockNumber !== undefined ? numberToHex(blockNumber) : undefined
|
84
94
|
|
@@ -4,7 +4,9 @@ import type { Chain } from '../../types/chain.js'
|
|
4
4
|
import { getCache, withCache } from '../../utils/promise/withCache.js'
|
5
5
|
|
6
6
|
export type GetBlockNumberParameters = {
|
7
|
-
/**
|
7
|
+
/** Time (in ms) that cached block number will remain in memory. */
|
8
|
+
cacheTime?: number
|
9
|
+
/** @deprecated use `cacheTime` instead. */
|
8
10
|
maxAge?: number
|
9
11
|
}
|
10
12
|
|
@@ -41,14 +43,14 @@ export function getBlockNumberCache(id: string) {
|
|
41
43
|
*/
|
42
44
|
export async function getBlockNumber<TChain extends Chain | undefined>(
|
43
45
|
client: Client<Transport, TChain>,
|
44
|
-
{
|
46
|
+
{ cacheTime = client.cacheTime, maxAge }: GetBlockNumberParameters = {},
|
45
47
|
): Promise<GetBlockNumberReturnType> {
|
46
48
|
const blockNumberHex = await withCache(
|
47
49
|
() =>
|
48
50
|
client.request({
|
49
51
|
method: 'eth_blockNumber',
|
50
52
|
}),
|
51
|
-
{ cacheKey: cacheKey(client.uid), maxAge },
|
53
|
+
{ cacheKey: cacheKey(client.uid), cacheTime: maxAge ?? cacheTime },
|
52
54
|
)
|
53
55
|
return BigInt(blockNumberHex)
|
54
56
|
}
|
@@ -6,6 +6,7 @@ import {
|
|
6
6
|
DecodeLogDataMismatch,
|
7
7
|
DecodeLogTopicsMismatch,
|
8
8
|
} from '../../errors/abi.js'
|
9
|
+
import type { BlockNumber, BlockTag } from '../../types/block.js'
|
9
10
|
import type { Chain } from '../../types/chain.js'
|
10
11
|
import type { Filter, FilterType } from '../../types/filter.js'
|
11
12
|
import type { Log } from '../../types/log.js'
|
@@ -15,25 +16,40 @@ import { formatLog } from '../../utils/formatters/log.js'
|
|
15
16
|
|
16
17
|
export type GetFilterChangesParameters<
|
17
18
|
TFilterType extends FilterType = FilterType,
|
18
|
-
TAbi extends Abi | readonly unknown[] =
|
19
|
-
TEventName extends string | undefined =
|
19
|
+
TAbi extends Abi | readonly unknown[] | undefined = undefined,
|
20
|
+
TEventName extends string | undefined = undefined,
|
20
21
|
TStrict extends boolean | undefined = undefined,
|
22
|
+
TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
|
23
|
+
TToBlock extends BlockNumber | BlockTag | undefined = undefined,
|
21
24
|
> = {
|
22
|
-
filter: Filter<
|
25
|
+
filter: Filter<
|
26
|
+
TFilterType,
|
27
|
+
TAbi,
|
28
|
+
TEventName,
|
29
|
+
any,
|
30
|
+
TStrict,
|
31
|
+
TFromBlock,
|
32
|
+
TToBlock
|
33
|
+
>
|
23
34
|
}
|
24
35
|
|
25
36
|
export type GetFilterChangesReturnType<
|
26
37
|
TFilterType extends FilterType = FilterType,
|
27
|
-
TAbi extends Abi | readonly unknown[] =
|
28
|
-
TEventName extends string | undefined =
|
38
|
+
TAbi extends Abi | readonly unknown[] | undefined = undefined,
|
39
|
+
TEventName extends string | undefined = undefined,
|
29
40
|
TStrict extends boolean | undefined = undefined,
|
41
|
+
TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
|
42
|
+
TToBlock extends BlockNumber | BlockTag | undefined = undefined,
|
30
43
|
_AbiEvent extends AbiEvent | undefined = TAbi extends Abi
|
31
44
|
? TEventName extends string
|
32
45
|
? ExtractAbiEvent<TAbi, TEventName>
|
33
46
|
: undefined
|
34
47
|
: undefined,
|
48
|
+
_Pending extends boolean =
|
49
|
+
| (TFromBlock extends 'pending' ? true : false)
|
50
|
+
| (TToBlock extends 'pending' ? true : false),
|
35
51
|
> = TFilterType extends 'event'
|
36
|
-
? Log<bigint, number, _AbiEvent, TStrict, TAbi, TEventName>[]
|
52
|
+
? Log<bigint, number, _Pending, _AbiEvent, TStrict, TAbi, TEventName>[]
|
37
53
|
: Hash[]
|
38
54
|
|
39
55
|
/**
|
@@ -122,15 +138,33 @@ export async function getFilterChanges<
|
|
122
138
|
TTransport extends Transport,
|
123
139
|
TChain extends Chain | undefined,
|
124
140
|
TFilterType extends FilterType,
|
125
|
-
TAbi extends Abi | readonly unknown[],
|
141
|
+
TAbi extends Abi | readonly unknown[] | undefined,
|
126
142
|
TEventName extends string | undefined,
|
127
143
|
TStrict extends boolean | undefined = undefined,
|
144
|
+
TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
|
145
|
+
TToBlock extends BlockNumber | BlockTag | undefined = undefined,
|
128
146
|
>(
|
129
147
|
_client: Client<TTransport, TChain>,
|
130
148
|
{
|
131
149
|
filter,
|
132
|
-
}: GetFilterChangesParameters<
|
133
|
-
|
150
|
+
}: GetFilterChangesParameters<
|
151
|
+
TFilterType,
|
152
|
+
TAbi,
|
153
|
+
TEventName,
|
154
|
+
TStrict,
|
155
|
+
TFromBlock,
|
156
|
+
TToBlock
|
157
|
+
>,
|
158
|
+
): Promise<
|
159
|
+
GetFilterChangesReturnType<
|
160
|
+
TFilterType,
|
161
|
+
TAbi,
|
162
|
+
TEventName,
|
163
|
+
TStrict,
|
164
|
+
TFromBlock,
|
165
|
+
TToBlock
|
166
|
+
>
|
167
|
+
> {
|
134
168
|
const strict = 'strict' in filter && filter.strict
|
135
169
|
|
136
170
|
const logs = await filter.request({
|
@@ -172,6 +206,8 @@ export async function getFilterChanges<
|
|
172
206
|
TFilterType,
|
173
207
|
TAbi,
|
174
208
|
TEventName,
|
175
|
-
TStrict
|
209
|
+
TStrict,
|
210
|
+
TFromBlock,
|
211
|
+
TToBlock
|
176
212
|
>
|
177
213
|
}
|
@@ -6,6 +6,7 @@ import {
|
|
6
6
|
DecodeLogDataMismatch,
|
7
7
|
DecodeLogTopicsMismatch,
|
8
8
|
} from '../../errors/abi.js'
|
9
|
+
import type { BlockNumber, BlockTag } from '../../types/block.js'
|
9
10
|
import type { Chain } from '../../types/chain.js'
|
10
11
|
import type { Filter } from '../../types/filter.js'
|
11
12
|
import type { Log } from '../../types/log.js'
|
@@ -13,22 +14,29 @@ import { decodeEventLog } from '../../utils/abi/decodeEventLog.js'
|
|
13
14
|
import { formatLog } from '../../utils/formatters/log.js'
|
14
15
|
|
15
16
|
export type GetFilterLogsParameters<
|
16
|
-
TAbi extends Abi | readonly unknown[] =
|
17
|
-
TEventName extends string | undefined =
|
17
|
+
TAbi extends Abi | readonly unknown[] | undefined = undefined,
|
18
|
+
TEventName extends string | undefined = undefined,
|
18
19
|
TStrict extends boolean | undefined = undefined,
|
20
|
+
TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
|
21
|
+
TToBlock extends BlockNumber | BlockTag | undefined = undefined,
|
19
22
|
> = {
|
20
|
-
filter: Filter<'event', TAbi, TEventName, any, TStrict>
|
23
|
+
filter: Filter<'event', TAbi, TEventName, any, TStrict, TFromBlock, TToBlock>
|
21
24
|
}
|
22
25
|
export type GetFilterLogsReturnType<
|
23
|
-
TAbi extends Abi | readonly unknown[] =
|
24
|
-
TEventName extends string | undefined =
|
26
|
+
TAbi extends Abi | readonly unknown[] | undefined = undefined,
|
27
|
+
TEventName extends string | undefined = undefined,
|
25
28
|
TStrict extends boolean | undefined = undefined,
|
29
|
+
TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
|
30
|
+
TToBlock extends BlockNumber | BlockTag | undefined = undefined,
|
26
31
|
_AbiEvent extends AbiEvent | undefined = TAbi extends Abi
|
27
32
|
? TEventName extends string
|
28
33
|
? ExtractAbiEvent<TAbi, TEventName>
|
29
34
|
: undefined
|
30
35
|
: undefined,
|
31
|
-
|
36
|
+
_Pending extends boolean =
|
37
|
+
| (TFromBlock extends 'pending' ? true : false)
|
38
|
+
| (TToBlock extends 'pending' ? true : false),
|
39
|
+
> = Log<bigint, number, _Pending, _AbiEvent, TStrict, TAbi, TEventName>[]
|
32
40
|
|
33
41
|
/**
|
34
42
|
* Returns a list of event logs since the filter was created.
|
@@ -59,13 +67,19 @@ export type GetFilterLogsReturnType<
|
|
59
67
|
*/
|
60
68
|
export async function getFilterLogs<
|
61
69
|
TChain extends Chain | undefined,
|
62
|
-
TAbi extends Abi | readonly unknown[],
|
70
|
+
TAbi extends Abi | readonly unknown[] | undefined,
|
63
71
|
TEventName extends string | undefined,
|
64
72
|
TStrict extends boolean | undefined = undefined,
|
73
|
+
TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
|
74
|
+
TToBlock extends BlockNumber | BlockTag | undefined = undefined,
|
65
75
|
>(
|
66
76
|
_client: Client<Transport, TChain>,
|
67
|
-
{
|
68
|
-
|
77
|
+
{
|
78
|
+
filter,
|
79
|
+
}: GetFilterLogsParameters<TAbi, TEventName, TStrict, TFromBlock, TToBlock>,
|
80
|
+
): Promise<
|
81
|
+
GetFilterLogsReturnType<TAbi, TEventName, TStrict, TFromBlock, TToBlock>
|
82
|
+
> {
|
69
83
|
const strict = filter.strict ?? false
|
70
84
|
|
71
85
|
const logs = await filter.request({
|
@@ -105,6 +119,8 @@ export async function getFilterLogs<
|
|
105
119
|
.filter(Boolean) as unknown as GetFilterLogsReturnType<
|
106
120
|
TAbi,
|
107
121
|
TEventName,
|
108
|
-
TStrict
|
122
|
+
TStrict,
|
123
|
+
TFromBlock,
|
124
|
+
TToBlock
|
109
125
|
>
|
110
126
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { AbiEvent, Address, Narrow } from 'abitype'
|
1
|
+
import type { Abi, 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'
|
@@ -25,7 +25,13 @@ import { formatLog } from '../../utils/formatters/log.js'
|
|
25
25
|
|
26
26
|
export type GetLogsParameters<
|
27
27
|
TAbiEvent extends AbiEvent | undefined = undefined,
|
28
|
+
TAbiEvents extends
|
29
|
+
| readonly AbiEvent[]
|
30
|
+
| readonly unknown[]
|
31
|
+
| undefined = TAbiEvent extends AbiEvent ? [TAbiEvent] : undefined,
|
28
32
|
TStrict extends boolean | undefined = undefined,
|
33
|
+
TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
|
34
|
+
TToBlock extends BlockNumber | BlockTag | undefined = undefined,
|
29
35
|
_EventName extends string | undefined = MaybeAbiEventName<TAbiEvent>,
|
30
36
|
> = {
|
31
37
|
/** Address or list of addresses from which logs originated */
|
@@ -33,7 +39,8 @@ export type GetLogsParameters<
|
|
33
39
|
} & (
|
34
40
|
| {
|
35
41
|
event: Narrow<TAbiEvent>
|
36
|
-
|
42
|
+
events?: never
|
43
|
+
args?: MaybeExtractEventArgsFromAbi<TAbiEvents, _EventName>
|
37
44
|
/**
|
38
45
|
* Whether or not the logs must match the indexed/non-indexed arguments on `event`.
|
39
46
|
* @default false
|
@@ -42,6 +49,17 @@ export type GetLogsParameters<
|
|
42
49
|
}
|
43
50
|
| {
|
44
51
|
event?: never
|
52
|
+
events: Narrow<TAbiEvents>
|
53
|
+
args?: never
|
54
|
+
/**
|
55
|
+
* Whether or not the logs must match the indexed/non-indexed arguments on `event`.
|
56
|
+
* @default false
|
57
|
+
*/
|
58
|
+
strict?: TStrict
|
59
|
+
}
|
60
|
+
| {
|
61
|
+
event?: never
|
62
|
+
events?: never
|
45
63
|
args?: never
|
46
64
|
strict?: never
|
47
65
|
}
|
@@ -49,9 +67,9 @@ export type GetLogsParameters<
|
|
49
67
|
(
|
50
68
|
| {
|
51
69
|
/** Block number or tag after which to include logs */
|
52
|
-
fromBlock?: BlockNumber
|
70
|
+
fromBlock?: TFromBlock | BlockNumber | BlockTag
|
53
71
|
/** Block number or tag before which to include logs */
|
54
|
-
toBlock?: BlockNumber
|
72
|
+
toBlock?: TToBlock | BlockNumber | BlockTag
|
55
73
|
blockHash?: never
|
56
74
|
}
|
57
75
|
| {
|
@@ -64,9 +82,18 @@ export type GetLogsParameters<
|
|
64
82
|
|
65
83
|
export type GetLogsReturnType<
|
66
84
|
TAbiEvent extends AbiEvent | undefined = undefined,
|
85
|
+
TAbiEvents extends
|
86
|
+
| readonly AbiEvent[]
|
87
|
+
| readonly unknown[]
|
88
|
+
| undefined = TAbiEvent extends AbiEvent ? [TAbiEvent] : undefined,
|
67
89
|
TStrict extends boolean | undefined = undefined,
|
90
|
+
TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
|
91
|
+
TToBlock extends BlockNumber | BlockTag | undefined = undefined,
|
68
92
|
_EventName extends string | undefined = MaybeAbiEventName<TAbiEvent>,
|
69
|
-
|
93
|
+
_Pending extends boolean =
|
94
|
+
| (TFromBlock extends 'pending' ? true : false)
|
95
|
+
| (TToBlock extends 'pending' ? true : false),
|
96
|
+
> = Log<bigint, number, _Pending, TAbiEvent, TStrict, TAbiEvents, _EventName>[]
|
70
97
|
|
71
98
|
/**
|
72
99
|
* Returns a list of event logs matching the provided parameters.
|
@@ -92,8 +119,14 @@ export type GetLogsReturnType<
|
|
92
119
|
*/
|
93
120
|
export async function getLogs<
|
94
121
|
TChain extends Chain | undefined,
|
95
|
-
TAbiEvent extends AbiEvent | undefined,
|
122
|
+
TAbiEvent extends AbiEvent | undefined = undefined,
|
123
|
+
TAbiEvents extends
|
124
|
+
| readonly AbiEvent[]
|
125
|
+
| readonly unknown[]
|
126
|
+
| undefined = TAbiEvent extends AbiEvent ? [TAbiEvent] : undefined,
|
96
127
|
TStrict extends boolean | undefined = undefined,
|
128
|
+
TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
|
129
|
+
TToBlock extends BlockNumber | BlockTag | undefined = undefined,
|
97
130
|
>(
|
98
131
|
client: Client<Transport, TChain>,
|
99
132
|
{
|
@@ -102,19 +135,35 @@ export async function getLogs<
|
|
102
135
|
fromBlock,
|
103
136
|
toBlock,
|
104
137
|
event,
|
138
|
+
events: events_,
|
105
139
|
args,
|
106
140
|
strict: strict_,
|
107
|
-
}: GetLogsParameters<
|
108
|
-
|
141
|
+
}: GetLogsParameters<
|
142
|
+
TAbiEvent,
|
143
|
+
TAbiEvents,
|
144
|
+
TStrict,
|
145
|
+
TFromBlock,
|
146
|
+
TToBlock
|
147
|
+
> = {},
|
148
|
+
): Promise<
|
149
|
+
GetLogsReturnType<TAbiEvent, TAbiEvents, TStrict, TFromBlock, TToBlock>
|
150
|
+
> {
|
109
151
|
const strict = strict_ ?? false
|
152
|
+
const events = events_ ?? (event ? [event] : undefined)
|
110
153
|
|
111
154
|
let topics: LogTopic[] = []
|
112
|
-
if (
|
113
|
-
topics =
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
155
|
+
if (events) {
|
156
|
+
topics = [
|
157
|
+
(events as AbiEvent[]).flatMap((event) =>
|
158
|
+
encodeEventTopics({
|
159
|
+
abi: [event],
|
160
|
+
eventName: (event as AbiEvent).name,
|
161
|
+
args,
|
162
|
+
} as EncodeEventTopicsParameters),
|
163
|
+
),
|
164
|
+
]
|
165
|
+
if (event) topics = topics[0] as LogTopic[]
|
166
|
+
}
|
118
167
|
|
119
168
|
let logs: RpcLog[]
|
120
169
|
if (blockHash) {
|
@@ -140,15 +189,15 @@ export async function getLogs<
|
|
140
189
|
return logs
|
141
190
|
.map((log) => {
|
142
191
|
try {
|
143
|
-
const { eventName, args } =
|
192
|
+
const { eventName, args } = events
|
144
193
|
? decodeEventLog({
|
145
|
-
abi:
|
194
|
+
abi: events as Abi,
|
146
195
|
data: log.data,
|
147
196
|
topics: log.topics as any,
|
148
197
|
strict,
|
149
198
|
})
|
150
199
|
: { eventName: undefined, args: undefined }
|
151
|
-
return formatLog(log, { args, eventName })
|
200
|
+
return formatLog(log, { args, eventName: eventName as string })
|
152
201
|
} catch (err) {
|
153
202
|
let eventName
|
154
203
|
let isUnnamed
|
@@ -166,5 +215,11 @@ export async function getLogs<
|
|
166
215
|
return formatLog(log, { args: isUnnamed ? [] : {}, eventName })
|
167
216
|
}
|
168
217
|
})
|
169
|
-
.filter(Boolean) as unknown as GetLogsReturnType<
|
218
|
+
.filter(Boolean) as unknown as GetLogsReturnType<
|
219
|
+
TAbiEvent,
|
220
|
+
TAbiEvents,
|
221
|
+
TStrict,
|
222
|
+
TFromBlock,
|
223
|
+
TToBlock
|
224
|
+
>
|
170
225
|
}
|
@@ -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,7 +20,7 @@ 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
26
|
export type WatchContractEventOnLogsParameter<
|
@@ -28,7 +28,7 @@ export type WatchContractEventOnLogsParameter<
|
|
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
33
|
export type WatchContractEventOnLogsFn<
|
34
34
|
TAbi extends Abi | readonly unknown[] = readonly unknown[],
|
@@ -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
|
}
|