evm-contracts-tools 0.0.11 → 0.0.14

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/evm-contract-call CHANGED
@@ -3,7 +3,7 @@
3
3
  // SPDX-License-Identifier: AGPL-3.0-or-later
4
4
 
5
5
  /** ----------------------------------------------------------------
6
- * evm-chains-info.js
6
+ * evm-contract-call.js
7
7
  * ----------------------------------------------------------------
8
8
  * Copyright ©
9
9
  * Pellegrino Prevete
@@ -30,6 +30,34 @@
30
30
  /* eslint-disable
31
31
  no-unused-vars */
32
32
 
33
+ /* global
34
+ call_auth:
35
+ writable */
36
+ /* global
37
+ call_timeout:
38
+ writable */
39
+ /* global
40
+ msg_value:
41
+ writable */
42
+ /* global
43
+ target_network:
44
+ writable */
45
+ /* global
46
+ target_networks:
47
+ writable */
48
+ /* global
49
+ api_key:
50
+ writable */
51
+ /* global
52
+ wallet_path:
53
+ writable */
54
+ /* global
55
+ wallet_password:
56
+ writable */
57
+ /* global
58
+ wallet_seed:
59
+ writable */
60
+
33
61
  const
34
62
  _libcrash =
35
63
  require(
@@ -69,56 +97,59 @@ const
69
97
  const
70
98
  _process_exit =
71
99
  _libcrash._process_exit;
72
-
73
-
74
100
  const
75
101
  _libevm_module =
76
102
  require(
77
103
  "libevm");
104
+ /* global
105
+ _libevm_cmdline_parse */
106
+ const
107
+ _libevm_cmdline_parse =
108
+ _libevm_module._libevm_cmdline_parse;
78
109
  /* global
79
110
  _libevm_global_variables */
80
111
  const
81
112
  _libevm_global_variables =
82
113
  _libevm_module._libevm_global_variables;
114
+ /* global
115
+ _libevm_url_parse */
116
+ const
117
+ _libevm_url_parse =
118
+ _libevm_module._libevm_url_parse;
83
119
  /* global
84
120
  _wallet_overrides_set */
85
121
  const
86
122
  _wallet_overrides_set =
87
123
  _libevm_module._wallet_overrides_set;
88
124
  const
89
- _libevm_chains_info_module =
125
+ _libevm_contract_call_module =
90
126
  require(
91
- "libevm-chains-info");
92
- /* global
93
- _evm_chains_db_path_get */
94
- const
95
- _evm_chains_db_path_get =
96
- _libevm_chains_info_module._evm_chains_db_path_get;
127
+ "./libevm-contract-call");
97
128
  /* global
98
- _evm_chains_info_get */
129
+ _artifact_local_auto_detect */
99
130
  const
100
- _evm_chain_info_get =
101
- _libevm_chains_info_module._evm_chain_info_get;
131
+ _artifact_local_auto_detect =
132
+ _libevm_contract_call_module._artifact_local_auto_detect;
102
133
  /* global
103
- _rpc_backends_get */
134
+ _default_artifact_path_get */
104
135
  const
105
- _rpc_backend_get =
106
- _libevm_chains_info_module._rpc_backend_get;
136
+ _default_artifact_path_get =
137
+ _libevm_contract_call_module._default_artifact_path_get;
107
138
  /* global
108
- _evm_chains_info */
139
+ _contract_abi_auto_detect */
109
140
  const
110
- _evm_chains_info =
111
- _libevm_chains_info_module._evm_chains_info;
141
+ _contract_abi_auto_detect =
142
+ _libevm_contract_call_module._contract_abi_auto_detect;
112
143
  /* global
113
- _db_paths_auto_detect */
144
+ _evm_contract_call */
114
145
  const
115
- _db_paths_auto_detect =
116
- _libevm_chains_info_module._db_paths_auto_detect;
146
+ _evm_contract_call =
147
+ _libevm_contract_call_module._evm_contract_call;
117
148
  /* global
118
- _input_type_auto_detect */
149
+ _call_auth_auto_detect */
119
150
  const
