evm-contracts-tools 0.0.55 → 0.0.62

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
@@ -88,6 +88,11 @@ const
88
88
  const
89
89
  _echo =
90
90
  _libcrash._echo;
91
+ /* global
92
+ _echo2 */
93
+ const
94
+ _echo2 =
95
+ _libcrash._echo2;
91
96
  /* global
92
97
  _exit */
93
98
  const
@@ -108,6 +113,11 @@ const
108
113
  const
109
114
  _global_get =
110
115
  _libcrash._global_get;
116
+ /* global
117
+ _homedir_get */
118
+ const
119
+ _homedir_get =
120
+ _libcrash._homedir_get;
111
121
  /* global
112
122
  _msg_info */
113
123
  const
@@ -176,6 +186,16 @@ const
176
186
  const
177
187
  _address_check =
178
188
  _libevm_contract_call_module._address_check;
189
+ /* global
190
+ _cache_dir_auto_detect */
191
+ const
192
+ _cache_dir_auto_detect =
193
+ _libevm_contract_call_module._cache_dir_auto_detect;
194
+ /* global
195
+ _data_dir_auto_detect */
196
+ const
197
+ _data_dir_auto_detect =
198
+ _libevm_contract_call_module._data_dir_auto_detect;
179
199
  /* global
180
200
  _default_artifact_path_get */
181
201
  const
@@ -196,6 +216,21 @@ const
196
216
  const
197
217
  _call_auth_auto_detect =
198
218
  _libevm_contract_call_module._call_auth_auto_detect;
219
+ /* global
220
+ _target_app_auto_detect */
221
+ const
222
+ _target_app_auto_detect =
223
+ _libevm_contract_call_module._target_app_auto_detect;
224
+ /* global
225
+ _contract_address_auto_detect */
226
+ const
227
+ _contract_address_auto_detect =
228
+ _libevm_contract_call_module._contract_address_auto_detect;
229
+ /* global
230
+ _target_contract_auto_detect */
231
+ const
232
+ _target_contract_auto_detect =
233
+ _libevm_contract_call_module._target_contract_auto_detect;
199
234
 
200
235
  function
201
236
  _global_variables() {
@@ -227,6 +262,20 @@ function
227
262
  "call",
228
263
  "date",
229
264
  "");
265
+ /* global
266
+ cache_dir:
267
+ writable */
268
+ _set(
269
+ "cache",
270
+ "dir",
271
+ "");
272
+ /* global
273
+ data_dir:
274
+ writable */
275
+ _set(
276
+ "data",
277
+ "dir",
278
+ "");
230
279
  /* global
231
280
  wallet_name:
232
281
  writable */
@@ -262,6 +311,20 @@ function
262
311
  "index",
263
312
  "retrieve",
264
313
  "");
314
+ /* global
315
+ target_app:
316
+ writable */
317
+ _set(
318
+ "target",
319
+ "app",
320
+ "");
321
+ /* global
322
+ target_contract:
323
+ writable */
324
+ _set(
325
+ "target",
326
+ "contract",
327
+ "");
265
328
  /* global
266
329
  contract_address:
267
330
  writable */
@@ -335,24 +398,35 @@ function
335
398
  async function
336
399
  _overrides_set(
337
400
  _help_display) {
338
- if ( ! _help_display &&
339
- typeof(_help_display) != "undefined" &&
340
- _help_display != "" ) {
341
- const
342
- _address_valid =
343
- _address_check(
344
- contract_address);
345
- if ( ! _address_valid ) {
346
- const
347
- _msg =
348
- "Contract address " +
349
- `'${contract_address}' is ` +
350
- `invalid.`;
351
- _msg_error(
352
- _msg,
353
- 1);
354
- }
401
+ let
402
+ _address_valid,
403
+ _contract_abi,
404
+ _contract_address,
405
+ _msg;
406
+ const
407
+ _global =
408
+ _global_get();
409
+ const
410
+ _quiet =
411
+ _global[
412
+ "quiet"];
413
+ if ( _quiet == "" ) {
414
+ _global[
415
+ "quiet"] =
416
+ "y";
355
417
  }
418
+ const
419
+ _target_app =
420
+ _get(
421
+ "target",
422
+ "app");
423
+ const
424
+ _target_networks =
425
+ _get(
426
+ "target",
427
+ "networks");
428
+ await _cache_dir_auto_detect();
429
+ await _data_dir_auto_detect();
356
430
  _override_set(
357
431
  "call",
358
432
  "date",
@@ -361,10 +435,6 @@ async function
361
435
  "wallet",
362
436
  "name",
363
437
  "default");
364
- _override_set(
365
- "index",
366
- "retrieve",
367
- "n");
368
438
  _override_set(
369
439
  "retries",
370
440
  "max",
@@ -390,27 +460,158 @@ async function
390
460
  "msg",
391
461
  "value",
392
462
  "0");
463
+ await _wallet_overrides_set(
464
+ "evm-wallet",
465
+ wallet_name,
466
+ call_auth,
467
+ "n", // qr support
468
+ _target_networks);
469
+ await _target_app_auto_detect();
470
+ await _target_contract_auto_detect();
471
+ // await _target_networks_auto_detect();
472
+ try {
473
+ await _contract_address_auto_detect();
474
+ }
475
+ catch(
476
+ _error) {
477
+ _msg =
478
+ "Error auto-detecting address.";
479
+ _msg_error(
480
+ _msg,
481
+ 0);
482
+ _echo2(
483
+ _msg);
484
+ throw _error;
485
+ }
486
+ const
487
+ _help_display_type =
488
+ typeof(
489
+ _help_display);
490
+ if ( ( _help_display_type !== "undefined" &&
491
+ _help_display !== "" ) &&
492
+ ( _help_display_type !== "boolean" &&
493
+ _help_display !== true ) ) {
494
+ try {
495
+ _contract_address =
496
+ _get(
497
+ "contract",
498
+ "address");
499
+ _address_valid =
500
+ await _address_check(
501
+ _contract_address);
502
+ }
503
+ catch(
504
+ _error) {
505
+ _msg =
506
+ "Error detecting validity " +
507
+ ` of address '${_contract_address}'`;
508
+ _msg_error(
509
+ _msg,
510
+ 0);
511
+ _echo2(
512
+ _error);
513
+ throw _error;
514
+ }
515
+ if ( ! _address_valid ) {
516
+ _msg =
517
+ "Contract address " +
518
+ `'${contract_address}' is ` +
519
+ `invalid.`;
520
+ _msg_error(
521
+ _msg,
522
+ 0);
523
+ throw _msg;
524
+ }
525
+ }
526
+ _override_set(
527
+ "index",
528
+ "retrieve",
529
+ "n");
393
530
  // _api_key_auto_detect();
394
- if ( contract_address != "" ) {
395
- if ( contract_abi == "" ) {
396
- contract_abi =
397
- _default_artifact_path_get(
398
- "abi");
399
- _artifact_local_auto_detect(
400
- "bytecode");
401
- _artifact_local_auto_detect(
402
- "compiler_output");
403
- if ( contract_abi == "" ||
404
- _default_artifact_path_get(
405
- "abi") == contract_abi ) {
406
- _contract_abi_auto_detect();
531
+ _contract_abi =
532
+ _get(
533
+ "contract",
534
+ "abi");
535
+ _contract_address =
536
+ _get(
537
+ "contract",
538
+ "address");
539
+ const
540
+ _target_contract =
541
+ _get(
542
+ "target",
543
+ "contract");
544
+ const
545
+ _contract_address_type =
546
+ typeof(
547
+ _contract_address);
548
+ const
549
+ _contract_abi_type =
550
+ typeof(
551
+ _contract_abi);
552
+ if ( _contract_address_type !== "undefined" &&
553
+ _contract_address != "" ) {
554
+ if ( _contract_abi_type === "array" ) {
555
+ _msg =
556
+ "Not implemented.";
557
+ _msg_error(
558
+ _msg,
559
+ 1);
560
+ }
561
+ else if ( _contract_abi_type === "string" ) {
562
+ if ( 0 < _contract_abi.length ) {
563
+ _msg =
564
+ "Contract ABI:";
565
+ _msg_error(
566
+ _msg,
567
+ 0);
568
+ _echo2(
569
+ _contract_abi);
570
+ }
571
+ else {
572
+ _msg =
573
+ "Specified no contract ABI " +
574
+ `for contract '${_target_contract}' ` +
575
+ `and address'${_contract_address}',` +
576
+ "auto-detecting.";
577
+ _msg_info(
578
+ _msg);
579
+ try {
580
+ _contract_abi =
581
+ await _default_artifact_path_get(
582
+ "abi");
583
+ await _artifact_local_auto_detect(
584
+ "bytecode");
585
+ await _artifact_local_auto_detect(
586
+ "compiler_output");
587
+ if ( _contract_abi == "" ||
588
+ _default_artifact_path_get(
589
+ "abi") == _contract_abi ) {
590
+ await _contract_abi_auto_detect();
591
+ }
592
+ }
593
+ catch(
594
+ _error) {
595
+ _msg =
596
+ "Sigh.";
597
+ _msg_error(
598
+ _msg,
599
+ 0);
600
+ throw _error;
601
+ }
407
602
  }
408
603
  }
409
604
  }
410
- await _wallet_overrides_set(
411
- "evm-wallet",
412
- wallet_name,
413
- call_auth);
605
+ else {
606
+ _msg =
607
+ `Contract address (type ` +
608
+ `'${_contract_address_type}'):`;
609
+ _msg_error(
610
+ _msg,
611
+ 0);
612
+ _echo2(
613
+ _contract_address);
614
+ }
414
615
  }
415
616
 
416
617
  function
@@ -429,6 +630,9 @@ function
429
630
  ` Runtime environment: ${runtime_environment}`,
430
631
  ` Call type: ${call_type}`,
431
632
  ` Call authentication: ${call_auth}`,
633
+ ` Application options:`,
634
+ ` Cache directory: ${cache_dir}`,
635
+ ` Data directory: ${data_dir}`,
432
636
  ` Credentials options:`,
433
637
  ` Wallet name: ${wallet_name}`,
434
638
  ` Wallet address: ${api_key}`,
@@ -436,13 +640,15 @@ function
436
640
  ` Wallet password: ${wallet_password}`,
437
641
  ` Wallet seed: ${wallet_seed}`,
438
642
  ` Network options:`,
439
- ` Target network: ${target_network}`,
643
+ ` Target networks: ${target_networks}`,
440
644
  ` Max retries: ${retries_max}`,
441
645
  ` Call timeout: ${call_timeout}`,
442
646
  ` API key: ${api_key}`,
443
647
  ` RPC selection method: ${rpc_selection}`,
444
648
  ` Gas price: ${price_gas}`,
445
649
  ` Contract options:`,
650
+ ` Target application: ${target_app}`,
651
+ ` Target contract: ${target_contract}`,
446
652
  ` Contract address: ${contract_address}`,
447
653
  ` Contract ABI: ${contract_abi}`,
448
654
  ` Contract bytecode: ${contract_bytecode}`,
@@ -549,6 +755,9 @@ function
549
755
  "",
550
756
  " libEVM options:",
551
757
  "",
758
+ " -K --app Target application.",
759
+ ` Default: '${target_app}'`,
760
+ "",
552
761
  " -a --auth Call authentication.",
553
762
  ` Default: '${call_auth}'`,
554
763
  "",
@@ -561,7 +770,15 @@ function
561
770
  " <rpc-selection> 'kirsh', 'random' or 'all'.",
562
771
  ` Default: '${rpc_selection}'.`,
563
772
  "",
773
+ " Application options:",
774
+ "",
775
+ " -W --cache-dir Cache directory.",
776
+ ` Default: '${cache_dir}'`,
777
+ "",
778
+ " -D --data-dir Data directory.",
779
+ ` Default: '${data_dir}'`,
564
780
  " -h --help This message.",
781
+ "",
565
782
  " -v --verbose Enable verbose output.",
566
783
  ""
567
784
  ];
@@ -577,7 +794,9 @@ async function
577
794
  _cmdline_parse() {
578
795
  let
579
796
  _help_display,
580
- _msg;
797
+ _msg,
798
+ _network,
799
+ _target_networks_set;
581
800
  const
582
801
  _argv_args = {
583
802
  "booleans": [
@@ -589,7 +808,9 @@ async function
589
808
  "index-retrieve",
590
809
  "v",
591
810
  "verbose"
592
- ]
811
+ ],
812
+ "string":
813
+ true
593
814
  };
594
815
  const
595
816
  _argv =
@@ -719,6 +940,48 @@ async function
719
940
  _argv[
720
941
  "index-retrieve"]);
721
942
  }
943
+ if ( "app" in _argv ) {
944
+ _set(
945
+ "target",
946
+ "app",
947
+ _argv[
948
+ "app"]);
949
+ }
950
+ if ( "K" in _argv ) {
951
+ _set(
952
+ "target",
953
+ "app",
954
+ _argv[
955
+ "K"]);
956
+ }
957
+ if ( "cache-dir" in _argv ) {
958
+ _set(
959
+ "cache",
960
+ "dir",
961
+ _argv[
962
+ "cache-dir"]);
963
+ }
964
+ if ( "W" in _argv ) {
965
+ _set(
966
+ "cache",
967
+ "dir",
968
+ _argv[
969
+ "W"]);
970
+ }
971
+ if ( "data-dir" in _argv ) {
972
+ _set(
973
+ "data",
974
+ "dir",
975
+ _argv[
976
+ "data-dir"]);
977
+ }
978
+ if ( "D" in _argv ) {
979
+ _set(
980
+ "data",
981
+ "dir",
982
+ _argv[
983
+ "D"]);
984
+ }
722
985
  if ( "P" in _argv ) {
723
986
  _set(
724
987
  "price",
@@ -843,25 +1106,6 @@ async function
843
1106
  "auth",
844
1107
  "y");
845
1108
  }
846
- const
847
- _target_networks =
848
- _get(
849
- "target",
850
- "networks");
851
- if ( "n" in _argv ) {
852
- _target_networks.push(
853
- _argv[
854
- "n"]);
855
- }
856
- if ( "network" in _argv ) {
857
- _target_networks.push(
858
- _argv[
859
- "network"]);
860
- }
861
- _set(
862
- "target",
863
- "networks",
864
- _target_networks);
865
1109
  _libevm_cmdline_parse(
866
1110
  _argv);
867
1111
  if ( _argv[
@@ -901,6 +1145,24 @@ function
901
1145
  _argv_url_get(
902
1146
  "index_retrieve")[
903
1147
  0]);
1148
+ _set(
1149
+ "target",
1150
+ "app",
1151
+ _argv_url_get(
1152
+ "app")[
1153
+ 0]);
1154
+ _set(
1155
+ "data",
1156
+ "dir",
1157
+ _argv_url_get(
1158
+ "data_dir")[
1159
+ 0]);
1160
+ _set(
1161
+ "cache",
1162
+ "dir",
1163
+ _argv_url_get(
1164
+ "cache_dir")[
1165
+ 0]);
904
1166
  _set(
905
1167
  "price",
906
1168
  "gas",
@@ -1002,57 +1264,144 @@ async function
1002
1264
  _evm_contract_call_cmdline(
1003
1265
  _app_opts) {
1004
1266
  let
1005
- _result;
1006
- const
1267
+ _msg,
1268
+ _results;
1269
+ try {
1007
1270
  _results =
1008
1271
  await _evm_contract_call.apply(
1009
1272
  null,
1010
- app_opts);
1011
- const
1012
- _results_type =
1013
- typeof(
1014
- _results);
1015
- if ( _results_type == "object" ) {
1016
- for ( _result of _results ) {
1017
- _echo(
1018
- _result);
1019
- }
1273
+ _app_opts);
1020
1274
  }
1021
- else if ( _results_type == "string" ) {
1022
- _printf(
1023
- _results);
1275
+ catch(
1276
+ _error) {
1277
+ _msg =
1278
+ "Error running '_evm_contract_call' " +
1279
+ `with options '${_app_opts}'.`;
1280
+ _msg_error(
1281
+ _msg,
1282
+ 0);
1283
+ _echo(
1284
+ _msg);
1285
+ _echo2(
1286
+ _error);
1287
+ throw _error;
1024
1288
  }
1289
+ // const
1290
+ // _results_type =
1291
+ // typeof(
1292
+ // _results);
1293
+ // if ( _results_type == "array" ) {
1294
+ // for ( _result of _results ) {
1295
+ // _echo(
1296
+ // _result);
1297
+ // }
1298
+ // }
1299
+ // else if ( _results_type == "object" ) {
1300
+ // for ( _result in _results ) {
1301
+ // _echo(
1302
+ // _results[
1303
+ // _result]);
1304
+ // }
1305
+ // }
1306
+ // else if ( _results_type == "string" ) {
1307
+ // _printf(
1308
+ // _results);
1309
+ // }
1310
+ // else if ( _results_type == "undefined" ) {
1311
+ // _msg =
1312
+ // "No results";
1313
+ // _msg_error(
1314
+ // _msg,
1315
+ // 0);
1316
+ // throw _msg;
1317
+ // }
1318
+ return _results;
1025
1319
  }
1026
1320
 
1027
1321
  async function
1028
1322
  _main() {
1029
- const
1323
+ let
1324
+ _cmdline_out,
1325
+ _msg,
1326
+ _overrides_set_up;
1327
+ try {
1030
1328
  _overrides_set_up =
1031
1329
  await _overrides_set();
1330
+ }
1331
+ catch(
1332
+ _error) {
1333
+ _msg =
1334
+ "Error setting up " +
1335
+ "overrides.";
1336
+ _msg_error(
1337
+ _msg,
1338
+ 0);
1339
+ throw _error;
1340
+ }
1341
+ const
1342
+ _global =
1343
+ _global_get();
1344
+ const
1345
+ _quiet =
1346
+ _global[
1347
+ "quiet"];
1032
1348
  _config_show();
1033
- app_opts = [
1034
- call_type,
1035
- call_timeout,
1036
- wallet_name,
1037
- wallet_path,
1038
- wallet_password,
1039
- wallet_seed,
1040
- api_key,
1041
- msg_value,
1042
- price_gas,
1043
- measure_unit,
1044
- retries_max,
1045
- target_network,
1046
- rpc_selection,
1047
- contract_address,
1048
- contract_abi,
1049
- contract_bytecode,
1050
- contract_compiler_output,
1051
- contract_method,
1052
- method_args
1053
- ];
1054
- await _evm_contract_call_cmdline(
1055
- app_opts);
1349
+ _set(
1350
+ "app",
1351
+ "opts",
1352
+ [
1353
+ call_type,
1354
+ call_timeout,
1355
+ wallet_name,
1356
+ wallet_path,
1357
+ wallet_password,
1358
+ wallet_seed,
1359
+ api_key,
1360
+ msg_value,
1361
+ price_gas,
1362
+ measure_unit,
1363
+ retries_max,
1364
+ target_networks,
1365
+ rpc_selection,
1366
+ contract_address,
1367
+ contract_abi,
1368
+ contract_bytecode,
1369
+ contract_compiler_output,
1370
+ contract_method,
1371
+ method_args
1372
+ ]);
1373
+ const
1374
+ _app_opts =
1375
+ _get(
1376
+ "app",
1377
+ "opts");
1378
+ try {
1379
+ _msg =
1380
+ "Running '_evm_contract_call_cmdline' " +
1381
+ `with parameters:`;
1382
+ _msg_info(
1383
+ _msg);
1384
+ if ( _quiet == "n" ) {
1385
+ _echo(
1386
+ _app_opts);
1387
+ }
1388
+ _cmdline_out =
1389
+ await _evm_contract_call_cmdline(
1390
+ _app_opts);
1391
+ }
1392
+ catch(
1393
+ _error) {
1394
+ _msg =
1395
+ "Running '_evm_contract_call_cmdline' " +
1396
+ `with parameters '${_app_opts}' failed.`;
1397
+ _msg_error(
1398
+ _msg,
1399
+ 0);
1400
+ _echo2(
1401
+ _error);
1402
+ throw _error;
1403
+ }
1404
+ return _cmdline_out;
1056
1405
  }
1057
1406
 
1058
1407
  _global_variables();
@@ -1069,9 +1418,21 @@ else{
1069
1418
  _url_parse();
1070
1419
  _libevm_url_parse();
1071
1420
  }
1072
- _echo(
1073
- contract_address);
1074
- _main();
1421
+ try {
1422
+ await _main();
1423
+ }
1424
+ catch(
1425
+ _error) {
1426
+ const
1427
+ _msg =
1428
+ "Error running 'main'.";
1429
+ _msg_error(
1430
+ _msg,
1431
+ 0);
1432
+ _echo2(
1433
+ _error);
1434
+ throw _error;
1435
+ }
1075
1436
 
1076
1437
  export {
1077
1438
  _evm_contract_call