viem 0.0.1-alpha.35 → 0.0.1-alpha.36
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 +132 -0
- package/dist/abi.d.ts +2 -2
- package/dist/abi.js +2 -2
- package/dist/abi.mjs +1 -1
- package/dist/{chain-7b7ac245.d.ts → chain-a34aa9a2.d.ts} +65 -63
- package/dist/{chain-145cfaf3.d.ts → chain-b1229232.d.ts} +1 -1
- package/dist/chains.d.ts +3 -3
- package/dist/chains.js +46 -46
- package/dist/chains.mjs +1 -1
- package/dist/{chunk-57YM6E7I.js → chunk-4AEFOF5R.js} +21 -23
- package/dist/chunk-4AEFOF5R.js.map +1 -0
- package/dist/{chunk-PBW4YL37.mjs → chunk-AXATFOBJ.mjs} +1835 -140
- package/dist/chunk-AXATFOBJ.mjs.map +1 -0
- package/dist/{chunk-5NDMORWZ.mjs → chunk-CUT73KXY.mjs} +3 -5
- package/dist/{chunk-5NDMORWZ.mjs.map → chunk-CUT73KXY.mjs.map} +1 -1
- package/dist/{chunk-HQCSH22G.js → chunk-KXGQFW2R.js} +1824 -129
- package/dist/chunk-KXGQFW2R.js.map +1 -0
- package/dist/contract.d.ts +7 -7
- package/dist/contract.js +2 -6
- package/dist/contract.mjs +11 -15
- package/dist/{createClient-7c715e2c.d.ts → createClient-8024655d.d.ts} +3 -11
- package/dist/{createPublicClient-4d24afb2.d.ts → createPublicClient-f283b09d.d.ts} +62 -59
- package/dist/{eip1193-d538ae6d.d.ts → eip1193-a4f254d2.d.ts} +2 -2
- package/dist/{encodeFunctionResult-f59f4cfe.d.ts → encodeFunctionResult-c3d6c7ea.d.ts} +1 -1
- package/dist/ens.d.ts +4 -4
- package/dist/ens.js +3 -4
- package/dist/ens.js.map +1 -1
- package/dist/ens.mjs +2 -3
- package/dist/ens.mjs.map +1 -1
- package/dist/{formatAbiItem-89d97367.d.ts → formatAbiItem-d79cb207.d.ts} +1 -1
- package/dist/{getAbiItem-c9cbc8b8.d.ts → getAbiItem-48e793da.d.ts} +1 -1
- package/dist/index.d.ts +27 -16
- package/dist/index.js +89 -93
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -82
- package/dist/index.mjs.map +1 -1
- package/dist/{parseGwei-ad6d1914.d.ts → parseGwei-5dc2744d.d.ts} +9 -20
- package/dist/public.d.ts +6 -6
- package/dist/public.js +2 -3
- package/dist/public.mjs +1 -2
- package/dist/{test-8646fb50.d.ts → test-f8bc2fa7.d.ts} +3 -11
- package/dist/test.d.ts +5 -5
- package/dist/test.js +2 -3
- package/dist/test.mjs +1 -2
- package/dist/utils/index.d.ts +27 -16
- package/dist/utils/index.js +2 -4
- package/dist/utils/index.mjs +7 -9
- package/dist/wallet.d.ts +4 -4
- package/dist/wallet.js +2 -4
- package/dist/wallet.mjs +5 -7
- package/dist/window.d.ts +2 -2
- package/package.json +1 -1
- package/dist/chunk-3FT7UKPT.js +0 -1216
- package/dist/chunk-3FT7UKPT.js.map +0 -1
- package/dist/chunk-57YM6E7I.js.map +0 -1
- package/dist/chunk-A665BF7O.js +0 -205
- package/dist/chunk-A665BF7O.js.map +0 -1
- package/dist/chunk-HQCSH22G.js.map +0 -1
- package/dist/chunk-PBW4YL37.mjs.map +0 -1
- package/dist/chunk-PH5LCMME.mjs +0 -205
- package/dist/chunk-PH5LCMME.mjs.map +0 -1
- package/dist/chunk-TJK6AFBM.js +0 -265
- package/dist/chunk-TJK6AFBM.js.map +0 -1
- package/dist/chunk-WQDVW7EJ.mjs +0 -1216
- package/dist/chunk-WQDVW7EJ.mjs.map +0 -1
- package/dist/chunk-YEVW7GK5.mjs +0 -265
- package/dist/chunk-YEVW7GK5.mjs.map +0 -1
package/dist/chunk-WQDVW7EJ.mjs
DELETED
@@ -1,1216 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
AbiDecodingZeroDataError,
|
3
|
-
BlockNotFoundError,
|
4
|
-
RawContractError,
|
5
|
-
TransactionNotFoundError,
|
6
|
-
TransactionReceiptNotFoundError,
|
7
|
-
WaitForTransactionReceiptTimeoutError,
|
8
|
-
assertRequest,
|
9
|
-
decodeEventLog,
|
10
|
-
decodeFunctionResult,
|
11
|
-
encodeEventTopics,
|
12
|
-
encodeFunctionData,
|
13
|
-
extract,
|
14
|
-
format,
|
15
|
-
formatBlock,
|
16
|
-
formatFeeHistory,
|
17
|
-
formatLog,
|
18
|
-
formatTransaction,
|
19
|
-
formatTransactionReceipt,
|
20
|
-
formatTransactionRequest,
|
21
|
-
getAbiItem,
|
22
|
-
getCache,
|
23
|
-
getCallError,
|
24
|
-
getContractError,
|
25
|
-
getEstimateGasError,
|
26
|
-
hexToNumber,
|
27
|
-
multicall3Abi,
|
28
|
-
numberToHex,
|
29
|
-
wait,
|
30
|
-
withCache
|
31
|
-
} from "./chunk-PBW4YL37.mjs";
|
32
|
-
|
33
|
-
// src/actions/public/call.ts
|
34
|
-
async function call(client, args) {
|
35
|
-
const {
|
36
|
-
blockNumber,
|
37
|
-
blockTag = "latest",
|
38
|
-
from,
|
39
|
-
accessList,
|
40
|
-
data,
|
41
|
-
gas,
|
42
|
-
gasPrice,
|
43
|
-
maxFeePerGas,
|
44
|
-
maxPriorityFeePerGas,
|
45
|
-
nonce,
|
46
|
-
to,
|
47
|
-
value,
|
48
|
-
...rest
|
49
|
-
} = args;
|
50
|
-
try {
|
51
|
-
assertRequest(args);
|
52
|
-
const blockNumberHex = blockNumber ? numberToHex(blockNumber) : void 0;
|
53
|
-
const formatter = client.chain?.formatters?.transactionRequest;
|
54
|
-
const request_ = format(
|
55
|
-
{
|
56
|
-
from,
|
57
|
-
accessList,
|
58
|
-
data,
|
59
|
-
gas,
|
60
|
-
gasPrice,
|
61
|
-
maxFeePerGas,
|
62
|
-
maxPriorityFeePerGas,
|
63
|
-
nonce,
|
64
|
-
to,
|
65
|
-
value,
|
66
|
-
// Pick out extra data that might exist on the chain's transaction request type.
|
67
|
-
...extract(rest, { formatter })
|
68
|
-
},
|
69
|
-
{
|
70
|
-
formatter: formatter || formatTransactionRequest
|
71
|
-
}
|
72
|
-
);
|
73
|
-
const response = await client.request({
|
74
|
-
method: "eth_call",
|
75
|
-
params: [request_, blockNumberHex || blockTag]
|
76
|
-
});
|
77
|
-
if (response === "0x")
|
78
|
-
return { data: void 0 };
|
79
|
-
return { data: response };
|
80
|
-
} catch (err) {
|
81
|
-
throw getCallError(err, {
|
82
|
-
...args,
|
83
|
-
chain: client.chain
|
84
|
-
});
|
85
|
-
}
|
86
|
-
}
|
87
|
-
|
88
|
-
// src/actions/public/simulateContract.ts
|
89
|
-
async function simulateContract(client, {
|
90
|
-
abi,
|
91
|
-
address,
|
92
|
-
args,
|
93
|
-
functionName,
|
94
|
-
...callRequest
|
95
|
-
}) {
|
96
|
-
const calldata = encodeFunctionData({
|
97
|
-
abi,
|
98
|
-
args,
|
99
|
-
functionName
|
100
|
-
});
|
101
|
-
try {
|
102
|
-
const { data } = await call(client, {
|
103
|
-
data: calldata,
|
104
|
-
to: address,
|
105
|
-
...callRequest
|
106
|
-
});
|
107
|
-
const result = decodeFunctionResult({
|
108
|
-
abi,
|
109
|
-
args,
|
110
|
-
functionName,
|
111
|
-
data: data || "0x"
|
112
|
-
});
|
113
|
-
return {
|
114
|
-
result,
|
115
|
-
request: {
|
116
|
-
abi,
|
117
|
-
address,
|
118
|
-
args,
|
119
|
-
functionName,
|
120
|
-
...callRequest
|
121
|
-
}
|
122
|
-
};
|
123
|
-
} catch (err) {
|
124
|
-
throw getContractError(err, {
|
125
|
-
abi,
|
126
|
-
address,
|
127
|
-
args,
|
128
|
-
docsPath: "/docs/contract/simulateContract",
|
129
|
-
functionName,
|
130
|
-
sender: callRequest.from
|
131
|
-
});
|
132
|
-
}
|
133
|
-
}
|
134
|
-
|
135
|
-
// src/actions/public/createPendingTransactionFilter.ts
|
136
|
-
async function createPendingTransactionFilter(client) {
|
137
|
-
const id = await client.request({
|
138
|
-
method: "eth_newPendingTransactionFilter"
|
139
|
-
});
|
140
|
-
return { id, type: "transaction" };
|
141
|
-
}
|
142
|
-
|
143
|
-
// src/actions/public/createBlockFilter.ts
|
144
|
-
async function createBlockFilter(client) {
|
145
|
-
const id = await client.request({
|
146
|
-
method: "eth_newBlockFilter"
|
147
|
-
});
|
148
|
-
return { id, type: "block" };
|
149
|
-
}
|
150
|
-
|
151
|
-
// src/actions/public/createEventFilter.ts
|
152
|
-
async function createEventFilter(client, {
|
153
|
-
address,
|
154
|
-
args,
|
155
|
-
event,
|
156
|
-
fromBlock,
|
157
|
-
toBlock
|
158
|
-
} = {}) {
|
159
|
-
let topics = [];
|
160
|
-
if (event)
|
161
|
-
topics = encodeEventTopics({
|
162
|
-
abi: [event],
|
163
|
-
eventName: event.name,
|
164
|
-
args
|
165
|
-
});
|
166
|
-
const id = await client.request({
|
167
|
-
method: "eth_newFilter",
|
168
|
-
params: [
|
169
|
-
{
|
170
|
-
address,
|
171
|
-
fromBlock: typeof fromBlock === "bigint" ? numberToHex(fromBlock) : fromBlock,
|
172
|
-
toBlock: typeof toBlock === "bigint" ? numberToHex(toBlock) : toBlock,
|
173
|
-
...topics.length ? { topics } : {}
|
174
|
-
}
|
175
|
-
]
|
176
|
-
});
|
177
|
-
return {
|
178
|
-
abi: event ? [event] : void 0,
|
179
|
-
args,
|
180
|
-
eventName: event ? event.name : void 0,
|
181
|
-
id,
|
182
|
-
type: "event"
|
183
|
-
};
|
184
|
-
}
|
185
|
-
|
186
|
-
// src/actions/public/createContractEventFilter.ts
|
187
|
-
async function createContractEventFilter(client, {
|
188
|
-
address,
|
189
|
-
abi,
|
190
|
-
args,
|
191
|
-
eventName,
|
192
|
-
fromBlock,
|
193
|
-
toBlock
|
194
|
-
}) {
|
195
|
-
const topics = eventName ? encodeEventTopics({
|
196
|
-
abi,
|
197
|
-
args,
|
198
|
-
eventName
|
199
|
-
}) : void 0;
|
200
|
-
const id = await client.request({
|
201
|
-
method: "eth_newFilter",
|
202
|
-
params: [
|
203
|
-
{
|
204
|
-
address,
|
205
|
-
fromBlock: typeof fromBlock === "bigint" ? numberToHex(fromBlock) : fromBlock,
|
206
|
-
toBlock: typeof toBlock === "bigint" ? numberToHex(toBlock) : toBlock,
|
207
|
-
topics
|
208
|
-
}
|
209
|
-
]
|
210
|
-
});
|
211
|
-
return {
|
212
|
-
abi,
|
213
|
-
args,
|
214
|
-
eventName,
|
215
|
-
id,
|
216
|
-
type: "event"
|
217
|
-
};
|
218
|
-
}
|
219
|
-
|
220
|
-
// src/actions/public/estimateGas.ts
|
221
|
-
async function estimateGas(client, args) {
|
222
|
-
const {
|
223
|
-
accessList,
|
224
|
-
blockNumber,
|
225
|
-
blockTag = "latest",
|
226
|
-
data,
|
227
|
-
from,
|
228
|
-
gas,
|
229
|
-
gasPrice,
|
230
|
-
maxFeePerGas,
|
231
|
-
maxPriorityFeePerGas,
|
232
|
-
nonce,
|
233
|
-
to,
|
234
|
-
value,
|
235
|
-
...rest
|
236
|
-
} = args;
|
237
|
-
try {
|
238
|
-
assertRequest(args);
|
239
|
-
const blockNumberHex = blockNumber ? numberToHex(blockNumber) : void 0;
|
240
|
-
const formatter = client.chain?.formatters?.transactionRequest;
|
241
|
-
const request_ = format(
|
242
|
-
{
|
243
|
-
from,
|
244
|
-
accessList,
|
245
|
-
data,
|
246
|
-
gas,
|
247
|
-
gasPrice,
|
248
|
-
maxFeePerGas,
|
249
|
-
maxPriorityFeePerGas,
|
250
|
-
nonce,
|
251
|
-
to,
|
252
|
-
value,
|
253
|
-
// Pick out extra data that might exist on the chain's transaction request type.
|
254
|
-
...extract(rest, { formatter })
|
255
|
-
},
|
256
|
-
{
|
257
|
-
formatter: formatter || formatTransactionRequest
|
258
|
-
}
|
259
|
-
);
|
260
|
-
const balance = await client.request({
|
261
|
-
method: "eth_estimateGas",
|
262
|
-
params: [request_, blockNumberHex || blockTag]
|
263
|
-
});
|
264
|
-
return BigInt(balance);
|
265
|
-
} catch (err) {
|
266
|
-
throw getEstimateGasError(err, {
|
267
|
-
...args,
|
268
|
-
chain: client.chain
|
269
|
-
});
|
270
|
-
}
|
271
|
-
}
|
272
|
-
|
273
|
-
// src/actions/public/estimateContractGas.ts
|
274
|
-
async function estimateContractGas(client, {
|
275
|
-
abi,
|
276
|
-
address,
|
277
|
-
args,
|
278
|
-
functionName,
|
279
|
-
...request
|
280
|
-
}) {
|
281
|
-
const data = encodeFunctionData({
|
282
|
-
abi,
|
283
|
-
args,
|
284
|
-
functionName
|
285
|
-
});
|
286
|
-
try {
|
287
|
-
const gas = await estimateGas(client, {
|
288
|
-
data,
|
289
|
-
to: address,
|
290
|
-
...request
|
291
|
-
});
|
292
|
-
return gas;
|
293
|
-
} catch (err) {
|
294
|
-
throw getContractError(err, {
|
295
|
-
abi,
|
296
|
-
address,
|
297
|
-
args,
|
298
|
-
docsPath: "/docs/contract/simulateContract",
|
299
|
-
functionName,
|
300
|
-
sender: request.from
|
301
|
-
});
|
302
|
-
}
|
303
|
-
}
|
304
|
-
|
305
|
-
// src/actions/public/getBalance.ts
|
306
|
-
async function getBalance(client, { address, blockNumber, blockTag = "latest" }) {
|
307
|
-
const blockNumberHex = blockNumber ? numberToHex(blockNumber) : void 0;
|
308
|
-
const balance = await client.request({
|
309
|
-
method: "eth_getBalance",
|
310
|
-
params: [address, blockNumberHex || blockTag]
|
311
|
-
});
|
312
|
-
return BigInt(balance);
|
313
|
-
}
|
314
|
-
|
315
|
-
// src/actions/public/getBlock.ts
|
316
|
-
async function getBlock(client, {
|
317
|
-
blockHash,
|
318
|
-
blockNumber,
|
319
|
-
blockTag = "latest",
|
320
|
-
includeTransactions = false
|
321
|
-
} = {}) {
|
322
|
-
const blockNumberHex = blockNumber !== void 0 ? numberToHex(blockNumber) : void 0;
|
323
|
-
let block = null;
|
324
|
-
if (blockHash) {
|
325
|
-
block = await client.request({
|
326
|
-
method: "eth_getBlockByHash",
|
327
|
-
params: [blockHash, includeTransactions]
|
328
|
-
});
|
329
|
-
} else {
|
330
|
-
block = await client.request({
|
331
|
-
method: "eth_getBlockByNumber",
|
332
|
-
params: [blockNumberHex || blockTag, includeTransactions]
|
333
|
-
});
|
334
|
-
}
|
335
|
-
if (!block)
|
336
|
-
throw new BlockNotFoundError({ blockHash, blockNumber });
|
337
|
-
return format(block, {
|
338
|
-
formatter: client.chain?.formatters?.block || formatBlock
|
339
|
-
});
|
340
|
-
}
|
341
|
-
|
342
|
-
// src/actions/public/getBlockNumber.ts
|
343
|
-
var cacheKey = (id) => `blockNumber.${id}`;
|
344
|
-
function getBlockNumberCache(id) {
|
345
|
-
return getCache(cacheKey(id));
|
346
|
-
}
|
347
|
-
async function getBlockNumber(client, { maxAge = client.pollingInterval } = {}) {
|
348
|
-
const blockNumberHex = await withCache(
|
349
|
-
() => client.request({
|
350
|
-
method: "eth_blockNumber"
|
351
|
-
}),
|
352
|
-
{ cacheKey: cacheKey(client.uid), maxAge }
|
353
|
-
);
|
354
|
-
return BigInt(blockNumberHex);
|
355
|
-
}
|
356
|
-
|
357
|
-
// src/actions/public/getBlockTransactionCount.ts
|
358
|
-
async function getBlockTransactionCount(client, {
|
359
|
-
blockHash,
|
360
|
-
blockNumber,
|
361
|
-
blockTag = "latest"
|
362
|
-
} = {}) {
|
363
|
-
const blockNumberHex = blockNumber !== void 0 ? numberToHex(blockNumber) : void 0;
|
364
|
-
let count = null;
|
365
|
-
if (blockHash) {
|
366
|
-
count = await client.request({
|
367
|
-
method: "eth_getBlockTransactionCountByHash",
|
368
|
-
params: [blockHash]
|
369
|
-
});
|
370
|
-
} else {
|
371
|
-
count = await client.request({
|
372
|
-
method: "eth_getBlockTransactionCountByNumber",
|
373
|
-
params: [blockNumberHex || blockTag]
|
374
|
-
});
|
375
|
-
}
|
376
|
-
return hexToNumber(count);
|
377
|
-
}
|
378
|
-
|
379
|
-
// src/actions/public/getBytecode.ts
|
380
|
-
async function getBytecode(client, { address, blockNumber, blockTag = "latest" }) {
|
381
|
-
const blockNumberHex = blockNumber !== void 0 ? numberToHex(blockNumber) : void 0;
|
382
|
-
const hex = await client.request({
|
383
|
-
method: "eth_getCode",
|
384
|
-
params: [address, blockNumberHex || blockTag]
|
385
|
-
});
|
386
|
-
if (hex === "0x")
|
387
|
-
return void 0;
|
388
|
-
return hex;
|
389
|
-
}
|
390
|
-
|
391
|
-
// src/actions/public/getChainId.ts
|
392
|
-
async function getChainId(client) {
|
393
|
-
const chainIdHex = await client.request({ method: "eth_chainId" });
|
394
|
-
return hexToNumber(chainIdHex);
|
395
|
-
}
|
396
|
-
|
397
|
-
// src/actions/public/getFeeHistory.ts
|
398
|
-
async function getFeeHistory(client, {
|
399
|
-
blockCount,
|
400
|
-
blockNumber,
|
401
|
-
blockTag = "latest",
|
402
|
-
rewardPercentiles
|
403
|
-
}) {
|
404
|
-
const blockNumberHex = blockNumber ? numberToHex(blockNumber) : void 0;
|
405
|
-
const feeHistory = await client.request({
|
406
|
-
method: "eth_feeHistory",
|
407
|
-
params: [
|
408
|
-
numberToHex(blockCount),
|
409
|
-
blockNumberHex || blockTag,
|
410
|
-
rewardPercentiles
|
411
|
-
]
|
412
|
-
});
|
413
|
-
return formatFeeHistory(feeHistory);
|
414
|
-
}
|
415
|
-
|
416
|
-
// src/actions/public/getFilterChanges.ts
|
417
|
-
async function getFilterChanges(client, { filter }) {
|
418
|
-
const logs = await client.request({
|
419
|
-
method: "eth_getFilterChanges",
|
420
|
-
params: [filter.id]
|
421
|
-
});
|
422
|
-
return logs.map((log) => {
|
423
|
-
if (typeof log === "string")
|
424
|
-
return log;
|
425
|
-
const { eventName, args } = "abi" in filter && filter.abi ? decodeEventLog({
|
426
|
-
abi: filter.abi,
|
427
|
-
data: log.data,
|
428
|
-
topics: log.topics
|
429
|
-
}) : { eventName: void 0, args: void 0 };
|
430
|
-
return formatLog(log, { args, eventName });
|
431
|
-
});
|
432
|
-
}
|
433
|
-
|
434
|
-
// src/actions/public/getFilterLogs.ts
|
435
|
-
async function getFilterLogs(client, { filter }) {
|
436
|
-
const logs = await client.request({
|
437
|
-
method: "eth_getFilterLogs",
|
438
|
-
params: [filter.id]
|
439
|
-
});
|
440
|
-
return logs.map((log) => {
|
441
|
-
const { eventName, args } = "abi" in filter && filter.abi ? decodeEventLog({
|
442
|
-
abi: filter.abi,
|
443
|
-
data: log.data,
|
444
|
-
topics: log.topics
|
445
|
-
}) : { eventName: void 0, args: void 0 };
|
446
|
-
return formatLog(log, { args, eventName });
|
447
|
-
});
|
448
|
-
}
|
449
|
-
|
450
|
-
// src/actions/public/getGasPrice.ts
|
451
|
-
async function getGasPrice(client) {
|
452
|
-
const gasPrice = await client.request({
|
453
|
-
method: "eth_gasPrice"
|
454
|
-
});
|
455
|
-
return BigInt(gasPrice);
|
456
|
-
}
|
457
|
-
|
458
|
-
// src/actions/public/getLogs.ts
|
459
|
-
async function getLogs(client, {
|
460
|
-
address,
|
461
|
-
blockHash,
|
462
|
-
fromBlock,
|
463
|
-
toBlock,
|
464
|
-
event,
|
465
|
-
args
|
466
|
-
} = {}) {
|
467
|
-
let topics = [];
|
468
|
-
if (event)
|
469
|
-
topics = encodeEventTopics({
|
470
|
-
abi: [event],
|
471
|
-
eventName: event.name,
|
472
|
-
args
|
473
|
-
});
|
474
|
-
let logs;
|
475
|
-
if (blockHash) {
|
476
|
-
logs = await client.request({
|
477
|
-
method: "eth_getLogs",
|
478
|
-
params: [{ address, topics, blockHash }]
|
479
|
-
});
|
480
|
-
} else {
|
481
|
-
logs = await client.request({
|
482
|
-
method: "eth_getLogs",
|
483
|
-
params: [
|
484
|
-
{
|
485
|
-
address,
|
486
|
-
topics,
|
487
|
-
fromBlock: typeof fromBlock === "bigint" ? numberToHex(fromBlock) : fromBlock,
|
488
|
-
toBlock: typeof toBlock === "bigint" ? numberToHex(toBlock) : toBlock
|
489
|
-
}
|
490
|
-
]
|
491
|
-
});
|
492
|
-
}
|
493
|
-
return logs.map((log) => {
|
494
|
-
const { eventName, args: args2 } = event ? decodeEventLog({
|
495
|
-
abi: [event],
|
496
|
-
data: log.data,
|
497
|
-
topics: log.topics
|
498
|
-
}) : { eventName: void 0, args: void 0 };
|
499
|
-
return formatLog(log, { args: args2, eventName });
|
500
|
-
});
|
501
|
-
}
|
502
|
-
|
503
|
-
// src/actions/public/getStorageAt.ts
|
504
|
-
async function getStorageAt(client, { address, blockNumber, blockTag = "latest", slot }) {
|
505
|
-
const blockNumberHex = blockNumber !== void 0 ? numberToHex(blockNumber) : void 0;
|
506
|
-
const data = await client.request({
|
507
|
-
method: "eth_getStorageAt",
|
508
|
-
params: [address, slot, blockNumberHex || blockTag]
|
509
|
-
});
|
510
|
-
return data;
|
511
|
-
}
|
512
|
-
|
513
|
-
// src/actions/public/getTransaction.ts
|
514
|
-
async function getTransaction(client, {
|
515
|
-
blockHash,
|
516
|
-
blockNumber,
|
517
|
-
blockTag = "latest",
|
518
|
-
hash,
|
519
|
-
index
|
520
|
-
}) {
|
521
|
-
const blockNumberHex = blockNumber !== void 0 ? numberToHex(blockNumber) : void 0;
|
522
|
-
let transaction = null;
|
523
|
-
if (hash) {
|
524
|
-
transaction = await client.request({
|
525
|
-
method: "eth_getTransactionByHash",
|
526
|
-
params: [hash]
|
527
|
-
});
|
528
|
-
} else if (blockHash) {
|
529
|
-
transaction = await client.request({
|
530
|
-
method: "eth_getTransactionByBlockHashAndIndex",
|
531
|
-
params: [blockHash, numberToHex(index)]
|
532
|
-
});
|
533
|
-
} else if (blockNumberHex || blockTag) {
|
534
|
-
transaction = await client.request({
|
535
|
-
method: "eth_getTransactionByBlockNumberAndIndex",
|
536
|
-
params: [blockNumberHex || blockTag, numberToHex(index)]
|
537
|
-
});
|
538
|
-
}
|
539
|
-
if (!transaction)
|
540
|
-
throw new TransactionNotFoundError({
|
541
|
-
blockHash,
|
542
|
-
blockNumber,
|
543
|
-
blockTag,
|
544
|
-
hash,
|
545
|
-
index
|
546
|
-
});
|
547
|
-
return format(transaction, {
|
548
|
-
formatter: client.chain?.formatters?.transaction || formatTransaction
|
549
|
-
});
|
550
|
-
}
|
551
|
-
|
552
|
-
// src/actions/public/getTransactionConfirmations.ts
|
553
|
-
async function getTransactionConfirmations(client, { hash, transactionReceipt }) {
|
554
|
-
const [blockNumber, transaction] = await Promise.all([
|
555
|
-
getBlockNumber(client),
|
556
|
-
hash ? getTransaction(client, { hash }) : void 0
|
557
|
-
]);
|
558
|
-
const transactionBlockNumber = transactionReceipt?.blockNumber || transaction?.blockNumber;
|
559
|
-
if (!transactionBlockNumber)
|
560
|
-
return 0n;
|
561
|
-
return blockNumber - transactionBlockNumber + 1n;
|
562
|
-
}
|
563
|
-
|
564
|
-
// src/actions/public/getTransactionCount.ts
|
565
|
-
async function getTransactionCount(client, { address, blockTag = "latest", blockNumber }) {
|
566
|
-
const count = await client.request({
|
567
|
-
method: "eth_getTransactionCount",
|
568
|
-
params: [address, blockNumber ? numberToHex(blockNumber) : blockTag]
|
569
|
-
});
|
570
|
-
return hexToNumber(count);
|
571
|
-
}
|
572
|
-
|
573
|
-
// src/actions/public/getTransactionReceipt.ts
|
574
|
-
async function getTransactionReceipt(client, { hash }) {
|
575
|
-
const receipt = await client.request({
|
576
|
-
method: "eth_getTransactionReceipt",
|
577
|
-
params: [hash]
|
578
|
-
});
|
579
|
-
if (!receipt)
|
580
|
-
throw new TransactionReceiptNotFoundError({ hash });
|
581
|
-
return format(receipt, {
|
582
|
-
formatter: client.chain?.formatters?.transactionReceipt || formatTransactionReceipt
|
583
|
-
});
|
584
|
-
}
|
585
|
-
|
586
|
-
// src/actions/public/readContract.ts
|
587
|
-
async function readContract(client, {
|
588
|
-
abi,
|
589
|
-
address,
|
590
|
-
args,
|
591
|
-
functionName,
|
592
|
-
...callRequest
|
593
|
-
}) {
|
594
|
-
const calldata = encodeFunctionData({
|
595
|
-
abi,
|
596
|
-
args,
|
597
|
-
functionName
|
598
|
-
});
|
599
|
-
try {
|
600
|
-
const { data } = await call(client, {
|
601
|
-
data: calldata,
|
602
|
-
to: address,
|
603
|
-
...callRequest
|
604
|
-
});
|
605
|
-
return decodeFunctionResult({
|
606
|
-
abi,
|
607
|
-
args,
|
608
|
-
functionName,
|
609
|
-
data: data || "0x"
|
610
|
-
});
|
611
|
-
} catch (err) {
|
612
|
-
throw getContractError(err, {
|
613
|
-
abi,
|
614
|
-
address,
|
615
|
-
args,
|
616
|
-
docsPath: "/docs/contract/readContract",
|
617
|
-
functionName
|
618
|
-
});
|
619
|
-
}
|
620
|
-
}
|
621
|
-
|
622
|
-
// src/actions/public/multicall.ts
|
623
|
-
async function multicall(client, args) {
|
624
|
-
const {
|
625
|
-
allowFailure = true,
|
626
|
-
blockNumber,
|
627
|
-
blockTag,
|
628
|
-
contracts,
|
629
|
-
multicallAddress
|
630
|
-
} = args;
|
631
|
-
const calls = contracts.map(({ abi, address, args: args2, functionName }) => {
|
632
|
-
try {
|
633
|
-
const callData = encodeFunctionData({
|
634
|
-
abi,
|
635
|
-
args: args2,
|
636
|
-
functionName
|
637
|
-
});
|
638
|
-
return {
|
639
|
-
allowFailure: true,
|
640
|
-
callData,
|
641
|
-
target: address
|
642
|
-
};
|
643
|
-
} catch (err) {
|
644
|
-
const error = getContractError(err, {
|
645
|
-
abi,
|
646
|
-
address,
|
647
|
-
args: args2,
|
648
|
-
docsPath: "/docs/contract/multicall",
|
649
|
-
functionName
|
650
|
-
});
|
651
|
-
if (!allowFailure)
|
652
|
-
throw error;
|
653
|
-
return {
|
654
|
-
allowFailure: true,
|
655
|
-
callData: "0x",
|
656
|
-
target: address
|
657
|
-
};
|
658
|
-
}
|
659
|
-
});
|
660
|
-
const results = await readContract(client, {
|
661
|
-
abi: multicall3Abi,
|
662
|
-
address: multicallAddress,
|
663
|
-
args: [calls],
|
664
|
-
blockNumber,
|
665
|
-
blockTag,
|
666
|
-
functionName: "aggregate3"
|
667
|
-
});
|
668
|
-
return results.map(({ returnData, success }, i) => {
|
669
|
-
const { callData } = calls[i];
|
670
|
-
const { abi, address, functionName, args: args2 } = contracts[i];
|
671
|
-
try {
|
672
|
-
if (callData === "0x")
|
673
|
-
throw new AbiDecodingZeroDataError();
|
674
|
-
if (!success)
|
675
|
-
throw new RawContractError({ data: returnData });
|
676
|
-
const result = decodeFunctionResult({
|
677
|
-
abi,
|
678
|
-
data: returnData,
|
679
|
-
functionName
|
680
|
-
});
|
681
|
-
return { result, status: "success" };
|
682
|
-
} catch (err) {
|
683
|
-
const error = getContractError(err, {
|
684
|
-
abi,
|
685
|
-
address,
|
686
|
-
args: args2,
|
687
|
-
docsPath: "/docs/contract/multicall",
|
688
|
-
functionName
|
689
|
-
});
|
690
|
-
if (!allowFailure)
|
691
|
-
throw error;
|
692
|
-
return { error, result: void 0, status: "failure" };
|
693
|
-
}
|
694
|
-
});
|
695
|
-
}
|
696
|
-
|
697
|
-
// src/actions/public/uninstallFilter.ts
|
698
|
-
async function uninstallFilter(client, { filter }) {
|
699
|
-
return client.request({
|
700
|
-
method: "eth_uninstallFilter",
|
701
|
-
params: [filter.id]
|
702
|
-
});
|
703
|
-
}
|
704
|
-
|
705
|
-
// src/utils/observe.ts
|
706
|
-
var listenersCache = /* @__PURE__ */ new Map();
|
707
|
-
var cleanupCache = /* @__PURE__ */ new Map();
|
708
|
-
var callbackCount = 0;
|
709
|
-
function observe(observerId, callbacks, fn) {
|
710
|
-
const callbackId = ++callbackCount;
|
711
|
-
const getListeners = () => listenersCache.get(observerId) || [];
|
712
|
-
const unsubscribe = () => {
|
713
|
-
const listeners2 = getListeners();
|
714
|
-
listenersCache.set(
|
715
|
-
observerId,
|
716
|
-
listeners2.filter((cb) => cb.id !== callbackId)
|
717
|
-
);
|
718
|
-
};
|
719
|
-
const unwatch = () => {
|
720
|
-
const cleanup2 = cleanupCache.get(observerId);
|
721
|
-
if (getListeners().length === 1 && cleanup2)
|
722
|
-
cleanup2();
|
723
|
-
unsubscribe();
|
724
|
-
};
|
725
|
-
const listeners = getListeners();
|
726
|
-
listenersCache.set(observerId, [
|
727
|
-
...listeners,
|
728
|
-
{ id: callbackId, fns: callbacks }
|
729
|
-
]);
|
730
|
-
if (listeners && listeners.length > 0)
|
731
|
-
return unwatch;
|
732
|
-
let emit = {};
|
733
|
-
for (const key in callbacks) {
|
734
|
-
emit[key] = (...args) => {
|
735
|
-
const listeners2 = getListeners();
|
736
|
-
if (listeners2.length === 0)
|
737
|
-
return;
|
738
|
-
listeners2.forEach((listener) => listener.fns[key]?.(...args));
|
739
|
-
};
|
740
|
-
}
|
741
|
-
const cleanup = fn(emit);
|
742
|
-
if (typeof cleanup === "function")
|
743
|
-
cleanupCache.set(observerId, cleanup);
|
744
|
-
return unwatch;
|
745
|
-
}
|
746
|
-
|
747
|
-
// src/utils/poll.ts
|
748
|
-
function poll(fn, { emitOnBegin, initialWaitTime, interval }) {
|
749
|
-
let active = true;
|
750
|
-
const unwatch = () => active = false;
|
751
|
-
const watch = async () => {
|
752
|
-
let data;
|
753
|
-
if (emitOnBegin)
|
754
|
-
data = await fn({ unpoll: unwatch });
|
755
|
-
const initialWait = await initialWaitTime?.(data) ?? interval;
|
756
|
-
await wait(initialWait);
|
757
|
-
const poll2 = async () => {
|
758
|
-
if (!active)
|
759
|
-
return;
|
760
|
-
await fn({ unpoll: unwatch });
|
761
|
-
await wait(interval);
|
762
|
-
poll2();
|
763
|
-
};
|
764
|
-
poll2();
|
765
|
-
};
|
766
|
-
watch();
|
767
|
-
return unwatch;
|
768
|
-
}
|
769
|
-
|
770
|
-
// src/actions/public/watchBlockNumber.ts
|
771
|
-
function watchBlockNumber(client, {
|
772
|
-
emitOnBegin = false,
|
773
|
-
emitMissed = false,
|
774
|
-
onBlockNumber,
|
775
|
-
onError,
|
776
|
-
pollingInterval = client.pollingInterval
|
777
|
-
}) {
|
778
|
-
const observerId = JSON.stringify([
|
779
|
-
"watchBlockNumber",
|
780
|
-
client.uid,
|
781
|
-
emitOnBegin,
|
782
|
-
emitMissed,
|
783
|
-
pollingInterval
|
784
|
-
]);
|
785
|
-
let prevBlockNumber;
|
786
|
-
return observe(
|
787
|
-
observerId,
|
788
|
-
{ onBlockNumber, onError },
|
789
|
-
(emit) => poll(
|
790
|
-
async () => {
|
791
|
-
try {
|
792
|
-
const blockNumber = await getBlockNumber(client, { maxAge: 0 });
|
793
|
-
if (prevBlockNumber) {
|
794
|
-
if (blockNumber === prevBlockNumber)
|
795
|
-
return;
|
796
|
-
if (blockNumber - prevBlockNumber > 1 && emitMissed) {
|
797
|
-
for (let i = prevBlockNumber + 1n; i < blockNumber; i++) {
|
798
|
-
emit.onBlockNumber(i, prevBlockNumber);
|
799
|
-
prevBlockNumber = i;
|
800
|
-
}
|
801
|
-
}
|
802
|
-
}
|
803
|
-
prevBlockNumber = blockNumber;
|
804
|
-
emit.onBlockNumber(blockNumber, prevBlockNumber);
|
805
|
-
} catch (err) {
|
806
|
-
emit.onError?.(err);
|
807
|
-
}
|
808
|
-
},
|
809
|
-
{
|
810
|
-
emitOnBegin,
|
811
|
-
interval: pollingInterval
|
812
|
-
}
|
813
|
-
)
|
814
|
-
);
|
815
|
-
}
|
816
|
-
|
817
|
-
// src/actions/public/watchBlocks.ts
|
818
|
-
function watchBlocks(client, {
|
819
|
-
blockTag = "latest",
|
820
|
-
emitMissed = false,
|
821
|
-
emitOnBegin = false,
|
822
|
-
onBlock,
|
823
|
-
onError,
|
824
|
-
includeTransactions = false,
|
825
|
-
pollingInterval = client.pollingInterval
|
826
|
-
}) {
|
827
|
-
const observerId = JSON.stringify([
|
828
|
-
"watchBlocks",
|
829
|
-
client.uid,
|
830
|
-
emitMissed,
|
831
|
-
emitOnBegin,
|
832
|
-
includeTransactions,
|
833
|
-
pollingInterval
|
834
|
-
]);
|
835
|
-
let prevBlock;
|
836
|
-
return observe(
|
837
|
-
observerId,
|
838
|
-
{ onBlock, onError },
|
839
|
-
(emit) => poll(
|
840
|
-
async () => {
|
841
|
-
try {
|
842
|
-
const block = await getBlock(client, {
|
843
|
-
blockTag,
|
844
|
-
includeTransactions
|
845
|
-
});
|
846
|
-
if (block.number && prevBlock?.number) {
|
847
|
-
if (block.number === prevBlock.number)
|
848
|
-
return;
|
849
|
-
if (block.number - prevBlock.number > 1 && emitMissed) {
|
850
|
-
for (let i = prevBlock?.number + 1n; i < block.number; i++) {
|
851
|
-
const block2 = await getBlock(client, {
|
852
|
-
blockNumber: i,
|
853
|
-
includeTransactions
|
854
|
-
});
|
855
|
-
emit.onBlock(block2, prevBlock);
|
856
|
-
prevBlock = block2;
|
857
|
-
}
|
858
|
-
}
|
859
|
-
}
|
860
|
-
emit.onBlock(block, prevBlock);
|
861
|
-
prevBlock = block;
|
862
|
-
} catch (err) {
|
863
|
-
emit.onError?.(err);
|
864
|
-
}
|
865
|
-
},
|
866
|
-
{
|
867
|
-
emitOnBegin,
|
868
|
-
interval: pollingInterval
|
869
|
-
}
|
870
|
-
)
|
871
|
-
);
|
872
|
-
}
|
873
|
-
|
874
|
-
// src/actions/public/watchContractEvent.ts
|
875
|
-
function watchContractEvent(client, {
|
876
|
-
abi,
|
877
|
-
address,
|
878
|
-
args,
|
879
|
-
batch = true,
|
880
|
-
eventName,
|
881
|
-
onError,
|
882
|
-
onLogs,
|
883
|
-
pollingInterval = client.pollingInterval
|
884
|
-
}) {
|
885
|
-
const observerId = JSON.stringify([
|
886
|
-
"watchContractEvent",
|
887
|
-
address,
|
888
|
-
args,
|
889
|
-
batch,
|
890
|
-
client.uid,
|
891
|
-
eventName,
|
892
|
-
pollingInterval
|
893
|
-
]);
|
894
|
-
return observe(observerId, { onLogs, onError }, (emit) => {
|
895
|
-
let currentBlockNumber;
|
896
|
-
let filter;
|
897
|
-
let initialized = false;
|
898
|
-
const unwatch = poll(
|
899
|
-
async () => {
|
900
|
-
if (!initialized) {
|
901
|
-
try {
|
902
|
-
filter = await createContractEventFilter(client, {
|
903
|
-
abi,
|
904
|
-
address,
|
905
|
-
args,
|
906
|
-
eventName
|
907
|
-
});
|
908
|
-
} catch {
|
909
|
-
}
|
910
|
-
initialized = true;
|
911
|
-
return;
|
912
|
-
}
|
913
|
-
try {
|
914
|
-
let logs;
|
915
|
-
if (filter) {
|
916
|
-
logs = await getFilterChanges(client, { filter });
|
917
|
-
} else {
|
918
|
-
const blockNumber = await getBlockNumber(client);
|
919
|
-
if (currentBlockNumber && currentBlockNumber !== blockNumber) {
|
920
|
-
logs = await getLogs(client, {
|
921
|
-
address,
|
922
|
-
args,
|
923
|
-
fromBlock: blockNumber,
|
924
|
-
toBlock: blockNumber,
|
925
|
-
event: getAbiItem({
|
926
|
-
abi,
|
927
|
-
name: eventName
|
928
|
-
})
|
929
|
-
});
|
930
|
-
} else {
|
931
|
-
logs = [];
|
932
|
-
}
|
933
|
-
currentBlockNumber = blockNumber;
|
934
|
-
}
|
935
|
-
if (logs.length === 0)
|
936
|
-
return;
|
937
|
-
if (batch)
|
938
|
-
emit.onLogs(logs);
|
939
|
-
else
|
940
|
-
logs.forEach((log) => emit.onLogs([log]));
|
941
|
-
} catch (err) {
|
942
|
-
emit.onError?.(err);
|
943
|
-
}
|
944
|
-
},
|
945
|
-
{
|
946
|
-
emitOnBegin: true,
|
947
|
-
interval: pollingInterval
|
948
|
-
}
|
949
|
-
);
|
950
|
-
return async () => {
|
951
|
-
if (filter)
|
952
|
-
await uninstallFilter(client, { filter });
|
953
|
-
unwatch();
|
954
|
-
};
|
955
|
-
});
|
956
|
-
}
|
957
|
-
|
958
|
-
// src/actions/public/watchEvent.ts
|
959
|
-
function watchEvent(client, {
|
960
|
-
address,
|
961
|
-
args,
|
962
|
-
batch = true,
|
963
|
-
event,
|
964
|
-
onError,
|
965
|
-
onLogs,
|
966
|
-
pollingInterval = client.pollingInterval
|
967
|
-
}) {
|
968
|
-
const observerId = JSON.stringify([
|
969
|
-
"watchEvent",
|
970
|
-
address,
|
971
|
-
args,
|
972
|
-
batch,
|
973
|
-
client.uid,
|
974
|
-
event,
|
975
|
-
pollingInterval
|
976
|
-
]);
|
977
|
-
return observe(observerId, { onLogs, onError }, (emit) => {
|
978
|
-
let currentBlockNumber;
|
979
|
-
let filter;
|
980
|
-
let initialized = false;
|
981
|
-
const unwatch = poll(
|
982
|
-
async () => {
|
983
|
-
if (!initialized) {
|
984
|
-
try {
|
985
|
-
filter = await createEventFilter(client, {
|
986
|
-
address,
|
987
|
-
args,
|
988
|
-
event
|
989
|
-
});
|
990
|
-
} catch {
|
991
|
-
}
|
992
|
-
initialized = true;
|
993
|
-
return;
|
994
|
-
}
|
995
|
-
try {
|
996
|
-
let logs;
|
997
|
-
if (filter) {
|
998
|
-
logs = await getFilterChanges(client, { filter });
|
999
|
-
} else {
|
1000
|
-
const blockNumber = await getBlockNumber(client);
|
1001
|
-
if (currentBlockNumber && currentBlockNumber !== blockNumber) {
|
1002
|
-
logs = await getLogs(client, {
|
1003
|
-
address,
|
1004
|
-
args,
|
1005
|
-
fromBlock: blockNumber,
|
1006
|
-
toBlock: blockNumber,
|
1007
|
-
event
|
1008
|
-
});
|
1009
|
-
} else {
|
1010
|
-
logs = [];
|
1011
|
-
}
|
1012
|
-
currentBlockNumber = blockNumber;
|
1013
|
-
}
|
1014
|
-
if (logs.length === 0)
|
1015
|
-
return;
|
1016
|
-
if (batch)
|
1017
|
-
emit.onLogs(logs);
|
1018
|
-
else
|
1019
|
-
logs.forEach((log) => emit.onLogs([log]));
|
1020
|
-
} catch (err) {
|
1021
|
-
emit.onError?.(err);
|
1022
|
-
}
|
1023
|
-
},
|
1024
|
-
{
|
1025
|
-
emitOnBegin: true,
|
1026
|
-
interval: pollingInterval
|
1027
|
-
}
|
1028
|
-
);
|
1029
|
-
return async () => {
|
1030
|
-
if (filter)
|
1031
|
-
await uninstallFilter(client, { filter });
|
1032
|
-
unwatch();
|
1033
|
-
};
|
1034
|
-
});
|
1035
|
-
}
|
1036
|
-
|
1037
|
-
// src/actions/public/watchPendingTransactions.ts
|
1038
|
-
function watchPendingTransactions(client, {
|
1039
|
-
batch = true,
|
1040
|
-
onError,
|
1041
|
-
onTransactions,
|
1042
|
-
pollingInterval = client.pollingInterval
|
1043
|
-
}) {
|
1044
|
-
const observerId = JSON.stringify([
|
1045
|
-
"watchPendingTransactions",
|
1046
|
-
client.uid,
|
1047
|
-
batch,
|
1048
|
-
pollingInterval
|
1049
|
-
]);
|
1050
|
-
return observe(observerId, { onTransactions, onError }, (emit) => {
|
1051
|
-
let filter;
|
1052
|
-
const unwatch = poll(
|
1053
|
-
async () => {
|
1054
|
-
try {
|
1055
|
-
if (!filter) {
|
1056
|
-
try {
|
1057
|
-
filter = await createPendingTransactionFilter(client);
|
1058
|
-
return;
|
1059
|
-
} catch (err) {
|
1060
|
-
unwatch();
|
1061
|
-
throw err;
|
1062
|
-
}
|
1063
|
-
}
|
1064
|
-
const hashes = await getFilterChanges(client, { filter });
|
1065
|
-
if (hashes.length === 0)
|
1066
|
-
return;
|
1067
|
-
if (batch)
|
1068
|
-
emit.onTransactions(hashes);
|
1069
|
-
else
|
1070
|
-
hashes.forEach((hash) => emit.onTransactions([hash]));
|
1071
|
-
} catch (err) {
|
1072
|
-
emit.onError?.(err);
|
1073
|
-
}
|
1074
|
-
},
|
1075
|
-
{
|
1076
|
-
emitOnBegin: true,
|
1077
|
-
interval: pollingInterval
|
1078
|
-
}
|
1079
|
-
);
|
1080
|
-
return async () => {
|
1081
|
-
if (filter)
|
1082
|
-
await uninstallFilter(client, { filter });
|
1083
|
-
unwatch();
|
1084
|
-
};
|
1085
|
-
});
|
1086
|
-
}
|
1087
|
-
|
1088
|
-
// src/actions/public/waitForTransactionReceipt.ts
|
1089
|
-
async function waitForTransactionReceipt(client, {
|
1090
|
-
confirmations = 1,
|
1091
|
-
hash,
|
1092
|
-
onReplaced,
|
1093
|
-
pollingInterval = client.pollingInterval,
|
1094
|
-
timeout
|
1095
|
-
}) {
|
1096
|
-
const observerId = JSON.stringify([
|
1097
|
-
"waitForTransactionReceipt",
|
1098
|
-
client.uid,
|
1099
|
-
hash
|
1100
|
-
]);
|
1101
|
-
let transaction;
|
1102
|
-
let replacedTransaction;
|
1103
|
-
let receipt;
|
1104
|
-
return new Promise((resolve, reject) => {
|
1105
|
-
if (timeout)
|
1106
|
-
setTimeout(
|
1107
|
-
() => reject(new WaitForTransactionReceiptTimeoutError({ hash })),
|
1108
|
-
timeout
|
1109
|
-
);
|
1110
|
-
const unobserve = observe(
|
1111
|
-
observerId,
|
1112
|
-
{ onReplaced, resolve, reject },
|
1113
|
-
(emit) => {
|
1114
|
-
const unwatch = watchBlockNumber(client, {
|
1115
|
-
emitMissed: true,
|
1116
|
-
emitOnBegin: true,
|
1117
|
-
pollingInterval,
|
1118
|
-
async onBlockNumber(blockNumber) {
|
1119
|
-
const done = async (fn) => {
|
1120
|
-
unwatch();
|
1121
|
-
fn();
|
1122
|
-
unobserve();
|
1123
|
-
};
|
1124
|
-
try {
|
1125
|
-
if (receipt) {
|
1126
|
-
if (blockNumber - receipt.blockNumber + 1n < confirmations)
|
1127
|
-
return;
|
1128
|
-
done(() => emit.resolve(receipt));
|
1129
|
-
return;
|
1130
|
-
}
|
1131
|
-
transaction = await getTransaction(client, { hash });
|
1132
|
-
receipt = await getTransactionReceipt(client, { hash });
|
1133
|
-
if (blockNumber - receipt.blockNumber + 1n < confirmations)
|
1134
|
-
return;
|
1135
|
-
done(() => emit.resolve(receipt));
|
1136
|
-
} catch (err) {
|
1137
|
-
if (transaction && (err instanceof TransactionNotFoundError || err instanceof TransactionReceiptNotFoundError)) {
|
1138
|
-
replacedTransaction = transaction;
|
1139
|
-
const block = await getBlock(client, {
|
1140
|
-
blockNumber,
|
1141
|
-
includeTransactions: true
|
1142
|
-
});
|
1143
|
-
const replacementTransaction = block.transactions.find(
|
1144
|
-
({ from, nonce }) => from === replacedTransaction.from && nonce === replacedTransaction.nonce
|
1145
|
-
);
|
1146
|
-
if (!replacementTransaction)
|
1147
|
-
return;
|
1148
|
-
receipt = await getTransactionReceipt(client, {
|
1149
|
-
hash: replacementTransaction.hash
|
1150
|
-
});
|
1151
|
-
if (blockNumber - receipt.blockNumber + 1n < confirmations)
|
1152
|
-
return;
|
1153
|
-
let reason = "replaced";
|
1154
|
-
if (replacementTransaction.to === replacedTransaction.to && replacementTransaction.value === replacedTransaction.value) {
|
1155
|
-
reason = "repriced";
|
1156
|
-
} else if (replacementTransaction.from === replacementTransaction.to && replacementTransaction.value === 0n) {
|
1157
|
-
reason = "cancelled";
|
1158
|
-
}
|
1159
|
-
done(() => {
|
1160
|
-
emit.onReplaced?.({
|
1161
|
-
reason,
|
1162
|
-
replacedTransaction,
|
1163
|
-
transaction: replacementTransaction,
|
1164
|
-
transactionReceipt: receipt
|
1165
|
-
});
|
1166
|
-
emit.resolve(receipt);
|
1167
|
-
});
|
1168
|
-
} else {
|
1169
|
-
done(() => emit.reject(err));
|
1170
|
-
}
|
1171
|
-
}
|
1172
|
-
}
|
1173
|
-
});
|
1174
|
-
return unwatch;
|
1175
|
-
}
|
1176
|
-
);
|
1177
|
-
});
|
1178
|
-
}
|
1179
|
-
|
1180
|
-
export {
|
1181
|
-
call,
|
1182
|
-
simulateContract,
|
1183
|
-
createPendingTransactionFilter,
|
1184
|
-
createBlockFilter,
|
1185
|
-
createEventFilter,
|
1186
|
-
createContractEventFilter,
|
1187
|
-
estimateGas,
|
1188
|
-
estimateContractGas,
|
1189
|
-
getBalance,
|
1190
|
-
getBlock,
|
1191
|
-
getBlockNumberCache,
|
1192
|
-
getBlockNumber,
|
1193
|
-
getBlockTransactionCount,
|
1194
|
-
getBytecode,
|
1195
|
-
getChainId,
|
1196
|
-
getFeeHistory,
|
1197
|
-
getFilterChanges,
|
1198
|
-
getFilterLogs,
|
1199
|
-
getGasPrice,
|
1200
|
-
getLogs,
|
1201
|
-
getStorageAt,
|
1202
|
-
getTransaction,
|
1203
|
-
getTransactionConfirmations,
|
1204
|
-
getTransactionCount,
|
1205
|
-
getTransactionReceipt,
|
1206
|
-
readContract,
|
1207
|
-
multicall,
|
1208
|
-
uninstallFilter,
|
1209
|
-
waitForTransactionReceipt,
|
1210
|
-
watchBlockNumber,
|
1211
|
-
watchBlocks,
|
1212
|
-
watchContractEvent,
|
1213
|
-
watchEvent,
|
1214
|
-
watchPendingTransactions
|
1215
|
-
};
|
1216
|
-
//# sourceMappingURL=chunk-WQDVW7EJ.mjs.map
|