120
- _input_type_auto_detect =
121
- _libevm_chains_info_module._input_type_auto_detect;
151
+ _call_auth_auto_detect =
152
+ _libevm_contract_call_module._db_paths_auto_detect;
122
153
 
123
154
  function
124
155
  _global_variables() {
@@ -142,6 +173,21 @@ function
142
173
  writable */
143
174
  call_date =
144
175
  "";
176
+ /* global
177
+ wallet_name:
178
+ writable */
179
+ wallet_name =
180
+ "";
181
+ /* global
182
+ retries_max:
183
+ writable */
184
+ retries_max =
185
+ "";
186
+ /* global
187
+ rpc_selection:
188
+ writable */
189
+ rpc_selection =
190
+ "";
145
191
  /* global
146
192
  call_type:
147
193
  writable */
@@ -210,41 +256,59 @@ function
210
256
  call_date =
211
257
  _get_date_human();
212
258
  }
213
- _wallet_overrides_set();
214
- if ( target_command == "" ) {
215
- target_command =
216
- "get";
217
- }
218
- _input_type_auto_detect();
219
- if ( output_type == "" ) {
220
- output_type =
221
- "name";
222
- }
223
- if ( retrieval_mode == "" ) {
224
- retrieval_mode =
225
- "offline";
226
- }
227
- if ( selection_method == "" ) {
228
- // TODO:
229
- // remove all references
230
- // to that monster
231
- selection_method =
232
- "kirsh";
259
+ if ( wallet_name == "" ) {
260
+ wallet_name =
261
+ "default";
233
262
  }
234
- if ( api_key == "" ) {
235
- api_key =
263
+ if ( index_retrieve == "" ) {
264
+ index_retrieve =
236
265
  "n";
237
266
  }
238
- if ( user_level == "" ) {
239
- user_level =
240
- "y";
267
+ if ( retries_max == "" ) {
268
+ retries_max =
269
+ "300";
241
270
  }
242
- if ( networks_all == "" ) {
243
- networks_all =
244
- "n";
271
+ if ( rpc_selection == "" ) {
272
+ rpc_selection =
273
+ "kirsh";
274
+ }
275
+ if ( call_type == "" ) {
276
+ call_type =
277
+ "static";
278
+ }
279
+ _call_auth_auto_detect();
280
+ if ( call_timeout == "" ) {
281
+ call_timeout =
282
+ "300000";
283
+ }
284
+ if ( measure_unit == "" ) {
285
+ measure_unit =
286
+ "ether";
245
287
  }
246
- _db_paths_auto_detect(
247
- target_chain);
288
+ if ( msg_value == "" ) {
289
+ msg_value =
290
+ "0";
291
+ }
292
+ // _api_key_auto_detect();
293
+ if ( contract_address != "" ) {
294
+ if ( contract_abi == "" ) {
295
+ contract_abi =
296
+ _default_artifact_path_get();
297
+ _artifact_local_auto_detect(
298
+ "bytecode");
299
+ _artifact_local_auto_detect(
300
+ "compiler_output");
301
+ if ( contract_abi == "" ||
302
+ _default_artifact_path_get(
303
+ "abi") == contract_abi ) {
304
+ _contract_abi_auto_detect();
305
+ }
306
+ }
307
+ }
308
+ _wallet_overrides_set(
309
+ "evm-wallet",
310
+ wallet_name,
311
+ call_auth);
248
312
  }
249
313
 
250
314
  function
@@ -256,16 +320,31 @@ function
256
320
  `${app_name} configuration:`,
257
321
  ` Call date: ${call_date}`,
258
322
  ` Runtime environment: ${runtime_environment}`,
259
- ` Target command: ${target_command}`,
260
- ` Input type: ${input_type}`,
261
- ` Output type: ${output_type}`,
262
- ` Retrieval mode: ${retrieval_mode}`,
263
- ` User-level database: ${user_level}`,
323
+ ` Call type: ${call_type}`,
324
+ ` Call authentication: ${call_auth}`,
325
+ ` Credentials options:`,
326
+ ` Wallet name: ${wallet_name}`,
327
+ ` Wallet address: ${api_key}`,
328
+ ` Wallet path: ${wallet_path}`,
329
+ ` Wallet password: ${wallet_password}`,
330
+ ` Wallet seed: ${wallet_seed}`,
331
+ ` Network options:`,
332
+ ` Target network: ${target_network}`,
333
+ ` Max retries: ${retries_max}`,
334
+ ` Call timeout: ${call_timeout}`,
264
335
  ` API key: ${api_key}`,
265
- ` RPC selection method: ${selection_method}`,
266
- ` All networks: ${networks_all}`,
267
- ` Target chain: ${target_chain}`,
268
- ` Database paths: ${db_paths}`,
336
+ ` RPC selection method: ${rpc_selection}`,
337
+ ` Gas price: ${price_gas}`,
338
+ ` Contract options:`,
339
+ ` Contract address: ${contract_address}`,
340
+ ` Contract ABI: ${contract_abi}`,
341
+ ` Contract bytecode: ${contract_bytecode}`,
342
+ ` Contract compiler output: ${contract_compiler_output}`,
343
+ ` Call options:`,
344
+ ` Message value: ${msg_value}`,
345
+ ` Measure unit: ${measure_unit}`,
346
+ ` Contract method: ${contract_method}`,
347
+ ` Method arguments: ${method_args}`,
269
348
  ];
270
349
  for ( _line of _text ) {
271
350
  _msg_info(
@@ -280,47 +359,93 @@ function
280
359
  _line;
281
360
  const
282
361
  _text = [
283
- "Returns info about EVM blockchains.",
362
+ "Runs a smart contract function.",
284
363
  "",
285
364
  "Usage:",
286
365
  "",
287
- " evm-chains-info.js",
366
+ " evm-contract-call.js",
288
367
  " [options]",
289
- " <target-chain>",
368
+ " <contract-address>",
369
+ " <contract-method>",
370
+ " ([method-args])",
371
+ "",
372
+ " networks:",
373
+ " all those supported by",
374
+ " 'evm-chains-info' as well",
375
+ " as directly RPC addresses",
290
376
  "",
291
377
  " options:",
292
378
  "",
293
- " -C --command Target command. Can be 'get' or 'set'.",
294
- ` <target-command> Default: '${target_command}`,
379
+ " -t --call-type It can be 'static' or 'dynamic'.",
380
+ ` <call-type> Default: '${call_type}`,
381
+ "",
382
+ " call options:",
383
+ ` -V --msg-value How much '${measure_unit} to attach to the`,
384
+ ` <msg-value> transaction.`,
385
+ ` Default: '${msg_value}'`,
386
+ "",
387
+ " -u --measure-unit Measure unit for the transacion.",
388
+ ` <measure-unit> It can be 'ether' or 'wei'.`,
389
+ ` Default: '${measure_unit}'`,
390
+ "",
391
+ " -P --price-gas I dont remember. It can be 'idontknow'.",
392
+ " <price-gas>",
393
+ ` Default: '${price_gas}'`,
394
+ "",
395
+ " -r --retries-max Maximum number of retries before",
396
+ ` <retries-max> Declaring the call failed.`,
397
+ ` Default: '${retries_max}'`,
398
+ "",
399
+ " -T --call-timeout Maximum number of milliseconds before",
400
+ " <call-timeout> declaring the call failed.",
401
+ ` Default: '${call_timeout}'`,
295
402
  "",
296
- " -i --input-type Input type. It can be 'id' or 'name'.",
297
- ` <input-type> Default: '${input_type}'`,
403
+ " contract options:",
298
404
  "",
299
- " -o --output-type Output type. It can be 'id', 'name',",
300
- " <output-type> 'rpc', 'explorers'.",
301
- ` Default: '${output_type}'`,
405
+ " -A --abi Contract ABI path.",
406
+ ` <contract-abi> Default: '${contract_abi}'.`,
302
407
  "",
303
- " -m --retrieval-mode It can be 'offline'.",
304
- ` <retrieval-mode> Default: '${retrieval_mode}'`,
408
+ " -B --bytecode Contract bytecode path.",
409
+ ` <contract-bytecode> Default: '${contract_bytecode}'.`,
305
410
  "",
306
- " -u --user-level It can be 'y' or 'n'.",
307
- ` <user-level> Default: '${user_level}'`,
411
+ " -C --compiler-output Contract compiler output path",
412
+ ` <contract-bytecode> (the hardhat artifact.`,
413
+ ` Default: '${contract_compiler_output}'.`,
308
414
  "",
309
- " -d --db-path Path of the chains' info json file",
310
- " <db-path> to be used for 'offline' retrieval.",
311
- ` Default: '${db_paths}'`,
415
+ " -I --index-retrieve Enables retrieving contract's artifacts",
416
+ ` from the EVM Contracts Source Index.`,
417
+ ` Default: '${contract_compiler_output}'.`,
312
418
  "",
313
- " -s --selection-method When output type is 'rpc',",
314
- " <selection-method> selection criterion to use when",
315
- " more than one is available.",
316
- " It can be 'kirsh', 'random' or 'all'.",
317
- ` Default: '${selection_method}'`,
419
+ " credentials options:",
318
420
  "",
319
- " -k If selected, when output type is 'rpc',",
320
- " includes the ones requiring an API key.",
321
- ` Default: '${api_key}'`,
322
- " -a --all Whether to show results for all networks.",
323
- ` Default: '${networks_all}'`,
421
+ " -N --wallet-name EVM Wallet name.",
422
+ ` <wallet-name> Default: '${wallet_name}'.`,
423
+ "",
424
+ " -w --wallet-path EVM Wallet path.",
425
+ ` <wallet-path> Default: '${wallet_path}'.`,
426
+ "",
427
+ " -p --wallet-password EVM Wallet password file.",
428
+ ` <wallet-password> Default: '${wallet_password}'.`,
429
+ "",
430
+ " -s --wallet-seed EVM Wallet seed file.",
431
+ ` <wallet-seed> Default: '${wallet_seed}'.`,
432
+ "",
433
+ " -k --api-key Etherscan-like service key file.",
434
+ ` <api-key> Default: '${api_key}'.`,
435
+ "",
436
+ " libEVM options:",
437
+ "",
438
+ " -a --auth Call authentication.",
439
+ ` Default: '${call_auth}'`,
440
+ "",
441
+ " -n --network EVM network name. Accepted",
442
+ " <network> values are all those supported by",
443
+ ` 'evm-chains-info' and RPC addresses.`,
444
+ ` Default: '${target_network}'.`,
445
+ "",
446
+ " -S --rpc-selection RPC selection method. It can be",
447
+ " <rpc-selection> 'kirsh', 'random' or 'all'.",
448
+ ` Default: '${rpc_selection}'.`,
324
449
  "",
325
450
  " -h --help This message.",
326
451
  " -v --verbose Enable verbose output."
@@ -341,8 +466,12 @@ function
341
466
  const
342
467
  _argv_args = {
343
468
  "booleans": [
469
+ "a",
470
+ "auth",
344
471
  "h",
345
472
  "help",
473
+ "I",
474
+ "index-retrieve",
346
475
  "v",
347
476
  "verbose"
348
477
  ]
@@ -415,7 +544,8 @@ function
415
544
  0];
416
545
  const
417
546
  method_args =
418
- _out.slice(
547
+ _argv[
548
+ "_"].slice(
419
549
  2,
420
550
  _argv[
421
551
  "_"].length - 2);
@@ -504,26 +634,36 @@ function
504
634
  _argv[
505
635
  "A"];
506
636
  }
507
- if ( "contract-abi" in _argv ) {
637
+ if ( "abi" in _argv ) {
508
638
  contract_abi =
509
639
  _argv[
510
- "contract-abi"];
640
+ "abi"];
641
+ }
642
+ if ( "B" in _argv ) {
643
+ contract_bytecode =
644
+ _argv[
645
+ "B"];
646
+ }
647
+ if ( "bytecode" in _argv ) {
648
+ contract_bytecode =
649
+ _argv[
650
+ "bytecode"];
511
651
  }
512
652
  if ( "C" in _argv ) {
513
653
  contract_compiler_output =
514
654
  _argv[
515
655
  "C"];
516
656
  }
517
- if ( "contract-compiler-output" in _argv ) {
657
+ if ( "compiler-output" in _argv ) {
518
658
  contract_compiler_output =
519
659
  _argv[
520
- "contract-compiler-output"];
660
+ "compiler-output"];
521
661
  }
522
662
  if ( "a" in _argv ) {
523
663
  call_auth =
524
664
  "y";
525
665
  }
526
- if ( "call-auth" in _argv ) {
666
+ if ( "auth" in _argv ) {
527
667
  call_auth =
528
668
  "y";
529
669
  }
@@ -553,52 +693,69 @@ function
553
693
 
554
694
  function
555
695
  _url_parse() {
696
+ let
697
+ _method,
698
+ _network;
556
699
  runtime_environment =
557
700
  "browser";
558
- target_chain =
701
+ call_type =
702
+ _argv_url_get(
703
+ "call_type")[
704
+ 0];
705
+ call_timeout =
559
706
  _argv_url_get(
560
- "chain")[
707
+ "call_timeout")[
561
708
  0];
562
- target_command =
709
+ index_retrieve =
563
710
  _argv_url_get(
564
- "command")[
711
+ "index_retrieve")[
565
712
  0];
566
- input_type =
713
+ price_gas =
567
714
  _argv_url_get(
568
- "input_type")[
715
+ "price_gas")[
569
716
  0];
570
- output_type =
717
+ measure_unit =
571
718
  _argv_url_get(
572
- "output_type")[
719
+ "measure_unit")[
573
720
  0];
574
- input_type =
721
+ msg_value =
575
722
  _argv_url_get(
576
- "input_type")[
723
+ "msg_value")[
577
724
  0];
578
- retrieval_mode =
725
+ retries_max =
579
726
  _argv_url_get(
580
- "retrieval_mode")[
727
+ "retries_max")[
581
728
  0];
582
- user_level =
729
+ rpc_selection =
583
730
  _argv_url_get(
584
- "user_level")[
731
+ "rpc_selection")[
585
732
  0];
586
- db_paths.push(
733
+ contract_abi =
587
734
  _argv_url_get(
588
- "db_path")[
589
- 0]);
590
- selection_method =
735
+ "abi")[
736
+ 0];
737
+ contract_bytecode =
591
738
  _argv_url_get(
592
- "selection_method")[
739
+ "bytecode")[
593
740
  0];
594
- api_key =
741
+ contract_compiler_output =
595
742
  _argv_url_get(
596
- "api_key")[
743
+ "compiler_output")[
597
744
  0];
598
- networks_all =
745
+ rpc_selection =
599
746
  _argv_url_get(
600
- "networks_all")[
747
+ "rpc_selection")[
601
748
  0];
749
+ for ( _network of _argv_url_get(
750
+ "network") ) {
751
+ target_networks.push(
752
+ _network);
753
+ }
754
+ for ( _method of _argv_url_get(
755
+ "method_args") ) {
756
+ method_args.push(
757
+ _method);
758
+ }
602
759
  quiet =
603
760
  _argv_url_get(
604
761
  "quiet");
@@ -631,22 +788,34 @@ if ( _cmdline_check(
631
788
  _cmdline_check(
632
789
  "evm-contract-call") == true ) {
633
790
  _cmdline_parse();
791
+ _libevm_cmdline_parse();
634
792
  }
635
793
  else{
636
794
  _url_parse();
795
+ _libevm_url_parse();
637
796
  }
638
797
  _overrides_set();
639
798
  _config_show();
640
799
  app_opts = [
641
- target_command,
642
- input_type,
643
- output_type,
644
- retrieval_mode,
645
- selection_method,
800
+ call_type,
801
+ call_timeout,
802
+ wallet_name,
803
+ wallet_path,
804
+ wallet_password,
805
+ wallet_seed,
646
806
  api_key,
647
- networks_all,
648
- target_chain,
649
- db_paths
807
+ msg_value,
808
+ price_gas,
809
+ measure_unit,
810
+ retries_max,
811
+ target_network,
812
+ rpc_selection,
813
+ contract_address,
814
+ contract_abi,
815
+ contract_bytecode,
816
+ contract_compiler_output,
817
+ contract_method,
818
+ method_args
650
819
  ];
651
820
  _evm_contract_call_cmdline(
652
821
  app_opts);