evm-chains-info 0.0.6 → 0.0.9

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 */
@@ -114,24 +116,27 @@ function
114
116
  _db_path,
115
117
  _msg;
116
118
  if ( typeof(
117
- _user) == "undefined" ) {
119
+ _user) == "undefined" ||
120
+ _user == "" ) {
118
121
  _user =
119
- false;
122
+ "n";
120
123
  }
121
124
  if ( typeof(
122
- _chain_id) == "undefined" ) {
125
+ _chain_id) == "undefined" ||
126
+ _chain_id == "" ) {
123
127
  _chain_id =
124
128
  "";
125
129
  }
126
130
  if ( typeof(
127
- _format) == "undefined" ) {
131
+ _format) == "undefined" ||
132
+ _format == "" ) {
128
133
  if ( _chain_id != "" ) {
129
134
  _format =
130
135
  "split";
131
136
  }
132
137
  else if ( _chain_id == "" ) {
133
- _format =
134
- "unified";
138
+ _format =
139
+ "unified";
135
140
  }
136
141
  }
137
142
  _msg =
@@ -149,12 +154,17 @@ function
149
154
  _db_name =
150
155
  `${_chain_id}.json`;
151
156
  }
152
- if ( _user == true ) {
157
+ if ( _user == "y" ) {
158
+ const
159
+ _home_dir =
160
+ _homedir_get();
153
161
  _msg =
154
- `Home directory: '${_homedir_get()}'`;
162
+ `Home directory: '${_home_dir}'`;
163
+ _msg_info(
164
+ _msg);
155
165
  _db_path =
156
166
  _path_join(
157
- [ _homedir_get(),
167
+ [ _home_dir,
158
168
  ".config",
159
169
  "evm-chains",
160
170
  _db_name ]);
@@ -168,17 +178,23 @@ function
168
178
  _msg_info(
169
179
  _msg);
170
180
  }
171
- if ( _db_exists == false ) {
181
+ else if ( _db_exists == false ) {
172
182
  _msg =
173
183
  `Database '${_db_path}' ` +
174
184
  "not found";
175
185
  _msg_info(
176
186
  _msg);
177
- _user =
178
- false;
187
+ // _user =
188
+ // "n";
189
+ }
190
+ else {
191
+ _msg =
192
+ "wat";
193
+ _msg_error(
194
+ _msg);
179
195
  }
180
196
  }
181
- else if ( _user == false ) {
197
+ else if ( _user == "n" ) {
182
198
  const
183
199
  _lib =
184
200
  _lib_get();
@@ -186,7 +202,7 @@ function
186
202
  _path_join(
187
203
  [ _lib,
188
204
  "evm-chains",
189
- "chains.json" ]);
205
+ _db_name ]);
190
206
  }
191
207
  else {
192
208
  _msg =
@@ -202,17 +218,31 @@ function
202
218
  function
203
219
  _evm_chain_info_get(
204
220
  _chain_id,
205
- _chain_info,
206
221
  _db_path,
222
+ _user_level,
223
+ _format,
207
224
  _db_types) {
208
225
  let
226
+ _chain_info,
209
227
  _data,
210
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
+ }
211
239
  if ( typeof(
212
240
  _db_path) == "undefined" ) {
213
241
  _db_path =
214
242
  _evm_chains_db_path_get(
215
- false);
243
+ _user_level,
244
+ _chain_id,
245
+ _format);
216
246
  }
217
247
  const
218
248
  _db_exists =
@@ -268,8 +298,10 @@ function
268
298
  _network_chain_id,
269
299
  _selection_method,
270
300
  _db_path,
301
+ _user_level,
271
302
  _db_types) {
272
- if ( _network_chain_id == undefined ) {
303
+ if ( typeof(
304
+ _network_chain_id) == "undefined" ) {
273
305
  const
274
306
  _msg =
275
307
  "Network's ChainID not specified.";
@@ -277,18 +309,27 @@ function
277
309
  _msg,
278
310
  1);
279
311
  }
280
- if ( _selection_method == undefined ) {
312
+ if ( typeof(
313
+ _selection_method) == "undefined" ) {
281
314
  _selection_method =
282
315
  "kirsh";
283
316
  }
284
- if ( _db_path == undefined ) {
317
+ if ( typeof(
318
+ _db_path) == "undefined" ) {
285
319
  _db_path =
286
320
  _evm_chains_db_path_get(
287
321
  false);
288
322
  }
289
- if ( _db_types == undefined ) {
290
- _db_types.push(
291
- "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;
292
333
  }
293
334
  const
294
335
  _chain_id =
@@ -299,6 +340,7 @@ function
299
340
  _evm_chain_info_get(
300
341
  _chain_id,
301
342
  _db_path,
343
+ _user_level,
302
344
  _db_types);
303
345
  if ( _selection_method == "kirsh" ) {
304
346
  return _chain_info["rpc"][0];
@@ -378,9 +420,12 @@ function
378
420
  _networks_all,
379
421
  _target_chain) {
380
422
  let
423
+ _db,
424
+ _entry,
381
425
  _filter,
382
426
  _filter_key,
383
427
  _filter_output_type,
428
+ _filter_value,
384
429
  _results,
385
430
  _msg;
386
431
  _filter_output_type =
@@ -426,8 +471,10 @@ function
426
471
  _json_read(
427
472
  _db_path);
428
473
  _msg =
429
- "Found 'Showing results for all networks " +
474
+ "Showing results for all networks " +
430
475
  `with filter '${_filter}'.`;
476
+ _msg_info(
477
+ _msg);
431
478
  return _db;
432
479
  }
433
480
  else if ( _networks_all == "n" ) {
@@ -447,10 +494,9 @@ function
447
494
  // _filter_output_type);
448
495
  // _json_read(
449
496
  // _db_path);
450
- const
451
- _db =
452
- _json_read(
453
- _db_path);
497
+ _db =
498
+ _json_read(
499
+ _db_path);
454
500
  _msg =
455
501
  `Database '${_db_path}' ` +
456
502
  `contains '${_db.length}' items.`;
@@ -461,8 +507,16 @@ function
461
507
  _filter_key] == _target_chain ) {
462
508
  _results.push(
463
509
  _entry);
510
+ if ( _selection_method == "kirsh" ) {
511
+ break;
512
+ }
464
513
  }
465
514
  }
515
+ _msg =
516
+ `Total results returned for '${_db_path}' ` +
517
+ `are '${_results.length}'.`;
518
+ _msg_info(
519
+ _msg);
466
520
  return _results;
467
521
  }
468
522
  }
