evm-contracts-tools 0.0.62 → 0.0.65

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.
Files changed (56) hide show
  1. package/dist/evm-contract-call/evm-contract-call.js +1 -1
  2. package/dist/evm-contract-call/fs-worker.js +1 -1
  3. package/dist/evm-contract-deployment-abi/evm-contract-deployment-abi.js +1 -1
  4. package/dist/evm-contract-deployment-abi/fs-worker.js +1 -1
  5. package/dist/evm-contract-deployment-address/evm-contract-deployment-address.js +1 -1
  6. package/dist/evm-contract-deployment-address/fs-worker.js +1 -1
  7. package/dist/evm-contract-deployment-bytecode/evm-contract-deployment-bytecode.js +1 -1
  8. package/dist/evm-contract-deployment-bytecode/fs-worker.js +1 -1
  9. package/dist/evm-contract-deployment-compiler-output/evm-contract-deployment-compiler-output.js +1 -1
  10. package/dist/evm-contract-deployment-compiler-output/fs-worker.js +1 -1
  11. package/dist/evm-contract-deployment-deployment-networks +1 -1
  12. package/dist/evm-contract-deployment-networks/evm-contract-deployment-networks.js +1 -1
  13. package/dist/evm-contract-deployment-versions/evm-contract-deployment-versions.js +1 -1
  14. package/dist/evm-contract-deployment-versions/fs-worker.js +1 -1
  15. package/dist/evm-contract-deployments-dir/evm-contract-deployments-dir.js +1 -1
  16. package/dist/evm-contract-deployments-dir/fs-worker.js +1 -1
  17. package/dist/evm-contracts-tools/evm-contracts-tools.js +1 -1
  18. package/dist/evm-contracts-tools/fs-worker.js +1 -1
  19. package/dist/libevm-contract-call/fs-worker.js +1 -1
  20. package/dist/libevm-contract-call/libevm-contract-call.js +1 -1
  21. package/dist/libevm-contract-deployment-abi/fs-worker.js +1 -1
  22. package/dist/libevm-contract-deployment-abi/libevm-contract-deployment-abi.js +1 -1
  23. package/dist/libevm-contract-deployment-address/fs-worker.js +1 -1
  24. package/dist/libevm-contract-deployment-address/libevm-contract-deployment-address.js +1 -1
  25. package/dist/libevm-contract-deployment-bytecode/fs-worker.js +1 -1
  26. package/dist/libevm-contract-deployment-bytecode/libevm-contract-deployment-bytecode.js +1 -1
  27. package/dist/libevm-contract-deployment-compiler-output/fs-worker.js +1 -1
  28. package/dist/libevm-contract-deployment-compiler-output/libevm-contract-deployment-compiler-output.js +1 -1
  29. package/dist/libevm-contract-deployment-deployment-networks +1 -1
  30. package/dist/libevm-contract-deployment-networks/libevm-contract-deployment-networks.js +1 -1
  31. package/dist/libevm-contract-deployment-versions/fs-worker.js +1 -1
  32. package/dist/libevm-contract-deployment-versions/libevm-contract-deployment-versions.js +1 -1
  33. package/dist/libevm-contract-deployments-dir/fs-worker.js +1 -1
  34. package/dist/libevm-contract-deployments-dir/libevm-contract-deployments-dir.js +1 -1
  35. package/dist/libevm-contracts-tools +1 -1
  36. package/eslint.config.mjs +1 -1
  37. package/evm-contract-call +514 -172
  38. package/evm-contract-deployment-abi +16 -12
  39. package/evm-contract-deployment-address +15 -12
  40. package/evm-contract-deployment-bytecode +15 -12
  41. package/evm-contract-deployment-compiler-output +16 -13
  42. package/evm-contract-deployment-networks +15 -12
  43. package/evm-contract-deployment-versions +15 -12
  44. package/evm-contract-deployments-dir +16 -13
  45. package/evm-contracts-tools +14 -12
  46. package/lib/contract-get +169 -39
  47. package/lib/evm-contract-call-dynamic +1112 -361
  48. package/lib/evm-contract-call-static +463 -73
  49. package/libevm-contract-call +625 -435
  50. package/libevm-contract-deployment +4388 -481
  51. package/libevm-contract-deployment-abi +287 -91
  52. package/libevm-contract-deployment-address +27 -16
  53. package/libevm-contract-deployment-bytecode +275 -80
  54. package/libevm-contract-deployment-compiler-output +341 -93
  55. package/libevm-contract-deployments-dir +53 -50
  56. package/package.json +12 -12
