viem 0.0.1-alpha.3 → 0.0.1-alpha.31
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/chains/package.json +1 -1
- package/contract/package.json +4 -0
- package/dist/chain-00b37e4e.d.ts +543 -0
- package/dist/chain-38182d92.d.ts +5 -0
- package/dist/chains.d.ts +1305 -74
- package/dist/chains.js +125 -130
- package/dist/chains.js.map +1 -0
- package/dist/chains.mjs +129 -0
- package/dist/chains.mjs.map +1 -0
- package/dist/chunk-5STAX3WF.js +265 -0
- package/dist/chunk-5STAX3WF.js.map +1 -0
- package/dist/chunk-6ZFIUYGC.mjs +3436 -0
- package/dist/chunk-6ZFIUYGC.mjs.map +1 -0
- package/dist/chunk-APXHGB76.mjs +197 -0
- package/dist/chunk-APXHGB76.mjs.map +1 -0
- package/dist/chunk-C54QK7K3.mjs +210 -0
- package/dist/chunk-C54QK7K3.mjs.map +1 -0
- package/dist/{chunk-YZEQFYZ3.js → chunk-IBWRBL2I.mjs} +725 -556
- package/dist/chunk-IBWRBL2I.mjs.map +1 -0
- package/dist/chunk-J7QHQ26Y.js +3436 -0
- package/dist/chunk-J7QHQ26Y.js.map +1 -0
- package/dist/chunk-MYFKW55L.js +210 -0
- package/dist/chunk-MYFKW55L.js.map +1 -0
- package/dist/chunk-NCPBWOQA.js +1216 -0
- package/dist/chunk-NCPBWOQA.js.map +1 -0
- package/dist/chunk-QBB3DFIB.mjs +265 -0
- package/dist/chunk-QBB3DFIB.mjs.map +1 -0
- package/dist/chunk-UUULPQHV.js +197 -0
- package/dist/chunk-UUULPQHV.js.map +1 -0
- package/dist/contract.d.ts +11 -0
- package/dist/contract.js +57 -0
- package/dist/contract.js.map +1 -0
- package/dist/contract.mjs +57 -0
- package/dist/contract.mjs.map +1 -0
- package/dist/createClient-5258d590.d.ts +70 -0
- package/dist/createPublicClient-99be385b.d.ts +650 -0
- package/dist/{eip1193-8b4d90ce.d.ts → eip1193-fcdeee04.d.ts} +13 -10
- package/dist/ens.d.ts +22 -0
- package/dist/ens.js +22 -0
- package/dist/ens.js.map +1 -0
- package/dist/ens.mjs +22 -0
- package/dist/ens.mjs.map +1 -0
- package/dist/formatAbiItem-50cb39d8.d.ts +14 -0
- package/dist/getAbiItem-6d4f64d2.d.ts +97 -0
- package/dist/index.d.ts +251 -67
- package/dist/index.js +769 -344
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +769 -0
- package/dist/index.mjs.map +1 -0
- package/dist/namehash-88f4639d.d.ts +22 -0
- package/dist/parseGwei-8af7a0a6.d.ts +509 -0
- package/dist/public.d.ts +29 -0
- package/dist/public.js +60 -0
- package/dist/public.js.map +1 -0
- package/dist/public.mjs +60 -0
- package/dist/public.mjs.map +1 -0
- package/dist/test-79ec416c.d.ts +213 -0
- package/dist/test.d.ts +20 -0
- package/dist/test.js +62 -0
- package/dist/test.js.map +1 -0
- package/dist/test.mjs +62 -0
- package/dist/test.mjs.map +1 -0
- package/dist/utils/index.d.ts +52 -7
- package/dist/utils/index.js +187 -126
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +187 -0
- package/dist/utils/index.mjs.map +1 -0
- package/dist/wallet-cf5c8351.d.ts +115 -0
- package/dist/wallet.d.ts +7 -0
- package/dist/wallet.js +24 -0
- package/dist/wallet.js.map +1 -0
- package/dist/wallet.mjs +24 -0
- package/dist/wallet.mjs.map +1 -0
- package/dist/window.d.ts +5 -2
- package/dist/window.js +1 -0
- package/dist/window.js.map +1 -0
- package/dist/window.mjs +1 -0
- package/dist/window.mjs.map +1 -0
- package/ens/package.json +4 -0
- package/package.json +46 -73
- package/public/package.json +4 -0
- package/test/package.json +4 -0
- package/utils/package.json +1 -1
- package/wallet/package.json +4 -0
- package/window/package.json +1 -1
- package/actions/package.json +0 -4
- package/clients/package.json +0 -4
- package/dist/actions/index.d.ts +0 -7
- package/dist/actions/index.js +0 -124
- package/dist/chunk-SRDTRROA.js +0 -1214
- package/dist/chunk-TLEMV4T3.js +0 -258
- package/dist/chunk-WZITKXV3.js +0 -996
- package/dist/clients/index.d.ts +0 -7
- package/dist/clients/index.js +0 -23
- package/dist/createWalletClient-15ad1601.d.ts +0 -130
- package/dist/parseGwei-0f85e8ca.d.ts +0 -248
- package/dist/rpc-15b85963.d.ts +0 -292
- package/dist/rpc-26932bae.d.ts +0 -61
- package/dist/transactionRequest-f538ea86.d.ts +0 -44
- package/dist/watchAsset-0c9d01e2.d.ts +0 -522
- package/dist/webSocket-b55b0951.d.ts +0 -83
@@ -0,0 +1,1216 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
var _chunkJ7QHQ26Yjs = require('./chunk-J7QHQ26Y.js');
|
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
|
+
_chunkJ7QHQ26Yjs.assertRequest.call(void 0, args);
|
52
|
+
const blockNumberHex = blockNumber ? _chunkJ7QHQ26Yjs.numberToHex.call(void 0, blockNumber) : void 0;
|
53
|
+
const formatter = _optionalChain([client, 'access', _ => _.chain, 'optionalAccess', _2 => _2.formatters, 'optionalAccess', _3 => _3.transactionRequest]);
|
54
|
+
const request_ = _chunkJ7QHQ26Yjs.format.call(void 0,
|
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
|
+
..._chunkJ7QHQ26Yjs.extract.call(void 0, rest, { formatter })
|
68
|
+
},
|
69
|
+
{
|
70
|
+
formatter: formatter || _chunkJ7QHQ26Yjs.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 _chunkJ7QHQ26Yjs.getCallError.call(void 0, 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 = _chunkJ7QHQ26Yjs.encodeFunctionData.call(void 0, {
|
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 = _chunkJ7QHQ26Yjs.decodeFunctionResult.call(void 0, {
|
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 _chunkJ7QHQ26Yjs.getContractError.call(void 0, 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 = _chunkJ7QHQ26Yjs.encodeEventTopics.call(void 0, {
|
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" ? _chunkJ7QHQ26Yjs.numberToHex.call(void 0, fromBlock) : fromBlock,
|
172
|
+
toBlock: typeof toBlock === "bigint" ? _chunkJ7QHQ26Yjs.numberToHex.call(void 0, 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 ? _chunkJ7QHQ26Yjs.encodeEventTopics.call(void 0, {
|
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" ? _chunkJ7QHQ26Yjs.numberToHex.call(void 0, fromBlock) : fromBlock,
|
206
|
+
toBlock: typeof toBlock === "bigint" ? _chunkJ7QHQ26Yjs.numberToHex.call(void 0, 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
|
+
_chunkJ7QHQ26Yjs.assertRequest.call(void 0, args);
|
239
|
+
const blockNumberHex = blockNumber ? _chunkJ7QHQ26Yjs.numberToHex.call(void 0, blockNumber) : void 0;
|
240
|
+
const formatter = _optionalChain([client, 'access', _4 => _4.chain, 'optionalAccess', _5 => _5.formatters, 'optionalAccess', _6 => _6.transactionRequest]);
|
241
|
+
const request_ = _chunkJ7QHQ26Yjs.format.call(void 0,
|
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
|
+
..._chunkJ7QHQ26Yjs.extract.call(void 0, rest, { formatter })
|
255
|
+
},
|
256
|
+
{
|
257
|
+
formatter: formatter || _chunkJ7QHQ26Yjs.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 _chunkJ7QHQ26Yjs.getEstimateGasError.call(void 0, 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 = _chunkJ7QHQ26Yjs.encodeFunctionData.call(void 0, {
|
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 _chunkJ7QHQ26Yjs.getContractError.call(void 0, 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 ? _chunkJ7QHQ26Yjs.numberToHex.call(void 0, 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 ? _chunkJ7QHQ26Yjs.numberToHex.call(void 0, 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 (0, _chunkJ7QHQ26Yjs.BlockNotFoundError)({ blockHash, blockNumber });
|
337
|
+
return _chunkJ7QHQ26Yjs.format.call(void 0, block, {
|
338
|
+
formatter: _optionalChain([client, 'access', _7 => _7.chain, 'optionalAccess', _8 => _8.formatters, 'optionalAccess', _9 => _9.block]) || _chunkJ7QHQ26Yjs.formatBlock
|
339
|
+
});
|
340
|
+
}
|
341
|
+
|
342
|
+
// src/actions/public/getBlockNumber.ts
|
343
|
+
var cacheKey = (id) => `blockNumber.${id}`;
|
344
|
+
function getBlockNumberCache(id) {
|
345
|
+
return _chunkJ7QHQ26Yjs.getCache.call(void 0, cacheKey(id));
|
346
|
+
}
|
347
|
+
async function getBlockNumber(client, { maxAge = client.pollingInterval } = {}) {
|
348
|
+
const blockNumberHex = await _chunkJ7QHQ26Yjs.withCache.call(void 0,
|
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 ? _chunkJ7QHQ26Yjs.numberToHex.call(void 0, 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 _chunkJ7QHQ26Yjs.hexToNumber.call(void 0, count);
|
377
|
+
}
|
378
|
+
|
379
|
+
// src/actions/public/getBytecode.ts
|
380
|
+
async function getBytecode(client, { address, blockNumber, blockTag = "latest" }) {
|
381
|
+
const blockNumberHex = blockNumber !== void 0 ? _chunkJ7QHQ26Yjs.numberToHex.call(void 0, 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 _chunkJ7QHQ26Yjs.hexToNumber.call(void 0, 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 ? _chunkJ7QHQ26Yjs.numberToHex.call(void 0, blockNumber) : void 0;
|
405
|
+
const feeHistory = await client.request({
|
406
|
+
method: "eth_feeHistory",
|
407
|
+
params: [
|
408
|
+
_chunkJ7QHQ26Yjs.numberToHex.call(void 0, blockCount),
|
409
|
+
blockNumberHex || blockTag,
|
410
|
+
rewardPercentiles
|
411
|
+
]
|
412
|
+
});
|
413
|
+
return _chunkJ7QHQ26Yjs.formatFeeHistory.call(void 0, 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 ? _chunkJ7QHQ26Yjs.decodeEventLog.call(void 0, {
|
426
|
+
abi: filter.abi,
|
427
|
+
data: log.data,
|
428
|
+
topics: log.topics
|
429
|
+
}) : { eventName: void 0, args: void 0 };
|
430
|
+
return _chunkJ7QHQ26Yjs.formatLog.call(void 0, 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 ? _chunkJ7QHQ26Yjs.decodeEventLog.call(void 0, {
|
442
|
+
abi: filter.abi,
|
443
|
+
data: log.data,
|
444
|
+
topics: log.topics
|
445
|
+
}) : { eventName: void 0, args: void 0 };
|
446
|
+
return _chunkJ7QHQ26Yjs.formatLog.call(void 0, 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 = _chunkJ7QHQ26Yjs.encodeEventTopics.call(void 0, {
|
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" ? _chunkJ7QHQ26Yjs.numberToHex.call(void 0, fromBlock) : fromBlock,
|
488
|
+
toBlock: typeof toBlock === "bigint" ? _chunkJ7QHQ26Yjs.numberToHex.call(void 0, toBlock) : toBlock
|
489
|
+
}
|
490
|
+
]
|
491
|
+
});
|
492
|
+
}
|
493
|
+
return logs.map((log) => {
|
494
|
+
const { eventName, args: args2 } = event ? _chunkJ7QHQ26Yjs.decodeEventLog.call(void 0, {
|
495
|
+
abi: [event],
|
496
|
+
data: log.data,
|
497
|
+
topics: log.topics
|
498
|
+
}) : { eventName: void 0, args: void 0 };
|
499
|
+
return _chunkJ7QHQ26Yjs.formatLog.call(void 0, 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 ? _chunkJ7QHQ26Yjs.numberToHex.call(void 0, 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 ? _chunkJ7QHQ26Yjs.numberToHex.call(void 0, 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, _chunkJ7QHQ26Yjs.numberToHex.call(void 0, index)]
|
532
|
+
});
|
533
|
+
} else if (blockNumberHex || blockTag) {
|
534
|
+
transaction = await client.request({
|
535
|
+
method: "eth_getTransactionByBlockNumberAndIndex",
|
536
|
+
params: [blockNumberHex || blockTag, _chunkJ7QHQ26Yjs.numberToHex.call(void 0, index)]
|
537
|
+
});
|
538
|
+
}
|
539
|
+
if (!transaction)
|
540
|
+
throw new (0, _chunkJ7QHQ26Yjs.TransactionNotFoundError)({
|
541
|
+
blockHash,
|
542
|
+
blockNumber,
|
543
|
+
blockTag,
|
544
|
+
hash,
|
545
|
+
index
|
546
|
+
});
|
547
|
+
return _chunkJ7QHQ26Yjs.format.call(void 0, transaction, {
|
548
|
+
formatter: _optionalChain([client, 'access', _10 => _10.chain, 'optionalAccess', _11 => _11.formatters, 'optionalAccess', _12 => _12.transaction]) || _chunkJ7QHQ26Yjs.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 = _optionalChain([transactionReceipt, 'optionalAccess', _13 => _13.blockNumber]) || _optionalChain([transaction, 'optionalAccess', _14 => _14.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 ? _chunkJ7QHQ26Yjs.numberToHex.call(void 0, blockNumber) : blockTag]
|
569
|
+
});
|
570
|
+
return _chunkJ7QHQ26Yjs.hexToNumber.call(void 0, 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 (0, _chunkJ7QHQ26Yjs.TransactionReceiptNotFoundError)({ hash });
|
581
|
+
return _chunkJ7QHQ26Yjs.format.call(void 0, receipt, {
|
582
|
+
formatter: _optionalChain([client, 'access', _15 => _15.chain, 'optionalAccess', _16 => _16.formatters, 'optionalAccess', _17 => _17.transactionReceipt]) || _chunkJ7QHQ26Yjs.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 = _chunkJ7QHQ26Yjs.encodeFunctionData.call(void 0, {
|
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 _chunkJ7QHQ26Yjs.decodeFunctionResult.call(void 0, {
|
606
|
+
abi,
|
607
|
+
args,
|
608
|
+
functionName,
|
609
|
+
data: data || "0x"
|
610
|
+
});
|
611
|
+
} catch (err) {
|
612
|
+
throw _chunkJ7QHQ26Yjs.getContractError.call(void 0, 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 = _chunkJ7QHQ26Yjs.encodeFunctionData.call(void 0, {
|
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 = _chunkJ7QHQ26Yjs.getContractError.call(void 0, 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: _chunkJ7QHQ26Yjs.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 (0, _chunkJ7QHQ26Yjs.AbiDecodingZeroDataError)();
|
674
|
+
if (!success)
|
675
|
+
throw new (0, _chunkJ7QHQ26Yjs.RawContractError)({ data: returnData });
|
676
|
+
const result = _chunkJ7QHQ26Yjs.decodeFunctionResult.call(void 0, {
|
677
|
+
abi,
|
678
|
+
data: returnData,
|
679
|
+
functionName
|
680
|
+
});
|
681
|
+
return { result, status: "success" };
|
682
|
+
} catch (err) {
|
683
|
+
const error = _chunkJ7QHQ26Yjs.getContractError.call(void 0, 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) => _optionalChain([listener, 'access', _18 => _18.fns, 'access', _19 => _19[key], 'optionalCall', _20 => _20(...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 _asyncNullishCoalesce(await _optionalChain([initialWaitTime, 'optionalCall', _21 => _21(data)]), async () => ( interval));
|
756
|
+
await _chunkJ7QHQ26Yjs.wait.call(void 0, initialWait);
|
757
|
+
const poll2 = async () => {
|
758
|
+
if (!active)
|
759
|
+
return;
|
760
|
+
await fn({ unpoll: unwatch });
|
761
|
+
await _chunkJ7QHQ26Yjs.wait.call(void 0, 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
|
+
_optionalChain([emit, 'access', _22 => _22.onError, 'optionalCall', _23 => _23(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 && _optionalChain([prevBlock, 'optionalAccess', _24 => _24.number])) {
|
847
|
+
if (block.number === prevBlock.number)
|
848
|
+
return;
|
849
|
+
if (block.number - prevBlock.number > 1 && emitMissed) {
|
850
|
+
for (let i = _optionalChain([prevBlock, 'optionalAccess', _25 => _25.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
|
+
_optionalChain([emit, 'access', _26 => _26.onError, 'optionalCall', _27 => _27(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 (e) {
|
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: _chunkJ7QHQ26Yjs.getAbiItem.call(void 0, {
|
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
|
+
_optionalChain([emit, 'access', _28 => _28.onError, 'optionalCall', _29 => _29(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 (e2) {
|
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
|
+
_optionalChain([emit, 'access', _30 => _30.onError, 'optionalCall', _31 => _31(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
|
+
_optionalChain([emit, 'access', _32 => _32.onError, 'optionalCall', _33 => _33(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 (0, _chunkJ7QHQ26Yjs.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 _chunkJ7QHQ26Yjs.TransactionNotFoundError || err instanceof _chunkJ7QHQ26Yjs.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
|
+
_optionalChain([emit, 'access', _34 => _34.onReplaced, 'optionalCall', _35 => _35({
|
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
|
+
|
1181
|
+
|
1182
|
+
|
1183
|
+
|
1184
|
+
|
1185
|
+
|
1186
|
+
|
1187
|
+
|
1188
|
+
|
1189
|
+
|
1190
|
+
|
1191
|
+
|
1192
|
+
|
1193
|
+
|
1194
|
+
|
1195
|
+
|
1196
|
+
|
1197
|
+
|
1198
|
+
|
1199
|
+
|
1200
|
+
|
1201
|
+
|
1202
|
+
|
1203
|
+
|
1204
|
+
|
1205
|
+
|
1206
|
+
|
1207
|
+
|
1208
|
+
|
1209
|
+
|
1210
|
+
|
1211
|
+
|
1212
|
+
|
1213
|
+
|
1214
|
+
|
1215
|
+
exports.call = call; exports.simulateContract = simulateContract; exports.createPendingTransactionFilter = createPendingTransactionFilter; exports.createBlockFilter = createBlockFilter; exports.createEventFilter = createEventFilter; exports.createContractEventFilter = createContractEventFilter; exports.estimateGas = estimateGas; exports.estimateContractGas = estimateContractGas; exports.getBalance = getBalance; exports.getBlock = getBlock; exports.getBlockNumberCache = getBlockNumberCache; exports.getBlockNumber = getBlockNumber; exports.getBlockTransactionCount = getBlockTransactionCount; exports.getBytecode = getBytecode; exports.getChainId = getChainId; exports.getFeeHistory = getFeeHistory; exports.getFilterChanges = getFilterChanges; exports.getFilterLogs = getFilterLogs; exports.getGasPrice = getGasPrice; exports.getLogs = getLogs; exports.getStorageAt = getStorageAt; exports.getTransaction = getTransaction; exports.getTransactionConfirmations = getTransactionConfirmations; exports.getTransactionCount = getTransactionCount; exports.getTransactionReceipt = getTransactionReceipt; exports.readContract = readContract; exports.multicall = multicall; exports.uninstallFilter = uninstallFilter; exports.waitForTransactionReceipt = waitForTransactionReceipt; exports.watchBlockNumber = watchBlockNumber; exports.watchBlocks = watchBlocks; exports.watchContractEvent = watchContractEvent; exports.watchEvent = watchEvent; exports.watchPendingTransactions = watchPendingTransactions;
|
1216
|
+
//# sourceMappingURL=chunk-NCPBWOQA.js.map
|