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.
@@ -75,6 +75,11 @@ const
75
75
  const
76
76
  _dirname =
77
77
  _libcrash_module._dirname;
78
+ /* global
79
+ _echo */
80
+ const
81
+ _echo =
82
+ _libcrash_module._echo;
78
83
  /* global
79
84
  _file_exists */
80
85
  const
@@ -158,6 +163,15 @@ const
158
163
  const
159
164
  _evm_contract_deployment_address =
160
165
  _evm_contract_deployment_address_module._evm_contract_deployment_address;
166
+ const
167
+ _evm_contract_deployments_dir_module =
168
+ await import(
169
+ "./libevm-contract-deployments-dir");
170
+ /* global
171
+ _evm_contract_deployments_dir */
172
+ const
173
+ _evm_contract_deployments_dir =
174
+ _evm_contract_deployments_dir_module._evm_contract_deployments_dir;
161
175
  const
162
176
  _ethereum_data_module =
163
177
  await _require(
@@ -226,9 +240,33 @@ function
226
240
 
227
241
  function
228
242
  _default_artifact_path_get(
229
- _type) {
243
+ _type,
244
+ _target_network,
245
+ _contract_address) {
230
246
  let
231
247
  _file_name;
248
+ const
249
+ _network_type =
250
+ typeof(
251
+ _target_network);
252
+ if ( _network_type === "undefined" ||
253
+ _target_network === "" ) {
254
+ _target_network =
255
+ _get(
256
+ "target",
257
+ "network");
258
+ }
259
+ const
260
+ _contract_address_type =
261
+ typeof(
262
+ _contract_address);
263
+ if ( _contract_address_type === "undefined" ||
264
+ _contract_address === "" ) {
265
+ _contract_address =
266
+ _get(
267
+ "contract",
268
+ "address");
269
+ }
232
270
  const
233
271
  _home =
234
272
  _homedir_get();
@@ -241,15 +279,15 @@ function
241
279
  "evm-contract-call" ]);
242
280
  if ( _type == "abi" ) {
243
281
  _file_name =
244
- `${contract_address}.abi.json`;
282
+ `${_contract_address}.abi.json`;
245
283
  }
246
284
  else if ( _type == "bytecode" ) {
247
285
  _file_name =
248
- `${contract_address}.bin`;
286
+ `${_contract_address}.bin`;
249
287
  }
250
288
  else if ( _type == "compiler_output" ) {
251
289
  _file_name =
252
- `${contract_address}.json`;
290
+ `${_contract_address}.json`;
253
291
  }
254
292
  else {
255
293
  const
@@ -257,13 +295,14 @@ function
257
295
  `Unknown artifact type '${_type}'.`;
258
296
  _msg_error(
259
297
  _msg,
260
- 1);
298
+ 0);
299
+ throw _msg;
261
300
  }
262
301
  const
263
302
  _artifact =
264
303
  _path_join( [
265
304
  _data_dir,
266
- target_network,
305
+ _target_network,
267
306
  _file_name ]);
268
307
  return _artifact;
269
308
  }
@@ -335,8 +374,8 @@ function
335
374
  _abi_target =
336
375
  _abi;
