evm-contracts-tools 0.0.36 → 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,407 @@
1
+ #!/usr/bin/env node
2
+
3
+ // SPDX-License-Identifier: AGPL-3.0-or-later
4
+
5
+ /** ----------------------------------------------------------------
6
+ * evm-contract-deployment-address.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
+
83
+ function
84
+ _global_variables() {
85
+ /* global
86
+ app_name:
87
+ writable */
88
+ app_name =
89
+ "evm-contract-deployments-address.js";
90
+ /* global
91
+ app_opts:
92
+ writable */
93
+ app_opts =
94
+ [];
95
+ /* global
96
+ runtime_environment:
97
+ writable */
98
+ runtime_environment =
99
+ "";
100
+ /* global
101
+ resolve_date:
102
+ writable */
103
+ resolve_date =
104
+ "";
105
+ /* global
106
+ user_level:
107
+ writable */
108
+ user_level =
109
+ "";
110
+ /* global
111
+ target_networks:
112
+ writable */
113
+ target_networks =
114
+ [];
115
+ /* global
116
+ network_ids:
117
+ writable */
118
+ network_ids =
119
+ [];
120
+ /* global
121
+ networks_all:
122
+ writable */
123
+ networks_all =
124
+ "";
125
+ /* global
126
+ target_app:
127
+ writable */
128
+ target_app =
129
+ "";
130
+ /* global
131
+ target_contract:
132
+ writable */
133
+ target_contract =
134
+ "";
135
+ /* global
136
+ contract_version:
137
+ writable */
138
+ contract_version =
139
+ "";
140
+ /* global
141
+ user_defined:
142
+ writable */
143
+ user_defined =
144
+ "";
145
+ /* global
146
+ deployments_dir:
147
+ writable */
148
+ deployments_dir =
149
+ "";
150
+ quiet =
151
+ "";
152
+ /* global
153
+ verbose:
154
+ writable */
155
+ verbose =
156
+ "";
157
+ }
158
+
159
+ async function
160
+ _overrides_set(
161
+ _help_display) {
162
+ if ( ! _help_display &&
163
+ typeof(_help_display) != "undefined" &&
164
+ _help_display != "" ) {
165
+ const
166
+ _address_valid =
167
+ _address_check(
168
+ contract_address);
169
+ if ( ! _address_valid ) {
170
+ const
171
+ _msg =
172
+ "Contract address " +
173
+ `'${contract_address}' is ` +
174
+ `invalid.`;
175
+ _msg_error(
176
+ _msg,
177
+ 1);
178
+ }
179
+ }
180
+ if ( resolve_date == "" ||
181
+ typeof(
182
+ resolve_date) == "undefined" ) {
183
+ resolve_date =
184
+ _get_date_human();
185
+ }
186
+ if ( user_level == "" ) {
187
+ user_level =
188
+ "n";
189
+ }
190
+ }
191
+
192
+ function
193
+ _config_show() {
194
+ let
195
+ _line;
196
+ const
197
+ _text = [
198
+ `${app_name} configuration:`,
199
+ ` Resolve date: ${resolve_date}`,
200
+ ` Runtime environment: ${runtime_environment}`,
201
+ ` Target application: ${target_app}`,
202
+ ` User level: ${user_level}`,
203
+ ];
204
+ for ( _line of _text ) {
205
+ _msg_info(
206
+ _line);
207
+ }
208
+ }
209
+
210
+ function
211
+ _usage(
212
+ _exit_code) {
213
+ let
214
+ _line;
215
+ const
216
+ _text = [
217
+ "",
218
+ "Returns default deployments directory for an application",
219
+ "",
220
+ "Usage:",
221
+ "",
222
+ ` ${app_name}`,
223
+ " [options]",
224
+ " <target-app>",
225
+ "",
226
+ " options:",
227
+ "",
228
+ " -u --user-level Returns user-level location",
229
+ " for an application deployments",
230
+ ` Default: '${user_level}`,
231
+ "",
232
+ " -h --help This message.",
233
+ " -v --verbose Enable verbose output.",
234
+ ""
235
+ ];
236
+ for ( _line of _text ) {
237
+ console.log(
238
+ _line);
239
+ }
240
+ _process_exit(
241
+ _exit_code);
242
+ }
243
+
244
+ async function
245
+ _cmdline_parse() {
246
+ let
247
+ _help_display,
248
+ _msg;
249
+ const
250
+ _argv_args = {
251
+ "booleans": [
252
+ "u",
253
+ "user-level",
254
+ "h",
255
+ "help",
256
+ "v",
257
+ "verbose"
258
+ ]
259
+ };
260
+ const
261
+ _argv =
262
+ _argv_get(
263
+ _argv_args);
264
+ const
265
+ _options =
266
+ _argv[
267
+ "_"];
268
+ quiet =
269
+ "y";
270
+ runtime_environment =
271
+ "node";
272
+ if ( _argv[
273
+ "h"] ) {
274
+ _help_display =
275
+ true;
276
+ }
277
+ if ( _argv[
278
+ "help"] ) {
279
+ _help_display =
280
+ true;
281
+ }
282
+ if ( ( _options.indexOf(
283
+ "--help") > -1 ||
284
+ _options.indexOf(
285
+ "-h") > -1) ) {
286
+ _help_display =
287
+ true;
288
+ }
289
+ if ( _help_display ) {
290
+ quiet =
291
+ "n";
292
+ await _overrides_set(
293
+ _help_display);
294
+ _usage(
295
+ 0);
296
+ }
297
+ if ( typeof(
298
+ _argv) == "undefined" ||
299
+ _argv[
300
+ "_"].length < 1 ) {
301
+ _msg =
302
+ "Target application " +
303
+ "argument required.";
304
+ _msg_error(
305
+ _msg,
306
+ 0);
307
+ _usage(
308
+ 1);
309
+ }
310
+ target_app =
311
+ _argv[
312
+ "_"][
313
+ 0];
314
+ if ( "u" in _argv ) {
315
+ user_level =
316
+ _argv[
317
+ "u"];
318
+ }
319
+ if ( "user_level" in _argv ) {
320
+ user_level =
321
+ _argv[
322
+ "user_level"];
323
+ }
324
+ if ( _argv[
325
+ "v"] ||
326
+ _argv[
327
+ "verbose"] ) {
328
+ quiet =
329
+ "n";
330
+ }
331
+ }
332
+
333
+ function
334
+ _url_parse() {
335
+ let
336
+ _method,
337
+ _network;
338
+ runtime_environment =
339
+ "browser";
340
+ user_level =
341
+ _argv_url_get(
342
+ "user_level")[
343
+ 0];
344
+ quiet =
345
+ _argv_url_get(
346
+ "quiet");
347
+ if ( quiet.length === 0 ) {
348
+ quiet =
349
+ "n";
350
+ }
351
+ }
352
+
353
+ async function
354
+ _evm_contract_deployments_dir_cmdline(
355
+ _app_opts) {
356
+ let
357
+ _result;
358
+ const
359
+ _results =
360
+ await _evm_contract_deployments_dir.apply(
361
+ null,
362
+ app_opts);
363
+ const
364
+ _results_type =
365
+ typeof(
366
+ _results);
367
+ if ( _results_type == "object" ) {
368
+ for ( _result of _results ) {
369
+ console.log(
370
+ _result);
371
+ }
372
+ }
373
+ else if ( _results_type == "string" ) {
374
+ _printf(
375
+ _results);
376
+ }
377
+ }
378
+
379
+ async function
380
+ _main() {
381
+ const
382
+ _overrides_set_up =
383
+ await _overrides_set();
384
+ _config_show();
385
+ const
386
+ app_opts = [
387
+ target_app,
388
+ user_level
389
+ ];
390
+ const
391
+ _deployments =
392
+ await _evm_contract_deployments_dir.apply(
393
+ null,
394
+ app_opts);
395
+ }
396
+
397
+ _global_variables();
398
+ if ( _cmdline_check(
399
+ "evm-contract-deployments-dir.js") == true ||
400
+ _cmdline_check(
401
+ "evm-contract-deployments-dir") == true ) {
402
+ _cmdline_parse();
403
+ }
404
+ else{
405
+ _url_parse();
406
+ }
407
+ _main();