evm-chains-info 0.0.1 → 0.0.3

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
@@ -27,15 +27,33 @@
27
27
  * If not, see <https://www.gnu.org/licenses/>.
28
28
  */
29
29
 
30
+ /* eslint-disable
31
+ no-unused-vars */
32
+
30
33
  const
31
34
  _libcrash =
32
35
  require(
33
36
  'crash-js');
37
+ /* global
38
+ _argv_get */
39
+ const
40
+ _argv_get =
41
+ _libcrash._argv_get;
42
+ /* global
43
+ _argv_url_get */
44
+ const
45
+ _argv_url_get =
46
+ _libcrash._argv_url_get;
34
47
  /* global
35
48
  _cmdline_check */
36
49
  const
37
50
  _cmdline_check =
38
51
  _libcrash._cmdline_check;
52
+ /* global
53
+ _get_date_human */
54
+ const
55
+ _get_date_human =
56
+ _libcrash._get_date_human;
39
57
  /* global
40
58
  _msg_info */
41
59
  const
@@ -47,22 +65,22 @@ const
47
65
  _msg_error =
48
66
  _libcrash._msg_error;
49
67
  /* global
50
- _argv_get */
68
+ _process_exit */
51
69
  const
52
- _argv_get =
53
- _libcrash._argv_get;
70
+ _process_exit =
71
+ _libcrash._process_exit;
54
72
 
55
73
  const
56
74
  _libevm_chains_info =
57
75
  require(
58
76
  "./libevm-chains-info");
59
77
  /* global
60
- _rpc_backends_get */
78
+ _evm_chains_db_path_get */
61
79
  const
62
80
  _evm_chains_db_path_get =
63
81
  _libevm_chains_info._evm_chains_db_path_get;
64
82
  /* global
65
- _rpc_backends_get */
83
+ _evm_chains_info_get */
66
84
  const
67
85
  _evm_chain_info_get =
68
86
  _libevm_chains_info._evm_chain_info_get;
@@ -72,10 +90,20 @@ const
72
90
  _rpc_backend_get =
73
91
  _libevm_chains_info._rpc_backend_get;
74
92
  /* global
75
- _rpc_backends_get */
93
+ _evm_chains_info */
76
94
  const
77
- _rpc_backends_get =
78
- _rpc_backends_get;
95
+ _evm_chains_info =
96
+ _libevm_chains_info._evm_chains_info;
97
+ /* global
98
+ _db_path_auto_detect */
99
+ const
100
+ _db_path_auto_detect =
101
+ _libevm_chains_info._db_path_auto_detect;
102
+ /* global
103
+ _input_type_auto_detect */
104
+ const
105
+ _input_type_auto_detect =
106
+ _libevm_chains_info._input_type_auto_detect;
79
107
 
80
108
  function
81
109
  _global_variables() {
@@ -90,77 +118,138 @@ function
90
118
  app_opts =
91
119
  [];
92
120
  /* global
93
- encoding_format:
121
+ runtime_environment:
94
122
  writable */
95
- encoding_format =
123
+ runtime_environment =
96
124
  "";
97
125
  /* global
98
- buffer_size:
126
+ call_date:
99
127
  writable */
100
- buffer_size =
128
+ call_date =
101
129
  "";
102
130
  /* global
103
- string_length:
131
+ target_command:
104
132
  writable */
105
- string_length =
133
+ target_command =
106
134
  "";
107
135
  /* global
108
- in_file:
136
+ input_type:
109
137
  writable */
110
- in_file =
138
+ input_type =
111
139
  "";
112
140
  /* global
113
- out_txt_prefix:
141
+ output_type:
114
142
  writable */
115
- out_txt_prefix =
143
+ output_type =
116
144
  "";
117
145
  /* global
118
- amount_only:
146
+ retrieval_mode:
119
147
  writable */
120
- amount_only =
148
+ retrieval_mode =
149
+ "";
150
+ /* global
151
+ user_level:
152
+ writable */
153
+ user_level =
154
+ "";
155
+ /* global
156
+ db_paths:
157
+ writable */
158
+ db_paths =
159
+ [];
160
+ /* global
161
+ selection_method:
162
+ writable */
163
+ selection_method =
164
+ "";
165
+ /* global
166
+ api_key:
167
+ writable */
168
+ api_key =
169
+ "";
170
+ /* global
171
+ target_chain:
172
+ writable */
173
+ target_chain =
174
+ "";
175
+ /* global
176
+ networks_all:
177
+ writable */
178
+ networks_all =
121
179
  "";
122
180
  /* global
123
181
  quiet:
124
182
  writable */
125
183
  quiet =
126
184
  "";
185
+ /* global
186
+ verbose:
187
+ writable */
188
+ verbose =
189
+ "";
127
190
  }
