evm-contracts-tools 0.0.57 → 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
@@ -221,6 +226,11 @@ const
221
226
  const
222
227
  _contract_address_auto_detect =
223
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;
224
234
 
225
235
  function
226
236
  _global_variables() {
@@ -388,40 +398,43 @@ function
388
398
  async function
389
399
  _overrides_set(
390
400
  _help_display) {
391
- _cache_dir_auto_detect();
392
- _data_dir_auto_detect();
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";
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();
393
430
  _override_set(
394
431
  "call",
395
432
  "date",
396
433
  _get_date_human());
397
- _target_app_auto_detect();
398
- _contract_address_auto_detect();
399
- if ( ! _help_display &&
400
- typeof(_help_display) != "undefined" &&
401
- _help_display != "" ) {
402
- const
403
- _address_valid =
404
- _address_check(
405
- contract_address);
406
- if ( ! _address_valid ) {
407
- const
408
- _msg =
409
- "Contract address " +
410
- `'${contract_address}' is ` +
411
- `invalid.`;
412
- _msg_error(
413
- _msg,
414
- 1);
415
- }
416
- }
417
434
  _override_set(
418
435
  "wallet",
419
436
  "name",
420
437
  "default");
421
- _override_set(
422
- "index",
423
- "retrieve",
424
- "n");
425
438
  _override_set(
426
439
  "retries",
427
440
  "max",
@@ -447,27 +460,158 @@ async function
447
460
  "msg",
448
461
  "value",
449
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");
450
530
  // _api_key_auto_detect();
451
- if ( contract_address != "" ) {
452
- if ( contract_abi == "" ) {
453
- contract_abi =
454
- _default_artifact_path_get(
455
- "abi");
456
- _artifact_local_auto_detect(
457
- "bytecode");
458
- _artifact_local_auto_detect(
459
- "compiler_output");
460
- if ( contract_abi == "" ||
461
- _default_artifact_path_get(
462
- "abi") == contract_abi ) {
463
- _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
+ }
464
602
  }
465
603
  }
466
604
  }
467
- await _wallet_overrides_set(
468
- "evm-wallet",
469
- wallet_name,
470
- 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
+ }
471
615
  }
472
616
 
473
617
  function
@@ -496,7 +640,7 @@ function
496
640
  ` Wallet password: ${wallet_password}`,
497
641
  ` Wallet seed: ${wallet_seed}`,
498
642
  ` Network options:`,
499
- ` Target network: ${target_network}`,
643
+ ` Target networks: ${target_networks}`,
500
644
  ` Max retries: ${retries_max}`,
501
645
  ` Call timeout: ${call_timeout}`,
502
646
  ` API key: ${api_key}`,
@@ -650,7 +794,9 @@ async function
650
794
  _cmdline_parse() {
651
795
  let
652
796
  _help_display,
653
- _msg;
797
+ _msg,
798
+ _network,
799
+ _target_networks_set;
654
800
  const
655
801
  _argv_args = {
656
802
  "booleans": [
@@ -662,7 +808,9 @@ async function
662
808
  "index-retrieve",
663
809
  "v",
664
810
  "verbose"
665
- ]
811
+ ],
812
+ "string":
813
+ true
666
814
  };
667
815
  const
668
816
  _argv =
@@ -958,25 +1106,6 @@ async function
958
1106
  "auth",
959
1107
  "y");
960
1108
  }
961
- const
962
- _target_networks =
963
- _get(
964
- "target",
965
- "networks");
966
- if ( "n" in _argv ) {
967
- _target_networks.push(
968
- _argv[
969
- "n"]);
970
- }
971
- if ( "network" in _argv ) {
972
- _target_networks.push(
973
- _argv[
974
- "network"]);
975
- }
976
- _set(
977
- "target",
978
- "networks",
979
- _target_networks);
980
1109
  _libevm_cmdline_parse(
981
1110
  _argv);
982
1111
  if ( _argv[
@@ -1016,6 +1145,12 @@ function
1016
1145
  _argv_url_get(
1017
1146
  "index_retrieve")[
1018
1147
  0]);
1148
+ _set(
1149
+ "target",
1150
+ "app",
1151
+ _argv_url_get(
1152
+ "app")[
1153
+ 0]);
1019
1154
  _set(
1020
1155
  "data",
1021
1156
  "dir",
@@ -1129,57 +1264,144 @@ async function
1129
1264
  _evm_contract_call_cmdline(
1130
1265
  _app_opts) {
1131
1266
  let
1132
- _result;
1133
- const
1267
+ _msg,
1268
+ _results;
1269
+ try {
1134
1270
  _results =
1135
1271
  await _evm_contract_call.apply(
1136
1272
  null,
1137
- app_opts);
1138
- const
1139
- _results_type =
1140
- typeof(
1141
- _results);
1142
- if ( _results_type == "object" ) {
1143
- for ( _result of _results ) {
1144
- _echo(
1145
- _result);
1146
- }
1273
+ _app_opts);
1147
1274
  }
1148
- else if ( _results_type == "string" ) {
1149
- _printf(
1150
- _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;
1151
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;
1152
1319
  }
1153
1320
 
1154
1321
  async function
1155
1322
  _main() {
1156
- const
1323
+ let
1324
+ _cmdline_out,
1325
+ _msg,
1326
+ _overrides_set_up;
1327
+ try {
1157
1328
  _overrides_set_up =
1158
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"];
1159
1348
  _config_show();
1160
- app_opts = [
1161
- call_type,
1162
- call_timeout,
1163
- wallet_name,
1164
- wallet_path,
1165
- wallet_password,
1166
- wallet_seed,
1167
- api_key,
1168
- msg_value,
1169
- price_gas,
1170
- measure_unit,
1171
- retries_max,
1172
- target_network,
1173
- rpc_selection,
1174
- contract_address,
1175
- contract_abi,
1176
- contract_bytecode,
1177
- contract_compiler_output,
1178
- contract_method,
1179
- method_args
1180
- ];
1181
- await _evm_contract_call_cmdline(
1182
- 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;
1183
1405
  }
1184
1406
 
1185
1407
  _global_variables();
@@ -1196,9 +1418,21 @@ else{
1196
1418
  _url_parse();
1197
1419
  _libevm_url_parse();
1198
1420
  }
1199
- // _echo(
1200
- // contract_address);
1201
- _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
+ }
1202
1436
 
1203
1437
  export {
1204
1438
  _evm_contract_call