337
376
  if ( typeof(
338
- _abi_target) == "undefined" ||
339
- _abi_target == "" ) {
377
+ _abi_target) === "undefined" ||
378
+ _abi_target === "" ) {
340
379
  _abi_target =
341
380
  _default_artifact_path_get(
342
381
  "abi");
@@ -476,33 +515,69 @@ async function
476
515
  _contract_compiler_output,
477
516
  _contract_method,
478
517
  _method_args) {
479
- let
480
- _explorer,
481
- _out,
482
- _result,
483
- _rpc;
484
- if ( _call_type == "static" ) {
485
- const
486
- _infos =
487
- [];
488
- _out =
489
- "";
518
+ // let
519
+ // _msg,
520
+ // _out;
521
+ const
522
+ _call_type_type =
523
+ typeof(
524
+ _call_type);
525
+ if ( _call_type_type == "undefined" ) {
526
+ _call_type =
527
+ "static";
528
+ }
529
+ else if ( _call_type_type == "string" ) {
530
+ if ( _call_type.length < 1 ) {
531
+ // Properly
532
+ _call_type =
533
+ "static";
534
+ }
535
+ else {
536
+ _echo(
537
+ _call_type);
538
+ }
490
539
  }
491
- else if ( _call_type == "dynamic" ) {
492
- _out =
493
- "";
540
+ else if ( _call_type_type == "object" ) {
541
+ _echo(
542
+ _call_type);
494
543
  }
495
544
  else {
496
- const
497
- _msg =
498
- `Unknown call type ` +
499
- `'${_call_type}'.`;
500
- _msg_error(
501
- _msg,
502
- 0);
503
- throw _msg;
545
+ _echo(
546
+ _call_type);
504
547
  }
505
- return _out;
548
+ return [ _call_type ];
549
+ // _msg =
550
+ // "Running EVM network call " +
551
+ // `of type '${_call_type}'.`;
552
+ // _msg_info(
553
+ // _msg);
554
+ // if ( _call_type == "static" ) {
555
+ // _out =
556
+ // "static";
557
+ // _echo(
558
+ // "static");
559
+ // // const
560
+ // // _infos =
561
+ // // [];
562
+ // // _out =
563
+ // // "";
564
+ // }
565
+ // else if ( _call_type == "dynamic" ) {
566
+ // _echo(
567
+ // "dynamic");
568
+ // _out =
569
+ // "static";
570
+ // }
571
+ // else {
572
+ // _msg =
573
+ // `Unknown call type ` +
574
+ // `'${_call_type}'.`;
575
+ // _msg_error(
576
+ // _msg,
577
+ // 0);
578
+ // throw _msg;
579
+ // }
580
+ // return _out;
506
581
  }
507
582
 
508
583
  function
@@ -680,6 +755,7 @@ async function
680
755
  let
681
756
  _app,
682
757
  _contract_dir,
758
+ _is_dir,
683
759
  _msg;
684
760
  const
685
761
  _lib =
@@ -699,8 +775,14 @@ async function
699
775
  "deployments",
700
776
  _contract_name
701
777
  ]);
702
- if ( _dir_exists(
703
- _contract_dir) ) {
778
+ // _echo(_contract_dir);
779
+ _is_dir =
780
+ await _dir_exists(
781
+ _contract_dir);
782
+ // _echo(_is_dir);
783
+ if ( _is_dir ) {
784
+ // _echo(
785
+ // _contract_dir);
704
786
  _target_apps[
705
787
  _app] =
706
788
  1;
@@ -747,7 +829,7 @@ async function
747
829
  0];
748
830
  }
749
831
 