128
191
 
129
192
  function
130
193
  _overrides_set() {
131
- if ( encoding_format == "" ) {
132
- encoding_format =
133
- "base64";
194
+ if ( call_date == "" ) {
195
+ call_date =
196
+ _get_date_human();
197
+ }
198
+ if ( target_command == "" ) {
199
+ target_command =
200
+ "get";
134
201
  }
135
- if ( string_length == "" ) {
136
- string_length =
137
- "10000";
202
+ _input_type_auto_detect();
203
+ if ( output_type == "" ) {
204
+ output_type =
205
+ "name";
138
206
  }
139
- if ( buffer_size == "" ) {
140
- buffer_size =
141
- "2000000"; // 2MB
207
+ if ( retrieval_mode == "" ) {
208
+ retrieval_mode =
209
+ "offline";
142
210
  }
143
- if ( amount_only == "" ) {
144
- amount_only =
145
- "false";
211
+ if ( selection_method == "" ) {
212
+ // TODO:
213
+ // remove all references
214
+ // to that monster
215
+ selection_method =
216
+ "kirsh";
146
217
  }
218
+ if ( api_key == "" ) {
219
+ api_key =
220
+ "n";
221
+ }
222
+ if ( user_level == "" ) {
223
+ user_level =
224
+ "y";
225
+ }
226
+ if ( networks_all == "" ) {
227
+ networks_all =
228
+ "n";
229
+ }
230
+ _db_path_auto_detect();
147
231
  }
148
232
 
149
233
  function
150
234
  _config_show() {
151
235
  let
152
- _line,
153
- _text;
154
- _text = [
155
- `${app_name} configuration:`,
156
- ` Runtime environment: ${runtime_environment}`,
157
- ` Encoding format: ${encoding_format}`,
158
- ` Buffer size: ${buffer_size}`,
159
- ` Chunk string length: ${string_length}`,
160
- ` Chunks amount only: ${amount_only}`,
161
- ` In file: ${in_file}`,
162
- ` Out text prefix: ${out_txt_prefix}`,
163
- ];
236
+ _line;
237
+ const
238
+ _text = [
239
+ `${app_name} configuration:`,
240
+ ` Call date: ${call_date}`,
241
+ ` Runtime environment: ${runtime_environment}`,
242
+ ` Target command: ${target_command}`,
243
+ ` Input type: ${input_type}`,
244
+ ` Output type: ${output_type}`,
245
+ ` Retrieval mode: ${retrieval_mode}`,
246
+ ` User-level database: ${user_level}`,
247
+ ` API key: ${api_key}`,
248
+ ` RPC selection method: ${selection_method}`,
249
+ ` All networks: ${networks_all}`,
250
+ ` Target chain: ${target_chain}`,
251
+ ` Database paths: ${db_paths}`,
252
+ ];
164
253
  for ( _line of _text ) {
165
254
  _msg_info(
166
255
  _line);
@@ -171,60 +260,74 @@ function
171
260
  _usage(
172
261
  _exit_code) {
173
262
  let
174
- _line,
175
- _text;
176
- _text = [
177
- "Converts binary to ascii text.",
178
- "",
179
- "Usage:",
180
- "",
181
- " bin2txt",
182
- " <in-file>",
183
- " <out-txt-prefix>",
184
- "",
185
- " arguments:",
186
- " <in-file> An input file.",
187
- " <out-file-prefix> Prefix for the output file(s).",
188
- "",
189
- " options:",
190
- "",
191
- " -f --encoding-format Encoding format ('base64').",
192
- ` <encoding-format> Default: '${encoding_format}`,
193
- "",
194
- " -B --buffer-size Size in bytes the input file will",
195
- " <buffer-size> be split before being read",
196
- " in memory and passed to",
197
- " the encoder.",
198
- ` Default: '${buffer_size}'`,
199
- "",
200
- " -L --string-length String chunk length.",
201
- ` <string-length> Default: '${string_length}'`,
202
- "",
203
- " -s --amount-only Only print chunks amount.",
204
- ` Default: '${amount_only}'`,
205
- "",
206
- " -h --help This message.",
207
- " -v --verbose Enable verbose output."
208
- ];
263
+ _line;
264
+ const
265
+ _text = [
266
+ "Returns info about EVM blockchains.",
267
+ "",
268
+ "Usage:",
269
+ "",
270
+ " evm-chains-info.js",
271
+ " [options]",
272
+ " <target-chain>",
273
+ "",
274
+ " options:",
275
+ "",
276
+ " -C --command Target command. Can be 'get' or 'set'.",
277
+ ` <target-command> Default: '${target_command}`,
278
+ "",
279
+ " -i --input-type Input type. It can be 'id' or 'name'.",
280
+ ` <input-type> Default: '${input_type}'`,
281
+ "",
282
+ " -o --output-type Output type. It can be 'id', 'name',",
283
+ " <output-type> 'rpc', 'explorers'.",
284
+ ` Default: '${output_type}'`,
285
+ "",
286
+ " -m --retrieval-mode It can be 'offline'.",
287
+ ` <retrieval-mode> Default: '${retrieval_mode}'`,
288
+ "",
289
+ " -u --user-level It can be 'y' or 'n'.",
290
+ ` <user-level> Default: '${user_level}'`,
291
+ "",
292
+ " -d --db-path Path of the chains' info json file",
293
+ " <db-path> to be used for 'offline' retrieval.",
294
+ ` Default: '${db_paths}'`,
295
+ "",
296
+ " -s --selection-method When output type is 'rpc',",
297
+ " <selection-method> selection criterion to use when",
298
+ " more than one is available.",
299
+ " It can be 'kirsh', 'random' or 'all'.",
300
+ ` Default: '${selection_method}'`,
301
+ "",
302
+ " -k If selected, when output type is 'rpc',",
303
+ " includes the ones requiring an API key.",
304
+ ` Default: '${api_key}'`,
305
+ " -a --all Whether to show results for all networks.",
306
+ ` Default: '${networks_all}'`,
307
+ "",
308
+ " -h --help This message.",
309
+ " -v --verbose Enable verbose output."
310
+ ];
209
311
  for ( _line of _text ) {
210
312
  console.log(
211
313
  _line);
212
314
  }
213
- process.exit(
315
+ _process_exit(
214
316
  _exit_code);
215
317
  }
216
318
 
217
319
  function
218
320
  _cmdline_parse() {
219
321
  let
220
- _argv,
221
322
  _help_display,
222
323
  _msg;
223
- _argv =
224
- _argv_get();
225
- _options =
226
- _argv[
227
- "_"];
324
+ const
325
+ _argv =
326
+ _argv_get();
327
+ const
328
+ _options =
329
+ _argv[
330
+ "_"];
228
331
  quiet =
229
332
  "y";
230
333
  runtime_environment =
@@ -247,42 +350,102 @@ function
247
350
  _argv[
248
351
  "_"].length < 1 ) {
249
352
  _msg =
250
- "Input file argument required.";
353
+ "Target chain argument required.";
251
354
  _msg_error(
252
355
  _msg,
253
356
  0);
254
357
  _usage(
255
358
  1);
256
359
  }
257
- in_file =
360
+ target_chain =
258
361
  _argv[
259
362
  "_"][
260
363
  0];
261
- if ( _argv[
262
- "_"].length < 2 ) {
263
- out_txt_prefix =
264
- in_file +
265
- ".base64";
266
- }
267
- if ( "L" in _argv ) {
268
- string_length =
364
+ if ( "C" in _argv ) {
365
+ target_command =
366
+ _argv[
367
+ "C"];
368
+ }
369
+ if ( "command" in _argv ) {
370
+ target_command =
371
+ _argv[
372
+ "command"];
373
+ }
374
+ if ( "i" in _argv ) {
375
+ input_type =
376
+ _argv[
377
+ "i"];
378
+ }
379
+ if ( "input-type" in _argv ) {
380
+ input_type =
381
+ _argv[
382
+ "input-type"];
383
+ }
384
+ if ( "o" in _argv ) {
385
+ output_type =
386
+ _argv[
387
+ "o"];
388
+ }
389
+ if ( "output-type" in _argv ) {
390
+ output_type =
269
391
  _argv[
270
- "L"];
392
+ "output-type"];
271
393
  }
272
- if ( "string-length" in _argv ) {
273
- string_length =
394
+ if ( "m" in _argv ) {
395
+ retrieval_mode =
274
396
  _argv[
275
- "string-length"];
397
+ "m"];
398
+ }
399
+ if ( "retrieval-mode" in _argv ) {
400
+ retrieval_mode =
401
+ _argv[
402
+ "retrieval-mode"];
403
+ }
404
+ if ( "u" in _argv ) {
405
+ user_level =
406
+ _argv[
407
+ "u"];
408
+ }
409
+ if ( "user-level" in _argv ) {
410
+ user_level =
411
+ _argv[
412
+ "user-level"];
413
+ }
414
+ if ( "d" in _argv ) {
415
+ db_paths.push(
416
+ _argv[
417
+ "d"]);
418
+ }
419
+ if ( "db-path" in _argv ) {
420
+ db_paths.push(
421
+ _argv[
422
+ "user-level"]);
276
423
  }
277
424
  if ( "s" in _argv ) {
278
- amount_only =
425
+ selection_method =
279
426
  _argv[
280
427
  "s"];
281
428
  }
282
- if ( "amount-only" in _argv ) {
283
- amount_only =
429
+ if ( "selection-method" in _argv ) {
430
+ selection_method =
284
431
  _argv[
285
- "amount-only"];
432
+ "selection-method"];
433
+ }
434
+ if ( "k" in _argv ) {
435
+ api_key =
436
+ "y";
437
+ }
438
+ if ( "api-key" in _argv ) {
439
+ api_key =
440
+ "y";
441
+ }
442
+ if ( "a" in _argv ) {
443
+ networks_all =
444
+ "y";
445
+ }
446
+ if ( "networks-all" in _argv ) {
447
+ networks_all =
448
+ "y";
286
449
  }
287
450
  if ( "v" in _argv ) {
288
451
  verbose =
@@ -302,19 +465,51 @@ function
302
465
 
303
466
  function
304
467
  _url_parse() {
305
- let
306
- _argv;
307
468
  runtime_environment =
308
469
  "browser";
309
- _argv =
310
- _argv_url_get();
311
- in_file =
470
+ target_chain =
471
+ _argv_url_get(
472
+ "chain")[
473
+ 0];
474
+ target_command =
475
+ _argv_url_get(
476
+ "command")[
477
+ 0];
478
+ input_type =
479
+ _argv_url_get(
480
+ "input_type")[
481
+ 0];
482
+ output_type =
483
+ _argv_url_get(
484
+ "output_type")[
485
+ 0];
486
+ input_type =
487
+ _argv_url_get(
488
+ "input_type")[
489
+ 0];
490
+ retrieval_mode =
312
491
  _argv_url_get(
313
- "in_file")[
492
+ "retrieval_mode")[
314
493
  0];
315
- target_planet =
494
+ user_level =
495
+ _argv_url_get(
496
+ "user_level")[
497
+ 0];
498
+ db_paths.push(
499
+ _argv_url_get(
500
+ "db_path")[
501
+ 0]);
502
+ selection_method =
316
503
  _argv_url_get(
317
- "out_txt_prefix")[
504
+ "selection_method")[
505
+ 0];
506
+ api_key =
507
+ _argv_url_get(
508
+ "api_key")[
509
+ 0];
510
+ networks_all =
511
+ _argv_url_get(
512
+ "networks_all")[
318
513
  0];
319
514
  quiet =
320
515
  _argv_url_get(
@@ -327,19 +522,25 @@ function
327
522
 
328
523
  _global_variables();
329
524
  if ( _cmdline_check(
330
- "bin2txt.js") == true ) {
525
+ "evm-chains-info.js") == true ) {
331
526
  _cmdline_parse();
332
527
  }
528
+ else{
529
+ _url_parse();
530
+ }
333
531
  _overrides_set();
334
532
  _config_show();
335
533
  app_opts = [
336
- in_file,
337
- out_txt_prefix,
338
- encoding_format,
339
- string_length,
340
- buffer_size,
341
- amount_only
534
+ target_command,
535
+ input_type,
536
+ output_type,
537
+ retrieval_mode,
538
+ selection_method,
539
+ api_key,
540
+ networks_all,
541
+ target_chain,
542
+ db_paths
342
543
  ];
343
- _bin2txt.apply(
544
+ _evm_chains_info.apply(
344
545
  null,
345
546
  app_opts);