@witnet/sdk 1.2.6 → 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 -114
  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
@@ -14,8 +14,7 @@ import { utils, Witnet } from "../../../dist/src/index.js";
14
14
  import { default as legacy } from "../../../witnet/assets/index.cjs";
15
15
  import * as helpers from "../helpers.js";
16
16
 
17
- const WITNET_ASSETS_PATH =
18
- process.env.WITNET_SDK_RADON_ASSETS_PATH || "../../../../../witnet/assets";
17
+ const WITNET_ASSETS_PATH = process.env.WITNET_SDK_RADON_ASSETS_PATH || "../../../../../witnet/assets";
19
18
 
20
19
  /// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
21
20
  /// CLI SUBMODULE CONSTANTS ===========================================================================================
@@ -175,32 +174,18 @@ async function init() {
175
174
  fs.cpSync("node_modules/@witnet/sdk/.env_witnet", ".env_witnet");
176
175
  }
177
176
  if (!fs.existsSync("./witnet/assets/index.js")) {
178
- fs.cpSync(
179
- "node_modules/@witnet/sdk/witnet/assets/_index.js",
180
- "./witnet/assets/index.js",
181
- );
177
+ fs.cpSync("node_modules/@witnet/sdk/witnet/assets/_index.js", "./witnet/assets/index.js");
182
178
  }
183
179
  if (!fs.existsSync("./witnet/assets/requests.js")) {
184
- fs.cpSync(
185
- "node_modules/@witnet/sdk/witnet/assets/_requests.js",
186
- "./witnet/assets/requests.js",
187
- );
180
+ fs.cpSync("node_modules/@witnet/sdk/witnet/assets/_requests.js", "./witnet/assets/requests.js");
188
181
  }
189
182
  if (!fs.existsSync("./witnet/assets/sources.js")) {
190
- fs.cpSync(
191
- "node_modules/@witnet/sdk/witnet/assets/_sources.js",
192
- "./witnet/assets/sources.js",
193
- );
183
+ fs.cpSync("node_modules/@witnet/sdk/witnet/assets/_sources.js", "./witnet/assets/sources.js");
194
184
  }
195
185
  if (!fs.existsSync("./witnet/assets/templates.js")) {
196
- fs.cpSync(
197
- "node_modules/@witnet/sdk/witnet/assets/_templates.js",
198
- "./witnet/assets/templates.js",
199
- );
186
+ fs.cpSync("node_modules/@witnet/sdk/witnet/assets/_templates.js", "./witnet/assets/templates.js");
200
187
  }
201
- console.info(
202
- `Initialized Witnet Radon workspace at folder ${process.cwd()}/witnet/assets`,
203
- );
188
+ console.info(`Initialized Witnet Radon workspace at folder ${process.cwd()}/witnet/assets`);
204
189
  }
205
190
 
206
191
  async function assets(options = {}, [...patterns]) {
@@ -266,10 +251,7 @@ async function decode(options = {}, args = []) {
266
251
  traceWitnetRadonRequest(request, options);
267
252
  } catch (err) {
268
253
  console.error(err);
269
- if (
270
- (asset.startsWith("0x") && asset.length === 66) ||
271
- (!asset.startsWith("0x") && asset.length === 64)
272
- ) {
254
+ if ((asset.startsWith("0x") && asset.length === 66) || (!asset.startsWith("0x") && asset.length === 64)) {
273
255
  // TODO: assume it's a DR_TX_HASH
274
256
  // TODO: assume it's a RAD_HASH
275
257
  }
@@ -277,9 +259,7 @@ async function decode(options = {}, args = []) {
277
259
  } else {
278
260
  args = args.slice(1);
279
261
 
280
- const assets = options?.module
281
- ? require(`${options.module}/assets`)
282
- : loadAssets(options);
262
+ const assets = options?.module ? require(`${options.module}/assets`) : loadAssets(options);
283
263
  const headline = options?.headline;
284
264
  const crafts = flattenRadonArtifacts(assets).filter(
285
265
  (craft) => craft.key.toLowerCase().indexOf(asset.toLowerCase()) >= 0,
@@ -309,10 +289,7 @@ async function decode(options = {}, args = []) {
309
289
  prefix = "RadonTemplate::";
310
290
  } else if (artifact instanceof Witnet.Radon.RadonRetrieval) {
311
291
  if (artifact.argsCount > 0) {
312
- const retrievalArgs = Array.from(
313
- { length: artifact.argsCount },
314
- (_, i) => `{:${i + 1}}`,
315
- );
292
+ const retrievalArgs = Array.from({ length: artifact.argsCount }, (_, i) => `{:${i + 1}}`);
316
293
  artifact = artifact.foldArgs(retrievalArgs);
317
294
  }
318
295
  artifact = new Witnet.Radon.RadonRequest({ sources: artifact });
@@ -341,18 +318,13 @@ async function dryrun(options = {}, args = []) {
341
318
  const request = Witnet.Radon.RadonRequest.fromBytecode(asset);
342
319
  await traceWitnetRadonRequestDryRun(request, options);
343
320
  } catch {
344
- if (
345
- (asset.startsWith("0x") && asset.length === 66) ||
346
- (!asset.startsWith("0x") && asset.length === 64)
347
- ) {
321
+ if ((asset.startsWith("0x") && asset.length === 66) || (!asset.startsWith("0x") && asset.length === 64)) {
348
322
  // TODO: assume it's a RAD_HASH, and try to retrieve the BYTECODE from the Witnet network
349
323
  }
350
324
  }
351
325
  } else {
352
326
  args = args.slice(1);
353
- const assets = options?.module
354
- ? require(`${options.module}/assets`)
355
- : loadAssets(options);
327
+ const assets = options?.module ? require(`${options.module}/assets`) : loadAssets(options);
356
328
  const headline = options?.headline;
357
329
  const crafts = flattenRadonArtifacts(assets).filter(
358
330
  (craft) => craft.key.toLowerCase().indexOf(asset.toLowerCase()) >= 0,
@@ -379,11 +351,7 @@ async function dryrun(options = {}, args = []) {
379
351
  }
380
352
  artifact = artifact.homogeneous
381
353
  ? artifact.buildRadonRequest(modalArgs)
382
- : artifact.buildRadonRequest([
383
- ...artifact.sources.map((source) =>
384
- modalArgs.slice(0, source.argsCount),
385
- ),
386
- ]);
354
+ : artifact.buildRadonRequest([...artifact.sources.map((source) => modalArgs.slice(0, source.argsCount))]);
387
355
  prefix = "RadonModal::";
388
356
  } else {
389
357
  if (!artifact?.samples) {
@@ -443,9 +411,7 @@ const extractTypeName = (str) =>
443
411
 
444
412
  const stringifyFilter = (x, c) => {
445
413
  const color = c || helpers.colors.mcyan;
446
- return color(
447
- `${Witnet.Radon.filters.Opcodes[x.opcode]}(${x.args ? JSON.stringify(x.args) : ""})`,
448
- );
414
+ return color(`${Witnet.Radon.filters.Opcodes[x.opcode]}(${x.args ? JSON.stringify(x.args) : ""})`);
449
415
  };
450
416
 
451
417
  const stringifyReducer = (x, c) => {
@@ -455,9 +421,7 @@ const stringifyReducer = (x, c) => {
455
421
 
456
422
  export function loadAssets(options) {
457
423
  const assets = options?.legacy ? {} : legacy;
458
- return isModuleInitialized
459
- ? merge(assets, require(`${WITNET_ASSETS_PATH}/index.cjs`))
460
- : assets;
424
+ return isModuleInitialized ? merge(assets, require(`${WITNET_ASSETS_PATH}/index.cjs`)) : assets;
461
425
  }
462
426
 
463
427
  function flattenRadonArtifacts(tree, headers) {
@@ -489,14 +453,7 @@ function countWitnetArtifacts(assets, args, options) {
489
453
  (options?.templates && value instanceof Witnet.Radon.RadonTemplate) ||
490
454
  (options?.retrievals && value instanceof Witnet.Radon.RadonRetrieval) ||
491
455
  (options?.requests && value instanceof Witnet.Radon.RadonRequest);
492
- if (
493
- !(
494
- options?.modals ||
495
- options?.templates ||
496
- options?.retrievals ||
497
- options?.requests
498
- )
499
- ) {
456
+ if (!(options?.modals || options?.templates || options?.retrievals || options?.requests)) {
500
457
  include =
501
458
  value instanceof Witnet.Radon.RadonModal ||
502
459
  value instanceof Witnet.Radon.RadonRequest ||
@@ -525,32 +482,17 @@ function clearEmptyBranches(node, args, options) {
525
482
  .map(([key, value]) => {
526
483
  let include =
527
484
  (options?.modals && value instanceof Witnet.Radon.RadonModal) ||
528
- (options?.templates &&
529
- value instanceof Witnet.Radon.RadonTemplate) ||
530
- (options?.retrievals &&
531
- value instanceof Witnet.Radon.RadonRetrieval) ||
485
+ (options?.templates && value instanceof Witnet.Radon.RadonTemplate) ||
486
+ (options?.retrievals && value instanceof Witnet.Radon.RadonRetrieval) ||
532
487
  (options?.requests && value instanceof Witnet.Radon.RadonRequest);
533
- if (
534
- !(
535
- options?.modals ||
536
- options?.templates ||
537
- options?.retrievals ||
538
- options?.requests
539
- )
540
- ) {
488
+ if (!(options?.modals || options?.templates || options?.retrievals || options?.requests)) {
541
489
  include =
542
490
  value instanceof Witnet.Radon.RadonModal ||
543
491
  value instanceof Witnet.Radon.RadonRequest ||
544
492
  value instanceof Witnet.Radon.RadonTemplate ||
545
493
  value instanceof Witnet.Radon.RadonRetrieval;
546
494
  }
547
- if (
548
- include &&
549
- (!options?.filter ||
550
- args.find(
551
- (arg) => key.toLowerCase().indexOf(arg.toLowerCase()) >= 0,
552
- ))
553
- ) {
495
+ if (include && (!options?.filter || args.find((arg) => key.toLowerCase().indexOf(arg.toLowerCase()) >= 0))) {
554
496
  return [key, value];
555
497
  } else if (typeof value === "object") {
556
498
  if (countWitnetArtifacts(value, args, options) > 0) {
@@ -576,9 +518,7 @@ function traceWitnetArtifacts(assets, args, indent = "", options) {
576
518
  const prefix = `${indent}`;
577
519
  Object.keys(assets).forEach((key, index) => {
578
520
  const isLast = index === Object.keys(assets).length - 1;
579
- const found = args.find(
580
- (arg) => key.toLowerCase().indexOf(arg.toLowerCase()) >= 0,
581
- );
521
+ const found = args.find((arg) => key.toLowerCase().indexOf(arg.toLowerCase()) >= 0);
582
522
  const color = found ? helpers.colors.mcyan : helpers.colors.cyan;
583
523
  if (assets[key] instanceof Witnet.Radon.RadonRequest) {
584
524
  if (!options?.filter || found) {
@@ -589,15 +529,10 @@ function traceWitnetArtifacts(assets, args, indent = "", options) {
589
529
  console.info(`${prefix}`);
590
530
  }
591
531
  }
592
- } else if (
593
- assets[key] instanceof Witnet.Radon.RadonTemplate ||
594
- assets[key] instanceof Witnet.Radon.RadonModal
595
- ) {
532
+ } else if (assets[key] instanceof Witnet.Radon.RadonTemplate || assets[key] instanceof Witnet.Radon.RadonModal) {
596
533
  const argsCount = assets[key].argsCount;
597
534
  if (!options?.filter || found) {
598
- console.info(
599
- `${prefix}${color(key)} ${argsCount > 0 ? helpers.colors.green(`(${argsCount} args)`) : ""}`,
600
- );
535
+ console.info(`${prefix}${color(key)} ${argsCount > 0 ? helpers.colors.green(`(${argsCount} args)`) : ""}`);
601
536
  if (isLast) {
602
537
  console.info(`${prefix}`);
603
538
  }
@@ -605,24 +540,14 @@ function traceWitnetArtifacts(assets, args, indent = "", options) {
605
540
  } else if (assets[key] instanceof Witnet.Radon.RadonRetrieval) {
606
541
  const argsCount = assets[key].argsCount;
607
542
  if (!options?.filter || found) {
608
- console.info(
609
- `${prefix}${color(key)} ${argsCount > 0 ? helpers.colors.green(`(${argsCount} args)`) : ""}`,
610
- );
543
+ console.info(`${prefix}${color(key)} ${argsCount > 0 ? helpers.colors.green(`(${argsCount} args)`) : ""}`);
611
544
  if (isLast) {
612
545
  console.info(`${prefix}`);
613
546
  }
614
547
  }
615
- } else if (
616
- typeof assets[key] === "object" &&
617
- countWitnetArtifacts(assets[key], args, options) > 0
618
- ) {
548
+ } else if (typeof assets[key] === "object" && countWitnetArtifacts(assets[key], args, options) > 0) {
619
549
  console.info(`${indent}${isLast ? "└─ " : "├─ "}${key}`);
620
- traceWitnetArtifacts(
621
- assets[key],
622
- args,
623
- !isLast ? `${indent}│ ` : `${indent} `,
624
- options,
625
- );
550
+ traceWitnetArtifacts(assets[key], args, !isLast ? `${indent}│ ` : `${indent} `, options);
626
551
  }
627
552
  });
628
553
  }
@@ -631,24 +556,12 @@ function traceWitnetRadonReportHeadline(request, options) {
631
556
  const trait = (str) => `${str}${" ".repeat(66 - str.length)}`;
632
557
  const indent = options?.indent ? " ".repeat(options.indent) : "";
633
558
  const resultDataType = `Result<${extractTypeName(request.sources[0]?.script?.outputType.constructor.name)}, RadonError>`;
634
- console.info(
635
- `${indent}╔══════════════════════════════════════════════════════════════════════════════╗`,
636
- );
637
- console.info(
638
- `${indent}║ ${helpers.colors.white(options?.headline)}${" ".repeat(77 - options?.headline.length)}║`,
639
- );
640
- console.info(
641
- `${indent}╠══════════════════════════════════════════════════════════════════════════════╣`,
642
- );
643
- console.info(
644
- `${indent}║ ${helpers.colors.white("RAD hash")}: ${helpers.colors.lgreen(request.radHash)} ║`,
645
- );
646
- console.info(
647
- `${indent}║ RAD size: ${helpers.colors.green(trait(`${helpers.commas(request.weight())} bytes`))} ║`,
648
- );
649
- console.info(
650
- `${indent}║ RAD type: ${helpers.colors.yellow(trait(resultDataType))} ║`,
651
- );
559
+ console.info(`${indent}╔══════════════════════════════════════════════════════════════════════════════╗`);
560
+ console.info(`${indent}║ ${helpers.colors.white(options?.headline)}${" ".repeat(77 - options?.headline.length)}║`);
561
+ console.info(`${indent}╠══════════════════════════════════════════════════════════════════════════════╣`);
562
+ console.info(`${indent}║ ${helpers.colors.white("RAD hash")}: ${helpers.colors.lgreen(request.radHash)} ║`);
563
+ console.info(`${indent}║ RAD size: ${helpers.colors.green(trait(`${helpers.commas(request.weight())} bytes`))} ║`);
564
+ console.info(`${indent}║ RAD type: ${helpers.colors.yellow(trait(resultDataType))} ║`);
652
565
  // if (!options.verbose) {
653
566
  // console.info(`${indent}║ > Radon operators: ${white(trait(commas(request.opsCount())))} ║`)
654
567
  // }
@@ -666,19 +579,13 @@ function traceWitnetRadonReportHeadline(request, options) {
666
579
  }
667
580
 
668
581
  function traceWitnetRadonRequest(request, options) {
669
- const indent = options?.indent
670
- ? " ".repeat(parseInt(options.indent, 10))
671
- : "";
582
+ const indent = options?.indent ? " ".repeat(parseInt(options.indent, 10)) : "";
672
583
  if (options?.json) {
673
- console.info(
674
- JSON.stringify(request.toProtobuf(), null, options?.indent || 0),
675
- );
584
+ console.info(JSON.stringify(request.toProtobuf(), null, options?.indent || 0));
676
585
  } else {
677
586
  if (!options.headline) options.headline = "WITNET DATA REQUEST DISASSEMBLE";
678
587
  traceWitnetRadonReportHeadline(request, options);
679
- console.info(
680
- `${indent}╚══╤═══════════════════════════════════════════════════════════════════════════╝`,
681
- );
588
+ console.info(`${indent}╚══╤═══════════════════════════════════════════════════════════════════════════╝`);
682
589
  if (options?.bytecode) {
683
590
  console.info(request.toBytecode());
684
591
  return;
@@ -689,9 +596,7 @@ function traceWitnetRadonRequest(request, options) {
689
596
  request.sources.forEach((source, sourceIndex) => {
690
597
  const authority =
691
598
  source.authority?.toUpperCase().split(".").slice(-2).join(".") ||
692
- (source.method === Witnet.Radon.retrievals.Methods.RNG
693
- ? "WIT/RNG"
694
- : "");
599
+ (source.method === Witnet.Radon.retrievals.Methods.RNG ? "WIT/RNG" : "");
695
600
  const corner = sourceIndex === request.sources.length - 1 ? "└" : "├";
696
601
  const sep = sourceIndex === request.sources.length - 1 ? " " : "│";
697
602
  console.info(
@@ -708,18 +613,14 @@ function traceWitnetRadonRequest(request, options) {
708
613
  .toUpperCase(),
709
614
  )}`,
710
615
  );
711
- console.info(
712
- `${indent} │ ${sep} > URL query: ${helpers.colors.green(source.url)}`,
713
- );
616
+ console.info(`${indent} │ ${sep} > URL query: ${helpers.colors.green(source.url)}`);
714
617
  if (source?.headers && Object.keys(source.headers).length > 0) {
715
618
  console.info(
716
619
  `${indent} │ ${sep} > HTTP headers: ${helpers.colors.green(JSON.stringify(source.headers))}`,
717
620
  );
718
621
  }
719
622
  if (source?.body) {
720
- console.info(
721
- `${indent} │ ${sep} > HTTP body: ${helpers.colors.green(source.body)}`,
722
- );
623
+ console.info(`${indent} │ ${sep} > HTTP body: ${helpers.colors.green(source.body)}`);
723
624
  }
724
625
  if (source?.script) {
725
626
  // console.log(source.script.toBytecode())
@@ -727,9 +628,7 @@ function traceWitnetRadonRequest(request, options) {
727
628
  console.info(
728
629
  `${indent} │ ${sep} > Radon script: ${helpers.colors.lyellow(
729
630
  "[ ",
730
- )}${helpers.colors.yellow(steps[0][1])}${" ".repeat(
731
- 12 - steps[0][1].length,
732
- )}${helpers.colors.lyellow(
631
+ )}${helpers.colors.yellow(steps[0][1])}${" ".repeat(12 - steps[0][1].length)}${helpers.colors.lyellow(
733
632
  " ]",
734
633
  )} ${helpers.colors.mcyan(steps[0][2])}`,
735
634
  );
@@ -737,21 +636,16 @@ function traceWitnetRadonRequest(request, options) {
737
636
  console.info(
738
637
  `${indent} │ ${sep} ${helpers.colors.lyellow(
739
638
  "[ ",
740
- )}${helpers.colors.yellow(step[1])}${" ".repeat(
741
- 12 - step[1].length,
742
- )}${helpers.colors.lyellow(
639
+ )}${helpers.colors.yellow(step[1])}${" ".repeat(12 - step[1].length)}${helpers.colors.lyellow(
743
640
  " ]",
744
641
  )} ${" ".repeat(2 * step[0])}${helpers.colors.mcyan(step[2])}`,
745
642
  );
746
643
  });
747
- const outputType =
748
- source.script.outputType.constructor.name || "RadonAny";
644
+ const outputType = source.script.outputType.constructor.name || "RadonAny";
749
645
  console.info(
750
646
  `${indent} │ ${sep} ${helpers.colors.lyellow(
751
647
  "[ ",
752
- )}${helpers.colors.yellow(outputType)}${" ".repeat(
753
- 12 - outputType.length,
754
- )}${helpers.colors.lyellow(" ]")}`,
648
+ )}${helpers.colors.yellow(outputType)}${" ".repeat(12 - outputType.length)}${helpers.colors.lyellow(" ]")}`,
755
649
  );
756
650
  }
757
651
  }
@@ -762,36 +656,24 @@ function traceWitnetRadonRequest(request, options) {
762
656
  console.info(`${indent}┌──┴──────────────────┐`);
763
657
  console.info(`${indent}│ ${helpers.colors.white("AGGREGATE SOURCES")} │`);
764
658
  console.info(`${indent}└──┬──────────────────┘`); // ┬
765
- request.sourcesReducer?.filters.forEach((filter) =>
766
- console.info(
767
- `${indent} │ > Radon filter: ${stringifyFilter(filter)}`,
768
- ),
769
- );
770
- console.info(
771
- `${indent} │ > Radon reducer: ${stringifyReducer(request.sourcesReducer)}`,
772
- );
659
+ request.sourcesReducer?.filters.forEach((filter) => {
660
+ console.info(`${indent} │ > Radon filter: ${stringifyFilter(filter)}`);
661
+ });
662
+ console.info(`${indent} │ > Radon reducer: ${stringifyReducer(request.sourcesReducer)}`);
773
663
  console.info(`${indent}┌──┴──────────────────┐`);
774
664
  console.info(`${indent}│ ${helpers.colors.white("WITNESSING TALLY")} │`);
775
665
  console.info(`${indent}└─────────────────────┘`); // ┬
776
- request.witnessReducer?.filters.forEach((filter) =>
777
- console.info(
778
- `${indent} > Radon filter: ${stringifyFilter(filter)}`,
779
- ),
780
- );
781
- console.info(
782
- `${indent} > Radon reducer: ${stringifyReducer(request.witnessReducer)}`,
783
- );
666
+ request.witnessReducer?.filters.forEach((filter) => {
667
+ console.info(`${indent} > Radon filter: ${stringifyFilter(filter)}`);
668
+ });
669
+ console.info(`${indent} > Radon reducer: ${stringifyReducer(request.witnessReducer)}`);
784
670
  }
785
671
  }
786
672
 
787
673
  async function traceWitnetRadonRequestDryRun(request, options) {
788
674
  const bytecode = request.toBytecode();
789
675
  let report = await helpers
790
- .toolkitRun(options, [
791
- "try-data-request",
792
- "--hex",
793
- bytecode.startsWith("0x") ? bytecode.slice(2) : bytecode,
794
- ])
676
+ .toolkitRun(options, ["try-data-request", "--hex", bytecode.startsWith("0x") ? bytecode.slice(2) : bytecode])
795
677
  .catch((err) => {
796
678
  let errorMessage = err.message.split("\n").slice(1).join("\n").trim();
797
679
  const errorRegex = /.*^error: (?<message>.*)$.*/gm;
@@ -825,8 +707,7 @@ async function traceWitnetRadonRequestDryRun(request, options) {
825
707
  resultSize = 1;
826
708
  break;
827
709
  case "RadonBytes":
828
- resultSize =
829
- utils.cbor.encode(Uint8Array.from(resultValue)).byteLength - 2;
710
+ resultSize = utils.cbor.encode(Uint8Array.from(resultValue)).byteLength - 2;
830
711
  break;
831
712
  case "RadonInteger":
832
713
  case "RadonFloat":
@@ -841,46 +722,25 @@ async function traceWitnetRadonRequestDryRun(request, options) {
841
722
  }
842
723
  if (options?.json) {
843
724
  if (options?.verbose) {
844
- console.info(
845
- JSON.stringify(
846
- report,
847
- null,
848
- options?.indent ? " ".repeat(options.indent) : "",
849
- ),
850
- );
725
+ console.info(JSON.stringify(report, null, options?.indent ? " ".repeat(options.indent) : ""));
851
726
  } else {
852
727
  result[resultType] = resultValue;
853
- console.info(
854
- JSON.stringify(
855
- result,
856
- null,
857
- options?.indent ? " ".repeat(options.indent) : "",
858
- ),
859
- );
728
+ console.info(JSON.stringify(result, null, options?.indent ? " ".repeat(options.indent) : ""));
860
729
  }
861
730
  return;
862
731
  }
863
- if (!options.headline)
864
- options.headline = "WITNET DATA REQUEST DRY-RUN REPORT";
732
+ if (!options.headline) options.headline = "WITNET DATA REQUEST DRY-RUN REPORT";
865
733
  traceWitnetRadonReportHeadline(request, options);
866
734
  const indent = options?.indent ? " ".repeat(options.indent) : "";
867
- console.info(
868
- `${indent}╚══╤═══════════════════════════════════════════════════════════════════════════╝`,
869
- );
735
+ console.info(`${indent}╚══╤═══════════════════════════════════════════════════════════════════════════╝`);
870
736
  let execTimeMs = report.retrieve
871
- ?.map(
872
- (retrieval) =>
873
- (retrieval?.running_time.secs || 0) +
874
- (retrieval?.running_time.nanos || 0) / 1000,
875
- )
737
+ ?.map((retrieval) => (retrieval?.running_time.secs || 0) + (retrieval?.running_time.nanos || 0) / 1000)
876
738
  .reduce((sum, secs) => sum + secs);
877
739
  execTimeMs = `${Math.round(execTimeMs)} ms`;
878
740
  let flexbar = "─".repeat(17);
879
741
  let flexspc = " ".repeat(flexbar.length + 12);
880
742
  console.info(`${indent}┌──┴─────────────────────────────${flexbar}──────┐`);
881
- console.info(
882
- `${indent}│ ${helpers.colors.white("Data providers")} ${flexspc} │`,
883
- ); // ├ ┤
743
+ console.info(`${indent}│ ${helpers.colors.white("Data providers")} ${flexspc} │`); // ├ ┤
884
744
  console.info(`${indent}├────────────────────────────────${flexbar}──────┤`);
885
745
  console.info(
886
746
  `${indent}│ Execution time: ${helpers.colors.green(execTimeMs)} ${" ".repeat(flexbar.length + 19 - execTimeMs.length)} │`,
@@ -901,21 +761,14 @@ async function traceWitnetRadonRequestDryRun(request, options) {
901
761
  : helpers.colors.green;
902
762
  if (options?.verbose) {
903
763
  console.info(
904
- `${indent} │ ${corner}─ ${helpers.colors.white(
905
- "[ ",
906
- )}${helpers.colors.white(
764
+ `${indent} │ ${corner}─ ${helpers.colors.white("[ ")}${helpers.colors.white(
907
765
  `Data Source #${sourceIndex + 1}`,
908
- )} ${" ".repeat(3 - sourceIndex.toString().length)}${color(
909
- authority,
910
- )} ${helpers.colors.white("]")}`,
766
+ )} ${" ".repeat(3 - sourceIndex.toString().length)}${color(authority)} ${helpers.colors.white("]")}`,
911
767
  );
912
768
  } else {
913
769
  console.info(`${indent} │ ${corner}─ [ ${color(authority)} ]`);
914
770
  }
915
- if (
916
- source.method !== Witnet.Radon.retrievals.Methods.RNG &&
917
- options?.verbose
918
- ) {
771
+ if (source.method !== Witnet.Radon.retrievals.Methods.RNG && options?.verbose) {
919
772
  console.info(
920
773
  `${indent} │ ${sep} > Request: ${helpers.colors.mgreen(
921
774
  Witnet.Radon.retrievals.Methods[source.method]
@@ -924,31 +777,24 @@ async function traceWitnetRadonRequestDryRun(request, options) {
924
777
  .toUpperCase(),
925
778
  )}`,
926
779
  );
927
- console.info(
928
- `${indent} │ ${sep} > URL query: ${helpers.colors.green(source.url)}`,
929
- );
780
+ console.info(`${indent} │ ${sep} > URL query: ${helpers.colors.green(source.url)}`);
930
781
  if (source?.headers && Object.keys(source.headers).length > 0) {
931
782
  console.info(
932
783
  `${indent} │ ${sep} > HTTP headers: ${helpers.colors.green(JSON.stringify(source.headers))}`,
933
784
  );
934
785
  }
935
786
  if (source?.body) {
936
- console.info(
937
- `${indent} │ ${sep} > HTTP body: ${helpers.colors.green(source.body)}`,
938
- );
787
+ console.info(`${indent} │ ${sep} > HTTP body: ${helpers.colors.green(source.body)}`);
939
788
  }
940
789
  const printData = (headline, data, color) => {
941
790
  const type = Object.keys(data)[0];
942
791
  data =
943
- (typeof data[type] === "object" ||
944
- typeof data[type] === "boolean" ||
945
- Array.isArray(data[type])
792
+ (typeof data[type] === "object" || typeof data[type] === "boolean" || Array.isArray(data[type])
946
793
  ? JSON.stringify(data[type])
947
794
  : data[type]) || "";
948
795
  const lines = data.match(/.{1,96}/g)?.slice(0, 256) || [""];
949
796
  if (lines.length === 256) lines[255] += "...";
950
- const typeColor =
951
- type === "RadonError" ? helpers.colors.red : helpers.colors.yellow;
797
+ const typeColor = type === "RadonError" ? helpers.colors.red : helpers.colors.yellow;
952
798
  const lineColor = type === "RadonError" ? helpers.colors.gray : color;
953
799
  console.info(
954
800
  `${indent} │ ${sep} > ${headline}${" ".repeat(15 - headline.length)} \x1b[1;m${typeColor(
@@ -958,23 +804,13 @@ async function traceWitnetRadonRequestDryRun(request, options) {
958
804
  )}\x1b[1;m${typeColor(" ]")}\x1b[0m ${lineColor(lines[0])}`,
959
805
  );
960
806
  lines.slice(1).forEach((line) => {
961
- console.info(
962
- `${indent} │ ${sep} ${lineColor(line)}`,
963
- );
807
+ console.info(`${indent} │ ${sep} ${lineColor(line)}`);
964
808
  });
965
809
  };
966
810
  if (report?.retrieve[sourceIndex]?.partial_results) {
967
- printData(
968
- "HTTP response:",
969
- report?.retrieve[sourceIndex]?.partial_results[0],
970
- helpers.colors.cyan,
971
- );
811
+ printData("HTTP response:", report?.retrieve[sourceIndex]?.partial_results[0], helpers.colors.cyan);
972
812
  }
973
- printData(
974
- "Radon result:",
975
- report?.retrieve[sourceIndex]?.result,
976
- helpers.colors.mcyan,
977
- );
813
+ printData("Radon result:", report?.retrieve[sourceIndex]?.result, helpers.colors.mcyan);
978
814
  }
979
815
  if (options?.verbose && sourceIndex < request.sources.length - 1) {
980
816
  console.info(`${indent} │ │`);
@@ -983,17 +819,13 @@ async function traceWitnetRadonRequestDryRun(request, options) {
983
819
  flexbar = "─".repeat(24);
984
820
  flexspc = " ".repeat(36);
985
821
  console.info(`${indent}┌──┴───────────────────────────${flexbar}─┐`);
986
- console.info(
987
- `${indent}│ ${helpers.colors.white("Aggregated result")}${flexspc} │`,
988
- ); // ├ ┤
822
+ console.info(`${indent}│ ${helpers.colors.white("Aggregated result")}${flexspc} │`); // ├ ┤
989
823
  console.info(`${indent}├──────────────────────────────${flexbar}─┤`);
990
824
  if (options?.verbose) {
991
825
  let partial_index = 0;
992
826
  const partial_results = report.sourcesReducer?.partial_results;
993
827
  request.sourcesReducer?.filters.forEach((filter) => {
994
- const color = partial_results?.[partial_index]?.RadonArray
995
- ? helpers.colors.mcyan
996
- : helpers.colors.gray;
828
+ const color = partial_results?.[partial_index]?.RadonArray ? helpers.colors.mcyan : helpers.colors.gray;
997
829
  const items = partial_results?.[partial_index]?.RadonArray
998
830
  ? ` over ${partial_results[partial_index]?.RadonArray.length} sources`
999
831
  : "";
@@ -1005,9 +837,7 @@ async function traceWitnetRadonRequestDryRun(request, options) {
1005
837
  )}${" ".repeat(flexbar.length + 22 - filter.length - items.length)} │`,
1006
838
  );
1007
839
  });
1008
- const color = partial_results?.[partial_index]?.RadonArray
1009
- ? helpers.colors.mcyan
1010
- : helpers.colors.gray;
840
+ const color = partial_results?.[partial_index]?.RadonArray ? helpers.colors.mcyan : helpers.colors.gray;
1011
841
  const items = partial_results?.[partial_index]?.RadonArray
1012
842
  ? ` over ${partial_results[partial_index]?.RadonArray.length} sources`
1013
843
  : "";
@@ -1042,20 +872,12 @@ async function traceWitnetRadonRequestDryRun(request, options) {
1042
872
  console.info(
1043
873
  `${indent} ${helpers.colors.myellow(
1044
874
  `[ ${type}${" ".repeat(7 - type.length)} ]`,
1045
- )} ${helpers.colors.green(key)}${" ".repeat(
1046
- width - 12 - key.length,
1047
- )}`,
875
+ )} ${helpers.colors.green(key)}${" ".repeat(width - 12 - key.length)}`,
1048
876
  );
1049
877
  }
1050
- Object.entries(value).forEach(([key, value]) =>
1051
- printMapItem(
1052
- indent,
1053
- width,
1054
- type === "Map" ? key : null,
1055
- helpers.unescapeSlashes(value),
1056
- `${indent2} `,
1057
- ),
1058
- );
878
+ Object.entries(value).forEach(([key, value]) => {
879
+ printMapItem(indent, width, type === "Map" ? key : null, helpers.unescapeSlashes(value), `${indent2} `);
880
+ });
1059
881
  } else {
1060
882
  if (key.length > width - 12) {
1061
883
  console.info(
@@ -1084,17 +906,15 @@ async function traceWitnetRadonRequestDryRun(request, options) {
1084
906
  const printResult = (indent, width, resultType, resultValue) => {
1085
907
  resultType = extractTypeName(resultType);
1086
908
  resultValue =
1087
- typeof resultValue === "object" || Array.isArray(resultValue)
1088
- ? JSON.stringify(resultValue)
1089
- : resultValue;
909
+ typeof resultValue === "object" || Array.isArray(resultValue) ? JSON.stringify(resultValue) : resultValue;
1090
910
  if (["Map", "Array"].includes(resultType)) {
1091
911
  console.info(
1092
912
  `${indent} └─ ${helpers.colors.lyellow(`[ ${resultType}${" ".repeat(7 - resultType.length)} ]`)}`,
1093
913
  );
1094
914
  const obj = JSON.parse(resultValue);
1095
- Object.entries(obj).forEach(([key, value]) =>
1096
- printMapItem(indent, width, resultType === "Map" ? key : null, value),
1097
- );
915
+ Object.entries(obj).forEach(([key, value]) => {
916
+ printMapItem(indent, width, resultType === "Map" ? key : null, value);
917
+ });
1098
918
  } else {
1099
919
  if (resultType === "Bytes") {
1100
920
  resultValue = JSON.parse(resultValue)
@@ -1103,10 +923,7 @@ async function traceWitnetRadonRequestDryRun(request, options) {
1103
923
  } else if (resultType === "Boolean") {
1104
924
  resultValue = JSON.stringify(resultValue);
1105
925
  }
1106
- const color =
1107
- resultType.indexOf("Error") > -1
1108
- ? helpers.colors.gray
1109
- : helpers.colors.lcyan;
926
+ const color = resultType.indexOf("Error") > -1 ? helpers.colors.gray : helpers.colors.lcyan;
1110
927
  const typeText =
1111
928
  resultType.indexOf("Error") > -1
1112
929
  ? "\x1b[1;98;41m Error \x1b[0m"
@@ -1114,9 +931,7 @@ async function traceWitnetRadonRequestDryRun(request, options) {
1114
931
  const lines = resultValue.match(/.{1,96}/g)?.slice(0, 256) || [""];
1115
932
  console.info(`${indent} └─ ${typeText} ${color(lines[0])}`);
1116
933
  lines.slice(1).forEach((line) => {
1117
- console.info(
1118
- `${indent} ${" ".repeat(resultType.length)}${color(line)}`,
1119
- );
934
+ console.info(`${indent} ${" ".repeat(resultType.length)}${color(line)}`);
1120
935
  });
1121
936
  }
1122
937
  };