@@ -482,7 +536,7 @@ function
482
536
  }
483
537
 
484
538
  function
485
- _db_path_auto_detect(
539
+ _db_paths_auto_detect(
486
540
  _chain_id) {
487
541
  let
488
542
  _type_primary,
@@ -528,8 +582,15 @@ function
528
582
  _db_split) ) {
529
583
  db_paths.push(
530
584
  _db_split);
585
+ _msg =
586
+ `Found database ` +
587
+ `'${_db_split}', ` +
588
+ `adding.`;
589
+ _msg_info(
590
+ _msg);
531
591
  }
532
- else {
592
+ else if ( ! _file_exists(
593
+ _db_split) ) {
533
594
  _msg =
534
595
  `Default per-network database ` +
535
596
  `'${_db_split}' ` +
@@ -537,6 +598,13 @@ function
537
598
  _msg_info(
538
599
  _msg);
539
600
  }
601
+ else {
602
+ _msg =
603
+ `wat`;
604
+ _msg_error(
605
+ _msg,
606
+ 1);
607
+ }
540
608
  if ( _file_exists(
541
609
  _db) ) {
542
610
  db_paths.push(
@@ -621,6 +689,9 @@ function
621
689
  _api_key,
622
690
  _networks_all,
623
691
  _target_chain);
692
+ if ( _selection_method == "kirsh" ) {
693
+ break;
694
+ }
624
695
  }
625
696
  else if ( _input_type == "amount" ) {
626
697
  _db =
@@ -652,12 +723,13 @@ function
652
723
  if ( _selection_method != "all" ) {
653
724
  break;
654
725
  }
655
- }
726
+ }
656
727
  }
657
728
  _db =
658
729
  _results;
659
730
  _msg =
660
- `Found '${_networks_total}' networks.`;
731
+ `Found '${_networks_total}' ` +
732
+ `networks in database '${_db_path}'.`;
661
733
  _msg_info(
662
734
  _msg);
663
735
  }
@@ -682,10 +754,10 @@ function
682
754
  function
683
755
  _evm_chains_info_set(
684
756
  _input_type) {
757
+ const
758
+ _msg =
759
+ `Setting value for type '${_input_type}'.`;
685
760
  if ( _input_type == "id" ) {
686
- const
687
- _msg =
688
- `Setting value for type '${_input_type}'`.
689
761
  _msg_info(
690
762
  _msg);
691
763
  }
@@ -703,9 +775,13 @@ function
703
775
  _target_chain,
704
776
  _db_paths) {
705
777
  let
778
+ _explorer,
706
779
  _result,
707
780
  _rpc;
708
781
  if ( _target_command == "get" ) {
782
+ const
783
+ _infos =
784
+ [];
709
785
  const
710
786
  _results =
711
787
  _evm_chains_info_get(
@@ -720,10 +796,33 @@ function
720
796
  if ( _output_type == "rpc" ) {
721
797
  for ( _result of _results ) {
722
798
  for ( _rpc of _result) {
723
- console.log(
799
+ _infos.push(
724
800
  _rpc);
725
- }
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
+ }
726
824
  }
825
+ return _infos;
727
826
  }
728
827
  }
729
828
  else if ( _target_command == "set" ) {
@@ -744,8 +843,8 @@ function
744
843
  module.exports = {
745
844
  _data_get:
746
845
  _data_get,
747
- _db_path_auto_detect:
748
- _db_path_auto_detect,
846
+ _db_paths_auto_detect:
847
+ _db_paths_auto_detect,
749
848
  _evm_chains_db_path_get:
750
849
  _evm_chains_db_path_get,
751
850
  _evm_chains_info: