evm-chains-info 0.0.4 → 0.0.6

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-chains-info CHANGED
@@ -227,7 +227,8 @@ function
227
227
  networks_all =
228
228
  "n";
229
229
  }
230
- _db_path_auto_detect();
230
+ _db_path_auto_detect(
231
+ target_chain);
231
232
  }
232
233
 
233
234
  function
@@ -520,6 +521,16 @@ function
520
521
  }
521
522
  }
522
523
 
524
+ function
525
+ _evm_chains_info_cmdline(
526
+ _app_opts) {
527
+ const
528
+ _results =
529
+ _evm_chains_info.apply(
530
+ null,
531
+ app_opts);
532
+ }
533
+
523
534
  _global_variables();
524
535
  if ( _cmdline_check(
525
536
  "evm-chains-info.js") == true ) {
@@ -541,6 +552,5 @@ app_opts = [
541
552
  target_chain,
542
553
  db_paths
543
554
  ];
544
- _evm_chains_info.apply(
545
- null,
555
+ _evm_chains_info_cmdline(
546
556
  app_opts);
@@ -31,8 +31,6 @@
31
31
  /* eslint-disable
32
32
  no-unused-vars */
33
33
 
34
- /* global
35
- chain_id */
36
34
  /* global
37
35
  db_paths */
38
36
  /* global
@@ -65,6 +63,12 @@ _file_exists =
65
63
  no-global-assign */
66
64
  _json_read =
67
65
  _libcrash_module._json_read;
66
+ /* global
67
+ _lib_get */
68
+ /* eslint-disable-next-line
69
+ no-global-assign */
70
+ _lib_get =
71
+ _libcrash_module._lib_get;
68
72
  /* global
69
73
  _msg_info */
70
74
  /* eslint-disable-next-line
@@ -83,6 +87,12 @@ _msg_error =
83
87
  no-global-assign */
84
88
  _path_join =
85
89
  _libcrash_module._path_join;
90
+ /* global
91
+ _range */
92
+ /* eslint-disable-next-line
93
+ no-global-assign */
94
+ _range =
95
+ _libcrash_module._range;
86
96
 
87
97
  const
88
98
  _ethereum_data_module =
@@ -101,7 +111,8 @@ function
101
111
  _format) {
102
112
  let
103
113
  _db_name,
104
- _db_path;
114
+ _db_path,
115
+ _msg;
105
116
  if ( typeof(
106
117
  _user) == "undefined" ) {
107
118
  _user =
@@ -123,6 +134,13 @@ function
123
134
  "unified";
124
135
  }
125
136
  }
137
+ _msg =
138
+ `Getting path for chain ` +
139
+ `with chain id '${_chain_id}' ` +
140
+ `with privilege user set to ` +
141
+ `'${_user}' in format '${_format}'.`;
142
+ _msg_info(
143
+ _msg);
126
144
  if ( _format == "unified" ) {
127
145
  _db_name =
128
146
  "chains.json";
@@ -132,6 +150,8 @@ function
132
150
  `${_chain_id}.json`;
133
151
  }
134
152
  if ( _user == true ) {
153
+ _msg =
154
+ `Home directory: '${_homedir_get()}'`;
135
155
  _db_path =
136
156
  _path_join(
137
157
  [ _homedir_get(),
@@ -142,23 +162,36 @@ function
142
162
  _db_exists =
143
163
  _file_exists(
144
164
  _db_path);
165
+ if ( _db_exists == true ) {
166
+ _msg =
167
+ `Found database '${_db_path}'.`;
168
+ _msg_info(
169
+ _msg);
170
+ }
145
171
  if ( _db_exists == false ) {
172
+ _msg =
173
+ `Database '${_db_path}' ` +
174
+ "not found";
175
+ _msg_info(
176
+ _msg);
146
177
  _user =
147
178
  false;
148
179
  }
149
180
  }
150
- if ( _user == false ) {
181
+ else if ( _user == false ) {
182
+ const
183
+ _lib =
184
+ _lib_get();
151
185
  _db_path =
152
186
  _path_join(
153
- [ process.env.NODE_PATH,
154
- "..",
187
+ [ _lib,
155
188
  "evm-chains",
156
189
  "chains.json" ]);
157
190
  }
158
191
  else {
159
- const
160
- _msg =
161
- "Input variable '_user' must be a boolean.";
192
+ _msg =
193
+ "Input variable '_user' must be a boolean. " +
194
+ `_user value is '${_user}'.`;
162
195
  _msg_error(
163
196
  _msg,
164
197
  0);
@@ -218,8 +251,8 @@ function
218
251
  `of type '${_db_types}'.`;
219
252
  _msg_info(
220
253
  _msg);
221
- console.log(
222
- _db);
254
+ // console.log(
255
+ // _db);
223
256
  for ( _chain_info of _db) {
224
257
  if ( _chain_info["chainId"] == _chain_id ) {
225
258
  return _chain_info;
@@ -357,10 +390,12 @@ function
357
390
  no-useless-assignment */
358
391
  _filter_key =
359
392
  "chainId";
360
- _filter_key =
393
+ _filter_value =
361
394
  _target_chain;
362
395
  _msg =
363
- `Filter key: ${_filter_key}`;
396
+ `Getting data for filter ` +
397
+ `key: '${_filter_key}' and value ` +
398
+ `'${_filter_value}'.`;
364
399
  _msg_info(
365
400
  _msg);
366
401
  }
@@ -374,18 +409,35 @@ function
374
409
  _filter_output_type =
375
410
  "chainId";
376
411
  }
412
+ else if ( _output_type == "rpc" ) {
413
+ _filter_output_type =
414
+ _output_type;
415
+ }
377
416
  if ( _networks_all == "y" ) {
378
417
  _filter =
379
418
  _all_get(
380
419
  _filter_output_type);
381
- console.log(
382
- _filter);
383
- _results =
384
- [];
385
- console.log(
386
- _results);
420
+ _msg =
421
+ "Showing results for all networks " +
422
+ `with filter '${_filter}'.`;
423
+ _msg_info(
424
+ _msg);
425
+ _db =
426
+ _json_read(
427
+ _db_path);
428
+ _msg =
429
+ "Found 'Showing results for all networks " +
430
+ `with filter '${_filter}'.`;
431
+ return _db;
387
432
  }
388
433
  else if ( _networks_all == "n" ) {
434
+ _results =
435
+ [];
436
+ _msg =
437
+ `Showing results for chain '${_target_chain}' in ` +
438
+ `database '${_db_path}' with filter '${_filter_output_type}'.`;
439
+ _msg_info(
440
+ _msg);
389
441
  // this doesnt work the same in
390
442
  // javascript as in bash i suppose.
391
443
  // _filter =
@@ -393,16 +445,25 @@ function
393
445
  // _filter_key,
394
446
  // _filter_value,
395
447
  // _filter_output_type);
448
+ // _json_read(
449
+ // _db_path);
396
450
  const
397
451
  _db =
398
452
  _json_read(
399
453
  _db_path);
400
- console.log(
401
- _db);
402
- _results =
403
- [];
404
- console.log(
405
- _results);
454
+ _msg =
455
+ `Database '${_db_path}' ` +
456
+ `contains '${_db.length}' items.`;
457
+ _msg_info(
458
+ _msg);
459
+ for ( _entry of _db ) {
460
+ if ( _entry[
461
+ _filter_key] == _target_chain ) {
462
+ _results.push(
463
+ _entry);
464
+ }
465
+ }
466
+ return _results;
406
467
  }
407
468
  }
408
469
 
@@ -421,22 +482,23 @@ function
421
482
  }
422
483
 
423
484
  function
424
- _db_path_auto_detect() {
485
+ _db_path_auto_detect(
486
+ _chain_id) {
425
487
  let
426
488
  _type_primary,
427
489
  _type_fallback,
428
490
  _msg;
429
491
  if ( user_level == "y" ) {
430
492
  _type_primary =
431
- "user";
493
+ true;
432
494
  _type_fallback =
433
- "system";
495
+ false;
434
496
  }
435
497
  else if ( user_level == "n" ) {
436
498
  _type_primary =
437
- "system";
499
+ true;
438
500
  _type_fallback =
439
- "user";
501
+ false;
440
502
  }
441
503
  const
442
504
  _db =
@@ -448,7 +510,7 @@ function
448
510
  _db_split =
449
511
  _evm_chains_db_path_get(
450
512
  _type_primary,
451
- chain_id,
513
+ _chain_id,
452
514
  "split");
453
515
  const
454
516
  _db_fallback =
@@ -460,7 +522,7 @@ function
460
522
  _db_fallback_split =
461
523
  _evm_chains_db_path_get(
462
524
  _type_fallback,
463
- chain_id,
525
+ _chain_id,
464
526
  "split");
465
527
  if ( _file_exists(
466
528
  _db_split) ) {
@@ -530,13 +592,18 @@ function
530
592
  let
531
593
  _db,
532
594
  _db_path,
595
+ _entry,
533
596
  _msg,
534
597
  _networks_total,
535
- _result,
536
598
  _results;
537
599
  _networks_total =
538
600
  0;
539
601
  if ( _retrieval_mode == "offline" ) {
602
+ _msg =
603
+ `Getting data from databases ` +
604
+ `'${_db_paths}'`;
605
+ _msg_info(
606
+ _msg);
540
607
  for ( _db_path of _db_paths ) {
541
608
  _msg =
542
609
  `Looking in '${_db_path}'.`;
@@ -545,7 +612,7 @@ function
545
612
  _db_path_check(
546
613
  _db_path);
547
614
  if ( _input_type != "amount" ) {
548
- _results =
615
+ _db =
549
616
  _db_get(
550
617
  _db_path,
551
618
  _input_type,
@@ -559,12 +626,14 @@ function
559
626
  _db =
560
627
  _json_read(
561
628
  _db_path);
562
- _networks_total =
629
+ _networks_total =
563
630
  _db.length;
564
631
  }
565
632
  }
566
633
  if ( _input_type != "amount" ) {
567
- if ( _results.length == 0 ) {
634
+ _networks_total =
635
+ _db.length;
636
+ if ( _db.length == 0 ) {
568
637
  _msg =
569
638
  `No results found for network ` +
570
639
  `'${_target_chain}'.`;
@@ -572,17 +641,32 @@ function
572
641
  _msg,
573
642
  0);
574
643
  }
575
- for ( _result of _results ) {
576
- console.log(
577
- _result);
578
- if ( _selection_method != "all" ) {
579
- break;
580
- }
644
+ const
645
+ _results =
646
+ [];
647
+ for ( _entry of _db ) {
648
+ if ( _entry['chainId'] == _target_chain ) {
649
+ _results.push(
650
+ _entry[
651
+ _output_type]);
652
+ if ( _selection_method != "all" ) {
653
+ break;
654
+ }
655
+ }
581
656
  }
657
+ _db =
658
+ _results;
659
+ _msg =
660
+ `Found '${_networks_total}' networks.`;
661
+ _msg_info(
662
+ _msg);
582
663
  }
583
664
  else if ( _input_type == "amount" ) {
584
- console.log(
585
- _networks_total);
665
+ _msg =
666
+ `Found '${_networks_total}' networks.`;
667
+ _msg_info(
668
+ _msg);
669
+ return _networks_total;
586
670
  }
587
671
  }
588
672
  else if ( _retrieval_mode == "online" ) {
@@ -592,14 +676,18 @@ function
592
676
  _msg,
593
677
  1);
594
678
  }
679
+ return _db;
595
680
  }
596
681
 
597
682
  function
598
683
  _evm_chains_info_set(
599
684
  _input_type) {
600
685
  if ( _input_type == "id" ) {
601
- console.log(
602
- _input_type);
686
+ const
687
+ _msg =
688
+ `Setting value for type '${_input_type}'`.
689
+ _msg_info(
690
+ _msg);
603
691
  }
604
692
  }
605
693
 
@@ -614,16 +702,29 @@ function
614
702
  _networks_all,
615
703
  _target_chain,
616
704
  _db_paths) {
705
+ let
706
+ _result,
707
+ _rpc;
617
708
  if ( _target_command == "get" ) {
618
- _evm_chains_info_get(
619
- _target_chain,
620
- _retrieval_mode,
621
- _input_type,
622
- _output_type,
623
- _selection_method,
624
- _networks_all,
625
- _api_key,
626
- _db_paths);
709
+ const
710
+ _results =
711
+ _evm_chains_info_get(
712
+ _target_chain,
713
+ _retrieval_mode,
714
+ _input_type,
715
+ _output_type,
716
+ _selection_method,
717
+ _networks_all,
718
+ _api_key,
719
+ _db_paths);
720
+ if ( _output_type == "rpc" ) {
721
+ for ( _result of _results ) {
722
+ for ( _rpc of _result) {
723
+ console.log(
724
+ _rpc);
725
+ }
726
+ }
727
+ }
627
728
  }
628
729
  else if ( _target_command == "set" ) {
629
730
  _evm_chains_info_set(
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name":
3
3
  "evm-chains-info",
4
4
  "version":
5
- "0.0.4",
5
+ "0.0.6",
6
6
  "description":
7
7
  "Returns information about Ethereum Virtual Machine (EVM) blockchains.",
8
8
  "funding": {
@@ -59,7 +59,7 @@
59
59
  },
60
60
  "devDependencies": {
61
61
  "crash-js-webpack":
62
- "^0.0.5",
62
+ "^0.0.6",
63
63
  "flatted":
64
64
  "^3.2.9",
65
65
  "eslint":
@@ -77,7 +77,7 @@
77
77
  },
78
78
  "dependencies": {
79
79
  "crash-js":
80
- "^0.1.92",
80
+ "^0.1.96",
81
81
  "ethereum-data":
82
82
  "^0.0.3",
83
83
  "yargs":