750
- function
832
+ async function
751
833
  _target_app_auto_detect() {
752
834
  let
753
835
  _target_app;
@@ -765,7 +847,7 @@ function
765
847
  if ( _contract_address_type != "undefined" &&
766
848
  _contract_address != "" ) {
767
849
  _target_app =
768
- _target_app_get(
850
+ await _target_app_get(
769
851
  _contract_address);
770
852
  }
771
853
  _override_set(
@@ -774,12 +856,42 @@ function
774
856
  _target_app);
775
857
  }
776
858
 
859
+ async function
860
+ _target_contract_auto_detect() {
861
+ let
862
+ _target_contract;
863
+ _target_contract =
864
+ "";
865
+ const
866
+ _contract_address =
867
+ _get(
868
+ "contract",
869
+ "address");
870
+ const
871
+ _address_valid =
872
+ await _address_check(
873
+ _contract_address);
874
+ if ( ! _address_valid ) {
875
+ _target_contract =
876
+ _contract_address;
877
+ }
878
+ _override_set(
879
+ "target",
880
+ "contract",
881
+ _target_contract);
882
+ }
883
+
777
884
  async function
778
885
  _contract_address_auto_detect() {
779
886
  let
780
887
  _contract_address,
888
+ _contract_addresses,
781
889
  _evm_contract_deployment_address_args,
782
- _msg;
890
+ _msg,
891
+ _network;
892
+ const
893
+ _target_networks_index =
894
+ {};
783
895
  _contract_address =
784
896
  _get(
785
897
  "contract",
@@ -790,10 +902,10 @@ async function
790
902
  "target",
791
903
  "app");
792
904
  const
793
- _target_network =
905
+ _target_networks =
794
906
  _get(
795
907
  "target",
796
- "network");
908
+ "networks");
797
909
  const
798
910
  _target_contract =
799
911
  _get(
@@ -804,14 +916,37 @@ async function
804
916
  _get(
805
917
  "deployments",
806
918
  "dir");
919
+ for ( _network of _target_networks ) {
920
+ _target_networks_index[
921
+ _network] =
922
+ 1;
923
+ }
924
+ const
925
+ _target_networks_set =
926
+ Object.keys(
927
+ _target_networks_index);
928
+ _msg =
929
+ "Auto-detecting address " +
930
+ `for contract '${_contract_address}' ` +
931
+ `on network '${_target_networks_set}' ` +
932
+ `for application '${_target_app}'.`;
933
+ _msg_info(
934
+ _msg);
807
935
  if ( _contract_address != "" ) {
808
936
  const
809
937
  _address_valid =
810
938
  await _address_check(
811
939
  _contract_address);
812
- if ( ! _address_valid ) {
940
+ if ( _address_valid ) {
941
+ _msg =
942
+ `Address '${_contract_address}' ` +
943
+ `is valid.`;
944
+ _msg_info(
945
+ _msg);
946
+ }
947
+ else {
813
948
  if ( _target_app != "" &&
814
- _target_network != "" &&
949
+ 0 < _target_networks.length &&
815
950
  _target_contract != "" ) {
816
951
  _msg =
817
952
  "Looking for address " +
@@ -819,12 +954,13 @@ async function
819
954
  `'${_target_contract}' for the ` +
820
955
  `'${_target_app}' ` +
821
956
  "libEVM application on network " +
822
- `'${_target_network}'.`;
957
+ `'${_target_networks}' at deployments ` +
958
+ `directory '${_deployments_dir}'.`;
823
959
  _msg_info(
824
960
  _msg);
825
961
  _evm_contract_deployment_address_args = [
826
- [ _target_network ], // target networks
827
- [ _target_network ], // target chain ids
962
+ _target_networks_set, // target networks
963
+ _target_networks_set, // target chain ids
828
964
  "n", // all networks
829
965
  _target_app,
830
966
  _target_contract,
@@ -833,16 +969,35 @@ async function
833
969
  "", // configuration format
834
970
  _deployments_dir
835
971
  ];
836
- _contract_address =
837
- await _evm_contract_deployment_address.apply(
838
- null,
839
- _evm_contract_deployment_address_args);
972
+ try {
973
+ _contract_addresses =
974
+ await _evm_contract_deployment_address.apply(
975
+ null,
976
+ _evm_contract_deployment_address_args);
977
+ _contract_address =
978
+ _contract_addresses[
979
+ 0];
980
+ }
981
+ catch(
982
+ _error) {
983
+ _msg =
984
+ "Error while looking for contract " +
985
+ "address from local libEVM applications " +
986
+ "deployments directories.";
987
+ _msg_error(
988
+ _msg,
989
+ 0);
990
+ _msg_error(
991
+ _error,
992
+ 0);
993
+ throw _error;
994
+ }
840
995
  }
841
996
  else {
842
997
  _msg =
843
998
  "One between the " +
844
999
  `application '${_target_app}', ` +
845
- `the network '${_target_network}' ` +
1000
+ `the network '${_target_networks_set}' ` +
846
1001
  `or the contract '${_target_contract}' ` +
847
1002
  `has not been specified.`;
848
1003
  _msg_info(
@@ -919,6 +1074,7 @@ export {
919
1074
  _default_artifact_path_get,
920
1075
  _evm_contract_call,
921
1076
  _target_app_auto_detect,
1077
+ _target_contract_auto_detect,
922
1078
  _target_networks_auto_detect,
923
1079
  _target_networks_get
924
1080
  };
@@ -954,6 +1110,8 @@ export {
954
1110
  // _target_app_auto_detect,
955
1111
  // _target_networks_auto_detect:
956
1112
  // _target_networks_auto_detect,
1113
+ // _target_contract_auto_detect:
1114
+ // _target_contract_auto_detect,
957
1115
  // _target_networks_get:
958
1116
  // _target_networks_get
959
1117
  // };
@@ -85,6 +85,11 @@ const
85
85
  const
86
86
  _dir_exists =
87
87
  _libcrash_module._dir_exists;
88
+ /* global
89
+ _echo */
90
+ const
91
+ _echo =
92
+ _libcrash_module._echo;
88
93
  /* global
89
94
  _file_exists */
90
95
  const
@@ -100,6 +105,11 @@ const
100
105
  const
101
106
  _from_bash_ass_array =
102
107
  _libcrash_module._from_bash_ass_array;
108
+ /* global
109
+ _get */
110
+ const
111
+ _get =
112
+ _libcrash_module._get;
103
113
  /* global
104
114
  _homedir_get */
105
115
  const
@@ -154,33 +164,12 @@ const
154
164
  const
155
165
  _evm_chains_info =
156
166
  _evm_chains_info_module._evm_chains_info;
157
- const
158
- _libevm_contract_deployments_dir_module =
159
- await import(
160
- "./libevm-contract-deployments-dir");
161
- /* global
162
- _evm_contract_deployments_dir */
163
- const
164
- _evm_contract_deployments_dir =
165
- _libevm_contract_deployments_dir_module._evm_contract_deployments_dir;
166
- const
167
- _libevm_contract_deployment_networks_module =
168
- await import(
169
- "./libevm-contract-deployment-networks");
167
+ /* global
168
+ _evm_contract_deployments_dir */
170
169
  /* global
171
170
  _evm_contract_deployment_networks */
172
- const
173
- _evm_contract_deployment_networks =
174
- _libevm_contract_deployment_networks_module._evm_contract_deployment_networks;
175
- const
176
- _libevm_contract_deployment_versions_module =
177
- await import(
178
- "./libevm-contract-deployment-versions");
179
171
  /* global
180
172
  _evm_contract_deployment_versions */
181
- const
182
- _evm_contract_deployment_versions =
183
- _libevm_contract_deployment_versions_module._evm_contract_deployment_versions;
184
173
 
185
174
  async function
186
175
  _network_check(
@@ -189,18 +178,45 @@ async function
189
178
  _target_network,
190
179
  _target_network_id) {
191
180
  let
181
+ _contract_deployments_path,
192
182
  _error_flag,
183
+ _evm_contract_deployment_networks,
184
+ _evm_chains_info_args,
193
185
  _msg,
194
186
  _network_id;
187
+ _msg =
188
+ "Network check for deployments " +
189
+ `'${_deployments}', contract '${_contract}', ` +
190
+ `network '${_target_network}' and network with ID ` +
191
+ `'${_target_network_id}'.`;
192
+ _msg_info(
193
+ _msg);
194
+ _evm_contract_deployment_networks =
195
+ _get(
196
+ "_evm_contract",
197
+ "deployment_networks");
198
+ const
199
+ _evm_contract_deployment_networks_type =
200
+ typeof(
201
+ _evm_contract_deployment_networks_dir);
202
+ if ( _evm_contract_deployment_networks_type == "undefined" ||
203
+ _evm_contract_deployment_networks == "" ) {
204
+ const
205
+ _libevm_contract_deployment_networks_module =
206
+ await import(
207
+ "./libevm-contract-deployment-networks");
208
+ _evm_contract_deployment_networks =
209
+ _libevm_contract_deployment_networks_module._evm_contract_deployment_networks;
210
+ }
195
211
  _error_flag =
196
212
  false;
197
- _deployments_path =
213
+ _contract_deployments_path =
198
214
  _path_join( [
199
215
  _deployments,
200
216
  _contract ]);
201
217
  const
202
218
  _evm_contract_deployment_networks_args = [
203
- _deployments_path,
219
+ _contract_deployments_path,
204
220
  "y", // Display all
205
221
  "n", // Display safest
206
222
  "n" // Display cheapest
@@ -240,7 +256,8 @@ async function
240
256
  if ( _error_flag ) {
241
257
  _msg_error(
242
258
  _msg,
243
- 1);
259
+ 0);
260
+ throw _msg;
244
261
  }
245
262
  if ( _target_network_id == "" ) {
246
263
  _evm_chains_info_args = [
@@ -256,12 +273,29 @@ async function
256
273
  _target_network,
257
274
  [] // database paths
258
275
  ];
259
- _network_id =
260
- await _evm_chains_info.apply(
261
- null,
262
- _evm_chains_info_args);
276
+ try {
277
+ _network_id =
278
+ await _evm_chains_info.apply(
279
+ null,
280
+ _evm_chains_info_args);
281
+ }
282
+ catch(
283
+ _error) {
284
+ _msg =
285
+ "Error while running '_evm_chains_info' " +
286
+ `with arguments '${_evm_chains_info_args}'.`;
287
+ _msg_error(
288
+ _msg,
289
+ 0);
290
+ _msg_error(
291
+ _error,
292
+ 0);
293
+ throw _error;
294
+ }
263
295
  }
264
296
  else if ( _target_network == "" ) {
297
+ _network_id =
298
+ _target_network_id;
265
299
  _evm_chains_info_args = [
266
300
  "get", // target command
267
301
  "id" , // input type
@@ -275,9 +309,25 @@ async function
275
309
  _target_network_id,
276
310
  [] // database paths
277
311
  ];
278
- _target_network =
279
- await _evm_chains_info(
280
- _evm_chains_info_args);
312
+ try {
313
+ _target_network =
314
+ await _evm_chains_info.apply(
315
+ null,
316
+ _evm_chains_info_args);
317
+ }
318
+ catch(
319
+ _error) {
320
+ _msg =
321
+ "Error while running '_evm_chains_info' " +
322
+ `with arguments '${_evm_chains_info_args}'.`;
323
+ _msg_error(
324
+ _msg,
325
+ 0);
326
+ _msg_error(
327
+ _error,
328
+ 0);
329
+ throw _error;
330
+ }
281
331
  }
282
332
  if ( _target_network_id != "" ) {
283
333
  if ( _target_network_id != _network_id ) {
@@ -288,18 +338,45 @@ async function
288
338
  `known ID '${_network_id}'.`;
289
339
  _msg_error(
290
340
  _msg,
291
- 1);
341
+ 0);
342
+ throw _msg;
292
343
  }
293
344
  }
345
+ _msg =
346
+ "Network check for deployments " +
347
+ `'${_deployments}', contract '${_contract}', ` +
348
+ `network '${_target_network}' and network with ID ` +
349
+ `'${_target_network_id}' completed.`;
350
+ _msg_info(
351
+ _msg);
294
352
  }
295
353
 
296
354
  async function
297
355
  _user_deployments_init(
298
356
  _app,
299
357
  _deployments_dir) {
358
+ let
359
+ _evm_contract_deployments_dir;
300
360
  const
301
361
  _user_defined =
302
362
  "y";
363
+ _evm_contract_deployments_dir =
364
+ _get(
365
+ "_evm_contract",
366
+ "deployments_dir");
367
+ const
368
+ _evm_contract_deployments_dir_type =
369
+ typeof(
370
+ _evm_contract_deployments_dir);
371
+ if ( _evm_contract_deployments_dir_type == "undefined" ||
372
+ _evm_contract_deployments_dir == "" ) {
373
+ const
374
+ _libevm_contract_deployments_dir_module =
375
+ await import(
376
+ "./libevm-contract-deployments-dir");
377
+ _evm_contract_deployments_dir =
378
+ _libevm_contract_deployments_dir_module._evm_contract_deployments_dir;
379
+ }
303
380
  const
304
381
  _evm_contract_deployments_dir_args = [
305
382
  _app,
@@ -347,7 +424,8 @@ async function
347
424
  async function
348
425
  _deployments_dir_auto_detect() {
349
426
  let
350
- _deployments;
427
+ _deployments,
428
+ _evm_contract_deployments_dir;
351
429
  _deployments =
352
430
  "";
353
431
  const
@@ -362,6 +440,23 @@ async function
362
440
  const
363
441
  _user_defined =
364
442
  user_defined;
443
+ _evm_contract_deployments_dir =
444
+ _get(
445
+ "_evm_contract",
446
+ "deployments_dir");
447
+ const
448
+ _evm_contract_deployments_dir_type =
449
+ typeof(
450
+ _evm_contract_deployments_dir);
451
+ if ( _evm_contract_deployments_dir_type == "undefined" ||
452
+ _evm_contract_deployments_dir == "" ) {
453
+ const
454
+ _libevm_contract_deployments_dir_module =
455
+ await import(
456
+ "./libevm-contract-deployments-dir");
457
+ _evm_contract_deployments_dir =
458
+ _libevm_contract_deployments_dir_module._evm_contract_deployments_dir;
459
+ }
365
460
  const
366
461
  _evm_contract_deployments_dir_args = [
367
462
  _app,
@@ -384,6 +479,7 @@ async function
384
479
  _config,
385
480
  _config_ext,
386
481
  _deployments,
482
+ _evm_contracts_deployment_versions,
387
483
  _found,
388
484
  _net,
389
485
  _network,
@@ -485,6 +581,27 @@ async function
485
581
  _msg,
486
582
  1);
487
583
  }
584
+ const
585
+ _libevm_contract_deployment_versions_module =
586
+ await import(
587
+ "./libevm-contract-deployment-versions");
588
+ _evm_contract_deployment_versions =
589
+ _get(
590
+ "_evm_contract",
591
+ "deployment_versions");
592
+ const
593
+ _evm_contract_deployment_versions_type =
594
+ typeof(
595
+ _evm_contract_deployment_versions_dir);
596
+ if ( _evm_contract_deployment_versions_type == "undefined" ||
597
+ _evm_contract_deployment_versions == "" ) {
598
+ const
599
+ _libevm_contract_deployment_versions_module =
600
+ await import(
601
+ "./libevm-contract-deployment-versions");
602
+ _evm_contract_deployment_versions =
603
+ _libevm_contract_deployment_versions_module._evm_contract_deployment_versions;
604
+ }
488
605
  const
489
606
  _evm_contract_deployment_versions_args = [
490
607
  _config,
@@ -548,6 +665,7 @@ async function
548
665
  const
549
666
  _user_defined =
550
667
  user_defined;
668
+
551
669
  const
552
670
  _evm_contract_deployments_dir_args = [
553
671
  _dir_current_name,