evm-contracts-tools 0.0.37 → 0.0.38

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.
@@ -0,0 +1,433 @@
1
+ #!/usr/bin/env node
2
+
3
+ // SPDX-License-Identifier: AGPL-3.0-or-later
4
+
5
+ /** ----------------------------------------------------------------
6
+ * evm-contract-deployment-networks.js
7
+ * ----------------------------------------------------------------
8
+ * Copyright ©
9
+ * Pellegrino Prevete
10
+ * 2024, 2025, 2026
11
+ *
12
+ * All rights reserved
13
+ * ----------------------------------------------------------------
14
+ *
15
+ * This program is free software: you can redistribute it and/or
16
+ * modify it under the terms of the GNU General Public License as
17
+ * published by the Free Software Foundation, either version 3 of
18
+ * the License, or (at your option) any later version.
19
+ *
20
+ * This program is distributed in the hope that it will be useful,
21
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ * GNU General Public License for more details.
24
+ *
25
+ * You should have received a copy of the GNU General Public License
26
+ * along with this program.
27
+ * If not, see <https://www.gnu.org/licenses/>.
28
+ */
29
+
30
+ /* eslint-disable
31
+ no-unused-vars */
32
+
33
+ /* Crash Javascript global variables */
34
+ /* global
35
+ quiet:
36
+ writable */
37
+
38
+ const
39
+ _libcrash =
40
+ require(
41
+ "crash-js");
42
+ /* global
43
+ _argv_get */
44
+ const
45
+ _argv_get =
46
+ _libcrash._argv_get;
47
+ /* global
48
+ _argv_url_get */
49
+ const
50
+ _argv_url_get =
51
+ _libcrash._argv_url_get;
52
+ /* global
53
+ _cmdline_check */
54
+ const
55
+ _cmdline_check =
56
+ _libcrash._cmdline_check;
57
+ /* global
58
+ _get_date_human */
59
+ const
60
+ _get_date_human =
61
+ _libcrash._get_date_human;
62
+ /* global
63
+ _msg_info */
64
+ const
65
+ _msg_info =
66
+ _libcrash._msg_info;
67
+ /* global
68
+ _msg_error */
69
+ const
70
+ _msg_error =
71
+ _libcrash._msg_error;
72
+ /* global
73
+ _printf */
74
+ const
75
+ _printf =
76
+ _libcrash._printf;
77
+ /* global
78
+ _process_exit */
79
+ const
80
+ _process_exit =
81
+ _libcrash._process_exit;
82
+ /* global
83
+ _stat */
84
+ const
85
+ _stat =
86
+ _libcrash._stat;
87
+
88
+ function
89
+ _global_variables() {
90
+ /* global
91
+ app_name:
92
+ writable */
93
+ app_name =
94
+ "evm-contract-deployments-networks.js";
95
+ /* global
96
+ app_opts:
97
+ writable */
98
+ app_opts =
99
+ [];
100
+ /* global
101
+ runtime_environment:
102
+ writable */
103
+ runtime_environment =
104
+ "";
105
+ /* global
106
+ resolve_date:
107
+ writable */
108
+ resolve_date =
109
+ "";
110
+ /* global
111
+ deployments_dir:
112
+ writable */
113
+ deployments_dir =
114
+ "";
115
+ /* global
116
+ display_all:
117
+ writable */
118
+ display_all =
119
+ "";
120
+ /* global
121
+ display_safest:
122
+ writable */
123
+ display_safest =
124
+ "";
125
+ /* global
126
+ display_cheapest:
127
+ writable */
128
+ display_cheapest =
129
+ "";
130
+ quiet =
131
+ "";
132
+ /* global
133
+ verbose:
134
+ writable */
135
+ verbose =
136
+ "";
137
+ }
138
+
139
+ async function
140
+ _overrides_set(
141
+ _help_display) {
142
+ if ( resolve_date == "" ||
143
+ typeof(
144
+ resolve_date) == "undefined" ) {
145
+ resolve_date =
146
+ _get_date_human();
147
+ }
148
+ if ( user_level == "" ) {
149
+ user_level =
150
+ "n";
151
+ }
152
+ if ( display_all == "" ) {
153
+ display_all =
154
+ "y";
155
+ }
156
+ if ( display_cheapest == "" ) {
157
+ display_cheapest =
158
+ "n";
159
+ }
160
+ if ( display_safest == "" ) {
161
+ display_safest =
162
+ "n";
163
+ }
164
+ }
165
+
166
+ function
167
+ _config_show() {
168
+ let
169
+ _line;
170
+ const
171
+ _text = [
172
+ `${app_name} configuration:`,
173
+ ` Resolve date: ${resolve_date}`,
174
+ ` Runtime environment: ${runtime_environment}`,
175
+ ` Target application: ${target_app}`,
176
+ ` User level: ${user_level}`,
177
+ ];
178
+ for ( _line of _text ) {
179
+ _msg_info(
180
+ _line);
181
+ }
182
+ }
183
+
184
+ function
185
+ _usage(
186
+ _exit_code) {
187
+ let
188
+ _line;
189
+ const
190
+ _text = [
191
+ "",
192
+ "Returns a contract's deployment available networks",
193
+ "",
194
+ "Usage:",
195
+ "",
196
+ ` ${app_name}`,
197
+ " [options]",
198
+ " <deployment-dir>",
199
+ "",
200
+ " options:",
201
+ "",
202
+ " -A --display-all Display all available networks",
203
+ " for the deployment.",
204
+ ` Default: '${display_all}`,
205
+ "",
206
+ " -S --display-safest Display safest network",
207
+ " for the deployment.",
208
+ ` Default: '${display_safest}`,
209
+ "",
210
+ " -C --display-cheapest Display cheapest network",
211
+ " for the deployment.",
212
+ ` Default: '${display_cheapest}`,
213
+ "",
214
+ " -h --help This message.",
215
+ " -v --verbose Enable verbose output.",
216
+ ""
217
+ ];
218
+ for ( _line of _text ) {
219
+ console.log(
220
+ _line);
221
+ }
222
+ _process_exit(
223
+ _exit_code);
224
+ }
225
+
226
+ async function
227
+ _cmdline_parse() {
228
+ let
229
+ _help_display,
230
+ _msg;
231
+ const
232
+ _argv_args = {
233
+ "booleans": [
234
+ "A",
235
+ "display-all",
236
+ "S",
237
+ "display-safest",
238
+ "C",
239
+ "display-cheapest",
240
+ "h",
241
+ "help",
242
+ "v",
243
+ "verbose"
244
+ ]
245
+ };
246
+ const
247
+ _argv =
248
+ _argv_get(
249
+ _argv_args);
250
+ const
251
+ _options =
252
+ _argv[
253
+ "_"];
254
+ quiet =
255
+ "y";
256
+ runtime_environment =
257
+ "node";
258
+ if ( _argv[
259
+ "h"] ) {
260
+ _help_display =
261
+ true;
262
+ }
263
+ if ( _argv[
264
+ "help"] ) {
265
+ _help_display =
266
+ true;
267
+ }
268
+ if ( ( _options.indexOf(
269
+ "--help") > -1 ||
270
+ _options.indexOf(
271
+ "-h") > -1) ) {
272
+ _help_display =
273
+ true;
274
+ }
275
+ if ( _help_display ) {
276
+ quiet =
277
+ "n";
278
+ await _overrides_set(
279
+ _help_display);
280
+ _usage(
281
+ 0);
282
+ }
283
+ if ( typeof(
284
+ _argv) == "undefined" ||
285
+ _argv[
286
+ "_"].length < 1 ) {
287
+ _msg =
288
+ "A deployment directory " +
289
+ "must be specified.";
290
+ _msg_error(
291
+ _msg,
292
+ 0);
293
+ _usage(
294
+ 1);
295
+ }
296
+ target_app =
297
+ _argv[
298
+ "_"][
299
+ 0];
300
+ if ( _argv[
301
+ "A"] ) {
302
+ display_all =
303
+ _argv[
304
+ "A"];
305
+ }
306
+ if ( _argv[
307
+ "display-all"] ) {
308
+ display_all =
309
+ _argv[
310
+ "display-all"];
311
+ }
312
+ if ( _argv[
313
+ "S"] ) {
314
+ display_safest =
315
+ _argv[
316
+ "S"];
317
+ }
318
+ if ( _argv[
319
+ "display-safest"] ) {
320
+ display_safest =
321
+ _argv[
322
+ "display-safest"];
323
+ }
324
+ if ( _argv[
325
+ "C"] ) {
326
+ display_cheapest =
327
+ _argv[
328
+ "C"];
329
+ }
330
+ if ( _argv[
331
+ "display-cheapest"] ) {
332
+ display_cheapest =
333
+ _argv[
334
+ "display-cheapest"];
335
+ }
336
+ if ( _argv[
337
+ "v"] ||
338
+ _argv[
339
+ "verbose"] ) {
340
+ quiet =
341
+ "n";
342
+ }
343
+ }
344
+
345
+ function
346
+ _url_parse() {
347
+ let
348
+ _method,
349
+ _network;
350
+ runtime_environment =
351
+ "browser";
352
+ display_all =
353
+ _argv_url_get(
354
+ "display_all")[
355
+ 0];
356
+ display_safest =
357
+ _argv_url_get(
358
+ "display_safest")[
359
+ 0];
360
+ display_cheapest =
361
+ _argv_url_get(
362
+ "display_cheapest")[
363
+ 0];
364
+ deployment_dir =
365
+ _argv_url_get(
366
+ "deployment_dir")[
367
+ 0];
368
+ quiet =
369
+ _argv_url_get(
370
+ "quiet");
371
+ if ( quiet.length === 0 ) {
372
+ quiet =
373
+ "n";
374
+ }
375
+ }
376
+
377
+ async function
378
+ _evm_contract_deployment_networks_cmdline(
379
+ _app_opts) {
380
+ let
381
+ _result;
382
+ const
383
+ _results =
384
+ await _evm_contract_deployment_networks.apply(
385
+ null,
386
+ app_opts);
387
+ const
388
+ _results_type =
389
+ typeof(
390
+ _results);
391
+ if ( _results_type == "object" ) {
392
+ for ( _result of _results ) {
393
+ console.log(
394
+ _result);
395
+ }
396
+ }
397
+ else if ( _results_type == "string" ) {
398
+ _printf(
399
+ _results);
400
+ }
401
+ }
402
+
403
+ async function
404
+ _main() {
405
+ const
406
+ _overrides_set_up =
407
+ await _overrides_set();
408
+ _config_show();
409
+ const
410
+ app_opts = [
411
+ deployment_dir,
412
+ display_all,
413
+ display_safest,
414
+ display_cheapest
415
+ ];
416
+ const
417
+ _networks =
418
+ await _evm_contract_deployment_networks.apply(
419
+ null,
420
+ app_opts);
421
+ }
422
+
423
+ _global_variables();
424
+ if ( _cmdline_check(
425
+ "evm-contract-deployment-networks.js") == true ||
426
+ _cmdline_check(
427
+ "evm-contract-deployment-networks") == true ) {
428
+ _cmdline_parse();
429
+ }
430
+ else{
431
+ _url_parse();
432
+ }
433
+ _main();