evm-chains-info 0.0.14 → 0.0.16

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.
@@ -35,6 +35,8 @@
35
35
 
36
36
  /* global
37
37
  db_paths */
38
+ /* global
39
+ db_types */
38
40
  /* global
39
41
  input_type:
40
42
  writable */
@@ -253,7 +255,27 @@ function
253
255
  _format);
254
256
  }
255
257
  for ( _db_type of _db_types ) {
256
- if ( _db_type == "system" ) {
258
+ if ( _db_type == "node" ) {
259
+ _msg =
260
+ `Getting data from 'ethereum-data' module.`;
261
+ _msg_info(
262
+ _msg);
263
+ _data =
264
+ _data_get(
265
+ _chain_id);
266
+ _msg =
267
+ `Displaying data for ` +
268
+ `chain '${_chain_id}' `+
269
+ `of type '${_db_types}'.`;
270
+ _msg_info(
271
+ _msg);
272
+ for ( _chain_info of _data) {
273
+ if ( _chain_info["chainId"] == _chain_id ) {
274
+ return _chain_info;
275
+ }
276
+ }
277
+ }
278
+ else if ( _db_type == "system" ) {
257
279
  const
258
280
  _db_exists =
259
281
  _file_exists(
@@ -279,28 +301,6 @@ function
279
301
  _msg,
280
302
  1);
281
303
  }
282
- else if ( _db_type == "node" ) {
283
- _msg =
284
- `Getting data from 'ethereum-data' module.`;
285
- _msg_info(
286
- _msg);
287
- _data =
288
- _data_get(
289
- _chain_id);
290
- _msg =
291
- `Displaying data for ` +
292
- `chain '${_chain_id}' `+
293
- `of type '${_db_types}'.`;
294
- _msg_info(
295
- _msg);
296
- console.log(
297
- _data);
298
- for ( _chain_info of _data) {
299
- if ( _chain_info["chainId"] == _chain_id ) {
300
- return _chain_info;
301
- }
302
- }
303
- }
304
304
  }
305
305
  }
306
306
 
@@ -555,6 +555,19 @@ function
555
555
  }
556
556
  }
557
557
 
558
+ function
559
+ _db_types_auto_detect(
560
+ _chain_id) {
561
+ if ( db_types.length == 0 ) {
562
+ db_types.push(
563
+ "node");
564
+ }
565
+ if ( db_paths.length > 0 ) {
566
+ db_types.push(
567
+ "system");
568
+ }
569
+ }
570
+
558
571
  function
