evm-contracts-tools 0.0.38 → 0.0.39

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.
@@ -79,6 +79,15 @@ _printf =
79
79
  const
80
80
  _process_exit =
81
81
  _libcrash._process_exit;
82
+ const
83
+ _libevm_contract_deployment_versions_module =
84
+ require(
85
+ "./libevm-contract-deployment-versions");
86
+ /* global
87
+ _evm_contract_deployment_versions */
88
+ const
89
+ _evm_contract_deployment_versions =
90
+ _libevm_contract_deployment_versions_module._evm_contract_deployment_versions;
82
91
 
83
92
  function
84
93
  _global_variables() {
@@ -86,7 +95,7 @@ function
86
95
  app_name:
87
96
  writable */
88
97
  app_name =
89
- "evm-contract-deployments-address.js";
98
+ "evm-contract-deployments-versions.js";
90
99
  /* global
91
100
  app_opts:
92
101
  writable */
@@ -103,49 +112,19 @@ function
103
112
  resolve_date =
104
113
  "";
105
114
  /* 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:
115
+ config_file:
132
116
  writable */
133
- target_contract =
117
+ config_file =
134
118
  "";
135
119
  /* global
136
- contract_version:
120
+ display_highest:
137
121
  writable */
138
- contract_version =
122
+ display_highest =
139
123
  "";
140
124
  /* global
141
- user_defined:
125
+ display_lowest:
142
126
  writable */
143
- user_defined =
144
- "";
145
- /* global
146
- deployments_dir:
147
- writable */
148
- deployments_dir =
127
+ display_lowest =
149
128
  "";
150
129
  quiet =
151
130
  "";
@@ -159,32 +138,18 @@ function
159
138
  async function
160
139
  _overrides_set(
161
140
  _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
141
  if ( resolve_date == "" ||
181
142
  typeof(
182
143
  resolve_date) == "undefined" ) {
183
144
  resolve_date =
184
145
  _get_date_human();
185
146
  }
186
- if ( user_level == "" ) {
187
- user_level =
147
+ if ( display_highest == "" ) {
148
+ display_highest =
149
+ "n";
150
+ }
151
+ if ( display_lowest == "" ) {
152
+ display_lowest =
188
153
  "n";
189
154
  }
190
155
  }
@@ -197,9 +162,9 @@ function
197
162
  _text = [
198
163
  `${app_name} configuration:`,
199
164
  ` Resolve date: ${resolve_date}`,
200
- ` Runtime environment: ${runtime_environment}`,
201
- ` Target application: ${target_app}`,
202
- ` User level: ${user_level}`,
165
+ ` Configuration file: ${config_file}`,
166
+ ` Display highest: ${display_highest}`,
167
+ ` Display lowest: ${display_lowest}`,
203
168
  ];
204
169
  for ( _line of _text ) {
205
170
  _msg_info(
@@ -215,19 +180,21 @@ function
215
180
  const
216
181
  _text = [
217
182
  "",
218
- "Returns default deployments directory for an application",
183
+ "Returns available versions for contract deployments on a network",
219
184
  "",
220
185
  "Usage:",
221
186
  "",
222
187
  ` ${app_name}`,
223
188
  " [options]",
224
- " <target-app>",
189
+ " <config-file>",
225
190
  "",
226
191
  " options:",
227
192
  "",
228
- " -u --user-level Returns user-level location",
229
- " for an application deployments",
230
- ` Default: '${user_level}`,
193
+ " -H --display-highest Display highest versions available.",
194
+ ` Default: '${display_highest}`,
195
+ "",
196
+ " -L --display-lowest Display lowest versions available.",
197
+ ` Default: '${display_lowest}`,
231
198
  "",
232
199
  " -h --help This message.",
233
200
  " -v --verbose Enable verbose output.",
@@ -249,8 +216,10 @@ async function
249
216
  const
250
217
  _argv_args = {
251
218
  "booleans": [
252
- "u",
253
- "user-level",
219
+ "H",
220
+ "display-highest",
221
+ "L",
222
+ "display-lowest",
254
223
  "h",
255
224
  "help",
256
225
  "v",
@@ -299,7 +268,7 @@ async function
299
268
  _argv[
300
269
  "_"].length < 1 ) {
301
270
  _msg =
302
- "Target application " +
271
+ "Configuration file " +
303
272
  "argument required.";
304
273
  _msg_error(
305
274
  _msg,
@@ -307,19 +276,29 @@ async function
307
276
  _usage(
308
277
  1);
309
278
  }
310
- target_app =
279
+ config_file =
311
280
  _argv[
312
281
  "_"][
313
282
  0];
314
- if ( "u" in _argv ) {
315
- user_level =
283
+ if ( "H" in _argv ) {
284
+ display_highest =
285
+ _argv[
286
+ "H"];
287
+ }
288
+ if ( "display-highest" in _argv ) {
289
+ display_highest =
290
+ _argv[
291
+ "display-highest"];
292
+ }
293
+ if ( "L" in _argv ) {
294
+ display_lowest =
316
295
  _argv[
317
- "u"];
296
+ "L"];
318
297
  }
319
- if ( "user_level" in _argv ) {
320
- user_level =
298
+ if ( "display-lowest" in _argv ) {
299
+ display_lowest =
321
300
  _argv[
322
- "user_level"];
301
+ "display-lowest"];
323
302
  }
324
303
  if ( _argv[
325
304
  "v"] ||
@@ -337,9 +316,17 @@ function
337
316
  _network;
338
317
  runtime_environment =
339
318
  "browser";
340
- user_level =
319
+ config_file =
320
+ _argv_url_get(
321
+ "config_file")[
322
+ 0];
323
+ display_highest =
341
324
  _argv_url_get(
342
- "user_level")[
325
+ "display_highest")[
326
+ 0];
327
+ display_lowest =
328
+ _argv_url_get(
329
+ "display_lowest")[
343
330
  0];
344
331
  quiet =
345
332
  _argv_url_get(
@@ -351,15 +338,15 @@ function
351
338
  }
352
339
 
353
340
  async function
354
- _evm_contract_deployments_dir_cmdline(
341
+ _evm_contract_deployment_versions_cmdline(
355
342
  _app_opts) {
356
343
  let
357
344
  _result;
358
345
  const
359
346
  _results =
360
- await _evm_contract_deployments_dir.apply(
347
+ await _evm_contract_deployment_versions.apply(
361
348
  null,
362
- app_opts);
349
+ _app_opts);
363
350
  const
364
351
  _results_type =
365
352
  typeof(
@@ -384,21 +371,19 @@ async function
384
371
  _config_show();
385
372
  const
386
373
  app_opts = [
387
- target_app,
388
- user_level
374
+ config_file,
375
+ display_highest,
376
+ display_lowest
389
377
  ];
390
- const
391
- _deployments =
392
- await _evm_contract_deployments_dir.apply(
393
- null,
394
- app_opts);
378
+ _evm_contract_deployment_versions_cmdline(
379
+ app_opts);
395
380
  }
396
381
 
397
382
  _global_variables();
398
383
  if ( _cmdline_check(
399
- "evm-contract-deployments-dir.js") == true ||
384
+ "evm-contract-deployment-versions.js") ||
400
385
  _cmdline_check(
401
- "evm-contract-deployments-dir") == true ) {
386
+ "evm-contract-deployment-versions") ) {
402
387
  _cmdline_parse();
403
388
  }
404
389
  else{
package/lib/address-check CHANGED
File without changes
File without changes
File without changes
@@ -137,6 +137,15 @@ const
137
137
  const
138
138
  _evm_contract_deployments_dir =
139
139
  _libevm_contract_deployments_dir_module._evm_contract_deployments_dir;
140
+ const
141
+ _libevm_contract_deployment_networks =
142
+ require(
143
+ "./libevm-contract-deployment-networks");
144
+ /* global
145
+ _evm_contract_deployment_networks */
146
+ const
147
+ _evm_contract_deployment_networks =
148
+ _libevm_contract_deployment_networks_module._evm_contract_deployment_networks;
140
149
  const
141
150
  _evm_chains_info_module =
142
151
  require(
@@ -147,20 +156,43 @@ const
147
156
  _evm_chains_info =
148
157
  _evm_chains_info_module._evm_chains_info;
149
158
 
150
-
151
159
  function
152
160
  _contract_address_get(
153
161
  _deployments,
154
162
  _contract,
155
163
  _network,
156
164
  _network_id,
157
- _version) {
165
+ _version,
166
+ _configuration_format) {
158
167
  let
168
+ _config_file_ext,
159
169
  _config_path,
160
170
  _address,
161
171
  _found,
162
172
  _msg,
163
173
  _net;
174
+ if ( typeof(
175
+ _configuration_format) === "undefined" ||
176
+ _configuration_format == "" ) {
177
+ _configuration_format =
178
+ "bash";
179
+ }
180
+ if ( _configuration_format == "bash" ) {
181
+ _config_file_ext =
182
+ "sh";
183
+ }
184
+ if ( _configuration_format == "json" ) {
185
+ _config_file_ext =
186
+ "json"
187
+ }
188
+ else {
189
+ _msg =
190
+ "Unknown configuration format " +
191
+ `${_configuration_format}'.`;
192
+ _msg_error(
193
+ _msg,
194
+ 1);
195
+ }
164
196
  const
165
197
  _networks = [
166
198
  _network,
@@ -170,7 +202,7 @@ function
170
202
  false;
171
203
  for ( _net of _networks ) {
172
204
  _config_path =
173
- `${_deployments}/${_contract}/${_net}/config.sh`;
205
+ `${_deployments}/${_contract}/${_net}/config.${_config_file_ext}`;
174
206
  if ( _file_exists(
175
207
  _config_path) ) {
176
208
  _found =
@@ -181,7 +213,7 @@ function
181
213
  if ( ! _found ) {
182
214
  _msg =
183
215
  `No network '${_network}' deployment ` +
184
- `configuration for '${_contract}' ` +
216
+ `configuration for contract '${_contract}' ` +
185
217
  `found at path '${_deployments}'.`;
186
218
  _msg_error(
187
219
  _msg,
@@ -207,6 +239,7 @@ function
207
239
  _msg,
208
240
  1);
209
241
  }
242
+ return _contract_address;
210
243
  }
211
244
 
212
245
  function
@@ -248,40 +281,159 @@ function
248
281
  }
249
282
 
250
283
  function
251
- _evm_contract_deployments_dir(
252
- _app,
253
- _user_level) {
284
+ _evm_contract_deployment_address(
285
+ _target_networks,
286
+ _network_ids,
287
+ _networks_all,
288
+ _target_app,
289
+ _contract_version,
290
+ _user_defined,
291
+ _deployments_dir) {
254
292
  let
255
- _deployments,
256
- _deployment_type;
257
- _app_check(
258
- _app);
259
- if ( _user_level == "n" ) {
260
- _deployment_type =
261
- "system";
293
+ _args,
294
+ _contract_address,
295
+ _contract_address_get_args,
296
+ _contracts_addresses,
297
+ _network,
298
+ _network_check_args,
299
+ _target_network,
300
+ _target_network_id,
301
+ _user_deployments_dir,
302
+ _system_deployments_dir,
303
+ _msg;
304
+ if ( _user_defined == "n" ) {
305
+ if ( _target_app == "" ) {
306
+ _msg =
307
+ "A target application needs to " +
308
+ "be specified with option '-a' " +
309
+ "if not enabling user-defined " +
310
+ "deployments with '-u' and " +
311
+ "specifying a deployments directory " +
312
+ "path with '-d'.";
313
+ _msg_error(
314
+ _msg,
315
+ 1)
316
+ }
317
+ _system_deployments_dir =
318
+ _evm_contract_deployments_dir(
319
+ target_app);
320
+ if ( _deployments_dir != system_deployments_dir ) {
321
+ _msg =
322
+ "To set a custom deployments directory path " +
323
+ "you need to enable the user-defined " +
324
+ "deployments switch with '-u'." +
325
+ _msg_error(
326
+ _msg,
327
+ 1)
328
+ }
262
329
  }
263
- else if ( _user_level == "n" ) {
264
- _deployment_type =
265
- "system";
330
+ else if ( _user_defined == "y" ) {
331
+ if ( _target_app != "" ) {
332
+ _user_deployments_dir =
333
+ _evm_contract_deployments_dir(
334
+ _target_app,
335
+ _user_defined);
336
+ }
337
+ if ( _deployments_dir != _user_deployments_dir ) {
338
+ _msg =
339
+ "Using custom deployments directory " +
340
+ `path '${_deployments_dir}'.`;
341
+ _msg_info(
342
+ _msg);
343
+ }
344
+ else {
345
+ _user_deployments_check();
346
+ }
266
347
  }
267
348
  else {
268
349
  _msg =
269
- "User level argument must be " +
350
+ "The 'user-defined' switch argument must be " +
270
351
  "can be 'y' or 'n'."
271
352
  _msg_error(
272
353
  _msg,
273
354
  1);
274
355
  }
275
- _deployments =
276
- _default_deployments_dir_get(
277
- _app,
278
- _deployment_type);
279
- return _deployments;
356
+ if ( _networks_all == "y" ) {
357
+ _target_networks =
358
+ _evm_contract_deployment_networks(
359
+ `${_deployments_dir}/${_target_contract}`,
360
+ _networks_all);
361
+ }
362
+ for ( _network of _target_networks ) {
363
+ _target_network_id =
364
+ "";
365
+ _network_check_args = [
366
+ _deployments_dir,
367
+ _target_contract,
368
+ _network,
369
+ _target_network_id
370
+ ];
371
+ _network_check.apply(
372
+ null,
373
+ _network_check_args);
374
+ _contract_address_get_args.push( [
375
+ _deployments_dir,
376
+ _target_contract,
377
+ _target_network,
378
+ _target_network_id,
379
+ _contract_version
380
+ ] );
381
+ }
382
+ for ( _network of _network_ids ) {
383
+ _target_network =
384
+ "";
385
+ _network_check_args = [
386
+ _deployments_dir,
387
+ _target_contract,
388
+ _target_network,
389
+ _network
390
+ ];
391
+ _network_check.apply(
392
+ null,
393
+ _network_check_args);
394
+ _contract_address_get_args.push( [
395
+ _deployments_dir,
396
+ _target_contract,
397
+ _target_network,
398
+ _target_network_id,
399
+ _contract_version
400
+ ] );
401
+ }
402
+ for ( _args of _contract_address_args ) {
403
+ _contract_address =
404
+ _contract_address_get.apply(
405
+ null,
406
+ _args);
407
+ _contract_addresses.push(
408
+ _contract_address);
409
+ }
410
+ return _contracts_addresses;
411
+ }
412
+
413
+ function
414
+ _networks_all_auto_detect() {
415
+ let
416
+ _networks_all;
417
+ _networks_all =
418
+ "n";
419
+ if ( target_networks.length < 1 &&
420
+ network_ids.length < 1 ) {
421
+ _networks_all =
422
+ "y";
423
+ }
424
+ if ( typeof(
425
+ networks_all) === "undefined" ||
426
+ networks_all == "" ) {
427
+ networks_all =
428
+ _networks_all;
429
+ }
280
430
  }
281
431
 
282
432
  module.exports = {
283
433
  _default_deployments_dir_get:
284
434
  _default_deployments_dir_get,
285
- _evm_contract_deployments_dir:
286
- _evm_contract_deployments_dir,
435
+ _evm_contract_deployment_address:
436
+ _evm_contract_deployment_address,
437
+ _networks_all_auto_detect:
438
+ _networks_all_auto_detect,
287
439
  };