evm-transactions-tools 0.0.1
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/AUTHORS.rst +43 -0
- package/COPYING +661 -0
- package/README.md +101 -0
- package/lib/transaction-get +461 -0
- package/lib/transaction-receipt-get +461 -0
- package/libevm-transactions-tools +206 -0
- package/package.json +108 -0
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
4
|
+
|
|
5
|
+
/** -----------------------------------------------------
|
|
6
|
+
* transaction-receipt-get
|
|
7
|
+
* -----------------------------------------------------
|
|
8
|
+
* Copyright ©
|
|
9
|
+
* Pellegrino Prevete
|
|
10
|
+
* 2024, 2025, 2026
|
|
11
|
+
*
|
|
12
|
+
* All rights reserved
|
|
13
|
+
* -----------------------------------------------------
|
|
14
|
+
*
|
|
15
|
+
* This program is free software: you can redistribute
|
|
16
|
+
* it and/or modify it under the terms of the
|
|
17
|
+
* GNU General Public License as published by
|
|
18
|
+
* the Free Software Foundation, either version 3 of
|
|
19
|
+
* the License, or (at your option) any later version.
|
|
20
|
+
*
|
|
21
|
+
* This program is distributed in the hope that it
|
|
22
|
+
* will be useful, but WITHOUT ANY WARRANTY;
|
|
23
|
+
* without even the implied warranty of
|
|
24
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
25
|
+
* See the GNU General Public License
|
|
26
|
+
* for more details.
|
|
27
|
+
*
|
|
28
|
+
* You should have received a copy of the
|
|
29
|
+
* GNU General Public License
|
|
30
|
+
* along with this program.
|
|
31
|
+
* If not, see <https://www.gnu.org/licenses/>.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
// const
|
|
36
|
+
// { ethers } =
|
|
37
|
+
// require(
|
|
38
|
+
// "ethers");
|
|
39
|
+
// _ethers =
|
|
40
|
+
// ethers;
|
|
41
|
+
const
|
|
42
|
+
_libcrash =
|
|
43
|
+
require(
|
|
44
|
+
'../libcrash-js/crash-js');
|
|
45
|
+
_cmdline_check =
|
|
46
|
+
_libcrash._cmdline_check;
|
|
47
|
+
_dirname =
|
|
48
|
+
_libcrash._dirname;
|
|
49
|
+
_file_read =
|
|
50
|
+
_libcrash._file_read;
|
|
51
|
+
_file_write =
|
|
52
|
+
_libcrash._file_write;
|
|
53
|
+
_json_display =
|
|
54
|
+
_libcrash._json_display;
|
|
55
|
+
_path_join =
|
|
56
|
+
_libcrash._path_join;
|
|
57
|
+
_msg_info =
|
|
58
|
+
_libcrash._msg_info;
|
|
59
|
+
_msg_error =
|
|
60
|
+
_libcrash._msg_error;
|
|
61
|
+
_printf =
|
|
62
|
+
_libcrash._printf;
|
|
63
|
+
const
|
|
64
|
+
_evm_wallet_get =
|
|
65
|
+
require(
|
|
66
|
+
'../evm-wallet/wallet-get');
|
|
67
|
+
_wallet_get =
|
|
68
|
+
_evm_wallet_get._wallet_get;
|
|
69
|
+
const
|
|
70
|
+
_network_provider_module =
|
|
71
|
+
require(
|
|
72
|
+
'../evm-wallet/network-provider');
|
|
73
|
+
_provider_get =
|
|
74
|
+
_network_provider_module._provider_get;
|
|
75
|
+
|
|
76
|
+
function
|
|
77
|
+
_global_variables() {
|
|
78
|
+
app_name =
|
|
79
|
+
"transaction-receipt-get"
|
|
80
|
+
retries_max =
|
|
81
|
+
"";
|
|
82
|
+
wallet_seed =
|
|
83
|
+
"";
|
|
84
|
+
wallet_password_path =
|
|
85
|
+
"";
|
|
86
|
+
transaction_address =
|
|
87
|
+
"";
|
|
88
|
+
chain_id =
|
|
89
|
+
"";
|
|
90
|
+
chain_name =
|
|
91
|
+
"";
|
|
92
|
+
target_network =
|
|
93
|
+
"";
|
|
94
|
+
api_key_path =
|
|
95
|
+
"";
|
|
96
|
+
output_path =
|
|
97
|
+
"";
|
|
98
|
+
quiet =
|
|
99
|
+
"";
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function
|
|
103
|
+
_msg_error_no_input_data() {
|
|
104
|
+
let
|
|
105
|
+
_msg,
|
|
106
|
+
_text;
|
|
107
|
+
_text = [
|
|
108
|
+
"You need to provide either",
|
|
109
|
+
"the bytecode or the data"
|
|
110
|
+
];
|
|
111
|
+
_msg =
|
|
112
|
+
_text.join(
|
|
113
|
+
" ");
|
|
114
|
+
_msg_error(
|
|
115
|
+
_msg,
|
|
116
|
+
1);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function
|
|
120
|
+
_msg_info_wallet_selected(
|
|
121
|
+
_wallet) {
|
|
122
|
+
let
|
|
123
|
+
_msg,
|
|
124
|
+
_template;
|
|
125
|
+
_template =
|
|
126
|
+
"Wallet is '{_wallet}'.";
|
|
127
|
+
_msg =
|
|
128
|
+
_template.replaceAll(
|
|
129
|
+
"{_wallet}",
|
|
130
|
+
_wallet);
|
|
131
|
+
_msg_info(
|
|
132
|
+
_msg);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function
|
|
136
|
+
_transaction_receipt_get(
|
|
137
|
+
_retries_max,
|
|
138
|
+
_wallet_seed,
|
|
139
|
+
_wallet_password_path,
|
|
140
|
+
_chain_id,
|
|
141
|
+
_chain_name,
|
|
142
|
+
_target_network,
|
|
143
|
+
_api_key_path,
|
|
144
|
+
_output_path,
|
|
145
|
+
_transaction_address) {
|
|
146
|
+
let
|
|
147
|
+
_api_key,
|
|
148
|
+
_get_transaction_opts,
|
|
149
|
+
_json,
|
|
150
|
+
_network,
|
|
151
|
+
_network_provider,
|
|
152
|
+
_provider_get_opts,
|
|
153
|
+
_receipt,
|
|
154
|
+
_wallet,
|
|
155
|
+
_wallet_get_opts,
|
|
156
|
+
_wallet_path_list,
|
|
157
|
+
_wallet_path;
|
|
158
|
+
_provider_get_opts = [
|
|
159
|
+
_target_network
|
|
160
|
+
];
|
|
161
|
+
if ( _output_path == undefined ) {
|
|
162
|
+
_output_path =
|
|
163
|
+
"";
|
|
164
|
+
}
|
|
165
|
+
if ( _api_key_path != "" ) {
|
|
166
|
+
_api_key =
|
|
167
|
+
_file_read(
|
|
168
|
+
_api_key_path);
|
|
169
|
+
}
|
|
170
|
+
else if ( _api_key_path == undefined ) {
|
|
171
|
+
_api_key =
|
|
172
|
+
"";
|
|
173
|
+
}
|
|
174
|
+
_provider_get_opts.push(
|
|
175
|
+
_api_key);
|
|
176
|
+
if (_chain_id == undefined ) {
|
|
177
|
+
_chain_id =
|
|
178
|
+
"";
|
|
179
|
+
}
|
|
180
|
+
_provider_get_opts.push(
|
|
181
|
+
_chain_id);
|
|
182
|
+
if ( _chain_name == undefined ) {
|
|
183
|
+
_chain_name =
|
|
184
|
+
"";
|
|
185
|
+
}
|
|
186
|
+
_provider_get_opts.push(
|
|
187
|
+
_chain_name);
|
|
188
|
+
_network_provider =
|
|
189
|
+
await _provider_get.apply(
|
|
190
|
+
null,
|
|
191
|
+
_provider_get_opts);
|
|
192
|
+
if ( _wallet_seed != "" &&
|
|
193
|
+
_wallet_seed != undefined ) {
|
|
194
|
+
_wallet_path_list = [
|
|
195
|
+
_dirname(
|
|
196
|
+
_wallet_seed),
|
|
197
|
+
"wallet.dat"
|
|
198
|
+
];
|
|
199
|
+
_wallet_path =
|
|
200
|
+
_path_join(
|
|
201
|
+
_wallet_path_list);
|
|
202
|
+
_wallet_get_opts = [
|
|
203
|
+
_wallet_path,
|
|
204
|
+
_wallet_password_path,
|
|
205
|
+
_wallet_seed,
|
|
206
|
+
_network_provider
|
|
207
|
+
];
|
|
208
|
+
_wallet =
|
|
209
|
+
_wallet_get.apply(
|
|
210
|
+
null,
|
|
211
|
+
_wallet_get_opts);
|
|
212
|
+
_msg_info_wallet_selected(
|
|
213
|
+
_wallet);
|
|
214
|
+
_network_provider =
|
|
215
|
+
_wallet;
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
_receipt =
|
|
219
|
+
await _network_provider.getTransactionReceipt(
|
|
220
|
+
_transaction_address);
|
|
221
|
+
if ( _output_path != "" ) {
|
|
222
|
+
_json =
|
|
223
|
+
_json_display(
|
|
224
|
+
_receipt);
|
|
225
|
+
_file_write(
|
|
226
|
+
_output_path,
|
|
227
|
+
_json);
|
|
228
|
+
}
|
|
229
|
+
} catch (e) {
|
|
230
|
+
console.error(
|
|
231
|
+
e);
|
|
232
|
+
}
|
|
233
|
+
return _receipt;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function
|
|
237
|
+
_config_show() {
|
|
238
|
+
let
|
|
239
|
+
_line,
|
|
240
|
+
_text;
|
|
241
|
+
_text = [];
|
|
242
|
+
_text.push(
|
|
243
|
+
" Maximum retries: {retries_max}".replace(
|
|
244
|
+
"{retries_max}",
|
|
245
|
+
retries_max));
|
|
246
|
+
_text.push(
|
|
247
|
+
" Wallet seed: {wallet_seed}".replace(
|
|
248
|
+
"{wallet_seed}",
|
|
249
|
+
wallet_seed));
|
|
250
|
+
_text.push(
|
|
251
|
+
" Chain ID: {chain_id}".replace(
|
|
252
|
+
"{chain_id}",
|
|
253
|
+
chain_id));
|
|
254
|
+
_text.push(
|
|
255
|
+
" Chain Name: {chain_name}".replace(
|
|
256
|
+
"{chain_name}",
|
|
257
|
+
chain_name));
|
|
258
|
+
_text.push(
|
|
259
|
+
" Target network: {target_network}".replace(
|
|
260
|
+
"{target_network}",
|
|
261
|
+
target_network));
|
|
262
|
+
_text.push(
|
|
263
|
+
" API Key: {api_key_path}".replace(
|
|
264
|
+
"{api_key_path}",
|
|
265
|
+
api_key_path));
|
|
266
|
+
_text.push(
|
|
267
|
+
" Output path: {output_path}".replace(
|
|
268
|
+
"{output_path}",
|
|
269
|
+
output_path));
|
|
270
|
+
_text.push(
|
|
271
|
+
" Transaction address: {transaction_address}".replace(
|
|
272
|
+
"{transaction_address}",
|
|
273
|
+
transaction_address));
|
|
274
|
+
for ( _line of _text ) {
|
|
275
|
+
_msg_info(
|
|
276
|
+
_line);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function
|
|
281
|
+
_usage(
|
|
282
|
+
_exit_code) {
|
|
283
|
+
let
|
|
284
|
+
_line,
|
|
285
|
+
_text;
|
|
286
|
+
_text = [
|
|
287
|
+
"Usage:",
|
|
288
|
+
" contract-get",
|
|
289
|
+
" <quiet>",
|
|
290
|
+
" <retries_max>",
|
|
291
|
+
" <wallet_seed>",
|
|
292
|
+
" <wallet_password_path>",
|
|
293
|
+
" <chain_id>",
|
|
294
|
+
" <chain_name>",
|
|
295
|
+
" <target_network>",
|
|
296
|
+
" <api_key_path>",
|
|
297
|
+
" <output_path>",
|
|
298
|
+
" <transaction_address>",
|
|
299
|
+
"",
|
|
300
|
+
"Args:",
|
|
301
|
+
" <quiet> Can be 'y' or 'n'",
|
|
302
|
+
" Default: y",
|
|
303
|
+
" <retries_max> Maximum number of retries before",
|
|
304
|
+
" failing.",
|
|
305
|
+
" <wallet_seed> Path of the seed phrase.",
|
|
306
|
+
" <wallet_password_path> Wallet password path.",
|
|
307
|
+
" <chain_id> Chain ID for the network.",
|
|
308
|
+
" <chain_name> Name for the network.",
|
|
309
|
+
" <target_network> Network on which the transaction",
|
|
310
|
+
" resides.",
|
|
311
|
+
" <api_key_path> Path of the API key for the",
|
|
312
|
+
" contract ABI provider service.",
|
|
313
|
+
" <output_path> File on which to optionally save",
|
|
314
|
+
" the output.",
|
|
315
|
+
" <transaction_address> Transaction one wants to retrieve.",
|
|
316
|
+
"",
|
|
317
|
+
" Options:",
|
|
318
|
+
" -h This help."
|
|
319
|
+
];
|
|
320
|
+
for ( _line of _text ) {
|
|
321
|
+
_msg_info(
|
|
322
|
+
_line);
|
|
323
|
+
}
|
|
324
|
+
process.exit(
|
|
325
|
+
_exit_code);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function _cmdline_parse() {
|
|
329
|
+
quiet =
|
|
330
|
+
"y";
|
|
331
|
+
process.argv.forEach(
|
|
332
|
+
function (
|
|
333
|
+
_value,
|
|
334
|
+
_index,
|
|
335
|
+
_array) {
|
|
336
|
+
if ( _index == 2 ) {
|
|
337
|
+
quiet =
|
|
338
|
+
_value;
|
|
339
|
+
}
|
|
340
|
+
if ( _index == 3 ) {
|
|
341
|
+
retries_max =
|
|
342
|
+
_value;
|
|
343
|
+
}
|
|
344
|
+
if ( _index == 4 ) {
|
|
345
|
+
wallet_seed =
|
|
346
|
+
_value;
|
|
347
|
+
}
|
|
348
|
+
if ( _index == 5 ) {
|
|
349
|
+
wallet_password_path =
|
|
350
|
+
_value;
|
|
351
|
+
}
|
|
352
|
+
if ( _index == 6 ) {
|
|
353
|
+
chain_id =
|
|
354
|
+
_value;
|
|
355
|
+
}
|
|
356
|
+
if ( _index == 7 ) {
|
|
357
|
+
chain_name =
|
|
358
|
+
_value;
|
|
359
|
+
}
|
|
360
|
+
if ( _index == 8 ) {
|
|
361
|
+
target_network =
|
|
362
|
+
_value;
|
|
363
|
+
}
|
|
364
|
+
if ( _index == 9 ) {
|
|
365
|
+
api_key_path =
|
|
366
|
+
_value;
|
|
367
|
+
}
|
|
368
|
+
if ( _index == 10 ) {
|
|
369
|
+
output_path =
|
|
370
|
+
_value;
|
|
371
|
+
}
|
|
372
|
+
if ( _index == 11 ) {
|
|
373
|
+
transaction_address =
|
|
374
|
+
_value;
|
|
375
|
+
}
|
|
376
|
+
if ( _value == "-h" ||
|
|
377
|
+
_value == "--help" ) {
|
|
378
|
+
quiet =
|
|
379
|
+
"n";
|
|
380
|
+
_usage(
|
|
381
|
+
0);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
);
|
|
385
|
+
if ( transaction_address == "" ) {
|
|
386
|
+
quiet =
|
|
387
|
+
"n";
|
|
388
|
+
_usage(
|
|
389
|
+
1);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function
|
|
394
|
+
_overrides_set() {
|
|
395
|
+
if ( retries_max == "" ) {
|
|
396
|
+
retries_max =
|
|
397
|
+
100;
|
|
398
|
+
}
|
|
399
|
+
if ( chain_id == "" ) {
|
|
400
|
+
_msg_info(
|
|
401
|
+
"TODO: use evm_chains_info_module");
|
|
402
|
+
}
|
|
403
|
+
if ( chain_name == "" ) {
|
|
404
|
+
_msg_info(
|
|
405
|
+
"TODO: use evm_chains_info_module");
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
async function
|
|
410
|
+
_transaction_receipt_get_cmdline(
|
|
411
|
+
_app_opts) {
|
|
412
|
+
let
|
|
413
|
+
_json,
|
|
414
|
+
_receipt;
|
|
415
|
+
try {
|
|
416
|
+
_receipt =
|
|
417
|
+
await _transaction_receipt_get.apply(
|
|
418
|
+
null,
|
|
419
|
+
_app_opts);
|
|
420
|
+
if ( _receipt != undefined ) {
|
|
421
|
+
_json =
|
|
422
|
+
_json_display(
|
|
423
|
+
_receipt);
|
|
424
|
+
_printf(
|
|
425
|
+
_json);
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
throw "'Transaction Receipt Get' returned undefined value."
|
|
429
|
+
}
|
|
430
|
+
} catch (error) {
|
|
431
|
+
_msg_error(
|
|
432
|
+
error,
|
|
433
|
+
1);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
if ( _cmdline_check(
|
|
438
|
+
"transaction-receipt-get") ) {
|
|
439
|
+
_global_variables();
|
|
440
|
+
_cmdline_parse();
|
|
441
|
+
_overrides_set();
|
|
442
|
+
_config_show();
|
|
443
|
+
app_opts = [
|
|
444
|
+
retries_max,
|
|
445
|
+
wallet_seed,
|
|
446
|
+
wallet_password_path,
|
|
447
|
+
chain_id,
|
|
448
|
+
chain_name,
|
|
449
|
+
target_network,
|
|
450
|
+
api_key_path,
|
|
451
|
+
output_path,
|
|
452
|
+
transaction_address
|
|
453
|
+
];
|
|
454
|
+
_transaction_receipt_get_cmdline(
|
|
455
|
+
app_opts);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
module.exports = {
|
|
459
|
+
_transaction_receipt_get:
|
|
460
|
+
_transaction_receipt_get
|
|
461
|
+
};
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
|
+
|
|
6
|
+
/** ----------------------------------------------------------------
|
|
7
|
+
* libevm-transactions-tools
|
|
8
|
+
* ----------------------------------------------------------------
|
|
9
|
+
* Copyright ©
|
|
10
|
+
* Pellegrino Prevete
|
|
11
|
+
* 2025, 2026
|
|
12
|
+
*
|
|
13
|
+
* All rights reserved
|
|
14
|
+
* ----------------------------------------------------------------
|
|
15
|
+
*
|
|
16
|
+
* This program is free software: you can redistribute it and/or
|
|
17
|
+
* modify it under the terms of the GNU General Public License as
|
|
18
|
+
* published by the Free Software Foundation, either version 3 of
|
|
19
|
+
* the License, or (at your option) any later version.
|
|
20
|
+
*
|
|
21
|
+
* This program is distributed in the hope that it will be useful,
|
|
22
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
23
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
24
|
+
* GNU General Public License for more details.
|
|
25
|
+
*
|
|
26
|
+
* You should have received a copy of the
|
|
27
|
+
* GNU General Public License
|
|
28
|
+
* along with this program.
|
|
29
|
+
* If not, see <https://www.gnu.org/licenses/>.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
// const
|
|
33
|
+
// _libcrash =
|
|
34
|
+
// require(
|
|
35
|
+
// '../libcrash-js/crash-js');
|
|
36
|
+
const
|
|
37
|
+
_libcrash_module =
|
|
38
|
+
require(
|
|
39
|
+
"crash-js");
|
|
40
|
+
_file_exists =
|
|
41
|
+
_libcrash_module._file_exists;
|
|
42
|
+
_json_read =
|
|
43
|
+
_libcrash_module._json_read;
|
|
44
|
+
_path_join =
|
|
45
|
+
_libcrash_module._path_join;
|
|
46
|
+
|
|
47
|
+
function
|
|
48
|
+
_evm_chains_db_path_get(
|
|
49
|
+
_user) {
|
|
50
|
+
let
|
|
51
|
+
_db_exists,
|
|
52
|
+
_path;
|
|
53
|
+
if ( _user == undefined ) {
|
|
54
|
+
_user =
|
|
55
|
+
false;
|
|
56
|
+
}
|
|
57
|
+
if ( _user == true ) {
|
|
58
|
+
_path =
|
|
59
|
+
_path_join(
|
|
60
|
+
[process.env.HOME,
|
|
61
|
+
".local",
|
|
62
|
+
"share",
|
|
63
|
+
"evm-chains",
|
|
64
|
+
"chains.json"])
|
|
65
|
+
_db_exists =
|
|
66
|
+
_file_exists(
|
|
67
|
+
_db_path);
|
|
68
|
+
if ( _db_exists == false ) {
|
|
69
|
+
_user =
|
|
70
|
+
false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if ( _user == false ) {
|
|
74
|
+
_path =
|
|
75
|
+
_path_join(
|
|
76
|
+
[process.env.NODE_PATH,
|
|
77
|
+
"..",
|
|
78
|
+
"evm-chains",
|
|
79
|
+
"chains.json"])
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
_msg_error(
|
|
83
|
+
"Input variable '_user' must be a boolean",
|
|
84
|
+
0);
|
|
85
|
+
}
|
|
86
|
+
return _path;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function
|
|
90
|
+
_evm_chain_info_get(
|
|
91
|
+
_chain_id,
|
|
92
|
+
_chain_info,
|
|
93
|
+
_db_path) {
|
|
94
|
+
let
|
|
95
|
+
_db,
|
|
96
|
+
_db_exists;
|
|
97
|
+
if ( _db_path == undefined ) {
|
|
98
|
+
_db_path =
|
|
99
|
+
_evm_chains_db_path_get(
|
|
100
|
+
false);
|
|
101
|
+
}
|
|
102
|
+
_db_exists =
|
|
103
|
+
_file_exists(
|
|
104
|
+
_db_path);
|
|
105
|
+
if ( _db_exists == false ) {
|
|
106
|
+
_msg_error(
|
|
107
|
+
"Database file does not exists.",
|
|
108
|
+
1);
|
|
109
|
+
}
|
|
110
|
+
_db =
|
|
111
|
+
_json_read(
|
|
112
|
+
_db_path);
|
|
113
|
+
for ( _chain_info of _db) {
|
|
114
|
+
if ( _chain_info["chainId"] == _chain_id ) {
|
|
115
|
+
return _chain_info;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
_msg_error(
|
|
119
|
+
`Network '${_chain_id}' not found.`,
|
|
120
|
+
1);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function
|
|
124
|
+
_rpc_backend_get(
|
|
125
|
+
_network_chain_id,
|
|
126
|
+
_selection_method,
|
|
127
|
+
_db_path) {
|
|
128
|
+
let
|
|
129
|
+
_chain_id,
|
|
130
|
+
_chain_info;
|
|
131
|
+
if ( _network_chain_id == undefined ) {
|
|
132
|
+
_msg_error(
|
|
133
|
+
"Network's ChainID not specified.",
|
|
134
|
+
1);
|
|
135
|
+
}
|
|
136
|
+
if ( _selection_method == undefined ) {
|
|
137
|
+
_selection_method =
|
|
138
|
+
"kirsh";
|
|
139
|
+
}
|
|
140
|
+
if ( _db_path == undefined ) {
|
|
141
|
+
_db_path =
|
|
142
|
+
_evm_chains_db_path_get(
|
|
143
|
+
false);
|
|
144
|
+
}
|
|
145
|
+
_chain_id =
|
|
146
|
+
Number(
|
|
147
|
+
_network_chain_id);
|
|
148
|
+
_chain_info =
|
|
149
|
+
_evm_chain_info_get(
|
|
150
|
+
_chain_id,
|
|
151
|
+
_db_path);
|
|
152
|
+
if ( _selection_method == "kirsh" ) {
|
|
153
|
+
return _chain_info["rpc"][0];
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
_msg_error(
|
|
157
|
+
"Unknown selection method.",
|
|
158
|
+
1);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function _rpc_backends_get(
|
|
163
|
+
_networks_chain_ids,
|
|
164
|
+
_selection_method,
|
|
165
|
+
_db_path) {
|
|
166
|
+
let
|
|
167
|
+
_chain_id,
|
|
168
|
+
_rpc_backend_get_opts,
|
|
169
|
+
_rpcs;
|
|
170
|
+
if ( _selection_method == undefined ) {
|
|
171
|
+
_selection_method =
|
|
172
|
+
"kirsh";
|
|
173
|
+
}
|
|
174
|
+
if ( _db_path == undefined ) {
|
|
175
|
+
_db_path =
|
|
176
|
+
_evm_chains_db_path_get(
|
|
177
|
+
false);
|
|
178
|
+
}
|
|
179
|
+
_rpcs =
|
|
180
|
+
[];
|
|
181
|
+
for ( _chain_id of _networks_chain_ids ) {
|
|
182
|
+
_rpc_backend_get_opts = [
|
|
183
|
+
_chain_id,
|
|
184
|
+
_selection_method,
|
|
185
|
+
_db_path
|
|
186
|
+
];
|
|
187
|
+
_rpc_backend =
|
|
188
|
+
_rpc_backend_get.apply(
|
|
189
|
+
null,
|
|
190
|
+
_rpc_backend_get_opts);
|
|
191
|
+
_rpcs.append(
|
|
192
|
+
_rpc_backend);
|
|
193
|
+
}
|
|
194
|
+
return _rpcs;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
module.exports = {
|
|
198
|
+
_evm_chains_db_path_get:
|
|
199
|
+
_evm_chains_db_path_get,
|
|
200
|
+
_evm_chain_info_get:
|
|
201
|
+
_evm_chain_info_get,
|
|
202
|
+
_rpc_backend_get:
|
|
203
|
+
_rpc_backend_get,
|
|
204
|
+
_rpc_backends_get:
|
|
205
|
+
_rpc_backends_get
|
|
206
|
+
};
|