559
572
  _db_paths_auto_detect(
560
573
  _chain_id) {
@@ -695,6 +708,7 @@ function
695
708
  _evm_chains_info_get(
696
709
  _target_chain,
697
710
  _retrieval_mode,
711
+ _db_types,
698
712
  _input_type,
699
713
  _output_type,
700
714
  _selection_method,
@@ -704,6 +718,7 @@ function
704
718
  let
705
719
  _db,
706
720
  _db_path,
721
+ _db_type,
707
722
  _entry,
708
723
  _msg,
709
724
  _networks_total,
@@ -711,79 +726,100 @@ function
711
726
  _networks_total =
712
727
  0;
713
728
  if ( _retrieval_mode == "offline" ) {
714
- _msg =
715
- `Getting data from databases ` +
716
- `'${_db_paths}'`;
717
- _msg_info(
718
- _msg);
719
- for ( _db_path of _db_paths ) {
720
- _msg =
721
- `Looking in '${_db_path}'.`;
722
- _msg_info(
723
- _msg);
724
- _db_path_check(
725
- _db_path);
726
- if ( _input_type != "amount" ) {
729
+ for ( _db_type of _db_types ) {
730
+ if ( _db_type == "node" ) {
727
731
  _db =
728
- _db_get(
729
- _db_path,
730
- _input_type,
731
- _output_type,
732
- _selection_method,
733
- _api_key,
734
- _networks_all,
732
+ [];
733
+ _results =
734
+ _data_get(
735
735
  _target_chain);
736
- if ( _selection_method == "kirsh" ) {
737
- break;
738
- }
739
- }
740
- else if ( _input_type == "amount" ) {
741
- _db =
742
- _json_read(
743
- _db_path);
744
- _networks_total =
745
- _db.length;
736
+ for ( _entry of _results) {
737
+ if ( _entry["chainId"] == _target_chain ) {
738
+ _db.push(
739
+ _entry);
740
+ if ( _selection_method == "kirsh" ) {
741
+ break;
742
+ }
743
+ }
744
+ }
746
745
  }
747
- }
748
- if ( _input_type != "amount" ) {
749
- _networks_total =
750
- _db.length;
751
- if ( _db.length == 0 ) {
746
+ else if ( _db_type == "system" ) {
752
747
  _msg =
753
- `No results found for network ` +
754
- `'${_target_chain}'.`;
755
- _msg_error(
756
- _msg,
757
- 0);
758
- }
759
- const
760
- _results =
761
- [];
762
- for ( _entry of _db ) {
763
- if ( _entry['chainId'] == _target_chain ) {
764
- _results.push(
765
- _entry[
766
- _output_type]);
767
- if ( _selection_method != "all" ) {
768
- break;
748
+ `Getting data from databases ` +
749
+ `'${_db_paths}'`;
750
+ _msg_info(
751
+ _msg);
752
+ for ( _db_path of _db_paths ) {
753
+ _msg =
754
+ `Looking in '${_db_path}'.`;
755
+ _msg_info(
756
+ _msg);
757
+ _db_path_check(
758
+ _db_path);
759
+ if ( _input_type != "amount" ) {
760
+ _db =
761
+ _db_get(
762
+ _db_path,
763
+ _input_type,
764
+ _output_type,
765
+ _selection_method,
766
+ _api_key,
767
+ _networks_all,
768
+ _target_chain);
769
+ }
770
+ else if ( _input_type == "amount" ) {
771
+ _db =
772
+ _json_read(
773
+ _db_path);
774
+ _networks_total =
775
+ _db.length;
776
+ if ( _selection_method == "kirsh" ) {
777
+ break;
778
+ }
779
+ }
780
+ }
781
+ if ( _input_type != "amount" ) {
782
+ _networks_total =
783
+ _db.length;
784
+ if ( _db.length == 0 ) {
785
+ _msg =
786
+ `No results found for network ` +
787
+ `'${_target_chain}'.`;
788
+ _msg_error(
789
+ _msg,
790
+ 0);
769
791
  }
770
792
  }
793
+ else if ( _input_type == "amount" ) {
794
+ _msg =
795
+ `Found '${_networks_total}' networks.`;
796
+ _msg_info(
797
+ _msg);
798
+ return _networks_total;
799
+ }
771
800
  }
772
- _db =
773
- _results;
774
- _msg =
775
- `Found '${_networks_total}' ` +
776
- `networks in database '${_db_path}'.`;
777
- _msg_info(
778
- _msg);
779
801
  }
780
- else if ( _input_type == "amount" ) {
781
- _msg =
782
- `Found '${_networks_total}' networks.`;
783
- _msg_info(
784
- _msg);
785
- return _networks_total;
802
+ _results =
803
+ [];
804
+ for ( _entry of _db ) {
805
+ if ( _entry['chainId'] == _target_chain ) {
806
+ _results.push(
807
+ _entry[
808
+ _output_type]);
809
+ if ( _selection_method != "all" ) {
810
+ break;
811
+ }
812
+ }
786
813
  }
814
+ _db =
815
+ _results;
816
+ _networks_total =
817
+ _db.length;
818
+ _msg =
819
+ `Found '${_networks_total}' ` +
820
+ `networks in database '${_db_path}'.`;
821
+ _msg_info(
822
+ _msg);
787
823
  }
788
824
  else if ( _retrieval_mode == "online" ) {
789
825
  _msg =
@@ -813,6 +849,7 @@ function
813
849
  _input_type,
814
850
  _output_type,
815
851
  _retrieval_mode,
852
+ _db_types,
816
853
  _selection_method,
817
854
  _api_key,
818
855
  _networks_all,
@@ -831,6 +868,7 @@ function
831
868
  _evm_chains_info_get(
832
869
  _target_chain,
833
870
  _retrieval_mode,
871
+ _db_types,
834
872
  _input_type,
835
873
  _output_type,
836
874
  _selection_method,
@@ -889,6 +927,8 @@ module.exports = {
889
927
  _data_get,
890
928
  _db_paths_auto_detect:
891
929
  _db_paths_auto_detect,
930
+ _db_types_auto_detect:
931
+ _db_types_auto_detect,
892
932
  _evm_chains_db_path_get:
893
933
  _evm_chains_db_path_get,
894
934
  _evm_chains_info: