evm-chains-info 0.0.5 → 0.0.8

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.
@@ -30,6 +30,8 @@
30
30
 
31
31
  /* eslint-disable
32
32
  no-unused-vars */
33
+ /* eslint-disable
34
+ no-useless-assignment */
33
35
 
34
36
  /* global
35
37
  db_paths */
@@ -87,6 +89,12 @@ _msg_error =
87
89
  no-global-assign */
88
90
  _path_join =
89
91
  _libcrash_module._path_join;
92
+ /* global
93
+ _range */
94
+ /* eslint-disable-next-line
95
+ no-global-assign */
96
+ _range =
97
+ _libcrash_module._range;
90
98
 
91
99
  const
92
100
  _ethereum_data_module =
@@ -108,24 +116,27 @@ function
108
116
  _db_path,
109
117
  _msg;
110
118
  if ( typeof(
111
- _user) == "undefined" ) {
119
+ _user) == "undefined" ||
120
+ _user == "" ) {
112
121
  _user =
113
- false;
122
+ "n";
114
123
  }
115
124
  if ( typeof(
116
- _chain_id) == "undefined" ) {
125
+ _chain_id) == "undefined" ||
126
+ _chain_id == "" ) {
117
127
  _chain_id =
118
128
  "";
119
129
  }
120
130
  if ( typeof(
121
- _format) == "undefined" ) {
131
+ _format) == "undefined" ||
132
+ _format == "" ) {
122
133
  if ( _chain_id != "" ) {
123
134
  _format =
124
135
  "split";
125
136
  }
126
137
  else if ( _chain_id == "" ) {
127
- _format =
128
- "unified";
138
+ _format =
139
+ "unified";
129
140
  }
130
141
  }
131
142
  _msg =
@@ -143,12 +154,17 @@ function
143
154
  _db_name =
144
155
  `${_chain_id}.json`;
145
156
  }
146
- if ( _user == true ) {
157
+ if ( _user == "y" ) {
158
+ const
159
+ _home_dir =
160
+ _homedir_get();
147
161
  _msg =
148
- `Home directory: '${_homedir_get()}'`;
162
+ `Home directory: '${_home_dir}'`;
163
+ _msg_info(
164
+ _msg);
149
165
  _db_path =
150
166
  _path_join(
151
- [ _homedir_get(),
167
+ [ _home_dir,
152
168
  ".config",
153
169
  "evm-chains",
154
170
  _db_name ]);
@@ -162,17 +178,23 @@ function
162
178
  _msg_info(
163
179
  _msg);
164
180
  }
165
- if ( _db_exists == false ) {
181
+ else if ( _db_exists == false ) {
166
182
  _msg =
167
183
  `Database '${_db_path}' ` +
168
184
  "not found";
169
185
  _msg_info(
170
186
  _msg);
171
- _user =
172
- false;
187
+ // _user =
188
+ // "n";
189
+ }
190
+ else {
191
+ _msg =
192
+ "wat";
193
+ _msg_error(
194
+ _msg);
173
195
  }
174
196
  }
175
- if ( _user == false ) {
197
+ else if ( _user == "n" ) {
176
198
  const
177
199
  _lib =
178
200
  _lib_get();
@@ -180,7 +202,7 @@ function
180
202
  _path_join(
181
203
  [ _lib,
182
204
  "evm-chains",
183
- "chains.json" ]);
205
+ _db_name ]);
184
206
  }
185
207
  else {
186
208
  _msg =
@@ -196,17 +218,31 @@ function
196
218
  function
197
219
  _evm_chain_info_get(
198
220
  _chain_id,
199
- _chain_info,
200
221
  _db_path,
222
+ _user_level,
223
+ _format,
201
224
  _db_types) {
202
225
  let
226
+ _chain_info,
203
227
  _data,
204
228
  _msg;
229
+ if ( typeof(
230
+ _user_level) == "undefined" ) {
231
+ _user_level =
232
+ false;
233
+ }
234
+ if ( typeof(
235
+ _format) == "undefined" ) {
236
+ _format =
237
+ "split";
238
+ }
205
239
  if ( typeof(
206
240
  _db_path) == "undefined" ) {
207
241
  _db_path =
208
242
  _evm_chains_db_path_get(
209
- false);
243
+ _user_level,
244
+ _chain_id,
245
+ _format);
210
246
  }
211
247
  const
212
248
  _db_exists =
@@ -262,8 +298,10 @@ function
262
298
  _network_chain_id,
263
299
  _selection_method,
264
300
  _db_path,
301
+ _user_level,
265
302
  _db_types) {
266
- if ( _network_chain_id == undefined ) {
303
+ if ( typeof(
304
+ _network_chain_id) == "undefined" ) {
267
305
  const
268
306
  _msg =
269
307
  "Network's ChainID not specified.";
@@ -271,18 +309,27 @@ function
271
309
  _msg,
272
310
  1);
273
311
  }
274
- if ( _selection_method == undefined ) {
312
+ if ( typeof(
313
+ _selection_method) == "undefined" ) {
275
314
  _selection_method =
276
315
  "kirsh";
277
316
  }
278
- if ( _db_path == undefined ) {
317
+ if ( typeof(
318
+ _db_path) == "undefined" ) {
279
319
  _db_path =
280
320
  _evm_chains_db_path_get(
281
321
  false);
282
322
  }
283
- if ( _db_types == undefined ) {
284
- _db_types.push(
285
- "system-db");
323
+ if ( typeof(
324
+ _db_types) == "undefined" ) {
325
+ _db_types = [
326
+ "node",
327
+ "system"
328
+ ];
329
+ }
330
+ if ( _user_level == undefined ) {
331
+ _user_level =
332
+ true;
286
333
  }
287
334
  const
288
335
  _chain_id =
@@ -293,6 +340,7 @@ function
293
340
  _evm_chain_info_get(
294
341
  _chain_id,
295
342
  _db_path,
343
+ _user_level,
296
344
  _db_types);
297
345
  if ( _selection_method == "kirsh" ) {
298
346
  return _chain_info["rpc"][0];
@@ -372,9 +420,12 @@ function
372
420
  _networks_all,
373
421
  _target_chain) {
374
422
  let
423
+ _db,
424
+ _entry,
375
425
  _filter,
376
426
  _filter_key,
377
427
  _filter_output_type,
428
+ _filter_value,
378
429
  _results,
379
430
  _msg;
380
431
  _filter_output_type =
@@ -403,25 +454,35 @@ function
403
454
  _filter_output_type =
404
455
  "chainId";
405
456
  }
457
+ else if ( _output_type == "rpc" ) {
458
+ _filter_output_type =
459
+ _output_type;
460
+ }
406
461
  if ( _networks_all == "y" ) {
407
- _msg =
408
- "Showing results for all networks."
409
- _msg_info(
410
- _msg);
411
462
  _filter =
412
463
  _all_get(
413
464
  _filter_output_type);
414
- console.log(
415
- _filter);
416
- _results =
417
- [];
418
- console.log(
419
- _results);
465
+ _msg =
466
+ "Showing results for all networks " +
467
+ `with filter '${_filter}'.`;
468
+ _msg_info(
469
+ _msg);
470
+ _db =
471
+ _json_read(
472
+ _db_path);
473
+ _msg =
474
+ "Showing results for all networks " +
475
+ `with filter '${_filter}'.`;
476
+ _msg_info(
477
+ _msg);
478
+ return _db;
420
479
  }
421
480
  else if ( _networks_all == "n" ) {
481
+ _results =
482
+ [];
422
483
  _msg =
423
484
  `Showing results for chain '${_target_chain}' in ` +
424
- `database '${_db_path}'.`;
485
+ `database '${_db_path}' with filter '${_filter_output_type}'.`;
425
486
  _msg_info(
426
487
  _msg);
427
488
  // this doesnt work the same in
@@ -431,19 +492,33 @@ function
431
492
  // _filter_key,
432
493
  // _filter_value,
433
494
  // _filter_output_type);
434
- _json_read(
435
- _db_path);
436
- const
437
- _db =
438
- _json_read(
439
- _db_path);
440
- return _db;
441
- // _results =
442
- // [];
443
- // console.log(
444
- // _results);
495
+ // _json_read(
496
+ // _db_path);
497
+ _db =
498
+ _json_read(
499
+ _db_path);
500
+ _msg =
501
+ `Database '${_db_path}' ` +
502
+ `contains '${_db.length}' items.`;
503
+ _msg_info(
504
+ _msg);
505
+ for ( _entry of _db ) {
506
+ if ( _entry[
507
+ _filter_key] == _target_chain ) {
508
+ _results.push(
509
+ _entry);
510
+ if ( _selection_method == "kirsh" ) {
511
+ break;
512
+ }
513
+ }
514
+ }
515
+ _msg =
516
+ `Total results returned for '${_db_path}' ` +
517
+ `are '${_results.length}'.`;
518
+ _msg_info(
519
+ _msg);
520
+ return _results;
445
521
  }
446
- // return _db;
447
522
  }
448
523
 
449
524
  function
@@ -461,7 +536,7 @@ function
461
536
  }
462
537
 
463
538
  function
464
- _db_path_auto_detect(
539
+ _db_paths_auto_detect(
465
540
  _chain_id) {
466
541
  let
467
542
  _type_primary,
@@ -507,8 +582,15 @@ function
507
582
  _db_split) ) {
508
583
  db_paths.push(
509
584
  _db_split);
585
+ _msg =
586
+ `Found database ` +
587
+ `'${_db_split}', ` +
588
+ `adding.`;
589
+ _msg_info(
590
+ _msg);
510
591
  }
511
- else {
592
+ else if ( ! _file_exists(
593
+ _db_split) ) {
512
594
  _msg =
513
595
  `Default per-network database ` +
514
596
  `'${_db_split}' ` +
@@ -516,6 +598,13 @@ function
516
598
  _msg_info(
517
599
  _msg);
518
600
  }
601
+ else {
602
+ _msg =
603
+ `wat`;
604
+ _msg_error(
605
+ _msg,
606
+ 1);
607
+ }
519
608
  if ( _file_exists(
520
609
  _db) ) {
521
610
  db_paths.push(
@@ -573,7 +662,8 @@ function
573
662
  _db_path,
574
663
  _entry,
575
664
  _msg,
576
- _networks_total;
665
+ _networks_total,
666
+ _results;
577
667
  _networks_total =
578
668
  0;
579
669
  if ( _retrieval_mode == "offline" ) {
@@ -599,6 +689,9 @@ function
599
689
  _api_key,
600
690
  _networks_all,
601
691
  _target_chain);
692
+ if ( _selection_method == "kirsh" ) {
693
+ break;
694
+ }
602
695
  }
603
696
  else if ( _input_type == "amount" ) {
604
697
  _db =
@@ -619,13 +712,26 @@ function
619
712
  _msg,
620
713
  0);
621
714
  }
715
+ const
716
+ _results =
717
+ [];
622
718
  for ( _entry of _db ) {
623
- console.log(
624
- _entry);
625
- if ( _selection_method != "all" ) {
626
- break;
719
+ if ( _entry['chainId'] == _target_chain ) {
720
+ _results.push(
721
+ _entry[
722
+ _output_type]);
723
+ if ( _selection_method != "all" ) {
724
+ break;
725
+ }
627
726
  }
628
727
  }
728
+ _db =
729
+ _results;
730
+ _msg =
731
+ `Found '${_networks_total}' ` +
732
+ `networks in database '${_db_path}'.`;
733
+ _msg_info(
734
+ _msg);
629
735
  }
630
736
  else if ( _input_type == "amount" ) {
631
737
  _msg =
@@ -642,15 +748,16 @@ function
642
748
  _msg,
643
749
  1);
644
750
  }
751
+ return _db;
645
752
  }
646
753
 
647
754
  function
648
755
  _evm_chains_info_set(
649
756
  _input_type) {
757
+ const
758
+ _msg =
759
+ `Setting value for type '${_input_type}'.`;
650
760
  if ( _input_type == "id" ) {
651
- const
652
- _msg =
653
- `Setting value for type '${_input_type}'`.
654
761
  _msg_info(
655
762
  _msg);
656
763
  }
@@ -667,16 +774,56 @@ function
667
774
  _networks_all,
668
775
  _target_chain,
669
776
  _db_paths) {
777
+ let
778
+ _explorer,
779
+ _result,
780
+ _rpc;
670
781
  if ( _target_command == "get" ) {
671
- _evm_chains_info_get(
672
- _target_chain,
673
- _retrieval_mode,
674
- _input_type,
675
- _output_type,
676
- _selection_method,
677
- _networks_all,
678
- _api_key,
679
- _db_paths);
782
+ const
783
+ _infos =
784
+ [];
785
+ const
786
+ _results =
787
+ _evm_chains_info_get(
788
+ _target_chain,
789
+ _retrieval_mode,
790
+ _input_type,
791
+ _output_type,
792
+ _selection_method,
793
+ _networks_all,
794
+ _api_key,
795
+ _db_paths);
796
+ if ( _output_type == "rpc" ) {
797
+ for ( _result of _results ) {
798
+ for ( _rpc of _result) {
799
+ _infos.push(
800
+ _rpc);
801
+ if ( _selection_method == "kirsh" ) {
802
+ break;
803
+ }
804
+ }
805
+ }
806
+ return _infos;
807
+ }
808
+ else if ( _output_type == "name" ) {
809
+ return _results;
810
+ }
811
+ else if ( _output_type == "id" ) {
812
+ return _results;
813
+ }
814
+ else if ( _output_type == "explorers" ) {
815
+ for ( _result of _results ) {
816
+ for ( _explorer of _result ) {
817
+ _infos.push(
818
+ _explorer[
819
+ "url"]);
820
+ if ( _selection_method == "kirsh" ) {
821
+ break;
822
+ }
823
+ }
824
+ }
825
+ return _infos;
826
+ }
680
827
  }
681
828
  else if ( _target_command == "set" ) {
682
829
  _evm_chains_info_set(
@@ -696,8 +843,8 @@ function
696
843
  module.exports = {
697
844
  _data_get:
698
845
  _data_get,
699
- _db_path_auto_detect:
700
- _db_path_auto_detect,
846
+ _db_paths_auto_detect:
847
+ _db_paths_auto_detect,
701
848
  _evm_chains_db_path_get:
702
849
  _evm_chains_db_path_get,
703
850
  _evm_chains_info: