@witnet/sdk 1.2.7 → 3.0.0

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.
Files changed (88) hide show
  1. package/.env_witnet +18 -18
  2. package/LICENSE +21 -21
  3. package/README.md +116 -116
  4. package/dist/package.json +14 -3
  5. package/dist/src/bin/helpers.d.ts.map +1 -1
  6. package/dist/src/bin/helpers.js +22 -54
  7. package/dist/src/lib/crypto/account.d.ts.map +1 -1
  8. package/dist/src/lib/crypto/account.js +3 -9
  9. package/dist/src/lib/crypto/coinbase.d.ts.map +1 -1
  10. package/dist/src/lib/crypto/coinbase.js +2 -2
  11. package/dist/src/lib/crypto/interfaces.d.ts.map +1 -1
  12. package/dist/src/lib/crypto/interfaces.js +1 -1
  13. package/dist/src/lib/crypto/payloads/DataRequestPayload.d.ts +4 -6
  14. package/dist/src/lib/crypto/payloads/DataRequestPayload.d.ts.map +1 -1
  15. package/dist/src/lib/crypto/payloads/DataRequestPayload.js +20 -71
  16. package/dist/src/lib/crypto/payloads/StakePayload.d.ts.map +1 -1
  17. package/dist/src/lib/crypto/payloads/StakePayload.js +4 -9
  18. package/dist/src/lib/crypto/payloads/UnstakePayload.d.ts.map +1 -1
  19. package/dist/src/lib/crypto/payloads/UnstakePayload.js +4 -7
  20. package/dist/src/lib/crypto/payloads/ValueTransferPayload.d.ts.map +1 -1
  21. package/dist/src/lib/crypto/payloads/ValueTransferPayload.js +4 -9
  22. package/dist/src/lib/crypto/payloads.d.ts.map +1 -1
  23. package/dist/src/lib/crypto/payloads.js +6 -13
  24. package/dist/src/lib/crypto/signer.d.ts.map +1 -1
  25. package/dist/src/lib/crypto/signer.js +2 -2
  26. package/dist/src/lib/crypto/transmitters/DataRequests.d.ts.map +1 -1
  27. package/dist/src/lib/crypto/transmitters/DataRequests.js +2 -2
  28. package/dist/src/lib/crypto/transmitters/StakeDeposits.d.ts.map +1 -1
  29. package/dist/src/lib/crypto/transmitters/StakeDeposits.js +2 -2
  30. package/dist/src/lib/crypto/transmitters/StakeWithdrawals.d.ts.map +1 -1
  31. package/dist/src/lib/crypto/transmitters/StakeWithdrawals.js +2 -2
  32. package/dist/src/lib/crypto/transmitters/ValueTransfers.d.ts.map +1 -1
  33. package/dist/src/lib/crypto/transmitters/ValueTransfers.js +2 -2
  34. package/dist/src/lib/crypto/transmitters.d.ts.map +1 -1
  35. package/dist/src/lib/crypto/transmitters.js +22 -31
  36. package/dist/src/lib/crypto/types.d.ts.map +1 -1
  37. package/dist/src/lib/crypto/types.js +6 -13
  38. package/dist/src/lib/crypto/utils.d.ts.map +1 -1
  39. package/dist/src/lib/crypto/utils.js +5 -9
  40. package/dist/src/lib/crypto/wallet.d.ts.map +1 -1
  41. package/dist/src/lib/crypto/wallet.js +9 -23
  42. package/dist/src/lib/radon/ccdr/eth.d.ts.map +1 -1
  43. package/dist/src/lib/radon/ccdr/eth.js +12 -32
  44. package/dist/src/lib/radon/ccdr/wit.d.ts.map +1 -1
  45. package/dist/src/lib/radon/ccdr/wit.js +3 -6
  46. package/dist/src/lib/radon/index.d.ts.map +1 -1
  47. package/dist/src/lib/radon/index.js +18 -41
  48. package/dist/src/lib/radon/reducers.js +2 -2
  49. package/dist/src/lib/radon/types.d.ts.map +1 -1
  50. package/dist/src/lib/radon/types.js +6 -32
  51. package/dist/src/lib/radon/utils.d.ts +1 -1
  52. package/dist/src/lib/radon/utils.d.ts.map +1 -1
  53. package/dist/src/lib/radon/utils.js +3 -6
  54. package/dist/src/lib/rest/kermit.d.ts.map +1 -1
  55. package/dist/src/lib/rest/kermit.js +1 -1
  56. package/dist/src/lib/rpc/nodes.d.ts.map +1 -1
  57. package/dist/src/lib/rpc/nodes.js +8 -28
  58. package/dist/src/lib/rpc/provider.d.ts.map +1 -1
  59. package/dist/src/lib/rpc/provider.js +16 -38
  60. package/dist/src/lib/rpc/types.d.ts.map +1 -1
  61. package/dist/src/lib/rpc/types.js +1 -1
  62. package/dist/src/lib/utils.d.ts.map +1 -1
  63. package/dist/src/lib/utils.js +2 -5
  64. package/dist/witnet/assets/index.cjs +1 -1
  65. package/dist/witnet/assets/modals/index.cjs +1 -1
  66. package/dist/witnet/assets/modals/web3/eth.cjs +2 -2
  67. package/dist/witnet/assets/modals/web3/ipfs.cjs +2 -2
  68. package/dist/witnet/assets/modals/web3/wit.cjs +4 -11
  69. package/dist/witnet/assets/requests.cjs +3 -11
  70. package/package.json +7 -3
  71. package/src/bin/bots/watcher.cjs +27 -93
  72. package/src/bin/cli/inspect.js +30 -119
  73. package/src/bin/cli/network.js +46 -202
  74. package/src/bin/cli/nodes.js +12 -58
  75. package/src/bin/cli/radon.js +80 -265
  76. package/src/bin/cli/wallet.js +69 -241
  77. package/src/bin/helpers.js +56 -162
  78. package/src/bin/index.js +21 -51
  79. package/witnet/assets/_index.cjs +5 -5
  80. package/witnet/assets/_requests.cjs +25 -25
  81. package/witnet/assets/_sources.cjs +36 -36
  82. package/witnet/assets/_templates.cjs +36 -36
  83. package/witnet/assets/index.cjs +4 -4
  84. package/witnet/assets/modals/index.cjs +7 -7
  85. package/witnet/assets/modals/web3/eth.cjs +22 -27
  86. package/witnet/assets/modals/web3/ipfs.cjs +17 -22
  87. package/witnet/assets/modals/web3/wit.cjs +16 -28
  88. package/witnet/assets/requests.cjs +41 -49
@@ -8,10 +8,7 @@ import moment from "moment";
8
8
  const require = createRequire(import.meta.url);
9
9
 
10
10
  export const colorstrip = (str) =>
11
- str.replace(
12
- /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
13
- "",
14
- );
11
+ str.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, "");
15
12
 
16
13
  export const commas = (number) => {
17
14
  const parts = number.toString().split(".");
@@ -41,14 +38,8 @@ export const whole_wits = (number, digits) => {
41
38
  ];
42
39
  // const regexp = /\.0+$|(?<=\.[0-9])0+$/
43
40
  const item = lookup.findLast((item) => number >= item.value);
44
- const quotient = item
45
- ? Number(BigInt(number) / item.value)
46
- : number.toString();
47
- const decimals = item
48
- ? (item.value + BigInt(number) - BigInt(quotient) * item.value)
49
- .toString()
50
- .slice(1)
51
- : "";
41
+ const quotient = item ? Number(BigInt(number) / item.value) : number.toString();
42
+ const decimals = item ? (item.value + BigInt(number) - BigInt(quotient) * item.value).toString().slice(1) : "";
52
43
  return item
53
44
  ? `${commas(quotient)}${decimals !== "" ? `.${decimals.slice(0, digits)}` : ""} ${item.symbol}`
54
45
  : "(no coins)";
@@ -113,13 +104,8 @@ export const colors = {
113
104
  export function countLeaves(t, obj) {
114
105
  if (!obj || typeof obj === "string") return 0;
115
106
  if (obj instanceof t) return 1;
116
- if (Array.isArray(obj))
117
- return obj.reduce((sum, item) => sum + countLeaves(t, item), 0);
118
- else
119
- return Object.values(obj).reduce(
120
- (sum, item) => sum + countLeaves(t, item),
121
- 0,
122
- );
107
+ if (Array.isArray(obj)) return obj.reduce((sum, item) => sum + countLeaves(t, item), 0);
108
+ else return Object.values(obj).reduce((sum, item) => sum + countLeaves(t, item), 0);
123
109
  }
124
110
 
125
111
  export function deleteExtraFlags(args) {
@@ -128,19 +114,15 @@ export function deleteExtraFlags(args) {
128
114
 
129
115
  export function cmd(...command) {
130
116
  return new Promise((resolve, reject) => {
131
- exec(
132
- command.join(" "),
133
- { maxBuffer: 1024 * 1024 * 10 },
134
- (error, stdout, stderr) => {
135
- if (error) {
136
- reject(error);
137
- }
138
- if (stderr) {
139
- reject(stderr);
140
- }
141
- resolve(stdout);
142
- },
143
- );
117
+ exec(command.join(" "), { maxBuffer: 1024 * 1024 * 10 }, (error, stdout, stderr) => {
118
+ if (error) {
119
+ reject(error);
120
+ }
121
+ if (stderr) {
122
+ reject(stderr);
123
+ }
124
+ resolve(stdout);
125
+ });
144
126
  });
145
127
  }
146
128
 
@@ -189,9 +171,7 @@ export function extractFromArgs(args, flags) {
189
171
 
190
172
  export function fromHexString(hexString) {
191
173
  if (hexString.startsWith("0x")) hexString = hexString.slice(2);
192
- return Uint8Array.from(
193
- hexString.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)),
194
- );
174
+ return Uint8Array.from(hexString.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
195
175
  }
196
176
 
197
177
  export function ipIsPrivateOrLocalhost(ip) {
@@ -236,9 +216,7 @@ export function ipIsPrivateOrLocalhost(ip) {
236
216
 
237
217
  export function isHexStringOfLength(str, length) {
238
218
  return (
239
- (isHexString(str) &&
240
- ((str.startsWith("0x") && str.slice(2).length === length * 2) ||
241
- str.length === length * 2)) ||
219
+ (isHexString(str) && ((str.startsWith("0x") && str.slice(2).length === length * 2) || str.length === length * 2)) ||
242
220
  isWildcard(str)
243
221
  );
244
222
  }
@@ -246,8 +224,7 @@ export function isHexStringOfLength(str, length) {
246
224
  export function isHexString(str) {
247
225
  return (
248
226
  (typeof str === "string" &&
249
- ((str.startsWith("0x") && /^[a-fA-F0-9]+$/i.test(str.slice(2))) ||
250
- /^[a-fA-F0-9]+$/i.test(str))) ||
227
+ ((str.startsWith("0x") && /^[a-fA-F0-9]+$/i.test(str.slice(2))) || /^[a-fA-F0-9]+$/i.test(str))) ||
251
228
  isWildcard(str)
252
229
  );
253
230
  }
@@ -267,12 +244,7 @@ export function toHexString(buffer, prefix0x = false) {
267
244
  export function parseURL(url) {
268
245
  try {
269
246
  const parsedUrl = new URL(url);
270
- return [
271
- `${parsedUrl.protocol}//`,
272
- parsedUrl.host,
273
- parsedUrl.pathname.slice(1),
274
- parsedUrl.search.slice(1),
275
- ];
247
+ return [`${parsedUrl.protocol}//`, parsedUrl.host, parsedUrl.pathname.slice(1), parsedUrl.search.slice(1)];
276
248
  } catch {
277
249
  throw new TypeError(`Invalid URL was provided: ${url}`);
278
250
  }
@@ -292,12 +264,7 @@ export function showUsageRouter(router) {
292
264
  console.info("\nSUBCOMMANDS:");
293
265
  const maxLength = Math.max(...cmds.map(([cmd]) => cmd.length));
294
266
  cmds.forEach((cmd) => {
295
- console.info(
296
- " ",
297
- `${cmd[0]}${" ".repeat(maxLength - cmd[0].length)}`,
298
- " ",
299
- cmd[1].hint,
300
- );
267
+ console.info(" ", `${cmd[0]}${" ".repeat(maxLength - cmd[0].length)}`, " ", cmd[1].hint);
301
268
  });
302
269
  }
303
270
  }
@@ -328,11 +295,7 @@ export function showUsageEnvars(envars) {
328
295
  ` => Settled to "${myellow(process.env[envar])}"`,
329
296
  );
330
297
  } else {
331
- console.info(
332
- " ",
333
- `${yellow(envar.toUpperCase())}${" ".repeat(maxWidth - envar.length)}`,
334
- ` ${hint}`,
335
- );
298
+ console.info(" ", `${yellow(envar.toUpperCase())}${" ".repeat(maxWidth - envar.length)}`, ` ${hint}`);
336
299
  }
337
300
  });
338
301
  }
@@ -353,19 +316,12 @@ export function showUsageFlags(flags) {
353
316
  const maxLength = Math.max(
354
317
  ...flags
355
318
  .filter(([, { hint }]) => hint)
356
- .map(([key, { param }]) =>
357
- param ? key.length + param.length + 3 : key.length,
358
- ),
319
+ .map(([key, { param }]) => (param ? key.length + param.length + 3 : key.length)),
359
320
  );
360
321
  flags.forEach((flag) => {
361
322
  const str = `${flag[0]}${flag[1].param ? gray(` <${flag[1].param}>`) : ""}`;
362
323
  if (flag[1].hint) {
363
- console.info(
364
- " ",
365
- `--${str}${" ".repeat(maxLength - colorstrip(str).length)}`,
366
- " ",
367
- flag[1].hint,
368
- );
324
+ console.info(" ", `--${str}${" ".repeat(maxLength - colorstrip(str).length)}`, " ", flag[1].hint);
369
325
  }
370
326
  });
371
327
  }
@@ -379,11 +335,7 @@ export function showUsageHeadline(cmd, subcmd, module) {
379
335
  // const options = module.router[subcmd]?.options
380
336
  if (params) {
381
337
  const optionalize = (str) =>
382
- str.endsWith(" ...]")
383
- ? `[<${str.slice(1, -5)}> ...]`
384
- : str[0] === "["
385
- ? `[<${str.slice(1, -1)}>]`
386
- : `<${str}>`;
338
+ str.endsWith(" ...]") ? `[<${str.slice(1, -5)}> ...]` : str[0] === "[" ? `[<${str.slice(1, -1)}>]` : `<${str}>`;
387
339
  if (Array.isArray(params)) {
388
340
  params = `${params.map((param) => optionalize(param)).join(" ")} `;
389
341
  } else {
@@ -398,9 +350,7 @@ export function showUsageHeadline(cmd, subcmd, module) {
398
350
  console.info(` ${module.router[subcmd].hint}`);
399
351
  }
400
352
  } else {
401
- console.info(
402
- ` ${colors.white(`npx witsdk ${cmd}`)} <SUBCOMMAND> ... [OPTIONS] [FLAGS]`,
403
- );
353
+ console.info(` ${colors.white(`npx witsdk ${cmd}`)} <SUBCOMMAND> ... [OPTIONS] [FLAGS]`);
404
354
  }
405
355
  }
406
356
 
@@ -415,21 +365,12 @@ export function showUsageOptions(options) {
415
365
  if (options.length > 0) {
416
366
  console.info("\nOPTIONS:");
417
367
  const maxLength = options
418
- .map((option) =>
419
- option[1].param
420
- ? option[1].param.length + option[0].length + 3
421
- : option[0].length,
422
- )
368
+ .map((option) => (option[1].param ? option[1].param.length + option[0].length + 3 : option[0].length))
423
369
  .reduce((prev, curr) => (curr > prev ? curr : prev));
424
370
  options.forEach((option) => {
425
371
  if (option[1].hint) {
426
372
  const str = `${option[0]}${option[1].param ? gray(` <${option[1].param}>`) : ""}`;
427
- console.info(
428
- " ",
429
- `--${str}${" ".repeat(maxLength - colorstrip(str).length)}`,
430
- " ",
431
- option[1].hint,
432
- );
373
+ console.info(" ", `--${str}${" ".repeat(maxLength - colorstrip(str).length)}`, " ", option[1].hint);
433
374
  }
434
375
  });
435
376
  }
@@ -443,9 +384,7 @@ export function showUsageSubcommand(cmd, subcmd, module) {
443
384
  }
444
385
 
445
386
  export function showVersion() {
446
- console.info(
447
- `${colors.mcyan(`Witnet SDK v${require("../../package.json").version}`)}`,
448
- );
387
+ console.info(`${colors.mcyan(`Witnet SDK v${require("../../package.json").version}`)}`);
449
388
  }
450
389
 
451
390
  export function getWildcardsCountFromString(str) {
@@ -465,11 +404,15 @@ export function checkRpcWildcards(wildcards) {
465
404
  if (typeof wildcards === "object") {
466
405
  Object.values(wildcards).forEach((wildcard) => {
467
406
  if (Array.isArray(wildcard))
468
- wildcard.forEach((item) => checkRpcWildcards(item));
407
+ wildcard.forEach((item) => {
408
+ checkRpcWildcards(item);
409
+ });
469
410
  else checkRpcWildcards(wildcard);
470
411
  });
471
412
  } else if (Array.isArray(wildcards)) {
472
- wildcards.forEach((wildcard) => checkRpcWildcards(wildcard));
413
+ wildcards.forEach((wildcard) => {
414
+ checkRpcWildcards(wildcard);
415
+ });
473
416
  } else if (typeof wildcards === "string") {
474
417
  if (isWildcard(wildcards)) {
475
418
  const char = wildcards.charAt(1);
@@ -493,9 +436,7 @@ export function replaceWildcards(obj, args) {
493
436
  }
494
437
  } else if (obj && Array.isArray(obj)) {
495
438
  obj = obj.map((value) =>
496
- typeof value === "string" || Array.isArray(value)
497
- ? replaceWildcards(value, args)
498
- : value,
439
+ typeof value === "string" || Array.isArray(value) ? replaceWildcards(value, args) : value,
499
440
  );
500
441
  } else if (obj && typeof obj === "object") {
501
442
  obj = replaceObjectWildcards(obj, args);
@@ -525,9 +466,7 @@ export function spliceWildcard(obj, argIndex, argValue, argsCount) {
525
466
  }
526
467
  } else if (obj && Array.isArray(obj)) {
527
468
  obj = obj.map((value) =>
528
- typeof value === "string" || Array.isArray(value)
529
- ? spliceWildcard(value, argIndex, argValue, argsCount)
530
- : value,
469
+ typeof value === "string" || Array.isArray(value) ? spliceWildcard(value, argIndex, argValue, argsCount) : value,
531
470
  );
532
471
  }
533
472
  return obj;
@@ -549,9 +488,7 @@ export async function toolkitRun(settings, args) {
549
488
  }
550
489
 
551
490
  export function toUpperCamelCase(str) {
552
- return str
553
- .replace(/\b(\w)/g, (_match, capture) => capture.toUpperCase())
554
- .replace(/\s+/g, "");
491
+ return str.replace(/\b(\w)/g, (_match, capture) => capture.toUpperCase()).replace(/\s+/g, "");
555
492
  }
556
493
 
557
494
  export function toUtf16Bytes(str) {
@@ -572,19 +509,14 @@ export function toUtf8Array(str) {
572
509
  else if (charcode < 0x800) {
573
510
  utf8.push(0xc0 | (charcode >> 6), 0x80 | (charcode & 0x3f));
574
511
  } else if (charcode < 0xd800 || charcode >= 0xe000) {
575
- utf8.push(
576
- 0xe0 | (charcode >> 12),
577
- 0x80 | ((charcode >> 6) & 0x3f),
578
- 0x80 | (charcode & 0x3f),
579
- );
512
+ utf8.push(0xe0 | (charcode >> 12), 0x80 | ((charcode >> 6) & 0x3f), 0x80 | (charcode & 0x3f));
580
513
  } else {
581
514
  // surrogate pair
582
515
  i++;
583
516
  // UTF-16 encodes 0x10000-0x10FFFF by
584
517
  // subtracting 0x10000 and splitting the
585
518
  // 20 bits of 0x0-0xFFFFF into two halves
586
- charcode =
587
- 0x10000 + (((charcode & 0x3ff) << 10) | (str.charCodeAt(i) & 0x3ff));
519
+ charcode = 0x10000 + (((charcode & 0x3ff) << 10) | (str.charCodeAt(i) & 0x3ff));
588
520
  utf8.push(
589
521
  0xf0 | (charcode >> 18),
590
522
  0x80 | ((charcode >> 12) & 0x3f),
@@ -626,9 +558,7 @@ export function utf8ArrayToStr(array) {
626
558
  // 1110 xxxx 10xx xxxx 10xx xxxx
627
559
  char2 = array[i++];
628
560
  char3 = array[i++];
629
- out += String.fromCharCode(
630
- ((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0),
631
- );
561
+ out += String.fromCharCode(((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0));
632
562
  break;
633
563
  }
634
564
  }
@@ -667,22 +597,13 @@ export function prompter(promise) {
667
597
 
668
598
  export function traceChecklists(checklists) {
669
599
  if (checklists && Object.keys(checklists).length > 0) {
670
- const headlines = [
671
- "NODES",
672
- ...Object.keys(checklists).map((key) => `:${key}`),
673
- ];
600
+ const headlines = ["NODES", ...Object.keys(checklists).map((key) => `:${key}`)];
674
601
  checklists = Object.values(checklists);
675
602
  const urls = Object.keys(checklists[0]);
676
603
  const records = urls.map((url) => {
677
- const errors = checklists.filter(
678
- (checklist) => checklist[url] instanceof Error,
679
- ).length;
604
+ const errors = checklists.filter((checklist) => checklist[url] instanceof Error).length;
680
605
  return [
681
- errors === checklists.length
682
- ? colors.red(url)
683
- : errors > 0
684
- ? colors.myellow(url)
685
- : colors.mcyan(url),
606
+ errors === checklists.length ? colors.red(url) : errors > 0 ? colors.myellow(url) : colors.mcyan(url),
686
607
  ...checklists.map((checklist) =>
687
608
  checklist[url] instanceof Error
688
609
  ? colors.red(checklist[url])
@@ -707,12 +628,9 @@ export function traceHeader(headline, color = normal, indent = "") {
707
628
 
708
629
  export function traceTable(records, options) {
709
630
  const stringify = (data, humanizers, index) =>
710
- humanizers?.[index]
711
- ? humanizers[index](data).toString()
712
- : (data?.toString() ?? "");
631
+ humanizers?.[index] ? humanizers[index](data).toString() : (data?.toString() ?? "");
713
632
  const max = (a, b) => (a > b ? a : b);
714
- const reduceMax = (numbers) =>
715
- numbers.reduce((curr, prev) => (prev > curr ? prev : curr), 0);
633
+ const reduceMax = (numbers) => numbers.reduce((curr, prev) => (prev > curr ? prev : curr), 0);
716
634
  if (!options) options = {};
717
635
  const indent = options?.indent || "";
718
636
  const numColumns = reduceMax(records.map((record) => record?.length || 1));
@@ -721,17 +639,9 @@ export function traceTable(records, options) {
721
639
  options.widths =
722
640
  options?.widths ||
723
641
  table.map((column, index) => {
724
- let maxWidth = reduceMax(
725
- column.map(
726
- (field) =>
727
- colorstrip(stringify(field, options?.humanizers, index)).length,
728
- ),
729
- );
642
+ let maxWidth = reduceMax(column.map((field) => colorstrip(stringify(field, options?.humanizers, index)).length));
730
643
  if (options?.headlines?.[index]) {
731
- maxWidth = max(
732
- maxWidth,
733
- colorstrip(options.headlines[index].replaceAll(":", "")).length,
734
- );
644
+ maxWidth = max(maxWidth, colorstrip(options.headlines[index].replaceAll(":", "")).length);
735
645
  }
736
646
  return Math.min(maxWidth, maxColumnWidth);
737
647
  });
@@ -844,9 +754,7 @@ export function traceTransactionOnStatusChange(receipt) {
844
754
  if (["finalized", "confirmed"].includes(receipt.status)) {
845
755
  console.info(` > Block hash: ${colors.gray(receipt?.blockHash)}`);
846
756
  console.info(` > Block miner: ${colors.cyan(receipt?.blockMiner)}`);
847
- console.info(
848
- ` > Block epoch: ${colors.white(commas(receipt?.blockEpoch))}`,
849
- );
757
+ console.info(` > Block epoch: ${colors.white(commas(receipt?.blockEpoch))}`);
850
758
  console.info(
851
759
  ` > Included at: ${colors.green(moment.unix(receipt?.blockTimestamp).format("MMMM Do YYYY, h:mm:ss a"))}`,
852
760
  );
@@ -861,15 +769,10 @@ export function traceTransactionReceipt(receipt) {
861
769
  DataRequest: " > DRT hash: ",
862
770
  ValueTransfer: " > VTT hash: ",
863
771
  };
864
- console.info(
865
- `${captions[receipt.type] || " > TX hash: "}${colors.white(receipt.hash)}`,
866
- );
867
- if (receipt?.droHash)
868
- console.info(` > DRO hash: ${colors.green(receipt.droHash)}`);
869
- if (receipt?.radHash)
870
- console.info(` > RAD hash: ${colors.mgreen(receipt.radHash)}`);
871
- if (receipt?.droSLA)
872
- console.info(` > SLA params: ${JSON.stringify(receipt.droSLA)}`);
772
+ console.info(`${captions[receipt.type] || " > TX hash: "}${colors.white(receipt.hash)}`);
773
+ if (receipt?.droHash) console.info(` > DRO hash: ${colors.green(receipt.droHash)}`);
774
+ if (receipt?.radHash) console.info(` > RAD hash: ${colors.mgreen(receipt.radHash)}`);
775
+ if (receipt?.droSLA) console.info(` > SLA params: ${JSON.stringify(receipt.droSLA)}`);
873
776
  if (receipt?.withdrawer) {
874
777
  if (receipt?.validator) {
875
778
  console.info(` > Validator: ${colors.mcyan(receipt.validator)}`);
@@ -885,20 +788,13 @@ export function traceTransactionReceipt(receipt) {
885
788
  if (receipt?.recipients) {
886
789
  console.info(
887
790
  ` > Recipient/s: ${colors.mblue(
888
- receipt.recipients.filter(
889
- (pkh, index, array) => index === array.indexOf(pkh),
890
- ),
791
+ receipt.recipients.filter((pkh, index, array) => index === array.indexOf(pkh)),
891
792
  )}`,
892
793
  );
893
794
  }
894
- if (receipt?.fees)
895
- console.info(` > Network fee: ${colors.yellow(receipt.fees.toString(2))}`);
896
- if (receipt?.value)
897
- console.info(
898
- ` > Value: ${colors.myellow(receipt.value.toString(2))}`,
899
- );
900
- if (receipt?.weight)
901
- console.info(` > Weight: ${colors.mgreen(commas(receipt.weight))}`);
795
+ if (receipt?.fees) console.info(` > Network fee: ${colors.yellow(receipt.fees.toString(2))}`);
796
+ if (receipt?.value) console.info(` > Value: ${colors.myellow(receipt.value.toString(2))}`);
797
+ if (receipt?.weight) console.info(` > Weight: ${colors.mgreen(commas(receipt.weight))}`);
902
798
  if (receipt?.witnesses) {
903
799
  console.info(` > Witnesses: ${receipt.witnesses}`);
904
800
  }
@@ -947,9 +843,7 @@ export async function traceTransaction(transmitter, options) {
947
843
  }
948
844
  } catch (err) {
949
845
  if (err?.inFlight && err.inFlight) {
950
- console.info(
951
- `\n${colors.gray(JSON.stringify(err.inFligt?.message, txReceiptJsonReplacer))}`,
952
- );
846
+ console.info(`\n${colors.gray(JSON.stringify(err.inFligt?.message, txReceiptJsonReplacer))}`);
953
847
  }
954
848
  throw err;
955
849
  }
package/src/bin/index.js CHANGED
@@ -33,15 +33,13 @@ const toolkitDownloadUrlBase = `https://github.com/witnet/witnet-rust/releases/d
33
33
  const toolkitDownloadNames = {
34
34
  win32: (arch) => `witnet_toolkit-${arch}-pc-windows-msvc.exe`,
35
35
  // TODO: detect armv7
36
- linux: (arch) =>
37
- `witnet_toolkit-${arch}-unknown-linux-gnu${arch === "arm" ? "eabihf" : ""}`,
36
+ linux: (arch) => `witnet_toolkit-${arch}-unknown-linux-gnu${arch === "arm" ? "eabihf" : ""}`,
38
37
  darwin: (_arch) => `witnet_toolkit-x86_64-apple-darwin`,
39
38
  };
40
39
  const toolkitFileNames = {
41
40
  win32: (arch) => `witnet_toolkit-${version}-${arch}-pc-windows-msvc.exe`,
42
41
  // TODO: detect armv7
43
- linux: (arch) =>
44
- `witnet_toolkit-${version}-${arch}-unknown-linux-gnu${arch === "arm" ? "eabihf" : ""}`,
42
+ linux: (arch) => `witnet_toolkit-${version}-${arch}-unknown-linux-gnu${arch === "arm" ? "eabihf" : ""}`,
45
43
  darwin: (_arch) => `witnet_toolkit-${version}-x86_64-apple-darwin`,
46
44
  };
47
45
  const archsMap = {
@@ -89,13 +87,7 @@ function checkToolkitIsDownloaded(toolkitBinPath) {
89
87
 
90
88
  /// HELPER FUNCTIONS ================================================================================================
91
89
 
92
- async function downloadToolkit(
93
- toolkitDownloadName,
94
- _toolkitFileName,
95
- toolkitBinPath,
96
- platform,
97
- arch,
98
- ) {
90
+ async function downloadToolkit(toolkitDownloadName, _toolkitFileName, toolkitBinPath, platform, arch) {
99
91
  const downloadUrl = guessDownloadUrl(toolkitDownloadName);
100
92
  console.info("Downloading", downloadUrl, "into", toolkitBinPath);
101
93
 
@@ -136,9 +128,7 @@ async function installCommand(settings) {
136
128
  if (!settings.checks.toolkitIsDownloaded) {
137
129
  // Skip confirmation if install is forced
138
130
  if (!settings.force) {
139
- console.info(
140
- `The witnet_toolkit ${version} native binary hasn't been downloaded yet (this is a requirement).`,
141
- );
131
+ console.info(`The witnet_toolkit ${version} native binary hasn't been downloaded yet (this is a requirement).`);
142
132
  const will = await prompt("Do you want to download it now? (Y/n)");
143
133
  // Abort if not confirmed
144
134
  if (!["", "y"].includes(will.toLowerCase())) {
@@ -171,17 +161,15 @@ async function versionCommand(settings) {
171
161
  }
172
162
 
173
163
  async function fallbackBinaryCommand(settings, args) {
174
- const toolkitOutput = await toolkitRun(settings, args.slice(1)).catch(
175
- (err) => {
176
- let errorMessage = err.message.split("\n").slice(1).join("\n").trim();
177
- const errorRegex = /.*^error: (?<message>.*)$.*/gm;
178
- const matched = errorRegex.exec(err.message);
179
- if (matched) {
180
- errorMessage = matched.groups.message;
181
- }
182
- console.error(errorMessage || err);
183
- },
184
- );
164
+ const toolkitOutput = await toolkitRun(settings, args.slice(1)).catch((err) => {
165
+ let errorMessage = err.message.split("\n").slice(1).join("\n").trim();
166
+ const errorRegex = /.*^error: (?<message>.*)$.*/gm;
167
+ const matched = errorRegex.exec(err.message);
168
+ if (matched) {
169
+ errorMessage = matched.groups.message;
170
+ }
171
+ console.error(errorMessage || err);
172
+ });
185
173
  if (toolkitOutput) console.info(toolkitOutput);
186
174
  }
187
175
 
@@ -254,10 +242,7 @@ async function main() {
254
242
  if (!args[index].startsWith("--")) {
255
243
  try {
256
244
  await import(`./cli/${args[index]}.js`);
257
- args = [
258
- args[index],
259
- ...args.slice(0, index).concat(args.slice(index + 1)),
260
- ];
245
+ args = [args[index], ...args.slice(0, index).concat(args.slice(index + 1))];
261
246
  break;
262
247
  } catch {}
263
248
  }
@@ -283,10 +268,7 @@ async function main() {
283
268
  ...module.router[subcmd]?.options,
284
269
  });
285
270
  args = deleteExtraFlags(args);
286
- await module.subcommands[subcmd](
287
- { ...settings, ...flags, ...options },
288
- args,
289
- ).catch((err) => {
271
+ await module.subcommands[subcmd]({ ...settings, ...flags, ...options }, args).catch((err) => {
290
272
  showUsageError(cmd, subcmd, module, err, settings);
291
273
  });
292
274
  }
@@ -305,25 +287,13 @@ async function main() {
305
287
  console.info(" --force Avoids asking the user to confirm operation.");
306
288
  console.info(" --help Describes command or subcommand usage.");
307
289
  console.info(" --update Forces update of underlying binaries.");
308
- console.info(
309
- " --version Prints toolkit name and version as first line.",
310
- );
290
+ console.info(" --version Prints toolkit name and version as first line.");
311
291
  console.info("\nMODULES:");
312
- console.info(
313
- " inspect Inspect public data from the Wit/Oracle blockchain.",
314
- );
315
- console.info(
316
- " network Dynamic information from the Wit/Oracle P2P network.",
317
- );
318
- console.info(
319
- " nodes Interact with your private Wit/Oracle nodes, if reachable.",
320
- );
321
- console.info(
322
- " radon Manage Radon requests and templates within your project.",
323
- );
324
- console.info(
325
- " wallet Simple CLI wallet for spending and staking your Wits.",
326
- );
292
+ console.info(" inspect Inspect public data from the Wit/Oracle blockchain.");
293
+ console.info(" network Dynamic information from the Wit/Oracle P2P network.");
294
+ console.info(" nodes Interact with your private Wit/Oracle nodes, if reachable.");
295
+ console.info(" radon Manage Radon requests and templates within your project.");
296
+ console.info(" wallet Simple CLI wallet for spending and staking your Wits.");
327
297
  }
328
298
 
329
299
  main();
@@ -1,5 +1,5 @@
1
- module.exports = {
2
- requests: require("./requests.cjs"),
3
- sources: require("./sources.cjs"),
4
- templates: require("./templates.cjs"),
5
- };
1
+ module.exports = {
2
+ requests: require("./requests.cjs"),
3
+ sources: require("./sources.cjs"),
4
+ templates: require("./templates.cjs"),
5
+ };
@@ -1,25 +1,25 @@
1
- const { assets, Witnet } = require("@witnet/sdk");
2
- const { RadonRequest, RadonScript } = Witnet.Radon;
3
- const { filters, reducers, retrievals, types } = Witnet.Radon;
4
-
5
- const _sources = require("./sources.cjs");
6
- const _templates = require("./templates.cjs");
7
-
8
- module.exports = {
9
- /// //// REQUESTS FROM RETRIEVALS /////////////////////////////////////////////////
10
- // path: { ... path: {
11
- // WitOracleRequestXXX: new RadonRequest({
12
- // sources: [
13
- // sources...RadonRetrieval1,
14
- // sources...RadonRetrieval2.foldArgs("value21"),
15
- // sources...RadonRetrieval3.foldArgs("value31", "value32"),
16
- // retrievals..HttpXXX({ ... })
17
- // ...
18
- // ],
19
- // sourcesReducer?: reducers..,
20
- // witnessReducer?: reducers..,
21
- // }),
22
- /// /// REQUESTS FROM TEMPLATE ///////////////////////////////////////////////////
23
- // WitOracleRequestYYY: templates...RadonTemplate1.buildRequest([["arg11", "arg12", ..], ..])
24
- // }, ... },
25
- };
1
+ const { assets, Witnet } = require("@witnet/sdk");
2
+ const { RadonRequest, RadonScript } = Witnet.Radon;
3
+ const { filters, reducers, retrievals, types } = Witnet.Radon;
4
+
5
+ const _sources = require("./sources.cjs");
6
+ const _templates = require("./templates.cjs");
7
+
8
+ module.exports = {
9
+ /// //// REQUESTS FROM RETRIEVALS /////////////////////////////////////////////////
10
+ // path: { ... path: {
11
+ // WitOracleRequestXXX: new RadonRequest({
12
+ // sources: [
13
+ // sources...RadonRetrieval1,
14
+ // sources...RadonRetrieval2.foldArgs("value21"),
15
+ // sources...RadonRetrieval3.foldArgs("value31", "value32"),
16
+ // retrievals..HttpXXX({ ... })
17
+ // ...
18
+ // ],
19
+ // sourcesReducer?: reducers..,
20
+ // witnessReducer?: reducers..,
21
+ // }),
22
+ /// /// REQUESTS FROM TEMPLATE ///////////////////////////////////////////////////
23
+ // WitOracleRequestYYY: templates...RadonTemplate1.buildRequest([["arg11", "arg12", ..], ..])
24
+ // }, ... },
25
+ };