viem 0.0.0-main.20230727T170020 → 0.0.0-main.20230730T155828
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/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/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/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/decorators/public.js.map +1 -1
- package/dist/cjs/errors/version.js +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/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/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/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/decorators/public.js.map +1 -1
- package/dist/esm/errors/version.js +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/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/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/decorators/public.d.ts +10 -9
- package/dist/types/clients/decorators/public.d.ts.map +1 -1
- package/dist/types/errors/version.d.ts +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/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/package.json +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/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/watchBlocks.ts +37 -18
- package/src/actions/public/watchContractEvent.ts +5 -5
- package/src/actions/public/watchEvent.ts +50 -17
- package/src/clients/decorators/public.ts +114 -25
- package/src/errors/version.ts +1 -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/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
@@ -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
|
|
@@ -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
|
}
|
@@ -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
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,
|
33
|
+
> = Log<bigint, number, false, TAbiEvent, TStrict, TAbiEvents, TEventName>[]
|
30
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: WatchEventOnLogsFn<TAbiEvent, TStrict,
|
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
|
}
|