@@ -63,6 +63,11 @@ const
63
63
  const
64
64
  _echo =
65
65
  _libcrash._echo;
66
+ /* global
67
+ _echo2 */
68
+ const
69
+ _echo2 =
70
+ _libcrash._echo2;
66
71
  /* global
67
72
  _error_display */
68
73
  const
@@ -238,6 +243,285 @@ function
238
243
  _msg);
239
244
  }
240
245
 
246
+ async function
247
+ _contract_object_check(
248
+ _contract_object,
249
+ _wallet_seed,
250
+ _wallet_password,
251
+ _contract_address,
252
+ _contract_abi_path,
253
+ _contract_bytecode_path,
254
+ _contract_compiler_output_path,
255
+ _target_network,
256
+ _api_key_path) {
257
+ let
258
+ _contract_object_get,
259
+ _msg;
260
+ const
261
+ _contract_object_type =
262
+ typeof(
263
+ _contract_object);
264
+ _contract_object_get =
265
+ false;
266
+ if ( _contract_object_type === "undefined" ) {
267
+ _msg =
268
+ "Ethers contract object is " +
269
+ "undefined, generating " +
270
+ "ethers contract object.";
271
+ _msg_info(
272
+ _msg);
273
+ _contract_object_get =
274
+ true;
275
+ }
276
+ else if ( _contract_object_type === "string" ) {
277
+ if ( _contract_object.length < 1 ) {
278
+ _msg =
279
+ "Ethers contract object is an empty " +
280
+ "string, generating " +
281
+ "ethers contract object.";
282
+ _msg_info(
283
+ _msg);
284
+ _contract_object_get =
285
+ true;
286
+ }
287
+ }
288
+ else if ( _contract_object_type === "object" ) {
289
+ const
290
+ _contract_object_keys =
291
+ Object.keys(
292
+ _contract_object);
293
+ if ( _contract_object_keys.length < 1 ) {
294
+ _msg =
295
+ "Ethers contract object is an empty " +
296
+ "object, generating " +
297
+ "ethers contract object.";
298
+ _msg_info(
299
+ _msg);
300
+ _contract_object_get =
301
+ true;
302
+ }
303
+ }
304
+ if ( _contract_object_get ) {
305
+ const
306
+ _contract_get_args = [
307
+ _wallet_seed,
308
+ _wallet_password,
309
+ _contract_address,
310
+ _contract_abi_path,
311
+ _contract_bytecode_path,
312
+ _contract_compiler_output_path,
313
+ _target_network,
314
+ _api_key_path
315
+ ];
316
+ try {
317
+ _contract_object =
318
+ await _contract_get.apply(
319
+ null,
320
+ _contract_get_args);
321
+ }
322
+ catch(
323
+ _error) {
324
+ _msg =
325
+ "Error running '_contract_get' " +
326
+ "with arguments:";
327
+ _msg_error(
328
+ _msg,
329
+ 0);
330
+ _echo2(
331
+ _contract_get_args);
332
+ _echo2(
333
+ _error);
334
+ throw _error;
335
+ }
336
+ _msg_info_contract_obtained(
337
+ _contract_object);
338
+ }
339
+ return _contract_object;
340
+ }
341
+
342
+ async function
343
+ _method_object_check(
344
+ _method_object,
345
+ _contract_object,
346
+ _contract_method,
347
+ _wallet_seed,
348
+ _wallet_password,
349
+ _contract_address,
350
+ _contract_abi_path,
351
+ _contract_bytecode_path,
352
+ _contract_compiler_output_path,
353
+ _target_network,
354
+ _api_key_path) {
355
+ let
356
+ _method_object_get,
357
+ _msg;
358
+ const
359
+ _method_object_type =
360
+ typeof(
361
+ _method_object);
362
+ _method_object_get =
363
+ false;
364
+ if ( _method_object_type === "undefined" ) {
365
+ _msg =
366
+ "Ethers contract method object is " +
367
+ "undefined, generating " +
368
+ "ethers contract method object.";
369
+ _msg_info(
370
+ _msg);
371
+ _method_object_get =
372
+ true;
373
+ }
374
+ else if ( _method_object_type === "string" ) {
375
+ if ( _method_object.length < 1 ) {
376
+ _msg =
377
+ "Ethers contract method object is an empty " +
378
+ "string, generating " +
379
+ "ethers contract method object.";
380
+ _msg_info(
381
+ _msg);
382
+ _method_object_get =
383
+ true;
384
+ }
385
+ }
386
+ else if ( _method_object_type === "object" ) {
387
+ const
388
+ _method_object_keys =
389
+ Object.keys(
390
+ _method_object);
391
+ if ( _method_object_keys.length < 1 ) {
392
+ _msg =
393
+ "Ethers contract method object is an empty " +
394
+ "object, generating.";
395
+ _msg_info(
396
+ _msg);
397
+ _method_object_get =
398
+ true;
399
+ }
400
+ }
401
+ if ( _method_object_get ) {
402
+ const
403
+ _contract_object_check_args = [
404
+ _contract_object,
405
+ _wallet_seed,
406
+ _wallet_password,
407
+ _contract_address,
408
+ _contract_abi_path,
409
+ _contract_bytecode_path,
410
+ _contract_compiler_output_path,
411
+ _target_network,
412
+ _api_key_path
413
+ ];
414
+ try {
415
+ _contract_object =
416
+ await _contract_object_check.apply(
417
+ null,
418
+ _contract_object_check_args);
419
+ _msg =
420
+ "Contract object to derive method " +
421
+ "object checked.";
422
+ _msg_info(
423
+ _msg);
424
+ }
425
+ catch(
426
+ _error) {
427
+ _msg =
428
+ "Error running '_contract_object_check' " +
429
+ "with parameters:";
430
+ _msg_error(
431
+ _msg,
432
+ 0);
433
+ _echo2(
434
+ _contract_object_check_args);
435
+ _echo2(
436
+ _error);
437
+ throw _error;
438
+ }
439
+ const
440
+ _contract_get_function_args = [
441
+ _contract_method
442
+ ];
443
+ try {
444
+ _method_object =
445
+ await _contract_object.getFunction(
446
+ _contract_method);
447
+ }
448
+ catch(
449
+ _error) {
450
+ const
451
+ _msg_no_fragment =
452
+ "no matching fragment";
453
+ if ( "shortMessage" in _error ) {
454
+ const
455
+ _msg_short =
456
+ _error[
457
+ "shortMessage"];
458
+ if ( _msg_no_fragment == _msg_short ) {
459
+ _msg =
460
+ `Found no '${_contract_method}' method ` +
461
+ `nor contract ABI '${_contract_abi_path}' ` +
462
+ `nor in compiler output ` +
463
+ `'${_contract_compiler_output_path}'.`;
464
+ _msg_error(
465
+ _msg,
466
+ 0);
467
+ }
468
+ }
469
+ _msg =
470
+ "Error running '_contract_object.getFunction' " +
471
+ "with arguments:";
472
+ _msg_error(
473
+ _msg,
474
+ 0);
475
+ _echo2(
476
+ _contract_get_function_args);
477
+ _echo2(
478
+ _error);
479
+ throw _error;
480
+ }
481
+ _msg_info_method_obtained(
482
+ _method_object);
483
+ }
484
+ return _method_object;
485
+ }
486
+
487
+ function
488
+ _is_network_error(
489
+ _error) {
490
+ let
491
+ _is_error,
492
+ _msg;
493
+ _is_error =
494
+ false;
495
+ const
496
+ _error_type =
497
+ typeof(
498
+ _error);
499
+ if ( _error_type === "object" ) {
500
+ if ( "errno" in _error ) {
501
+ const
502
+ _errno =
503
+ _error[
504
+ "errno"];
505
+ if ( _errno === -3001 ) {
506
+ const
507
+ _rpc =
508
+ _error[
509
+ "hostname"];
510
+ _msg =
511
+ "Error connecting to RPC " +
512
+ `'${_rpc}', is the computer ` +
513
+ `connected to the internet?`;
514
+ _msg_error(
515
+ _msg,
516
+ 0);
517
+ _is_error =
518
+ true;
519
+ }
520
+ }
521
+ }
522
+ return _is_error;
523
+ }
524
+
241
525
  async function
242
526
  _contract_call_static(
243
527
  _wallet_seed,
@@ -250,13 +534,16 @@ async function
250
534
  _method_object,
251
535
  _contract_address,
252
536
  _contract_method,
253
- _method_args) {
537
+ _method_args,
538
+ _contract_object) {
254
539
  let
255
- _contract,
256
- _contract_get_opts,
540
+ _contract_get_args,
541
+ _contract_object_get,
542
+ _exception,
257
543
  _method,
258
544
  _msg,
259
545
  _passed,
546
+ _retry,
260
547
  _value;
261
548
  if ( _method_object == undefined ) {
262
549
  _method_object =
@@ -267,98 +554,201 @@ async function
267
554
  const
268
555
  _wallet_password =
269
556
  "";
270
- _contract_get_opts = [
271
- _wallet_seed,
272
- _wallet_password,
273
- _contract_address,
274
- _contract_abi_path,
275
- _contract_bytecode_path,
276
- _contract_compiler_output_path,
277
- _target_network,
278
- _api_key_path,
279
- ];
557
+ const
558
+ _contract_object_check_args = [
559
+ _contract_object,
560
+ _wallet_seed,
561
+ _wallet_password,
562
+ _contract_address,
563
+ _contract_abi_path,
564
+ _contract_bytecode_path,
565
+ _contract_compiler_output_path,
566
+ _target_network,
567
+ _api_key_path
568
+ ];
280
569
  _passed =
281
570
  false;
282
571
  while ( _retry <= _retries_max &&
283
572
  _passed == false ) {
284
573
  try {
285
- if ( _method_object === "" ||
286
- typeof(
287
- _method_object) === "undefined" ) {
288
- _contract =
289
- await _contract_get.apply(
574
+ _contract_object =
575
+ await _contract_object_check.apply(
576
+ null,
577
+ _contract_object_check_args);
578
+ _msg =
579
+ "Checked ethers contract object.";
580
+ _msg_info(
581
+ _msg);
582
+ }
583
+ catch(
584
+ _error) {
585
+ _msg =
586
+ "Error running '_contract_object_check' " +
587
+ "parameters:";
588
+ _msg_error(
589
+ _msg,
590
+ 0);
591
+ _echo2(
592
+ _contract_object_check_args);
593
+ _echo2(
594
+ _error);
595
+ throw _error;
596
+ }
597
+ const
598
+ _method_object_check_args = [
599
+ _method_object,
600
+ _contract_object,
601
+ _contract_method,
602
+ _wallet_seed,
603
+ _wallet_password,
604
+ _contract_address,
605
+ _contract_abi_path,
606
+ _contract_bytecode_path,
607
+ _contract_compiler_output_path,
608
+ _target_network,
609
+ _api_key_path
610
+ ];
611
+ try {
612
+ _method_object =
613
+ await _method_object_check.apply(
614
+ null,
615
+ _method_object_check_args);
616
+ _msg =
617
+ "Checked ethers contract method object.";
618
+ _msg_info(
619
+ _msg);
620
+ }
621
+ catch(
622
+ _error) {
623
+ _msg =
624
+ "Error running '_method_object_check' " +
625
+ "with parameters:";
626
+ _msg_error(
627
+ _msg,
628
+ 0);
629
+ _echo2(
630
+ _method_object_check_args);
631
+ _echo2(
632
+ _error);
633
+ throw _error;
634
+ }
635
+ _method =
636
+ _method_object;
637
+ try {
638
+ try {
639
+ _msg =
640
+ "Running static call."
641
+ _msg_info(
642
+ _msg);
643
+ _value =
644
+ await _method.staticCall.apply(
290
645
  null,
291
- _contract_get_opts);
292
- _msg_info_contract_obtained(
293
- _contract);
294
- try {
295
- _method =
296
- await _contract.getFunction(
297
- _contract_method);
298
- _msg_info_method_obtained(
299
- _method);
300
- }
301
- catch(
302
- _error) {
303
- const
304
- _msg_no_fragment =
305
- "no matching fragment";
306
- const
307
- _msg_short =
308
- _error[
309
- "shortMessage"];
310
- if ( _msg_no_fragment == _msg_short ) {
311
- _msg =
312
- `Found no '${_contract_method}' method ` +
313
- `nor contract ABI '${_contract_abi_path}' ` +
314
- `nor in compiler output ` +
315
- `'${_contract_compiler_output_path}'.`;
316
- _msg_error(
317
- _msg,
318
- 0);
319
- }
320
- throw _error;
321
- }
322
- }
323
- else if ( _method_object != "" ||
324
- _method_object != undefined ) {
646
+ _method_args);
325
647
  _msg =
326
- "Re-using contract method.";
648
+ "Value obtained;";
327
649
  _msg_info(
328
650
  _msg);
329
- _method =
330
- _method_object;
331
651
  }
332
- _value =
333
- await _method.staticCall.apply(
334
- null,
335
- _method_args);
336
- if ( _value != undefined ) {
652
+ catch(
653
+ _error) {
654
+ const
655
+ _error_is_network_error =
656
+ _is_network_error(
657
+ _error);
658
+ if ( ! _error_is_network_error ) {
659
+ _msg =
660
+ "Unknown error type " +
661
+ "for (evm-contract-call).";
662
+ _msg_error(
663
+ _msg,
664
+ 0);
665
+ }
666
+ _msg =
667
+ `Error running ` +
668
+ `'${_contract_method}.staticCall' with ` +
669
+ "the given parameters.";
670
+ _msg_error(
671
+ _msg,
672
+ 0);
673
+ _echo2(
674
+ _error);
675
+ throw _error;
676
+ }
677
+ const
678
+ _value_type =
679
+ typeof(
680
+ _value);
681
+ if ( _value_type !== "undefined" ) {
682
+ _msg =
683
+ "Call value obtained";
684
+ _msg_info(
685
+ _msg);
337
686
  _passed =
338
687
  true;
339
688
  }
340
- else if ( _value == undefined ) {
341
- throw { "error": {
342
- "message":
343
- "Value undefined, static call error" } };
689
+ else if ( _value_type === "undefined" ) {
690
+ _exception = {
691
+ "error": {
692
+ "message":
693
+ "Value undefined, static call error"
694
+ }
695
+ };
696
+ throw _exception;
344
697
  }
345
- } catch (
346
- _error) {
347
- _error_display(
698
+ }
699
+ catch (
700
+ _error) {
701
+ _msg =
702
+ "Error running static call.";
703
+ _msg_error(
704
+ _msg,
705
+ 0);
706
+ _echo2(
348
707
  _error);
708
+ // _error_display(
709
+ // _error);
349
710
  _retry =
350
711
  _retry + 1;
712
+ _msg =
713
+ "Destroying method and contract " +
714
+ "objects.";
715
+ _contract_object.runner.provider.destroy();
716
+ _contract_object =
717
+ {};
718
+ _method_object =
719
+ {};
720
+ _msg_info(
721
+ _msg);
722
+ _msg =
723
+ "Increasing retry and waiting 3 seconds.";
351
724
  _msg_error(
352
- "Increasing retry and waiting 3 seconds.",
725
+ _msg,
353
726
  0);
354
- await _sleep(
355
- 3000);
727
+ try {
728
+ await _sleep(
729
+ 3000);
730
+ }
731
+ catch(
732
+ _error) {
733
+ _msg =
734
+ "Problems sleeping?";
735
+ _msg_error(
736
+ _msg,
737
+ 0);
738
+ _echo2(
739
+ _error);
740
+ throw _error;
741
+ }
356
742
  }
357
743
  }
358
744
  if ( _retry > _retries_max ) {
359
- throw { "error": {
360
- "message":
361
- "Maximum number of retries reached." } };
745
+ _exception = {
746
+ "error": {
747
+ "message":
748
+ "Maximum number of retries reached."
749
+ }
750
+ };
751
+ throw _exception;
362
752
  }
363
753
  return [
364
754
  _value,