viem 0.0.1-alpha.8 → 0.0.1-cjs.10
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/actions/package.json +1 -1
- package/chains/package.json +1 -1
- package/clients/package.json +1 -1
- package/dist/actions/index.d.ts +5 -4
- package/dist/actions/index.js +125 -124
- package/dist/actions/index.mjs +125 -0
- package/dist/chains.d.ts +2 -2
- package/dist/chains.js +75 -76
- package/dist/chains.mjs +133 -0
- package/dist/chunk-2FDH6XP5.mjs +2616 -0
- package/dist/chunk-46ZFLVHC.js +1084 -0
- package/dist/chunk-5ZBNF5WM.js +2616 -0
- package/dist/{chunk-BIQ5KSX5.js → chunk-CWCWWGBC.mjs} +1 -1
- package/dist/{chunk-N6PIT2C5.js → chunk-HLVCJ7RV.mjs} +49 -12
- package/dist/chunk-SGTIBKHG.js +258 -0
- package/dist/clients/index.d.ts +3 -3
- package/dist/clients/index.js +23 -23
- package/dist/clients/index.mjs +23 -0
- package/dist/{createWalletClient-b5c3c89e.d.ts → createWalletClient-d612fe08.d.ts} +1 -1
- package/dist/{eip1193-100454ab.d.ts → eip1193-020a6f13.d.ts} +1 -1
- package/dist/index.d.ts +40 -18
- package/dist/index.js +374 -374
- package/dist/index.mjs +374 -0
- package/dist/{parseGwei-14f716fc.d.ts → parseGwei-7c87ff41.d.ts} +40 -118
- package/dist/transactionRequest-08d30731.d.ts +132 -0
- package/dist/utils/index.d.ts +38 -5
- package/dist/utils/index.js +148 -138
- package/dist/utils/index.mjs +148 -0
- package/dist/{watchAsset-e99e744d.d.ts → watchAsset-bc6373f4.d.ts} +17 -5
- package/dist/{webSocket-f4abf66c.d.ts → webSocket-7f88e9e0.d.ts} +1 -1
- package/dist/window.d.ts +1 -1
- package/dist/window.js +1 -0
- package/dist/window.mjs +0 -0
- package/package.json +9 -3
- package/utils/package.json +1 -1
- package/window/package.json +1 -1
- package/dist/chunk-4Z43OTO6.js +0 -1349
- package/dist/chunk-ALVD6MNU.js +0 -1113
- package/dist/transactionRequest-3e463099.d.ts +0 -44
@@ -0,0 +1,1084 @@
|
|
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
|
+
var _chunk5ZBNF5WMjs = require('./chunk-5ZBNF5WM.js');
|
27
|
+
|
28
|
+
// src/actions/public/call.ts
|
29
|
+
async function call(client, {
|
30
|
+
blockNumber,
|
31
|
+
blockTag = "latest",
|
32
|
+
chain,
|
33
|
+
from,
|
34
|
+
accessList,
|
35
|
+
data,
|
36
|
+
gas,
|
37
|
+
gasPrice,
|
38
|
+
maxFeePerGas,
|
39
|
+
maxPriorityFeePerGas,
|
40
|
+
nonce,
|
41
|
+
to,
|
42
|
+
value,
|
43
|
+
...rest
|
44
|
+
}) {
|
45
|
+
if (maxFeePerGas !== void 0 && maxPriorityFeePerGas !== void 0 && maxFeePerGas < maxPriorityFeePerGas)
|
46
|
+
throw new (0, _chunk5ZBNF5WMjs.InvalidGasArgumentsError)();
|
47
|
+
const blockNumberHex = blockNumber ? _chunk5ZBNF5WMjs.numberToHex.call(void 0, blockNumber) : void 0;
|
48
|
+
const request_ = _chunk5ZBNF5WMjs.format.call(void 0,
|
49
|
+
{
|
50
|
+
from,
|
51
|
+
accessList,
|
52
|
+
data,
|
53
|
+
gas,
|
54
|
+
gasPrice,
|
55
|
+
maxFeePerGas,
|
56
|
+
maxPriorityFeePerGas,
|
57
|
+
nonce,
|
58
|
+
to,
|
59
|
+
value,
|
60
|
+
...rest
|
61
|
+
},
|
62
|
+
{
|
63
|
+
formatter: _optionalChain([chain, 'optionalAccess', _ => _.formatters, 'optionalAccess', _2 => _2.transactionRequest]) || _chunk5ZBNF5WMjs.formatTransactionRequest
|
64
|
+
}
|
65
|
+
);
|
66
|
+
const response = await client.request({
|
67
|
+
method: "eth_call",
|
68
|
+
params: [request_, blockNumberHex || blockTag]
|
69
|
+
});
|
70
|
+
if (response === "0x")
|
71
|
+
return { data: void 0 };
|
72
|
+
return { data: response };
|
73
|
+
}
|
74
|
+
|
75
|
+
// src/actions/public/callContract.ts
|
76
|
+
async function callContract(client, {
|
77
|
+
abi,
|
78
|
+
address,
|
79
|
+
args,
|
80
|
+
functionName,
|
81
|
+
...callRequest
|
82
|
+
}) {
|
83
|
+
const calldata = _chunk5ZBNF5WMjs.encodeFunctionData.call(void 0, {
|
84
|
+
abi,
|
85
|
+
args,
|
86
|
+
functionName
|
87
|
+
});
|
88
|
+
try {
|
89
|
+
const { data } = await call(client, {
|
90
|
+
data: calldata,
|
91
|
+
to: address,
|
92
|
+
...callRequest
|
93
|
+
});
|
94
|
+
return _chunk5ZBNF5WMjs.decodeFunctionResult.call(void 0, {
|
95
|
+
abi,
|
96
|
+
functionName,
|
97
|
+
data: data || "0x"
|
98
|
+
});
|
99
|
+
} catch (err) {
|
100
|
+
throw _chunk5ZBNF5WMjs.getContractError.call(void 0, err, {
|
101
|
+
abi,
|
102
|
+
address,
|
103
|
+
args,
|
104
|
+
functionName,
|
105
|
+
sender: callRequest.from
|
106
|
+
});
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
// src/actions/public/createPendingTransactionFilter.ts
|
111
|
+
async function createPendingTransactionFilter(client) {
|
112
|
+
const id = await client.request({
|
113
|
+
method: "eth_newPendingTransactionFilter"
|
114
|
+
});
|
115
|
+
return { id, type: "transaction" };
|
116
|
+
}
|
117
|
+
|
118
|
+
// src/actions/public/createBlockFilter.ts
|
119
|
+
async function createBlockFilter(client) {
|
120
|
+
const id = await client.request({
|
121
|
+
method: "eth_newBlockFilter"
|
122
|
+
});
|
123
|
+
return { id, type: "block" };
|
124
|
+
}
|
125
|
+
|
126
|
+
// src/actions/public/estimateGas.ts
|
127
|
+
async function estimateGas(client, {
|
128
|
+
blockNumber,
|
129
|
+
blockTag = "latest",
|
130
|
+
data,
|
131
|
+
from,
|
132
|
+
gas,
|
133
|
+
gasPrice,
|
134
|
+
maxFeePerGas,
|
135
|
+
maxPriorityFeePerGas,
|
136
|
+
to,
|
137
|
+
value
|
138
|
+
}) {
|
139
|
+
const blockNumberHex = blockNumber ? _chunk5ZBNF5WMjs.numberToHex.call(void 0, blockNumber) : void 0;
|
140
|
+
const parameters = {
|
141
|
+
data,
|
142
|
+
from,
|
143
|
+
gas: gas ? _chunk5ZBNF5WMjs.numberToHex.call(void 0, gas) : void 0,
|
144
|
+
gasPrice: gasPrice ? _chunk5ZBNF5WMjs.numberToHex.call(void 0, gasPrice) : void 0,
|
145
|
+
maxFeePerGas: maxFeePerGas ? _chunk5ZBNF5WMjs.numberToHex.call(void 0, maxFeePerGas) : void 0,
|
146
|
+
maxPriorityFeePerGas: maxPriorityFeePerGas ? _chunk5ZBNF5WMjs.numberToHex.call(void 0, maxPriorityFeePerGas) : void 0,
|
147
|
+
to,
|
148
|
+
value: value ? _chunk5ZBNF5WMjs.numberToHex.call(void 0, value) : void 0
|
149
|
+
};
|
150
|
+
const balance = await client.request({
|
151
|
+
method: "eth_estimateGas",
|
152
|
+
params: [parameters, blockNumberHex || blockTag]
|
153
|
+
});
|
154
|
+
return BigInt(balance);
|
155
|
+
}
|
156
|
+
|
157
|
+
// src/actions/public/getBalance.ts
|
158
|
+
async function getBalance(client, { address, blockNumber, blockTag = "latest" }) {
|
159
|
+
const blockNumberHex = blockNumber ? _chunk5ZBNF5WMjs.numberToHex.call(void 0, blockNumber) : void 0;
|
160
|
+
const balance = await client.request({
|
161
|
+
method: "eth_getBalance",
|
162
|
+
params: [address, blockNumberHex || blockTag]
|
163
|
+
});
|
164
|
+
return BigInt(balance);
|
165
|
+
}
|
166
|
+
|
167
|
+
// src/actions/public/getBlock.ts
|
168
|
+
async function getBlock(client, {
|
169
|
+
blockHash,
|
170
|
+
blockNumber,
|
171
|
+
blockTag = "latest",
|
172
|
+
includeTransactions = false
|
173
|
+
} = {}) {
|
174
|
+
const blockNumberHex = blockNumber !== void 0 ? _chunk5ZBNF5WMjs.numberToHex.call(void 0, blockNumber) : void 0;
|
175
|
+
let block = null;
|
176
|
+
if (blockHash) {
|
177
|
+
block = await client.request({
|
178
|
+
method: "eth_getBlockByHash",
|
179
|
+
params: [blockHash, includeTransactions]
|
180
|
+
});
|
181
|
+
} else {
|
182
|
+
block = await client.request({
|
183
|
+
method: "eth_getBlockByNumber",
|
184
|
+
params: [blockNumberHex || blockTag, includeTransactions]
|
185
|
+
});
|
186
|
+
}
|
187
|
+
if (!block)
|
188
|
+
throw new (0, _chunk5ZBNF5WMjs.BlockNotFoundError)({ blockHash, blockNumber });
|
189
|
+
return _chunk5ZBNF5WMjs.format.call(void 0, block, {
|
190
|
+
formatter: _optionalChain([client, 'access', _3 => _3.chain, 'optionalAccess', _4 => _4.formatters, 'optionalAccess', _5 => _5.block]) || _chunk5ZBNF5WMjs.formatBlock
|
191
|
+
});
|
192
|
+
}
|
193
|
+
|
194
|
+
// src/actions/public/getBlockNumber.ts
|
195
|
+
var cacheKey = (id) => `blockNumber.${id}`;
|
196
|
+
function getBlockNumberCache(id) {
|
197
|
+
return _chunk5ZBNF5WMjs.getCache.call(void 0, cacheKey(id));
|
198
|
+
}
|
199
|
+
async function getBlockNumber(client, { maxAge = client.pollingInterval } = {}) {
|
200
|
+
const blockNumberHex = await _chunk5ZBNF5WMjs.withCache.call(void 0,
|
201
|
+
() => client.request({
|
202
|
+
method: "eth_blockNumber"
|
203
|
+
}),
|
204
|
+
{ cacheKey: cacheKey(client.uid), maxAge }
|
205
|
+
);
|
206
|
+
return BigInt(blockNumberHex);
|
207
|
+
}
|
208
|
+
|
209
|
+
// src/actions/public/getBlockTransactionCount.ts
|
210
|
+
async function getBlockTransactionCount(client, {
|
211
|
+
blockHash,
|
212
|
+
blockNumber,
|
213
|
+
blockTag = "latest"
|
214
|
+
} = {}) {
|
215
|
+
const blockNumberHex = blockNumber !== void 0 ? _chunk5ZBNF5WMjs.numberToHex.call(void 0, blockNumber) : void 0;
|
216
|
+
let count = null;
|
217
|
+
if (blockHash) {
|
218
|
+
count = await client.request({
|
219
|
+
method: "eth_getBlockTransactionCountByHash",
|
220
|
+
params: [blockHash]
|
221
|
+
});
|
222
|
+
} else {
|
223
|
+
count = await client.request({
|
224
|
+
method: "eth_getBlockTransactionCountByNumber",
|
225
|
+
params: [blockNumberHex || blockTag]
|
226
|
+
});
|
227
|
+
}
|
228
|
+
return _chunk5ZBNF5WMjs.hexToNumber.call(void 0, count);
|
229
|
+
}
|
230
|
+
|
231
|
+
// src/actions/public/getChainId.ts
|
232
|
+
async function getChainId(client) {
|
233
|
+
const chainIdHex = await client.request({ method: "eth_chainId" });
|
234
|
+
return _chunk5ZBNF5WMjs.hexToNumber.call(void 0, chainIdHex);
|
235
|
+
}
|
236
|
+
|
237
|
+
// src/actions/public/getFeeHistory.ts
|
238
|
+
async function getFeeHistory(client, {
|
239
|
+
blockCount,
|
240
|
+
blockNumber,
|
241
|
+
blockTag = "latest",
|
242
|
+
rewardPercentiles
|
243
|
+
}) {
|
244
|
+
const blockNumberHex = blockNumber ? _chunk5ZBNF5WMjs.numberToHex.call(void 0, blockNumber) : void 0;
|
245
|
+
const feeHistory = await client.request({
|
246
|
+
method: "eth_feeHistory",
|
247
|
+
params: [
|
248
|
+
_chunk5ZBNF5WMjs.numberToHex.call(void 0, blockCount),
|
249
|
+
blockNumberHex || blockTag,
|
250
|
+
rewardPercentiles
|
251
|
+
]
|
252
|
+
});
|
253
|
+
return _chunk5ZBNF5WMjs.formatFeeHistory.call(void 0, feeHistory);
|
254
|
+
}
|
255
|
+
|
256
|
+
// src/actions/public/getFilterChanges.ts
|
257
|
+
async function getFilterChanges(client, { filter }) {
|
258
|
+
const logs = await client.request({
|
259
|
+
method: "eth_getFilterChanges",
|
260
|
+
params: [filter.id]
|
261
|
+
});
|
262
|
+
return logs.map(
|
263
|
+
(log) => typeof log === "string" ? log : _chunk5ZBNF5WMjs.formatLog.call(void 0, log)
|
264
|
+
);
|
265
|
+
}
|
266
|
+
|
267
|
+
// src/actions/public/getFilterLogs.ts
|
268
|
+
async function getFilterLogs(client, { filter }) {
|
269
|
+
const logs = await client.request({
|
270
|
+
method: "eth_getFilterLogs",
|
271
|
+
params: [filter.id]
|
272
|
+
});
|
273
|
+
return logs.map(_chunk5ZBNF5WMjs.formatLog);
|
274
|
+
}
|
275
|
+
|
276
|
+
// src/actions/public/getGasPrice.ts
|
277
|
+
async function getGasPrice(client) {
|
278
|
+
const gasPrice = await client.request({
|
279
|
+
method: "eth_gasPrice"
|
280
|
+
});
|
281
|
+
return BigInt(gasPrice);
|
282
|
+
}
|
283
|
+
|
284
|
+
// src/actions/public/getTransaction.ts
|
285
|
+
async function getTransaction(client, {
|
286
|
+
blockHash,
|
287
|
+
blockNumber,
|
288
|
+
blockTag = "latest",
|
289
|
+
hash,
|
290
|
+
index
|
291
|
+
}) {
|
292
|
+
const blockNumberHex = blockNumber !== void 0 ? _chunk5ZBNF5WMjs.numberToHex.call(void 0, blockNumber) : void 0;
|
293
|
+
let transaction = null;
|
294
|
+
if (hash) {
|
295
|
+
transaction = await client.request({
|
296
|
+
method: "eth_getTransactionByHash",
|
297
|
+
params: [hash]
|
298
|
+
});
|
299
|
+
} else if (blockHash) {
|
300
|
+
transaction = await client.request({
|
301
|
+
method: "eth_getTransactionByBlockHashAndIndex",
|
302
|
+
params: [blockHash, _chunk5ZBNF5WMjs.numberToHex.call(void 0, index)]
|
303
|
+
});
|
304
|
+
} else if (blockNumberHex || blockTag) {
|
305
|
+
transaction = await client.request({
|
306
|
+
method: "eth_getTransactionByBlockNumberAndIndex",
|
307
|
+
params: [blockNumberHex || blockTag, _chunk5ZBNF5WMjs.numberToHex.call(void 0, index)]
|
308
|
+
});
|
309
|
+
}
|
310
|
+
if (!transaction)
|
311
|
+
throw new (0, _chunk5ZBNF5WMjs.TransactionNotFoundError)({
|
312
|
+
blockHash,
|
313
|
+
blockNumber,
|
314
|
+
blockTag,
|
315
|
+
hash,
|
316
|
+
index
|
317
|
+
});
|
318
|
+
return _chunk5ZBNF5WMjs.format.call(void 0, transaction, {
|
319
|
+
formatter: _optionalChain([client, 'access', _6 => _6.chain, 'optionalAccess', _7 => _7.formatters, 'optionalAccess', _8 => _8.transaction]) || _chunk5ZBNF5WMjs.formatTransaction
|
320
|
+
});
|
321
|
+
}
|
322
|
+
|
323
|
+
// src/actions/public/getTransactionConfirmations.ts
|
324
|
+
async function getTransactionConfirmations(client, { hash, transactionReceipt }) {
|
325
|
+
const [blockNumber, transaction] = await Promise.all([
|
326
|
+
getBlockNumber(client),
|
327
|
+
hash ? getTransaction(client, { hash }) : void 0
|
328
|
+
]);
|
329
|
+
const transactionBlockNumber = _optionalChain([transactionReceipt, 'optionalAccess', _9 => _9.blockNumber]) || _optionalChain([transaction, 'optionalAccess', _10 => _10.blockNumber]);
|
330
|
+
if (!transactionBlockNumber)
|
331
|
+
return 0n;
|
332
|
+
return blockNumber - transactionBlockNumber + 1n;
|
333
|
+
}
|
334
|
+
|
335
|
+
// src/actions/public/getTransactionCount.ts
|
336
|
+
async function getTransactionCount(client, { address, blockTag = "latest", blockNumber }) {
|
337
|
+
const count = await client.request({
|
338
|
+
method: "eth_getTransactionCount",
|
339
|
+
params: [address, blockNumber ? _chunk5ZBNF5WMjs.numberToHex.call(void 0, blockNumber) : blockTag]
|
340
|
+
});
|
341
|
+
return _chunk5ZBNF5WMjs.hexToNumber.call(void 0, count);
|
342
|
+
}
|
343
|
+
|
344
|
+
// src/actions/public/getTransactionReceipt.ts
|
345
|
+
async function getTransactionReceipt(client, { hash }) {
|
346
|
+
const receipt = await client.request({
|
347
|
+
method: "eth_getTransactionReceipt",
|
348
|
+
params: [hash]
|
349
|
+
});
|
350
|
+
if (!receipt)
|
351
|
+
throw new (0, _chunk5ZBNF5WMjs.TransactionReceiptNotFoundError)({ hash });
|
352
|
+
return _chunk5ZBNF5WMjs.format.call(void 0, receipt, {
|
353
|
+
formatter: _optionalChain([client, 'access', _11 => _11.chain, 'optionalAccess', _12 => _12.formatters, 'optionalAccess', _13 => _13.transactionReceipt]) || _chunk5ZBNF5WMjs.formatTransactionReceipt
|
354
|
+
});
|
355
|
+
}
|
356
|
+
|
357
|
+
// src/actions/public/uninstallFilter.ts
|
358
|
+
async function uninstallFilter(client, { filter }) {
|
359
|
+
return client.request({
|
360
|
+
method: "eth_uninstallFilter",
|
361
|
+
params: [filter.id]
|
362
|
+
});
|
363
|
+
}
|
364
|
+
|
365
|
+
// src/utils/observe.ts
|
366
|
+
var listenersCache = /* @__PURE__ */ new Map();
|
367
|
+
var cleanupCache = /* @__PURE__ */ new Map();
|
368
|
+
var callbackCount = 0;
|
369
|
+
function observe(observerId, callbacks, fn) {
|
370
|
+
const callbackId = ++callbackCount;
|
371
|
+
const getListeners = () => listenersCache.get(observerId) || [];
|
372
|
+
const unsubscribe = () => {
|
373
|
+
const listeners2 = getListeners();
|
374
|
+
listenersCache.set(
|
375
|
+
observerId,
|
376
|
+
listeners2.filter((cb) => cb.id !== callbackId)
|
377
|
+
);
|
378
|
+
};
|
379
|
+
const unwatch = () => {
|
380
|
+
const cleanup2 = cleanupCache.get(observerId);
|
381
|
+
if (getListeners().length === 1 && cleanup2)
|
382
|
+
cleanup2();
|
383
|
+
unsubscribe();
|
384
|
+
};
|
385
|
+
const listeners = getListeners();
|
386
|
+
listenersCache.set(observerId, [
|
387
|
+
...listeners,
|
388
|
+
{ id: callbackId, fns: callbacks }
|
389
|
+
]);
|
390
|
+
if (listeners && listeners.length > 0)
|
391
|
+
return unwatch;
|
392
|
+
let emit = {};
|
393
|
+
for (const key in callbacks) {
|
394
|
+
emit[key] = (...args) => {
|
395
|
+
const listeners2 = getListeners();
|
396
|
+
if (listeners2.length === 0)
|
397
|
+
return;
|
398
|
+
listeners2.forEach((listener) => _optionalChain([listener, 'access', _14 => _14.fns, 'access', _15 => _15[key], 'optionalCall', _16 => _16(...args)]));
|
399
|
+
};
|
400
|
+
}
|
401
|
+
const cleanup = fn(emit);
|
402
|
+
if (typeof cleanup === "function")
|
403
|
+
cleanupCache.set(observerId, cleanup);
|
404
|
+
return unwatch;
|
405
|
+
}
|
406
|
+
|
407
|
+
// src/actions/public/waitForTransactionReceipt.ts
|
408
|
+
async function waitForTransactionReceipt(client, {
|
409
|
+
confirmations = 1,
|
410
|
+
hash,
|
411
|
+
onReplaced,
|
412
|
+
pollingInterval = client.pollingInterval,
|
413
|
+
timeout
|
414
|
+
}) {
|
415
|
+
const observerId = JSON.stringify([
|
416
|
+
"waitForTransactionReceipt",
|
417
|
+
client.uid,
|
418
|
+
hash
|
419
|
+
]);
|
420
|
+
let transaction;
|
421
|
+
let replacedTransaction;
|
422
|
+
let receipt;
|
423
|
+
return new Promise((resolve, reject) => {
|
424
|
+
if (timeout)
|
425
|
+
setTimeout(
|
426
|
+
() => reject(new (0, _chunk5ZBNF5WMjs.WaitForTransactionReceiptTimeoutError)({ hash })),
|
427
|
+
timeout
|
428
|
+
);
|
429
|
+
const unobserve = observe(
|
430
|
+
observerId,
|
431
|
+
{ onReplaced, resolve, reject },
|
432
|
+
(emit) => {
|
433
|
+
const unwatch = watchBlockNumber(client, {
|
434
|
+
emitMissed: true,
|
435
|
+
emitOnBegin: true,
|
436
|
+
pollingInterval,
|
437
|
+
async onBlockNumber(blockNumber) {
|
438
|
+
const done = async (fn) => {
|
439
|
+
unwatch();
|
440
|
+
fn();
|
441
|
+
unobserve();
|
442
|
+
};
|
443
|
+
try {
|
444
|
+
if (receipt) {
|
445
|
+
if (blockNumber - receipt.blockNumber + 1n < confirmations)
|
446
|
+
return;
|
447
|
+
done(() => emit.resolve(receipt));
|
448
|
+
return;
|
449
|
+
}
|
450
|
+
transaction = await getTransaction(client, { hash });
|
451
|
+
receipt = await getTransactionReceipt(client, { hash });
|
452
|
+
if (blockNumber - receipt.blockNumber + 1n < confirmations)
|
453
|
+
return;
|
454
|
+
done(() => emit.resolve(receipt));
|
455
|
+
} catch (err) {
|
456
|
+
if (transaction && (err instanceof _chunk5ZBNF5WMjs.TransactionNotFoundError || err instanceof _chunk5ZBNF5WMjs.TransactionReceiptNotFoundError)) {
|
457
|
+
replacedTransaction = transaction;
|
458
|
+
const block = await getBlock(client, {
|
459
|
+
blockNumber,
|
460
|
+
includeTransactions: true
|
461
|
+
});
|
462
|
+
const replacementTransaction = block.transactions.find(
|
463
|
+
({ from, nonce }) => from === replacedTransaction.from && nonce === replacedTransaction.nonce
|
464
|
+
);
|
465
|
+
if (!replacementTransaction)
|
466
|
+
return;
|
467
|
+
receipt = await getTransactionReceipt(client, {
|
468
|
+
hash: replacementTransaction.hash
|
469
|
+
});
|
470
|
+
if (blockNumber - receipt.blockNumber + 1n < confirmations)
|
471
|
+
return;
|
472
|
+
let reason = "replaced";
|
473
|
+
if (replacementTransaction.to === replacedTransaction.to && replacementTransaction.value === replacedTransaction.value) {
|
474
|
+
reason = "repriced";
|
475
|
+
} else if (replacementTransaction.from === replacementTransaction.to && replacementTransaction.value === 0n) {
|
476
|
+
reason = "cancelled";
|
477
|
+
}
|
478
|
+
done(() => {
|
479
|
+
_optionalChain([emit, 'access', _17 => _17.onReplaced, 'optionalCall', _18 => _18({
|
480
|
+
reason,
|
481
|
+
replacedTransaction,
|
482
|
+
transaction: replacementTransaction,
|
483
|
+
transactionReceipt: receipt
|
484
|
+
})]);
|
485
|
+
emit.resolve(receipt);
|
486
|
+
});
|
487
|
+
} else {
|
488
|
+
done(() => emit.reject(err));
|
489
|
+
}
|
490
|
+
}
|
491
|
+
}
|
492
|
+
});
|
493
|
+
return unwatch;
|
494
|
+
}
|
495
|
+
);
|
496
|
+
});
|
497
|
+
}
|
498
|
+
|
499
|
+
// src/utils/poll.ts
|
500
|
+
function poll(fn, { emitOnBegin, initialWaitTime, interval }) {
|
501
|
+
let active = true;
|
502
|
+
const unwatch = () => active = false;
|
503
|
+
const watch = async () => {
|
504
|
+
let data;
|
505
|
+
if (emitOnBegin)
|
506
|
+
data = await fn({ unpoll: unwatch });
|
507
|
+
const initialWait = await _asyncNullishCoalesce(await _optionalChain([initialWaitTime, 'optionalCall', _19 => _19(data)]), async () => ( interval));
|
508
|
+
await _chunk5ZBNF5WMjs.wait.call(void 0, initialWait);
|
509
|
+
const poll2 = async () => {
|
510
|
+
if (!active)
|
511
|
+
return;
|
512
|
+
await fn({ unpoll: unwatch });
|
513
|
+
await _chunk5ZBNF5WMjs.wait.call(void 0, interval);
|
514
|
+
poll2();
|
515
|
+
};
|
516
|
+
poll2();
|
517
|
+
};
|
518
|
+
watch();
|
519
|
+
return unwatch;
|
520
|
+
}
|
521
|
+
|
522
|
+
// src/actions/public/watchBlockNumber.ts
|
523
|
+
function watchBlockNumber(client, {
|
524
|
+
emitOnBegin = false,
|
525
|
+
emitMissed = false,
|
526
|
+
onBlockNumber,
|
527
|
+
onError,
|
528
|
+
pollingInterval = client.pollingInterval
|
529
|
+
}) {
|
530
|
+
const observerId = JSON.stringify([
|
531
|
+
"watchBlockNumber",
|
532
|
+
client.uid,
|
533
|
+
emitOnBegin,
|
534
|
+
emitMissed,
|
535
|
+
pollingInterval
|
536
|
+
]);
|
537
|
+
let prevBlockNumber;
|
538
|
+
return observe(
|
539
|
+
observerId,
|
540
|
+
{ onBlockNumber, onError },
|
541
|
+
(emit) => poll(
|
542
|
+
async () => {
|
543
|
+
try {
|
544
|
+
const blockNumber = await getBlockNumber(client, { maxAge: 0 });
|
545
|
+
if (prevBlockNumber) {
|
546
|
+
if (blockNumber === prevBlockNumber)
|
547
|
+
return;
|
548
|
+
if (blockNumber - prevBlockNumber > 1 && emitMissed) {
|
549
|
+
for (let i = prevBlockNumber + 1n; i < blockNumber; i++) {
|
550
|
+
emit.onBlockNumber(i, prevBlockNumber);
|
551
|
+
prevBlockNumber = i;
|
552
|
+
}
|
553
|
+
}
|
554
|
+
}
|
555
|
+
prevBlockNumber = blockNumber;
|
556
|
+
emit.onBlockNumber(blockNumber, prevBlockNumber);
|
557
|
+
} catch (err) {
|
558
|
+
_optionalChain([emit, 'access', _20 => _20.onError, 'optionalCall', _21 => _21(err)]);
|
559
|
+
}
|
560
|
+
},
|
561
|
+
{
|
562
|
+
emitOnBegin,
|
563
|
+
interval: pollingInterval
|
564
|
+
}
|
565
|
+
)
|
566
|
+
);
|
567
|
+
}
|
568
|
+
|
569
|
+
// src/actions/public/watchBlocks.ts
|
570
|
+
function watchBlocks(client, {
|
571
|
+
blockTag = "latest",
|
572
|
+
emitMissed = false,
|
573
|
+
emitOnBegin = false,
|
574
|
+
onBlock,
|
575
|
+
onError,
|
576
|
+
includeTransactions = false,
|
577
|
+
pollingInterval = client.pollingInterval
|
578
|
+
}) {
|
579
|
+
const observerId = JSON.stringify([
|
580
|
+
"watchBlocks",
|
581
|
+
client.uid,
|
582
|
+
emitMissed,
|
583
|
+
emitOnBegin,
|
584
|
+
includeTransactions,
|
585
|
+
pollingInterval
|
586
|
+
]);
|
587
|
+
let prevBlock;
|
588
|
+
return observe(
|
589
|
+
observerId,
|
590
|
+
{ onBlock, onError },
|
591
|
+
(emit) => poll(
|
592
|
+
async () => {
|
593
|
+
try {
|
594
|
+
const block = await getBlock(client, {
|
595
|
+
blockTag,
|
596
|
+
includeTransactions
|
597
|
+
});
|
598
|
+
if (block.number && _optionalChain([prevBlock, 'optionalAccess', _22 => _22.number])) {
|
599
|
+
if (block.number === prevBlock.number)
|
600
|
+
return;
|
601
|
+
if (block.number - prevBlock.number > 1 && emitMissed) {
|
602
|
+
for (let i = _optionalChain([prevBlock, 'optionalAccess', _23 => _23.number]) + 1n; i < block.number; i++) {
|
603
|
+
const block2 = await getBlock(client, {
|
604
|
+
blockNumber: i,
|
605
|
+
includeTransactions
|
606
|
+
});
|
607
|
+
emit.onBlock(block2, prevBlock);
|
608
|
+
prevBlock = block2;
|
609
|
+
}
|
610
|
+
}
|
611
|
+
}
|
612
|
+
emit.onBlock(block, prevBlock);
|
613
|
+
prevBlock = block;
|
614
|
+
} catch (err) {
|
615
|
+
_optionalChain([emit, 'access', _24 => _24.onError, 'optionalCall', _25 => _25(err)]);
|
616
|
+
}
|
617
|
+
},
|
618
|
+
{
|
619
|
+
emitOnBegin,
|
620
|
+
interval: pollingInterval
|
621
|
+
}
|
622
|
+
)
|
623
|
+
);
|
624
|
+
}
|
625
|
+
|
626
|
+
// src/actions/public/watchPendingTransactions.ts
|
627
|
+
function watchPendingTransactions(client, {
|
628
|
+
batch = true,
|
629
|
+
onError,
|
630
|
+
onTransactions,
|
631
|
+
pollingInterval = client.pollingInterval
|
632
|
+
}) {
|
633
|
+
const observerId = JSON.stringify([
|
634
|
+
"watchPendingTransactions",
|
635
|
+
client.uid,
|
636
|
+
batch,
|
637
|
+
pollingInterval
|
638
|
+
]);
|
639
|
+
return observe(observerId, { onTransactions, onError }, (emit) => {
|
640
|
+
let filter;
|
641
|
+
const unwatch = poll(
|
642
|
+
async () => {
|
643
|
+
try {
|
644
|
+
if (!filter) {
|
645
|
+
try {
|
646
|
+
filter = await createPendingTransactionFilter(client);
|
647
|
+
return;
|
648
|
+
} catch (err) {
|
649
|
+
unwatch();
|
650
|
+
throw err;
|
651
|
+
}
|
652
|
+
}
|
653
|
+
const hashes = await getFilterChanges(client, { filter });
|
654
|
+
if (batch)
|
655
|
+
emit.onTransactions(hashes);
|
656
|
+
else
|
657
|
+
hashes.forEach((hash) => emit.onTransactions([hash]));
|
658
|
+
} catch (err) {
|
659
|
+
_optionalChain([emit, 'access', _26 => _26.onError, 'optionalCall', _27 => _27(err)]);
|
660
|
+
}
|
661
|
+
},
|
662
|
+
{
|
663
|
+
emitOnBegin: true,
|
664
|
+
interval: pollingInterval
|
665
|
+
}
|
666
|
+
);
|
667
|
+
return async () => {
|
668
|
+
if (filter)
|
669
|
+
await uninstallFilter(client, { filter });
|
670
|
+
unwatch();
|
671
|
+
};
|
672
|
+
});
|
673
|
+
}
|
674
|
+
|
675
|
+
// src/actions/test/dropTransaction.ts
|
676
|
+
async function dropTransaction(client, { hash }) {
|
677
|
+
return await client.request({
|
678
|
+
method: `${client.mode}_dropTransaction`,
|
679
|
+
params: [hash]
|
680
|
+
});
|
681
|
+
}
|
682
|
+
|
683
|
+
// src/actions/test/getAutomine.ts
|
684
|
+
async function getAutomine(client) {
|
685
|
+
return await client.request({
|
686
|
+
method: `${client.mode}_getAutomine`
|
687
|
+
});
|
688
|
+
}
|
689
|
+
|
690
|
+
// src/actions/test/getTxpoolContent.ts
|
691
|
+
async function getTxpoolContent(client) {
|
692
|
+
return await client.request({
|
693
|
+
method: "txpool_content"
|
694
|
+
});
|
695
|
+
}
|
696
|
+
|
697
|
+
// src/actions/test/getTxpoolStatus.ts
|
698
|
+
async function getTxpoolStatus(client) {
|
699
|
+
const { pending, queued } = await client.request({
|
700
|
+
method: "txpool_status"
|
701
|
+
});
|
702
|
+
return {
|
703
|
+
pending: _chunk5ZBNF5WMjs.hexToNumber.call(void 0, pending),
|
704
|
+
queued: _chunk5ZBNF5WMjs.hexToNumber.call(void 0, queued)
|
705
|
+
};
|
706
|
+
}
|
707
|
+
|
708
|
+
// src/actions/test/impersonateAccount.ts
|
709
|
+
async function impersonateAccount(client, { address }) {
|
710
|
+
return await client.request({
|
711
|
+
method: `${client.mode}_impersonateAccount`,
|
712
|
+
params: [address]
|
713
|
+
});
|
714
|
+
}
|
715
|
+
|
716
|
+
// src/actions/test/increaseTime.ts
|
717
|
+
async function increaseTime(client, { seconds }) {
|
718
|
+
return await client.request({
|
719
|
+
method: "evm_increaseTime",
|
720
|
+
params: [_chunk5ZBNF5WMjs.numberToHex.call(void 0, seconds)]
|
721
|
+
});
|
722
|
+
}
|
723
|
+
|
724
|
+
// src/actions/test/inspectTxpool.ts
|
725
|
+
async function inspectTxpool(client) {
|
726
|
+
return await client.request({
|
727
|
+
method: "txpool_inspect"
|
728
|
+
});
|
729
|
+
}
|
730
|
+
|
731
|
+
// src/actions/test/mine.ts
|
732
|
+
async function mine(client, { blocks, interval }) {
|
733
|
+
return await client.request({
|
734
|
+
method: `${client.mode}_mine`,
|
735
|
+
params: [_chunk5ZBNF5WMjs.numberToHex.call(void 0, blocks), _chunk5ZBNF5WMjs.numberToHex.call(void 0, interval || 0)]
|
736
|
+
});
|
737
|
+
}
|
738
|
+
|
739
|
+
// src/actions/test/removeBlockTimestampInterval.ts
|
740
|
+
async function removeBlockTimestampInterval(client) {
|
741
|
+
return await client.request({
|
742
|
+
method: `${client.mode}_removeBlockTimestampInterval`
|
743
|
+
});
|
744
|
+
}
|
745
|
+
|
746
|
+
// src/actions/test/reset.ts
|
747
|
+
async function reset(client, { blockNumber, jsonRpcUrl } = {}) {
|
748
|
+
return await client.request({
|
749
|
+
method: `${client.mode}_reset`,
|
750
|
+
params: [{ forking: { blockNumber: Number(blockNumber), jsonRpcUrl } }]
|
751
|
+
});
|
752
|
+
}
|
753
|
+
|
754
|
+
// src/actions/test/revert.ts
|
755
|
+
async function revert(client, { id }) {
|
756
|
+
return await client.request({
|
757
|
+
method: "evm_revert",
|
758
|
+
params: [id]
|
759
|
+
});
|
760
|
+
}
|
761
|
+
|
762
|
+
// src/actions/test/sendUnsignedTransaction.ts
|
763
|
+
async function sendUnsignedTransaction(client, request) {
|
764
|
+
const request_ = _chunk5ZBNF5WMjs.formatTransactionRequest.call(void 0, request);
|
765
|
+
const hash = await client.request({
|
766
|
+
method: "eth_sendUnsignedTransaction",
|
767
|
+
params: [request_]
|
768
|
+
});
|
769
|
+
return hash;
|
770
|
+
}
|
771
|
+
|
772
|
+
// src/actions/test/setAutomine.ts
|
773
|
+
async function setAutomine(client, enabled) {
|
774
|
+
return await client.request({
|
775
|
+
method: "evm_setAutomine",
|
776
|
+
params: [enabled]
|
777
|
+
});
|
778
|
+
}
|
779
|
+
|
780
|
+
// src/actions/test/setBalance.ts
|
781
|
+
async function setBalance(client, { address, value }) {
|
782
|
+
return await client.request({
|
783
|
+
method: `${client.mode}_setBalance`,
|
784
|
+
params: [address, _chunk5ZBNF5WMjs.numberToHex.call(void 0, value)]
|
785
|
+
});
|
786
|
+
}
|
787
|
+
|
788
|
+
// src/actions/test/setBlockGasLimit.ts
|
789
|
+
async function setBlockGasLimit(client, { gasLimit }) {
|
790
|
+
return await client.request({
|
791
|
+
method: "evm_setBlockGasLimit",
|
792
|
+
params: [_chunk5ZBNF5WMjs.numberToHex.call(void 0, gasLimit)]
|
793
|
+
});
|
794
|
+
}
|
795
|
+
|
796
|
+
// src/actions/test/setBlockTimestampInterval.ts
|
797
|
+
async function setBlockTimestampInterval(client, { interval }) {
|
798
|
+
return await client.request({
|
799
|
+
method: `${client.mode}_setBlockTimestampInterval`,
|
800
|
+
params: [interval]
|
801
|
+
});
|
802
|
+
}
|
803
|
+
|
804
|
+
// src/actions/test/setCode.ts
|
805
|
+
async function setCode(client, { address, bytecode }) {
|
806
|
+
return await client.request({
|
807
|
+
method: `${client.mode}_setCode`,
|
808
|
+
params: [address, bytecode]
|
809
|
+
});
|
810
|
+
}
|
811
|
+
|
812
|
+
// src/actions/test/setCoinbase.ts
|
813
|
+
async function setCoinbase(client, { address }) {
|
814
|
+
return await client.request({
|
815
|
+
method: `${client.mode}_setCoinbase`,
|
816
|
+
params: [address]
|
817
|
+
});
|
818
|
+
}
|
819
|
+
|
820
|
+
// src/actions/test/setIntervalMining.ts
|
821
|
+
async function setIntervalMining(client, { interval }) {
|
822
|
+
return await client.request({
|
823
|
+
method: "evm_setIntervalMining",
|
824
|
+
params: [interval]
|
825
|
+
});
|
826
|
+
}
|
827
|
+
|
828
|
+
// src/actions/test/setLoggingEnabled.ts
|
829
|
+
async function setLoggingEnabled(client, enabled) {
|
830
|
+
return await client.request({
|
831
|
+
method: `${client.mode}_setLoggingEnabled`,
|
832
|
+
params: [enabled]
|
833
|
+
});
|
834
|
+
}
|
835
|
+
|
836
|
+
// src/actions/test/setMinGasPrice.ts
|
837
|
+
async function setMinGasPrice(client, { gasPrice }) {
|
838
|
+
return await client.request({
|
839
|
+
method: `${client.mode}_setMinGasPrice`,
|
840
|
+
params: [_chunk5ZBNF5WMjs.numberToHex.call(void 0, gasPrice)]
|
841
|
+
});
|
842
|
+
}
|
843
|
+
|
844
|
+
// src/actions/test/setNextBlockBaseFeePerGas.ts
|
845
|
+
async function setNextBlockBaseFeePerGas(client, { baseFeePerGas }) {
|
846
|
+
return await client.request({
|
847
|
+
method: `${client.mode}_setNextBlockBaseFeePerGas`,
|
848
|
+
params: [_chunk5ZBNF5WMjs.numberToHex.call(void 0, baseFeePerGas)]
|
849
|
+
});
|
850
|
+
}
|
851
|
+
|
852
|
+
// src/actions/test/setNextBlockTimestamp.ts
|
853
|
+
async function setNextBlockTimestamp(client, { timestamp }) {
|
854
|
+
return await client.request({
|
855
|
+
method: "evm_setNextBlockTimestamp",
|
856
|
+
params: [_chunk5ZBNF5WMjs.numberToHex.call(void 0, timestamp)]
|
857
|
+
});
|
858
|
+
}
|
859
|
+
|
860
|
+
// src/actions/test/setNonce.ts
|
861
|
+
async function setNonce(client, { address, nonce }) {
|
862
|
+
return await client.request({
|
863
|
+
method: `${client.mode}_setNonce`,
|
864
|
+
params: [address, _chunk5ZBNF5WMjs.numberToHex.call(void 0, nonce)]
|
865
|
+
});
|
866
|
+
}
|
867
|
+
|
868
|
+
// src/actions/test/setStorageAt.ts
|
869
|
+
async function setStorageAt(client, { address, index, value }) {
|
870
|
+
return await client.request({
|
871
|
+
method: `${client.mode}_setStorageAt`,
|
872
|
+
params: [
|
873
|
+
address,
|
874
|
+
typeof index === "number" ? _chunk5ZBNF5WMjs.numberToHex.call(void 0, index) : index,
|
875
|
+
value
|
876
|
+
]
|
877
|
+
});
|
878
|
+
}
|
879
|
+
|
880
|
+
// src/actions/test/snapshot.ts
|
881
|
+
async function snapshot(client) {
|
882
|
+
return await client.request({
|
883
|
+
method: "evm_snapshot"
|
884
|
+
});
|
885
|
+
}
|
886
|
+
|
887
|
+
// src/actions/test/stopImpersonatingAccount.ts
|
888
|
+
async function stopImpersonatingAccount(client, { address }) {
|
889
|
+
return await client.request({
|
890
|
+
method: `${client.mode}_stopImpersonatingAccount`,
|
891
|
+
params: [address]
|
892
|
+
});
|
893
|
+
}
|
894
|
+
|
895
|
+
// src/actions/wallet/addChain.ts
|
896
|
+
async function addChain(client, chain) {
|
897
|
+
const { id, name, nativeCurrency, rpcUrls, blockExplorers } = chain;
|
898
|
+
await client.request({
|
899
|
+
method: "wallet_addEthereumChain",
|
900
|
+
params: [
|
901
|
+
{
|
902
|
+
chainId: _chunk5ZBNF5WMjs.numberToHex.call(void 0, id),
|
903
|
+
chainName: name,
|
904
|
+
nativeCurrency,
|
905
|
+
rpcUrls: rpcUrls.default.http,
|
906
|
+
blockExplorerUrls: blockExplorers ? Object.values(blockExplorers).map(({ url }) => url) : void 0
|
907
|
+
}
|
908
|
+
]
|
909
|
+
});
|
910
|
+
}
|
911
|
+
|
912
|
+
// src/actions/wallet/getAccounts.ts
|
913
|
+
async function getAccounts(client) {
|
914
|
+
const addresses = await client.request({ method: "eth_accounts" });
|
915
|
+
return addresses.map((address) => _chunk5ZBNF5WMjs.checksumAddress.call(void 0, address));
|
916
|
+
}
|
917
|
+
|
918
|
+
// src/actions/wallet/getPermissions.ts
|
919
|
+
async function getPermissions(client) {
|
920
|
+
const permissions = await client.request({ method: "wallet_getPermissions" });
|
921
|
+
return permissions;
|
922
|
+
}
|
923
|
+
|
924
|
+
// src/actions/wallet/requestAccounts.ts
|
925
|
+
async function requestAccounts(client) {
|
926
|
+
const addresses = await client.request({ method: "eth_requestAccounts" });
|
927
|
+
return addresses.map((address) => _chunk5ZBNF5WMjs.getAddress.call(void 0, address));
|
928
|
+
}
|
929
|
+
|
930
|
+
// src/actions/wallet/requestPermissions.ts
|
931
|
+
async function requestPermissions(client, permissions) {
|
932
|
+
return client.request({
|
933
|
+
method: "wallet_requestPermissions",
|
934
|
+
params: [permissions]
|
935
|
+
});
|
936
|
+
}
|
937
|
+
|
938
|
+
// src/actions/wallet/sendTransaction.ts
|
939
|
+
async function sendTransaction(client, {
|
940
|
+
chain,
|
941
|
+
from,
|
942
|
+
accessList,
|
943
|
+
data,
|
944
|
+
gas,
|
945
|
+
gasPrice,
|
946
|
+
maxFeePerGas,
|
947
|
+
maxPriorityFeePerGas,
|
948
|
+
nonce,
|
949
|
+
to,
|
950
|
+
value,
|
951
|
+
...rest
|
952
|
+
}) {
|
953
|
+
if (maxFeePerGas !== void 0 && maxPriorityFeePerGas !== void 0 && maxFeePerGas < maxPriorityFeePerGas)
|
954
|
+
throw new (0, _chunk5ZBNF5WMjs.InvalidGasArgumentsError)();
|
955
|
+
const request_ = _chunk5ZBNF5WMjs.format.call(void 0,
|
956
|
+
{
|
957
|
+
from,
|
958
|
+
accessList,
|
959
|
+
data,
|
960
|
+
gas,
|
961
|
+
gasPrice,
|
962
|
+
maxFeePerGas,
|
963
|
+
maxPriorityFeePerGas,
|
964
|
+
nonce,
|
965
|
+
to,
|
966
|
+
value,
|
967
|
+
...rest
|
968
|
+
},
|
969
|
+
{
|
970
|
+
formatter: _optionalChain([chain, 'optionalAccess', _28 => _28.formatters, 'optionalAccess', _29 => _29.transactionRequest]) || _chunk5ZBNF5WMjs.formatTransactionRequest
|
971
|
+
}
|
972
|
+
);
|
973
|
+
const hash = await client.request({
|
974
|
+
method: "eth_sendTransaction",
|
975
|
+
params: [request_]
|
976
|
+
});
|
977
|
+
return hash;
|
978
|
+
}
|
979
|
+
|
980
|
+
// src/actions/wallet/signMessage.ts
|
981
|
+
async function signMessage(client, { from, data: data_ }) {
|
982
|
+
let data;
|
983
|
+
if (typeof data_ === "string") {
|
984
|
+
if (!data_.startsWith("0x"))
|
985
|
+
throw new (0, _chunk5ZBNF5WMjs.BaseError)(
|
986
|
+
`data ("${data_}") must be a hex value. Encode it first to a hex with the \`encodeHex\` util.`,
|
987
|
+
{
|
988
|
+
docsPath: "/TODO"
|
989
|
+
}
|
990
|
+
);
|
991
|
+
data = data_;
|
992
|
+
} else {
|
993
|
+
data = _chunk5ZBNF5WMjs.encodeHex.call(void 0, data_);
|
994
|
+
}
|
995
|
+
const signed = await client.request({
|
996
|
+
method: "personal_sign",
|
997
|
+
params: [data, from]
|
998
|
+
});
|
999
|
+
return signed;
|
1000
|
+
}
|
1001
|
+
|
1002
|
+
// src/actions/wallet/switchChain.ts
|
1003
|
+
async function switchChain(client, { id }) {
|
1004
|
+
await client.request({
|
1005
|
+
method: "wallet_switchEthereumChain",
|
1006
|
+
params: [
|
1007
|
+
{
|
1008
|
+
chainId: _chunk5ZBNF5WMjs.numberToHex.call(void 0, id)
|
1009
|
+
}
|
1010
|
+
]
|
1011
|
+
});
|
1012
|
+
}
|
1013
|
+
|
1014
|
+
// src/actions/wallet/watchAsset.ts
|
1015
|
+
async function watchAsset(client, params) {
|
1016
|
+
const added = await client.request({
|
1017
|
+
method: "wallet_watchAsset",
|
1018
|
+
params: [params]
|
1019
|
+
});
|
1020
|
+
return added;
|
1021
|
+
}
|
1022
|
+
|
1023
|
+
|
1024
|
+
|
1025
|
+
|
1026
|
+
|
1027
|
+
|
1028
|
+
|
1029
|
+
|
1030
|
+
|
1031
|
+
|
1032
|
+
|
1033
|
+
|
1034
|
+
|
1035
|
+
|
1036
|
+
|
1037
|
+
|
1038
|
+
|
1039
|
+
|
1040
|
+
|
1041
|
+
|
1042
|
+
|
1043
|
+
|
1044
|
+
|
1045
|
+
|
1046
|
+
|
1047
|
+
|
1048
|
+
|
1049
|
+
|
1050
|
+
|
1051
|
+
|
1052
|
+
|
1053
|
+
|
1054
|
+
|
1055
|
+
|
1056
|
+
|
1057
|
+
|
1058
|
+
|
1059
|
+
|
1060
|
+
|
1061
|
+
|
1062
|
+
|
1063
|
+
|
1064
|
+
|
1065
|
+
|
1066
|
+
|
1067
|
+
|
1068
|
+
|
1069
|
+
|
1070
|
+
|
1071
|
+
|
1072
|
+
|
1073
|
+
|
1074
|
+
|
1075
|
+
|
1076
|
+
|
1077
|
+
|
1078
|
+
|
1079
|
+
|
1080
|
+
|
1081
|
+
|
1082
|
+
|
1083
|
+
|
1084
|
+
exports.call = call; exports.callContract = callContract; exports.createPendingTransactionFilter = createPendingTransactionFilter; exports.createBlockFilter = createBlockFilter; exports.estimateGas = estimateGas; exports.getBalance = getBalance; exports.getBlock = getBlock; exports.getBlockNumberCache = getBlockNumberCache; exports.getBlockNumber = getBlockNumber; exports.getBlockTransactionCount = getBlockTransactionCount; exports.getChainId = getChainId; exports.getFeeHistory = getFeeHistory; exports.getFilterChanges = getFilterChanges; exports.getFilterLogs = getFilterLogs; exports.getGasPrice = getGasPrice; exports.getTransaction = getTransaction; exports.getTransactionConfirmations = getTransactionConfirmations; exports.getTransactionCount = getTransactionCount; exports.getTransactionReceipt = getTransactionReceipt; exports.uninstallFilter = uninstallFilter; exports.waitForTransactionReceipt = waitForTransactionReceipt; exports.watchBlockNumber = watchBlockNumber; exports.watchBlocks = watchBlocks; exports.watchPendingTransactions = watchPendingTransactions; exports.dropTransaction = dropTransaction; exports.getAutomine = getAutomine; exports.getTxpoolContent = getTxpoolContent; exports.getTxpoolStatus = getTxpoolStatus; exports.impersonateAccount = impersonateAccount; exports.increaseTime = increaseTime; exports.inspectTxpool = inspectTxpool; exports.mine = mine; exports.removeBlockTimestampInterval = removeBlockTimestampInterval; exports.reset = reset; exports.revert = revert; exports.sendUnsignedTransaction = sendUnsignedTransaction; exports.setAutomine = setAutomine; exports.setBalance = setBalance; exports.setBlockGasLimit = setBlockGasLimit; exports.setBlockTimestampInterval = setBlockTimestampInterval; exports.setCode = setCode; exports.setCoinbase = setCoinbase; exports.setIntervalMining = setIntervalMining; exports.setLoggingEnabled = setLoggingEnabled; exports.setMinGasPrice = setMinGasPrice; exports.setNextBlockBaseFeePerGas = setNextBlockBaseFeePerGas; exports.setNextBlockTimestamp = setNextBlockTimestamp; exports.setNonce = setNonce; exports.setStorageAt = setStorageAt; exports.snapshot = snapshot; exports.stopImpersonatingAccount = stopImpersonatingAccount; exports.addChain = addChain; exports.getAccounts = getAccounts; exports.getPermissions = getPermissions; exports.requestAccounts = requestAccounts; exports.requestPermissions = requestPermissions; exports.sendTransaction = sendTransaction; exports.signMessage = signMessage; exports.switchChain = switchChain; exports.watchAsset = watchAsset;
|