@witnet/sdk 3.0.0 → 3.0.3
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.
- package/dist/package.json +1 -1
- package/dist/src/bin/helpers.d.ts +1 -0
- package/dist/src/bin/helpers.d.ts.map +1 -1
- package/dist/src/bin/helpers.js +10 -1
- package/dist/src/lib/crypto/wallet.d.ts +1 -1
- package/dist/src/lib/crypto/wallet.d.ts.map +1 -1
- package/dist/src/lib/crypto/wallet.js +2 -2
- package/dist/src/lib/radon/filters.d.ts.map +1 -1
- package/dist/src/lib/radon/filters.js +7 -1
- package/dist/src/lib/radon/utils.d.ts.map +1 -1
- package/dist/src/lib/radon/utils.js +6 -4
- package/package.json +1 -1
- package/src/bin/cli/inspect.js +7 -7
- package/src/bin/cli/radon.js +96 -144
- package/src/bin/helpers.js +10 -0
- package/src/bin/index.js +3 -2
package/src/bin/cli/radon.js
CHANGED
|
@@ -14,146 +14,99 @@ 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 = process.env.WITNET_SDK_RADON_ASSETS_PATH || "../../../../../witnet/assets";
|
|
18
|
-
|
|
19
17
|
/// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
20
18
|
/// CLI SUBMODULE CONSTANTS ===========================================================================================
|
|
21
19
|
|
|
22
|
-
const
|
|
20
|
+
const __dirname = helpers.searchWorkspace();
|
|
21
|
+
const isModuleInitialized = __dirname !== path.dirname(__dirname) && fs.existsSync(`${__dirname}/package.json`);
|
|
22
|
+
const WITNET_ASSETS_PATH = process.env.WITNET_SDK_RADON_ASSETS_PATH || `${__dirname}/witnet/assets`;
|
|
23
23
|
|
|
24
24
|
export const flags = {
|
|
25
|
-
|
|
26
|
-
hint: "
|
|
25
|
+
package: {
|
|
26
|
+
hint: "Imported package where to fetch Radon assets from (supersedes --legacy).",
|
|
27
27
|
param: "NPM_PACKAGE",
|
|
28
28
|
},
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
export const router =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
hint: "Restrict output to name-matching assets.",
|
|
39
|
-
},
|
|
40
|
-
legacy: {
|
|
41
|
-
hint: "List only those declared in witnet/assets folder.",
|
|
42
|
-
},
|
|
43
|
-
modals: {
|
|
44
|
-
hint: "Restrict output to Radon modals.",
|
|
45
|
-
},
|
|
46
|
-
requests: {
|
|
47
|
-
hint: "Restrict output to Radon requests.",
|
|
48
|
-
},
|
|
49
|
-
templates: {
|
|
50
|
-
hint: "Restrict output to Radon templates.",
|
|
51
|
-
},
|
|
52
|
-
},
|
|
31
|
+
export const router = {
|
|
32
|
+
assets: {
|
|
33
|
+
hint: "List available Witnet Radon assets.",
|
|
34
|
+
params: "[RADON_ASSETS ...]",
|
|
35
|
+
options: {
|
|
36
|
+
filter: {
|
|
37
|
+
hint: "Restrict output to name-matching assets.",
|
|
53
38
|
},
|
|
54
|
-
|
|
55
|
-
hint: "
|
|
56
|
-
params: [],
|
|
57
|
-
options: {},
|
|
39
|
+
legacy: {
|
|
40
|
+
hint: "List only those declared within the ./witnet/assets subfolder.",
|
|
58
41
|
},
|
|
59
|
-
|
|
60
|
-
hint: "
|
|
61
|
-
params: ["RAD_BYTECODE | RAD_HASH | RADON_ASSET"],
|
|
62
|
-
options: {
|
|
63
|
-
bytecode: {
|
|
64
|
-
hint: "Outputs RAD bytecode as hex string (supersedes --json).",
|
|
65
|
-
},
|
|
66
|
-
json: {
|
|
67
|
-
hint: "Outputs data in JSON format.",
|
|
68
|
-
},
|
|
69
|
-
headline: {
|
|
70
|
-
hint: "Settles output report headline.",
|
|
71
|
-
param: ":string",
|
|
72
|
-
},
|
|
73
|
-
indent: {
|
|
74
|
-
hint: "Prefixes given number of white spaces for every output line.",
|
|
75
|
-
param: ":number",
|
|
76
|
-
},
|
|
77
|
-
},
|
|
42
|
+
modals: {
|
|
43
|
+
hint: "Restrict output to Radon modals.",
|
|
78
44
|
},
|
|
79
|
-
|
|
80
|
-
hint: "
|
|
81
|
-
params: ["RAD_BYTECODE | RAD_HASH | RADON_ASSET"],
|
|
82
|
-
options: {
|
|
83
|
-
default: {
|
|
84
|
-
hint: "Use default sample parameters on parametrized Radon assets.",
|
|
85
|
-
},
|
|
86
|
-
json: {
|
|
87
|
-
hint: "Outputs data in JSON format.",
|
|
88
|
-
},
|
|
89
|
-
headline: {
|
|
90
|
-
hint: "Settles output report headline.",
|
|
91
|
-
param: ":string",
|
|
92
|
-
},
|
|
93
|
-
indent: {
|
|
94
|
-
hint: "Prefixes given number of white spaces for every output line.",
|
|
95
|
-
param: ":number",
|
|
96
|
-
},
|
|
97
|
-
verbose: {
|
|
98
|
-
hint: "Outputs detailed dry-run report.",
|
|
99
|
-
},
|
|
100
|
-
},
|
|
45
|
+
requests: {
|
|
46
|
+
hint: "Restrict output to Radon requests.",
|
|
101
47
|
},
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
assets: {
|
|
105
|
-
hint: "List available Witnet Radon assets.",
|
|
106
|
-
params: "[RADON_ASSETS ...]",
|
|
107
|
-
options: {
|
|
108
|
-
filter: {
|
|
109
|
-
hint: "Restrict output to name-matching assets.",
|
|
110
|
-
},
|
|
111
|
-
legacy: {
|
|
112
|
-
hint: "List only those declared in witnet/assets folder.",
|
|
113
|
-
},
|
|
114
|
-
},
|
|
48
|
+
templates: {
|
|
49
|
+
hint: "Restrict output to Radon templates.",
|
|
115
50
|
},
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
hint: "Settles output report headline.",
|
|
125
|
-
param: ":string",
|
|
126
|
-
},
|
|
127
|
-
indent: {
|
|
128
|
-
hint: "Prefixes given number of white spaces for every output line.",
|
|
129
|
-
param: ":number",
|
|
130
|
-
},
|
|
131
|
-
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
decode: {
|
|
54
|
+
hint: "Break down specs of one or more Radon assets.",
|
|
55
|
+
params: ["RAD_BYTECODE | RAD_HASH | RADON_ASSET"],
|
|
56
|
+
options: {
|
|
57
|
+
bytecode: {
|
|
58
|
+
hint: "Outputs RAD bytecode as hex string (supersedes --json).",
|
|
132
59
|
},
|
|
133
|
-
|
|
134
|
-
hint: "
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
60
|
+
json: {
|
|
61
|
+
hint: "Outputs data in JSON format.",
|
|
62
|
+
},
|
|
63
|
+
headline: {
|
|
64
|
+
hint: "Settles output report headline.",
|
|
65
|
+
param: ":string",
|
|
66
|
+
},
|
|
67
|
+
indent: {
|
|
68
|
+
hint: "Prefixes given number of white spaces for every output line.",
|
|
69
|
+
param: ":number",
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
"dry-run": {
|
|
74
|
+
hint: "Simulate resolution of one or more Radon assets, as if solved by the Wit/Oracle.",
|
|
75
|
+
params: ["RAD_BYTECODE | RAD_HASH | RADON_ASSET"],
|
|
76
|
+
options: {
|
|
77
|
+
default: {
|
|
78
|
+
hint: "Use default sample parameters on parametrized Radon assets.",
|
|
152
79
|
},
|
|
153
|
-
|
|
154
|
-
hint: "
|
|
80
|
+
json: {
|
|
81
|
+
hint: "Outputs data in JSON format.",
|
|
155
82
|
},
|
|
156
|
-
|
|
83
|
+
headline: {
|
|
84
|
+
hint: "Settles output report headline.",
|
|
85
|
+
param: ":string",
|
|
86
|
+
},
|
|
87
|
+
indent: {
|
|
88
|
+
hint: "Prefixes given number of white spaces for every output line.",
|
|
89
|
+
param: ":number",
|
|
90
|
+
},
|
|
91
|
+
verbose: {
|
|
92
|
+
hint: "Outputs detailed dry-run report.",
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
...(isModuleInitialized
|
|
97
|
+
? {
|
|
98
|
+
check: {
|
|
99
|
+
hint: "Check correctness of Witnet Radon artifacts declared in witnet/assets folder.",
|
|
100
|
+
params: [],
|
|
101
|
+
options: {},
|
|
102
|
+
},
|
|
103
|
+
}
|
|
104
|
+
: {
|
|
105
|
+
init: {
|
|
106
|
+
hint: "Initialize a Witnet Radon workspace within the current folder.",
|
|
107
|
+
},
|
|
108
|
+
}),
|
|
109
|
+
};
|
|
157
110
|
|
|
158
111
|
export const subcommands = {
|
|
159
112
|
assets,
|
|
@@ -174,16 +127,16 @@ async function init() {
|
|
|
174
127
|
fs.cpSync("node_modules/@witnet/sdk/.env_witnet", ".env_witnet");
|
|
175
128
|
}
|
|
176
129
|
if (!fs.existsSync("./witnet/assets/index.js")) {
|
|
177
|
-
fs.cpSync("node_modules/@witnet/sdk/witnet/assets/_index.
|
|
130
|
+
fs.cpSync("node_modules/@witnet/sdk/witnet/assets/_index.cjs", "./witnet/assets/index.cjs");
|
|
178
131
|
}
|
|
179
132
|
if (!fs.existsSync("./witnet/assets/requests.js")) {
|
|
180
|
-
fs.cpSync("node_modules/@witnet/sdk/witnet/assets/_requests.
|
|
133
|
+
fs.cpSync("node_modules/@witnet/sdk/witnet/assets/_requests.cjs", "./witnet/assets/requests.cjs");
|
|
181
134
|
}
|
|
182
135
|
if (!fs.existsSync("./witnet/assets/sources.js")) {
|
|
183
|
-
fs.cpSync("node_modules/@witnet/sdk/witnet/assets/_sources.
|
|
136
|
+
fs.cpSync("node_modules/@witnet/sdk/witnet/assets/_sources.cjs", "./witnet/assets/sources.cjs");
|
|
184
137
|
}
|
|
185
138
|
if (!fs.existsSync("./witnet/assets/templates.js")) {
|
|
186
|
-
fs.cpSync("node_modules/@witnet/sdk/witnet/assets/_templates.
|
|
139
|
+
fs.cpSync("node_modules/@witnet/sdk/witnet/assets/_templates.cjs", "./witnet/assets/templates.cjs");
|
|
187
140
|
}
|
|
188
141
|
console.info(`Initialized Witnet Radon workspace at folder ${process.cwd()}/witnet/assets`);
|
|
189
142
|
}
|
|
@@ -208,9 +161,8 @@ async function assets(options = {}, [...patterns]) {
|
|
|
208
161
|
|
|
209
162
|
async function check() {
|
|
210
163
|
if (!isModuleInitialized) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
);
|
|
164
|
+
console.error(`Sorry, no Witnet workspace was initialized yet.`);
|
|
165
|
+
return;
|
|
214
166
|
}
|
|
215
167
|
try {
|
|
216
168
|
const assets = loadAssets({ legacy: true });
|
|
@@ -421,7 +373,9 @@ const stringifyReducer = (x, c) => {
|
|
|
421
373
|
|
|
422
374
|
export function loadAssets(options) {
|
|
423
375
|
const assets = options?.legacy ? {} : legacy;
|
|
424
|
-
return
|
|
376
|
+
return fs.existsSync(`${WITNET_ASSETS_PATH}/index.cjs`)
|
|
377
|
+
? merge(assets, require(`${WITNET_ASSETS_PATH}/index.cjs`))
|
|
378
|
+
: assets;
|
|
425
379
|
}
|
|
426
380
|
|
|
427
381
|
function flattenRadonArtifacts(tree, headers) {
|
|
@@ -587,7 +541,8 @@ function traceWitnetRadonRequest(request, options) {
|
|
|
587
541
|
traceWitnetRadonReportHeadline(request, options);
|
|
588
542
|
console.info(`${indent}╚══╤═══════════════════════════════════════════════════════════════════════════╝`);
|
|
589
543
|
if (options?.bytecode) {
|
|
590
|
-
console.info(
|
|
544
|
+
console.info(`${indent} v`);
|
|
545
|
+
console.info(helpers.colors.gray(request.toBytecode()));
|
|
591
546
|
return;
|
|
592
547
|
}
|
|
593
548
|
console.info(`${indent}┌──┴─────────────────┐`);
|
|
@@ -623,16 +578,11 @@ function traceWitnetRadonRequest(request, options) {
|
|
|
623
578
|
console.info(`${indent} │ ${sep} > HTTP body: ${helpers.colors.green(source.body)}`);
|
|
624
579
|
}
|
|
625
580
|
if (source?.script) {
|
|
626
|
-
// console.log(source.script.toBytecode())
|
|
627
581
|
const steps = source.script.disect();
|
|
628
582
|
console.info(
|
|
629
|
-
`${indent} │ ${sep} > Radon script: ${helpers.colors.
|
|
630
|
-
"[ ",
|
|
631
|
-
)}${helpers.colors.yellow(steps[0][1])}${" ".repeat(12 - steps[0][1].length)}${helpers.colors.lyellow(
|
|
632
|
-
" ]",
|
|
633
|
-
)} ${helpers.colors.mcyan(steps[0][2])}`,
|
|
583
|
+
`${indent} │ ${sep} > Radon script: [ ${helpers.colors.gray(source.script.toBytecode())} ]`,
|
|
634
584
|
);
|
|
635
|
-
steps.
|
|
585
|
+
steps.forEach((step) => {
|
|
636
586
|
console.info(
|
|
637
587
|
`${indent} │ ${sep} ${helpers.colors.lyellow(
|
|
638
588
|
"[ ",
|
|
@@ -733,10 +683,12 @@ async function traceWitnetRadonRequestDryRun(request, options) {
|
|
|
733
683
|
traceWitnetRadonReportHeadline(request, options);
|
|
734
684
|
const indent = options?.indent ? " ".repeat(options.indent) : "";
|
|
735
685
|
console.info(`${indent}╚══╤═══════════════════════════════════════════════════════════════════════════╝`);
|
|
736
|
-
let execTimeMs =
|
|
737
|
-
?.map(
|
|
738
|
-
|
|
739
|
-
|
|
686
|
+
let execTimeMs = Math.max(
|
|
687
|
+
...(report.retrieve?.map(
|
|
688
|
+
(retrieval) => (retrieval?.running_time.secs || 0) * 1e3 + (retrieval?.running_time.nanos || 0) / 1e6,
|
|
689
|
+
) ?? 0),
|
|
690
|
+
);
|
|
691
|
+
execTimeMs = `${helpers.commas(Math.round(execTimeMs))} ms`;
|
|
740
692
|
let flexbar = "─".repeat(17);
|
|
741
693
|
let flexspc = " ".repeat(flexbar.length + 12);
|
|
742
694
|
console.info(`${indent}┌──┴─────────────────────────────${flexbar}──────┐`);
|
|
@@ -850,7 +802,7 @@ async function traceWitnetRadonRequestDryRun(request, options) {
|
|
|
850
802
|
}
|
|
851
803
|
if (resultSize) {
|
|
852
804
|
console.info(
|
|
853
|
-
`${indent}│
|
|
805
|
+
`${indent}│ Encoded size: ${helpers.colors.cyan(
|
|
854
806
|
`${resultSize} bytes`,
|
|
855
807
|
)}${" ".repeat(flexbar.length + 7 - resultSize.toString().length)} │`,
|
|
856
808
|
);
|
package/src/bin/helpers.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { exec } from "node:child_process";
|
|
2
|
+
import fs from "node:fs";
|
|
2
3
|
import { createRequire } from "node:module";
|
|
3
4
|
import * as net from "node:net";
|
|
4
5
|
import * as os from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
5
7
|
import * as readline from "node:readline";
|
|
6
8
|
import moment from "moment";
|
|
7
9
|
|
|
@@ -595,6 +597,14 @@ export function prompter(promise) {
|
|
|
595
597
|
});
|
|
596
598
|
}
|
|
597
599
|
|
|
600
|
+
export function searchWorkspace() {
|
|
601
|
+
let workspace = path.normalize(process.cwd());
|
|
602
|
+
while (!fs.existsSync(`${workspace}/witnet/assets`) && path.dirname(workspace) !== workspace) {
|
|
603
|
+
workspace = path.dirname(workspace);
|
|
604
|
+
}
|
|
605
|
+
return workspace;
|
|
606
|
+
}
|
|
607
|
+
|
|
598
608
|
export function traceChecklists(checklists) {
|
|
599
609
|
if (checklists && Object.keys(checklists).length > 0) {
|
|
600
610
|
const headlines = ["NODES", ...Object.keys(checklists).map((key) => `:${key}`)];
|
package/src/bin/index.js
CHANGED
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
|
|
29
29
|
const __dirname = import.meta.dirname;
|
|
30
30
|
|
|
31
|
-
const version = "2.0.
|
|
31
|
+
const version = "2.0.23";
|
|
32
32
|
const toolkitDownloadUrlBase = `https://github.com/witnet/witnet-rust/releases/download/${version}/`;
|
|
33
33
|
const toolkitDownloadNames = {
|
|
34
34
|
win32: (arch) => `witnet_toolkit-${arch}-pc-windows-msvc.exe`,
|
|
@@ -274,10 +274,11 @@ async function main() {
|
|
|
274
274
|
}
|
|
275
275
|
} else {
|
|
276
276
|
showUsage(cmd, module);
|
|
277
|
+
if (args?.[0]) console.error(colors.red(`\nInvalid subcommand: ${colors.mred(args[0])}`));
|
|
277
278
|
}
|
|
278
279
|
process.exit(0);
|
|
279
280
|
} catch (e) {
|
|
280
|
-
console.error(`EXCEPTION:\n${e}\n`);
|
|
281
|
+
console.error(colors.red(`EXCEPTION:\n${e}\n`));
|
|
281
282
|
}
|
|
282
283
|
}
|
|
283
284
|
console.info("USAGE:");
|