@witnet/sdk 1.2.7 → 3.0.2
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/.env_witnet +18 -18
- package/LICENSE +21 -21
- package/README.md +116 -116
- package/dist/package.json +14 -3
- 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 +31 -54
- package/dist/src/lib/crypto/account.d.ts.map +1 -1
- package/dist/src/lib/crypto/account.js +3 -9
- package/dist/src/lib/crypto/coinbase.d.ts.map +1 -1
- package/dist/src/lib/crypto/coinbase.js +2 -2
- package/dist/src/lib/crypto/interfaces.d.ts.map +1 -1
- package/dist/src/lib/crypto/interfaces.js +1 -1
- package/dist/src/lib/crypto/payloads/DataRequestPayload.d.ts +4 -6
- package/dist/src/lib/crypto/payloads/DataRequestPayload.d.ts.map +1 -1
- package/dist/src/lib/crypto/payloads/DataRequestPayload.js +20 -71
- package/dist/src/lib/crypto/payloads/StakePayload.d.ts.map +1 -1
- package/dist/src/lib/crypto/payloads/StakePayload.js +4 -9
- package/dist/src/lib/crypto/payloads/UnstakePayload.d.ts.map +1 -1
- package/dist/src/lib/crypto/payloads/UnstakePayload.js +4 -7
- package/dist/src/lib/crypto/payloads/ValueTransferPayload.d.ts.map +1 -1
- package/dist/src/lib/crypto/payloads/ValueTransferPayload.js +4 -9
- package/dist/src/lib/crypto/payloads.d.ts.map +1 -1
- package/dist/src/lib/crypto/payloads.js +6 -13
- package/dist/src/lib/crypto/signer.d.ts.map +1 -1
- package/dist/src/lib/crypto/signer.js +2 -2
- package/dist/src/lib/crypto/transmitters/DataRequests.d.ts.map +1 -1
- package/dist/src/lib/crypto/transmitters/DataRequests.js +2 -2
- package/dist/src/lib/crypto/transmitters/StakeDeposits.d.ts.map +1 -1
- package/dist/src/lib/crypto/transmitters/StakeDeposits.js +2 -2
- package/dist/src/lib/crypto/transmitters/StakeWithdrawals.d.ts.map +1 -1
- package/dist/src/lib/crypto/transmitters/StakeWithdrawals.js +2 -2
- package/dist/src/lib/crypto/transmitters/ValueTransfers.d.ts.map +1 -1
- package/dist/src/lib/crypto/transmitters/ValueTransfers.js +2 -2
- package/dist/src/lib/crypto/transmitters.d.ts.map +1 -1
- package/dist/src/lib/crypto/transmitters.js +22 -31
- package/dist/src/lib/crypto/types.d.ts.map +1 -1
- package/dist/src/lib/crypto/types.js +6 -13
- package/dist/src/lib/crypto/utils.d.ts.map +1 -1
- package/dist/src/lib/crypto/utils.js +5 -9
- package/dist/src/lib/crypto/wallet.d.ts.map +1 -1
- package/dist/src/lib/crypto/wallet.js +9 -23
- package/dist/src/lib/radon/ccdr/eth.d.ts.map +1 -1
- package/dist/src/lib/radon/ccdr/eth.js +12 -32
- package/dist/src/lib/radon/ccdr/wit.d.ts.map +1 -1
- package/dist/src/lib/radon/ccdr/wit.js +3 -6
- package/dist/src/lib/radon/index.d.ts.map +1 -1
- package/dist/src/lib/radon/index.js +18 -41
- package/dist/src/lib/radon/reducers.js +2 -2
- package/dist/src/lib/radon/types.d.ts.map +1 -1
- package/dist/src/lib/radon/types.js +6 -32
- package/dist/src/lib/radon/utils.d.ts +1 -1
- package/dist/src/lib/radon/utils.d.ts.map +1 -1
- package/dist/src/lib/radon/utils.js +8 -9
- package/dist/src/lib/rest/kermit.d.ts.map +1 -1
- package/dist/src/lib/rest/kermit.js +1 -1
- package/dist/src/lib/rpc/nodes.d.ts.map +1 -1
- package/dist/src/lib/rpc/nodes.js +8 -28
- package/dist/src/lib/rpc/provider.d.ts.map +1 -1
- package/dist/src/lib/rpc/provider.js +16 -38
- package/dist/src/lib/rpc/types.d.ts.map +1 -1
- package/dist/src/lib/rpc/types.js +1 -1
- package/dist/src/lib/utils.d.ts.map +1 -1
- package/dist/src/lib/utils.js +2 -5
- package/dist/witnet/assets/index.cjs +1 -1
- package/dist/witnet/assets/modals/index.cjs +1 -1
- package/dist/witnet/assets/modals/web3/eth.cjs +2 -2
- package/dist/witnet/assets/modals/web3/ipfs.cjs +2 -2
- package/dist/witnet/assets/modals/web3/wit.cjs +4 -11
- package/dist/witnet/assets/requests.cjs +3 -11
- package/package.json +7 -3
- package/src/bin/bots/watcher.cjs +27 -93
- package/src/bin/cli/inspect.js +30 -119
- package/src/bin/cli/network.js +46 -202
- package/src/bin/cli/nodes.js +12 -58
- package/src/bin/cli/radon.js +161 -396
- package/src/bin/cli/wallet.js +69 -241
- package/src/bin/helpers.js +66 -162
- package/src/bin/index.js +23 -52
- package/witnet/assets/_index.cjs +5 -5
- package/witnet/assets/_requests.cjs +25 -25
- package/witnet/assets/_sources.cjs +36 -36
- package/witnet/assets/_templates.cjs +36 -36
- package/witnet/assets/index.cjs +4 -4
- package/witnet/assets/modals/index.cjs +7 -7
- package/witnet/assets/modals/web3/eth.cjs +22 -27
- package/witnet/assets/modals/web3/ipfs.cjs +17 -22
- package/witnet/assets/modals/web3/wit.cjs +16 -28
- package/witnet/assets/requests.cjs +41 -49
package/src/bin/cli/radon.js
CHANGED
|
@@ -14,147 +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 =
|
|
18
|
-
process.env.WITNET_SDK_RADON_ASSETS_PATH || "../../../../../witnet/assets";
|
|
19
|
-
|
|
20
17
|
/// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
21
18
|
/// CLI SUBMODULE CONSTANTS ===========================================================================================
|
|
22
19
|
|
|
23
|
-
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`;
|
|
24
23
|
|
|
25
24
|
export const flags = {
|
|
26
|
-
|
|
27
|
-
hint: "
|
|
25
|
+
package: {
|
|
26
|
+
hint: "Imported package where to fetch Radon assets from (supersedes --legacy).",
|
|
28
27
|
param: "NPM_PACKAGE",
|
|
29
28
|
},
|
|
30
29
|
};
|
|
31
30
|
|
|
32
|
-
export const router =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
hint: "Restrict output to name-matching assets.",
|
|
40
|
-
},
|
|
41
|
-
legacy: {
|
|
42
|
-
hint: "List only those declared in witnet/assets folder.",
|
|
43
|
-
},
|
|
44
|
-
modals: {
|
|
45
|
-
hint: "Restrict output to Radon modals.",
|
|
46
|
-
},
|
|
47
|
-
requests: {
|
|
48
|
-
hint: "Restrict output to Radon requests.",
|
|
49
|
-
},
|
|
50
|
-
templates: {
|
|
51
|
-
hint: "Restrict output to Radon templates.",
|
|
52
|
-
},
|
|
53
|
-
},
|
|
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.",
|
|
54
38
|
},
|
|
55
|
-
|
|
56
|
-
hint: "
|
|
57
|
-
params: [],
|
|
58
|
-
options: {},
|
|
39
|
+
legacy: {
|
|
40
|
+
hint: "List only those declared within the ./witnet/assets subfolder.",
|
|
59
41
|
},
|
|
60
|
-
|
|
61
|
-
hint: "
|
|
62
|
-
params: ["RAD_BYTECODE | RAD_HASH | RADON_ASSET"],
|
|
63
|
-
options: {
|
|
64
|
-
bytecode: {
|
|
65
|
-
hint: "Outputs RAD bytecode as hex string (supersedes --json).",
|
|
66
|
-
},
|
|
67
|
-
json: {
|
|
68
|
-
hint: "Outputs data in JSON format.",
|
|
69
|
-
},
|
|
70
|
-
headline: {
|
|
71
|
-
hint: "Settles output report headline.",
|
|
72
|
-
param: ":string",
|
|
73
|
-
},
|
|
74
|
-
indent: {
|
|
75
|
-
hint: "Prefixes given number of white spaces for every output line.",
|
|
76
|
-
param: ":number",
|
|
77
|
-
},
|
|
78
|
-
},
|
|
42
|
+
modals: {
|
|
43
|
+
hint: "Restrict output to Radon modals.",
|
|
79
44
|
},
|
|
80
|
-
|
|
81
|
-
hint: "
|
|
82
|
-
params: ["RAD_BYTECODE | RAD_HASH | RADON_ASSET"],
|
|
83
|
-
options: {
|
|
84
|
-
default: {
|
|
85
|
-
hint: "Use default sample parameters on parametrized Radon assets.",
|
|
86
|
-
},
|
|
87
|
-
json: {
|
|
88
|
-
hint: "Outputs data in JSON format.",
|
|
89
|
-
},
|
|
90
|
-
headline: {
|
|
91
|
-
hint: "Settles output report headline.",
|
|
92
|
-
param: ":string",
|
|
93
|
-
},
|
|
94
|
-
indent: {
|
|
95
|
-
hint: "Prefixes given number of white spaces for every output line.",
|
|
96
|
-
param: ":number",
|
|
97
|
-
},
|
|
98
|
-
verbose: {
|
|
99
|
-
hint: "Outputs detailed dry-run report.",
|
|
100
|
-
},
|
|
101
|
-
},
|
|
45
|
+
requests: {
|
|
46
|
+
hint: "Restrict output to Radon requests.",
|
|
102
47
|
},
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
assets: {
|
|
106
|
-
hint: "List available Witnet Radon assets.",
|
|
107
|
-
params: "[RADON_ASSETS ...]",
|
|
108
|
-
options: {
|
|
109
|
-
filter: {
|
|
110
|
-
hint: "Restrict output to name-matching assets.",
|
|
111
|
-
},
|
|
112
|
-
legacy: {
|
|
113
|
-
hint: "List only those declared in witnet/assets folder.",
|
|
114
|
-
},
|
|
115
|
-
},
|
|
48
|
+
templates: {
|
|
49
|
+
hint: "Restrict output to Radon templates.",
|
|
116
50
|
},
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
hint: "Settles output report headline.",
|
|
126
|
-
param: ":string",
|
|
127
|
-
},
|
|
128
|
-
indent: {
|
|
129
|
-
hint: "Prefixes given number of white spaces for every output line.",
|
|
130
|
-
param: ":number",
|
|
131
|
-
},
|
|
132
|
-
},
|
|
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).",
|
|
133
59
|
},
|
|
134
|
-
|
|
135
|
-
hint: "
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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.",
|
|
153
79
|
},
|
|
154
|
-
|
|
155
|
-
hint: "
|
|
80
|
+
json: {
|
|
81
|
+
hint: "Outputs data in JSON format.",
|
|
156
82
|
},
|
|
157
|
-
|
|
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
|
+
};
|
|
158
110
|
|
|
159
111
|
export const subcommands = {
|
|
160
112
|
assets,
|
|
@@ -175,32 +127,18 @@ async function init() {
|
|
|
175
127
|
fs.cpSync("node_modules/@witnet/sdk/.env_witnet", ".env_witnet");
|
|
176
128
|
}
|
|
177
129
|
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
|
-
);
|
|
130
|
+
fs.cpSync("node_modules/@witnet/sdk/witnet/assets/_index.cjs", "./witnet/assets/index.cjs");
|
|
182
131
|
}
|
|
183
132
|
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
|
-
);
|
|
133
|
+
fs.cpSync("node_modules/@witnet/sdk/witnet/assets/_requests.cjs", "./witnet/assets/requests.cjs");
|
|
188
134
|
}
|
|
189
135
|
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
|
-
);
|
|
136
|
+
fs.cpSync("node_modules/@witnet/sdk/witnet/assets/_sources.cjs", "./witnet/assets/sources.cjs");
|
|
194
137
|
}
|
|
195
138
|
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
|
-
);
|
|
139
|
+
fs.cpSync("node_modules/@witnet/sdk/witnet/assets/_templates.cjs", "./witnet/assets/templates.cjs");
|
|
200
140
|
}
|
|
201
|
-
console.info(
|
|
202
|
-
`Initialized Witnet Radon workspace at folder ${process.cwd()}/witnet/assets`,
|
|
203
|
-
);
|
|
141
|
+
console.info(`Initialized Witnet Radon workspace at folder ${process.cwd()}/witnet/assets`);
|
|
204
142
|
}
|
|
205
143
|
|
|
206
144
|
async function assets(options = {}, [...patterns]) {
|
|
@@ -223,9 +161,8 @@ async function assets(options = {}, [...patterns]) {
|
|
|
223
161
|
|
|
224
162
|
async function check() {
|
|
225
163
|
if (!isModuleInitialized) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
);
|
|
164
|
+
console.error(`Sorry, no Witnet workspace was initialized yet.`);
|
|
165
|
+
return;
|
|
229
166
|
}
|
|
230
167
|
try {
|
|
231
168
|
const assets = loadAssets({ legacy: true });
|
|
@@ -266,10 +203,7 @@ async function decode(options = {}, args = []) {
|
|
|
266
203
|
traceWitnetRadonRequest(request, options);
|
|
267
204
|
} catch (err) {
|
|
268
205
|
console.error(err);
|
|
269
|
-
if (
|
|
270
|
-
(asset.startsWith("0x") && asset.length === 66) ||
|
|
271
|
-
(!asset.startsWith("0x") && asset.length === 64)
|
|
272
|
-
) {
|
|
206
|
+
if ((asset.startsWith("0x") && asset.length === 66) || (!asset.startsWith("0x") && asset.length === 64)) {
|
|
273
207
|
// TODO: assume it's a DR_TX_HASH
|
|
274
208
|
// TODO: assume it's a RAD_HASH
|
|
275
209
|
}
|
|
@@ -277,9 +211,7 @@ async function decode(options = {}, args = []) {
|
|
|
277
211
|
} else {
|
|
278
212
|
args = args.slice(1);
|
|
279
213
|
|
|
280
|
-
const assets = options?.module
|
|
281
|
-
? require(`${options.module}/assets`)
|
|
282
|
-
: loadAssets(options);
|
|
214
|
+
const assets = options?.module ? require(`${options.module}/assets`) : loadAssets(options);
|
|
283
215
|
const headline = options?.headline;
|
|
284
216
|
const crafts = flattenRadonArtifacts(assets).filter(
|
|
285
217
|
(craft) => craft.key.toLowerCase().indexOf(asset.toLowerCase()) >= 0,
|
|
@@ -309,10 +241,7 @@ async function decode(options = {}, args = []) {
|
|
|
309
241
|
prefix = "RadonTemplate::";
|
|
310
242
|
} else if (artifact instanceof Witnet.Radon.RadonRetrieval) {
|
|
311
243
|
if (artifact.argsCount > 0) {
|
|
312
|
-
const retrievalArgs = Array.from(
|
|
313
|
-
{ length: artifact.argsCount },
|
|
314
|
-
(_, i) => `{:${i + 1}}`,
|
|
315
|
-
);
|
|
244
|
+
const retrievalArgs = Array.from({ length: artifact.argsCount }, (_, i) => `{:${i + 1}}`);
|
|
316
245
|
artifact = artifact.foldArgs(retrievalArgs);
|
|
317
246
|
}
|
|
318
247
|
artifact = new Witnet.Radon.RadonRequest({ sources: artifact });
|
|
@@ -341,18 +270,13 @@ async function dryrun(options = {}, args = []) {
|
|
|
341
270
|
const request = Witnet.Radon.RadonRequest.fromBytecode(asset);
|
|
342
271
|
await traceWitnetRadonRequestDryRun(request, options);
|
|
343
272
|
} catch {
|
|
344
|
-
if (
|
|
345
|
-
(asset.startsWith("0x") && asset.length === 66) ||
|
|
346
|
-
(!asset.startsWith("0x") && asset.length === 64)
|
|
347
|
-
) {
|
|
273
|
+
if ((asset.startsWith("0x") && asset.length === 66) || (!asset.startsWith("0x") && asset.length === 64)) {
|
|
348
274
|
// TODO: assume it's a RAD_HASH, and try to retrieve the BYTECODE from the Witnet network
|
|
349
275
|
}
|
|
350
276
|
}
|
|
351
277
|
} else {
|
|
352
278
|
args = args.slice(1);
|
|
353
|
-
const assets = options?.module
|
|
354
|
-
? require(`${options.module}/assets`)
|
|
355
|
-
: loadAssets(options);
|
|
279
|
+
const assets = options?.module ? require(`${options.module}/assets`) : loadAssets(options);
|
|
356
280
|
const headline = options?.headline;
|
|
357
281
|
const crafts = flattenRadonArtifacts(assets).filter(
|
|
358
282
|
(craft) => craft.key.toLowerCase().indexOf(asset.toLowerCase()) >= 0,
|
|
@@ -379,11 +303,7 @@ async function dryrun(options = {}, args = []) {
|
|
|
379
303
|
}
|
|
380
304
|
artifact = artifact.homogeneous
|
|
381
305
|
? artifact.buildRadonRequest(modalArgs)
|
|
382
|
-
: artifact.buildRadonRequest([
|
|
383
|
-
...artifact.sources.map((source) =>
|
|
384
|
-
modalArgs.slice(0, source.argsCount),
|
|
385
|
-
),
|
|
386
|
-
]);
|
|
306
|
+
: artifact.buildRadonRequest([...artifact.sources.map((source) => modalArgs.slice(0, source.argsCount))]);
|
|
387
307
|
prefix = "RadonModal::";
|
|
388
308
|
} else {
|
|
389
309
|
if (!artifact?.samples) {
|
|
@@ -443,9 +363,7 @@ const extractTypeName = (str) =>
|
|
|
443
363
|
|
|
444
364
|
const stringifyFilter = (x, c) => {
|
|
445
365
|
const color = c || helpers.colors.mcyan;
|
|
446
|
-
return color(
|
|
447
|
-
`${Witnet.Radon.filters.Opcodes[x.opcode]}(${x.args ? JSON.stringify(x.args) : ""})`,
|
|
448
|
-
);
|
|
366
|
+
return color(`${Witnet.Radon.filters.Opcodes[x.opcode]}(${x.args ? JSON.stringify(x.args) : ""})`);
|
|
449
367
|
};
|
|
450
368
|
|
|
451
369
|
const stringifyReducer = (x, c) => {
|
|
@@ -455,7 +373,7 @@ const stringifyReducer = (x, c) => {
|
|
|
455
373
|
|
|
456
374
|
export function loadAssets(options) {
|
|
457
375
|
const assets = options?.legacy ? {} : legacy;
|
|
458
|
-
return
|
|
376
|
+
return fs.existsSync(`${WITNET_ASSETS_PATH}/index.cjs`)
|
|
459
377
|
? merge(assets, require(`${WITNET_ASSETS_PATH}/index.cjs`))
|
|
460
378
|
: assets;
|
|
461
379
|
}
|
|
@@ -489,14 +407,7 @@ function countWitnetArtifacts(assets, args, options) {
|
|
|
489
407
|
(options?.templates && value instanceof Witnet.Radon.RadonTemplate) ||
|
|
490
408
|
(options?.retrievals && value instanceof Witnet.Radon.RadonRetrieval) ||
|
|
491
409
|
(options?.requests && value instanceof Witnet.Radon.RadonRequest);
|
|
492
|
-
if (
|
|
493
|
-
!(
|
|
494
|
-
options?.modals ||
|
|
495
|
-
options?.templates ||
|
|
496
|
-
options?.retrievals ||
|
|
497
|
-
options?.requests
|
|
498
|
-
)
|
|
499
|
-
) {
|
|
410
|
+
if (!(options?.modals || options?.templates || options?.retrievals || options?.requests)) {
|
|
500
411
|
include =
|
|
501
412
|
value instanceof Witnet.Radon.RadonModal ||
|
|
502
413
|
value instanceof Witnet.Radon.RadonRequest ||
|
|
@@ -525,32 +436,17 @@ function clearEmptyBranches(node, args, options) {
|
|
|
525
436
|
.map(([key, value]) => {
|
|
526
437
|
let include =
|
|
527
438
|
(options?.modals && value instanceof Witnet.Radon.RadonModal) ||
|
|
528
|
-
(options?.templates &&
|
|
529
|
-
|
|
530
|
-
(options?.retrievals &&
|
|
531
|
-
value instanceof Witnet.Radon.RadonRetrieval) ||
|
|
439
|
+
(options?.templates && value instanceof Witnet.Radon.RadonTemplate) ||
|
|
440
|
+
(options?.retrievals && value instanceof Witnet.Radon.RadonRetrieval) ||
|
|
532
441
|
(options?.requests && value instanceof Witnet.Radon.RadonRequest);
|
|
533
|
-
if (
|
|
534
|
-
!(
|
|
535
|
-
options?.modals ||
|
|
536
|
-
options?.templates ||
|
|
537
|
-
options?.retrievals ||
|
|
538
|
-
options?.requests
|
|
539
|
-
)
|
|
540
|
-
) {
|
|
442
|
+
if (!(options?.modals || options?.templates || options?.retrievals || options?.requests)) {
|
|
541
443
|
include =
|
|
542
444
|
value instanceof Witnet.Radon.RadonModal ||
|
|
543
445
|
value instanceof Witnet.Radon.RadonRequest ||
|
|
544
446
|
value instanceof Witnet.Radon.RadonTemplate ||
|
|
545
447
|
value instanceof Witnet.Radon.RadonRetrieval;
|
|
546
448
|
}
|
|
547
|
-
if (
|
|
548
|
-
include &&
|
|
549
|
-
(!options?.filter ||
|
|
550
|
-
args.find(
|
|
551
|
-
(arg) => key.toLowerCase().indexOf(arg.toLowerCase()) >= 0,
|
|
552
|
-
))
|
|
553
|
-
) {
|
|
449
|
+
if (include && (!options?.filter || args.find((arg) => key.toLowerCase().indexOf(arg.toLowerCase()) >= 0))) {
|
|
554
450
|
return [key, value];
|
|
555
451
|
} else if (typeof value === "object") {
|
|
556
452
|
if (countWitnetArtifacts(value, args, options) > 0) {
|
|
@@ -576,9 +472,7 @@ function traceWitnetArtifacts(assets, args, indent = "", options) {
|
|
|
576
472
|
const prefix = `${indent}`;
|
|
577
473
|
Object.keys(assets).forEach((key, index) => {
|
|
578
474
|
const isLast = index === Object.keys(assets).length - 1;
|
|
579
|
-
const found = args.find(
|
|
580
|
-
(arg) => key.toLowerCase().indexOf(arg.toLowerCase()) >= 0,
|
|
581
|
-
);
|
|
475
|
+
const found = args.find((arg) => key.toLowerCase().indexOf(arg.toLowerCase()) >= 0);
|
|
582
476
|
const color = found ? helpers.colors.mcyan : helpers.colors.cyan;
|
|
583
477
|
if (assets[key] instanceof Witnet.Radon.RadonRequest) {
|
|
584
478
|
if (!options?.filter || found) {
|
|
@@ -589,15 +483,10 @@ function traceWitnetArtifacts(assets, args, indent = "", options) {
|
|
|
589
483
|
console.info(`${prefix}`);
|
|
590
484
|
}
|
|
591
485
|
}
|
|
592
|
-
} else if (
|
|
593
|
-
assets[key] instanceof Witnet.Radon.RadonTemplate ||
|
|
594
|
-
assets[key] instanceof Witnet.Radon.RadonModal
|
|
595
|
-
) {
|
|
486
|
+
} else if (assets[key] instanceof Witnet.Radon.RadonTemplate || assets[key] instanceof Witnet.Radon.RadonModal) {
|
|
596
487
|
const argsCount = assets[key].argsCount;
|
|
597
488
|
if (!options?.filter || found) {
|
|
598
|
-
console.info(
|
|
599
|
-
`${prefix}${color(key)} ${argsCount > 0 ? helpers.colors.green(`(${argsCount} args)`) : ""}`,
|
|
600
|
-
);
|
|
489
|
+
console.info(`${prefix}${color(key)} ${argsCount > 0 ? helpers.colors.green(`(${argsCount} args)`) : ""}`);
|
|
601
490
|
if (isLast) {
|
|
602
491
|
console.info(`${prefix}`);
|
|
603
492
|
}
|
|
@@ -605,24 +494,14 @@ function traceWitnetArtifacts(assets, args, indent = "", options) {
|
|
|
605
494
|
} else if (assets[key] instanceof Witnet.Radon.RadonRetrieval) {
|
|
606
495
|
const argsCount = assets[key].argsCount;
|
|
607
496
|
if (!options?.filter || found) {
|
|
608
|
-
console.info(
|
|
609
|
-
`${prefix}${color(key)} ${argsCount > 0 ? helpers.colors.green(`(${argsCount} args)`) : ""}`,
|
|
610
|
-
);
|
|
497
|
+
console.info(`${prefix}${color(key)} ${argsCount > 0 ? helpers.colors.green(`(${argsCount} args)`) : ""}`);
|
|
611
498
|
if (isLast) {
|
|
612
499
|
console.info(`${prefix}`);
|
|
613
500
|
}
|
|
614
501
|
}
|
|
615
|
-
} else if (
|
|
616
|
-
typeof assets[key] === "object" &&
|
|
617
|
-
countWitnetArtifacts(assets[key], args, options) > 0
|
|
618
|
-
) {
|
|
502
|
+
} else if (typeof assets[key] === "object" && countWitnetArtifacts(assets[key], args, options) > 0) {
|
|
619
503
|
console.info(`${indent}${isLast ? "└─ " : "├─ "}${key}`);
|
|
620
|
-
traceWitnetArtifacts(
|
|
621
|
-
assets[key],
|
|
622
|
-
args,
|
|
623
|
-
!isLast ? `${indent}│ ` : `${indent} `,
|
|
624
|
-
options,
|
|
625
|
-
);
|
|
504
|
+
traceWitnetArtifacts(assets[key], args, !isLast ? `${indent}│ ` : `${indent} `, options);
|
|
626
505
|
}
|
|
627
506
|
});
|
|
628
507
|
}
|
|
@@ -631,24 +510,12 @@ function traceWitnetRadonReportHeadline(request, options) {
|
|
|
631
510
|
const trait = (str) => `${str}${" ".repeat(66 - str.length)}`;
|
|
632
511
|
const indent = options?.indent ? " ".repeat(options.indent) : "";
|
|
633
512
|
const resultDataType = `Result<${extractTypeName(request.sources[0]?.script?.outputType.constructor.name)}, RadonError>`;
|
|
634
|
-
console.info(
|
|
635
|
-
|
|
636
|
-
);
|
|
637
|
-
console.info(
|
|
638
|
-
|
|
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
|
-
);
|
|
513
|
+
console.info(`${indent}╔══════════════════════════════════════════════════════════════════════════════╗`);
|
|
514
|
+
console.info(`${indent}║ ${helpers.colors.white(options?.headline)}${" ".repeat(77 - options?.headline.length)}║`);
|
|
515
|
+
console.info(`${indent}╠══════════════════════════════════════════════════════════════════════════════╣`);
|
|
516
|
+
console.info(`${indent}║ ${helpers.colors.white("RAD hash")}: ${helpers.colors.lgreen(request.radHash)} ║`);
|
|
517
|
+
console.info(`${indent}║ RAD size: ${helpers.colors.green(trait(`${helpers.commas(request.weight())} bytes`))} ║`);
|
|
518
|
+
console.info(`${indent}║ RAD type: ${helpers.colors.yellow(trait(resultDataType))} ║`);
|
|
652
519
|
// if (!options.verbose) {
|
|
653
520
|
// console.info(`${indent}║ > Radon operators: ${white(trait(commas(request.opsCount())))} ║`)
|
|
654
521
|
// }
|
|
@@ -666,21 +533,16 @@ function traceWitnetRadonReportHeadline(request, options) {
|
|
|
666
533
|
}
|
|
667
534
|
|
|
668
535
|
function traceWitnetRadonRequest(request, options) {
|
|
669
|
-
const indent = options?.indent
|
|
670
|
-
? " ".repeat(parseInt(options.indent, 10))
|
|
671
|
-
: "";
|
|
536
|
+
const indent = options?.indent ? " ".repeat(parseInt(options.indent, 10)) : "";
|
|
672
537
|
if (options?.json) {
|
|
673
|
-
console.info(
|
|
674
|
-
JSON.stringify(request.toProtobuf(), null, options?.indent || 0),
|
|
675
|
-
);
|
|
538
|
+
console.info(JSON.stringify(request.toProtobuf(), null, options?.indent || 0));
|
|
676
539
|
} else {
|
|
677
540
|
if (!options.headline) options.headline = "WITNET DATA REQUEST DISASSEMBLE";
|
|
678
541
|
traceWitnetRadonReportHeadline(request, options);
|
|
679
|
-
console.info(
|
|
680
|
-
`${indent}╚══╤═══════════════════════════════════════════════════════════════════════════╝`,
|
|
681
|
-
);
|
|
542
|
+
console.info(`${indent}╚══╤═══════════════════════════════════════════════════════════════════════════╝`);
|
|
682
543
|
if (options?.bytecode) {
|
|
683
|
-
console.info(
|
|
544
|
+
console.info(`${indent} v`);
|
|
545
|
+
console.info(helpers.colors.gray(request.toBytecode()));
|
|
684
546
|
return;
|
|
685
547
|
}
|
|
686
548
|
console.info(`${indent}┌──┴─────────────────┐`);
|
|
@@ -689,9 +551,7 @@ function traceWitnetRadonRequest(request, options) {
|
|
|
689
551
|
request.sources.forEach((source, sourceIndex) => {
|
|
690
552
|
const authority =
|
|
691
553
|
source.authority?.toUpperCase().split(".").slice(-2).join(".") ||
|
|
692
|
-
(source.method === Witnet.Radon.retrievals.Methods.RNG
|
|
693
|
-
? "WIT/RNG"
|
|
694
|
-
: "");
|
|
554
|
+
(source.method === Witnet.Radon.retrievals.Methods.RNG ? "WIT/RNG" : "");
|
|
695
555
|
const corner = sourceIndex === request.sources.length - 1 ? "└" : "├";
|
|
696
556
|
const sep = sourceIndex === request.sources.length - 1 ? " " : "│";
|
|
697
557
|
console.info(
|
|
@@ -708,50 +568,34 @@ function traceWitnetRadonRequest(request, options) {
|
|
|
708
568
|
.toUpperCase(),
|
|
709
569
|
)}`,
|
|
710
570
|
);
|
|
711
|
-
console.info(
|
|
712
|
-
`${indent} │ ${sep} > URL query: ${helpers.colors.green(source.url)}`,
|
|
713
|
-
);
|
|
571
|
+
console.info(`${indent} │ ${sep} > URL query: ${helpers.colors.green(source.url)}`);
|
|
714
572
|
if (source?.headers && Object.keys(source.headers).length > 0) {
|
|
715
573
|
console.info(
|
|
716
574
|
`${indent} │ ${sep} > HTTP headers: ${helpers.colors.green(JSON.stringify(source.headers))}`,
|
|
717
575
|
);
|
|
718
576
|
}
|
|
719
577
|
if (source?.body) {
|
|
720
|
-
console.info(
|
|
721
|
-
`${indent} │ ${sep} > HTTP body: ${helpers.colors.green(source.body)}`,
|
|
722
|
-
);
|
|
578
|
+
console.info(`${indent} │ ${sep} > HTTP body: ${helpers.colors.green(source.body)}`);
|
|
723
579
|
}
|
|
724
580
|
if (source?.script) {
|
|
725
|
-
// console.log(source.script.toBytecode())
|
|
726
581
|
const steps = source.script.disect();
|
|
727
582
|
console.info(
|
|
728
|
-
`${indent} │ ${sep} > Radon script: ${helpers.colors.
|
|
729
|
-
"[ ",
|
|
730
|
-
)}${helpers.colors.yellow(steps[0][1])}${" ".repeat(
|
|
731
|
-
12 - steps[0][1].length,
|
|
732
|
-
)}${helpers.colors.lyellow(
|
|
733
|
-
" ]",
|
|
734
|
-
)} ${helpers.colors.mcyan(steps[0][2])}`,
|
|
583
|
+
`${indent} │ ${sep} > Radon script: [ ${helpers.colors.gray(source.script.toBytecode())} ]`,
|
|
735
584
|
);
|
|
736
|
-
steps.
|
|
585
|
+
steps.forEach((step) => {
|
|
737
586
|
console.info(
|
|
738
587
|
`${indent} │ ${sep} ${helpers.colors.lyellow(
|
|
739
588
|
"[ ",
|
|
740
|
-
)}${helpers.colors.yellow(step[1])}${" ".repeat(
|
|
741
|
-
12 - step[1].length,
|
|
742
|
-
)}${helpers.colors.lyellow(
|
|
589
|
+
)}${helpers.colors.yellow(step[1])}${" ".repeat(12 - step[1].length)}${helpers.colors.lyellow(
|
|
743
590
|
" ]",
|
|
744
591
|
)} ${" ".repeat(2 * step[0])}${helpers.colors.mcyan(step[2])}`,
|
|
745
592
|
);
|
|
746
593
|
});
|
|
747
|
-
const outputType =
|
|
748
|
-
source.script.outputType.constructor.name || "RadonAny";
|
|
594
|
+
const outputType = source.script.outputType.constructor.name || "RadonAny";
|
|
749
595
|
console.info(
|
|
750
596
|
`${indent} │ ${sep} ${helpers.colors.lyellow(
|
|
751
597
|
"[ ",
|
|
752
|
-
)}${helpers.colors.yellow(outputType)}${" ".repeat(
|
|
753
|
-
12 - outputType.length,
|
|
754
|
-
)}${helpers.colors.lyellow(" ]")}`,
|
|
598
|
+
)}${helpers.colors.yellow(outputType)}${" ".repeat(12 - outputType.length)}${helpers.colors.lyellow(" ]")}`,
|
|
755
599
|
);
|
|
756
600
|
}
|
|
757
601
|
}
|
|
@@ -762,36 +606,24 @@ function traceWitnetRadonRequest(request, options) {
|
|
|
762
606
|
console.info(`${indent}┌──┴──────────────────┐`);
|
|
763
607
|
console.info(`${indent}│ ${helpers.colors.white("AGGREGATE SOURCES")} │`);
|
|
764
608
|
console.info(`${indent}└──┬──────────────────┘`); // ┬
|
|
765
|
-
request.sourcesReducer?.filters.forEach((filter) =>
|
|
766
|
-
console.info(
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
);
|
|
770
|
-
console.info(
|
|
771
|
-
`${indent} │ > Radon reducer: ${stringifyReducer(request.sourcesReducer)}`,
|
|
772
|
-
);
|
|
609
|
+
request.sourcesReducer?.filters.forEach((filter) => {
|
|
610
|
+
console.info(`${indent} │ > Radon filter: ${stringifyFilter(filter)}`);
|
|
611
|
+
});
|
|
612
|
+
console.info(`${indent} │ > Radon reducer: ${stringifyReducer(request.sourcesReducer)}`);
|
|
773
613
|
console.info(`${indent}┌──┴──────────────────┐`);
|
|
774
614
|
console.info(`${indent}│ ${helpers.colors.white("WITNESSING TALLY")} │`);
|
|
775
615
|
console.info(`${indent}└─────────────────────┘`); // ┬
|
|
776
|
-
request.witnessReducer?.filters.forEach((filter) =>
|
|
777
|
-
console.info(
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
);
|
|
781
|
-
console.info(
|
|
782
|
-
`${indent} > Radon reducer: ${stringifyReducer(request.witnessReducer)}`,
|
|
783
|
-
);
|
|
616
|
+
request.witnessReducer?.filters.forEach((filter) => {
|
|
617
|
+
console.info(`${indent} > Radon filter: ${stringifyFilter(filter)}`);
|
|
618
|
+
});
|
|
619
|
+
console.info(`${indent} > Radon reducer: ${stringifyReducer(request.witnessReducer)}`);
|
|
784
620
|
}
|
|
785
621
|
}
|
|
786
622
|
|
|
787
623
|
async function traceWitnetRadonRequestDryRun(request, options) {
|
|
788
624
|
const bytecode = request.toBytecode();
|
|
789
625
|
let report = await helpers
|
|
790
|
-
.toolkitRun(options, [
|
|
791
|
-
"try-data-request",
|
|
792
|
-
"--hex",
|
|
793
|
-
bytecode.startsWith("0x") ? bytecode.slice(2) : bytecode,
|
|
794
|
-
])
|
|
626
|
+
.toolkitRun(options, ["try-data-request", "--hex", bytecode.startsWith("0x") ? bytecode.slice(2) : bytecode])
|
|
795
627
|
.catch((err) => {
|
|
796
628
|
let errorMessage = err.message.split("\n").slice(1).join("\n").trim();
|
|
797
629
|
const errorRegex = /.*^error: (?<message>.*)$.*/gm;
|
|
@@ -825,8 +657,7 @@ async function traceWitnetRadonRequestDryRun(request, options) {
|
|
|
825
657
|
resultSize = 1;
|
|
826
658
|
break;
|
|
827
659
|
case "RadonBytes":
|
|
828
|
-
resultSize =
|
|
829
|
-
utils.cbor.encode(Uint8Array.from(resultValue)).byteLength - 2;
|
|
660
|
+
resultSize = utils.cbor.encode(Uint8Array.from(resultValue)).byteLength - 2;
|
|
830
661
|
break;
|
|
831
662
|
case "RadonInteger":
|
|
832
663
|
case "RadonFloat":
|
|
@@ -841,46 +672,25 @@ async function traceWitnetRadonRequestDryRun(request, options) {
|
|
|
841
672
|
}
|
|
842
673
|
if (options?.json) {
|
|
843
674
|
if (options?.verbose) {
|
|
844
|
-
console.info(
|
|
845
|
-
JSON.stringify(
|
|
846
|
-
report,
|
|
847
|
-
null,
|
|
848
|
-
options?.indent ? " ".repeat(options.indent) : "",
|
|
849
|
-
),
|
|
850
|
-
);
|
|
675
|
+
console.info(JSON.stringify(report, null, options?.indent ? " ".repeat(options.indent) : ""));
|
|
851
676
|
} else {
|
|
852
677
|
result[resultType] = resultValue;
|
|
853
|
-
console.info(
|
|
854
|
-
JSON.stringify(
|
|
855
|
-
result,
|
|
856
|
-
null,
|
|
857
|
-
options?.indent ? " ".repeat(options.indent) : "",
|
|
858
|
-
),
|
|
859
|
-
);
|
|
678
|
+
console.info(JSON.stringify(result, null, options?.indent ? " ".repeat(options.indent) : ""));
|
|
860
679
|
}
|
|
861
680
|
return;
|
|
862
681
|
}
|
|
863
|
-
if (!options.headline)
|
|
864
|
-
options.headline = "WITNET DATA REQUEST DRY-RUN REPORT";
|
|
682
|
+
if (!options.headline) options.headline = "WITNET DATA REQUEST DRY-RUN REPORT";
|
|
865
683
|
traceWitnetRadonReportHeadline(request, options);
|
|
866
684
|
const indent = options?.indent ? " ".repeat(options.indent) : "";
|
|
867
|
-
console.info(
|
|
868
|
-
`${indent}╚══╤═══════════════════════════════════════════════════════════════════════════╝`,
|
|
869
|
-
);
|
|
685
|
+
console.info(`${indent}╚══╤═══════════════════════════════════════════════════════════════════════════╝`);
|
|
870
686
|
let execTimeMs = report.retrieve
|
|
871
|
-
?.map(
|
|
872
|
-
(retrieval) =>
|
|
873
|
-
(retrieval?.running_time.secs || 0) +
|
|
874
|
-
(retrieval?.running_time.nanos || 0) / 1000,
|
|
875
|
-
)
|
|
687
|
+
?.map((retrieval) => (retrieval?.running_time.secs || 0) + (retrieval?.running_time.nanos || 0) / 1000)
|
|
876
688
|
.reduce((sum, secs) => sum + secs);
|
|
877
689
|
execTimeMs = `${Math.round(execTimeMs)} ms`;
|
|
878
690
|
let flexbar = "─".repeat(17);
|
|
879
691
|
let flexspc = " ".repeat(flexbar.length + 12);
|
|
880
692
|
console.info(`${indent}┌──┴─────────────────────────────${flexbar}──────┐`);
|
|
881
|
-
console.info(
|
|
882
|
-
`${indent}│ ${helpers.colors.white("Data providers")} ${flexspc} │`,
|
|
883
|
-
); // ├ ┤
|
|
693
|
+
console.info(`${indent}│ ${helpers.colors.white("Data providers")} ${flexspc} │`); // ├ ┤
|
|
884
694
|
console.info(`${indent}├────────────────────────────────${flexbar}──────┤`);
|
|
885
695
|
console.info(
|
|
886
696
|
`${indent}│ Execution time: ${helpers.colors.green(execTimeMs)} ${" ".repeat(flexbar.length + 19 - execTimeMs.length)} │`,
|
|
@@ -901,21 +711,14 @@ async function traceWitnetRadonRequestDryRun(request, options) {
|
|
|
901
711
|
: helpers.colors.green;
|
|
902
712
|
if (options?.verbose) {
|
|
903
713
|
console.info(
|
|
904
|
-
`${indent} │ ${corner}─ ${helpers.colors.white(
|
|
905
|
-
"[ ",
|
|
906
|
-
)}${helpers.colors.white(
|
|
714
|
+
`${indent} │ ${corner}─ ${helpers.colors.white("[ ")}${helpers.colors.white(
|
|
907
715
|
`Data Source #${sourceIndex + 1}`,
|
|
908
|
-
)} ${" ".repeat(3 - sourceIndex.toString().length)}${color(
|
|
909
|
-
authority,
|
|
910
|
-
)} ${helpers.colors.white("]")}`,
|
|
716
|
+
)} ${" ".repeat(3 - sourceIndex.toString().length)}${color(authority)} ${helpers.colors.white("]")}`,
|
|
911
717
|
);
|
|
912
718
|
} else {
|
|
913
719
|
console.info(`${indent} │ ${corner}─ [ ${color(authority)} ]`);
|
|
914
720
|
}
|
|
915
|
-
if (
|
|
916
|
-
source.method !== Witnet.Radon.retrievals.Methods.RNG &&
|
|
917
|
-
options?.verbose
|
|
918
|
-
) {
|
|
721
|
+
if (source.method !== Witnet.Radon.retrievals.Methods.RNG && options?.verbose) {
|
|
919
722
|
console.info(
|
|
920
723
|
`${indent} │ ${sep} > Request: ${helpers.colors.mgreen(
|
|
921
724
|
Witnet.Radon.retrievals.Methods[source.method]
|
|
@@ -924,31 +727,24 @@ async function traceWitnetRadonRequestDryRun(request, options) {
|
|
|
924
727
|
.toUpperCase(),
|
|
925
728
|
)}`,
|
|
926
729
|
);
|
|
927
|
-
console.info(
|
|
928
|
-
`${indent} │ ${sep} > URL query: ${helpers.colors.green(source.url)}`,
|
|
929
|
-
);
|
|
730
|
+
console.info(`${indent} │ ${sep} > URL query: ${helpers.colors.green(source.url)}`);
|
|
930
731
|
if (source?.headers && Object.keys(source.headers).length > 0) {
|
|
931
732
|
console.info(
|
|
932
733
|
`${indent} │ ${sep} > HTTP headers: ${helpers.colors.green(JSON.stringify(source.headers))}`,
|
|
933
734
|
);
|
|
934
735
|
}
|
|
935
736
|
if (source?.body) {
|
|
936
|
-
console.info(
|
|
937
|
-
`${indent} │ ${sep} > HTTP body: ${helpers.colors.green(source.body)}`,
|
|
938
|
-
);
|
|
737
|
+
console.info(`${indent} │ ${sep} > HTTP body: ${helpers.colors.green(source.body)}`);
|
|
939
738
|
}
|
|
940
739
|
const printData = (headline, data, color) => {
|
|
941
740
|
const type = Object.keys(data)[0];
|
|
942
741
|
data =
|
|
943
|
-
(typeof data[type] === "object" ||
|
|
944
|
-
typeof data[type] === "boolean" ||
|
|
945
|
-
Array.isArray(data[type])
|
|
742
|
+
(typeof data[type] === "object" || typeof data[type] === "boolean" || Array.isArray(data[type])
|
|
946
743
|
? JSON.stringify(data[type])
|
|
947
744
|
: data[type]) || "";
|
|
948
745
|
const lines = data.match(/.{1,96}/g)?.slice(0, 256) || [""];
|
|
949
746
|
if (lines.length === 256) lines[255] += "...";
|
|
950
|
-
const typeColor =
|
|
951
|
-
type === "RadonError" ? helpers.colors.red : helpers.colors.yellow;
|
|
747
|
+
const typeColor = type === "RadonError" ? helpers.colors.red : helpers.colors.yellow;
|
|
952
748
|
const lineColor = type === "RadonError" ? helpers.colors.gray : color;
|
|
953
749
|
console.info(
|
|
954
750
|
`${indent} │ ${sep} > ${headline}${" ".repeat(15 - headline.length)} \x1b[1;m${typeColor(
|
|
@@ -958,23 +754,13 @@ async function traceWitnetRadonRequestDryRun(request, options) {
|
|
|
958
754
|
)}\x1b[1;m${typeColor(" ]")}\x1b[0m ${lineColor(lines[0])}`,
|
|
959
755
|
);
|
|
960
756
|
lines.slice(1).forEach((line) => {
|
|
961
|
-
console.info(
|
|
962
|
-
`${indent} │ ${sep} ${lineColor(line)}`,
|
|
963
|
-
);
|
|
757
|
+
console.info(`${indent} │ ${sep} ${lineColor(line)}`);
|
|
964
758
|
});
|
|
965
759
|
};
|
|
966
760
|
if (report?.retrieve[sourceIndex]?.partial_results) {
|
|
967
|
-
printData(
|
|
968
|
-
"HTTP response:",
|
|
969
|
-
report?.retrieve[sourceIndex]?.partial_results[0],
|
|
970
|
-
helpers.colors.cyan,
|
|
971
|
-
);
|
|
761
|
+
printData("HTTP response:", report?.retrieve[sourceIndex]?.partial_results[0], helpers.colors.cyan);
|
|
972
762
|
}
|
|
973
|
-
printData(
|
|
974
|
-
"Radon result:",
|
|
975
|
-
report?.retrieve[sourceIndex]?.result,
|
|
976
|
-
helpers.colors.mcyan,
|
|
977
|
-
);
|
|
763
|
+
printData("Radon result:", report?.retrieve[sourceIndex]?.result, helpers.colors.mcyan);
|
|
978
764
|
}
|
|
979
765
|
if (options?.verbose && sourceIndex < request.sources.length - 1) {
|
|
980
766
|
console.info(`${indent} │ │`);
|
|
@@ -983,17 +769,13 @@ async function traceWitnetRadonRequestDryRun(request, options) {
|
|
|
983
769
|
flexbar = "─".repeat(24);
|
|
984
770
|
flexspc = " ".repeat(36);
|
|
985
771
|
console.info(`${indent}┌──┴───────────────────────────${flexbar}─┐`);
|
|
986
|
-
console.info(
|
|
987
|
-
`${indent}│ ${helpers.colors.white("Aggregated result")}${flexspc} │`,
|
|
988
|
-
); // ├ ┤
|
|
772
|
+
console.info(`${indent}│ ${helpers.colors.white("Aggregated result")}${flexspc} │`); // ├ ┤
|
|
989
773
|
console.info(`${indent}├──────────────────────────────${flexbar}─┤`);
|
|
990
774
|
if (options?.verbose) {
|
|
991
775
|
let partial_index = 0;
|
|
992
776
|
const partial_results = report.sourcesReducer?.partial_results;
|
|
993
777
|
request.sourcesReducer?.filters.forEach((filter) => {
|
|
994
|
-
const color = partial_results?.[partial_index]?.RadonArray
|
|
995
|
-
? helpers.colors.mcyan
|
|
996
|
-
: helpers.colors.gray;
|
|
778
|
+
const color = partial_results?.[partial_index]?.RadonArray ? helpers.colors.mcyan : helpers.colors.gray;
|
|
997
779
|
const items = partial_results?.[partial_index]?.RadonArray
|
|
998
780
|
? ` over ${partial_results[partial_index]?.RadonArray.length} sources`
|
|
999
781
|
: "";
|
|
@@ -1005,9 +787,7 @@ async function traceWitnetRadonRequestDryRun(request, options) {
|
|
|
1005
787
|
)}${" ".repeat(flexbar.length + 22 - filter.length - items.length)} │`,
|
|
1006
788
|
);
|
|
1007
789
|
});
|
|
1008
|
-
const color = partial_results?.[partial_index]?.RadonArray
|
|
1009
|
-
? helpers.colors.mcyan
|
|
1010
|
-
: helpers.colors.gray;
|
|
790
|
+
const color = partial_results?.[partial_index]?.RadonArray ? helpers.colors.mcyan : helpers.colors.gray;
|
|
1011
791
|
const items = partial_results?.[partial_index]?.RadonArray
|
|
1012
792
|
? ` over ${partial_results[partial_index]?.RadonArray.length} sources`
|
|
1013
793
|
: "";
|
|
@@ -1020,7 +800,7 @@ async function traceWitnetRadonRequestDryRun(request, options) {
|
|
|
1020
800
|
}
|
|
1021
801
|
if (resultSize) {
|
|
1022
802
|
console.info(
|
|
1023
|
-
`${indent}│
|
|
803
|
+
`${indent}│ Encoded size: ${helpers.colors.cyan(
|
|
1024
804
|
`${resultSize} bytes`,
|
|
1025
805
|
)}${" ".repeat(flexbar.length + 7 - resultSize.toString().length)} │`,
|
|
1026
806
|
);
|
|
@@ -1042,20 +822,12 @@ async function traceWitnetRadonRequestDryRun(request, options) {
|
|
|
1042
822
|
console.info(
|
|
1043
823
|
`${indent} ${helpers.colors.myellow(
|
|
1044
824
|
`[ ${type}${" ".repeat(7 - type.length)} ]`,
|
|
1045
|
-
)} ${helpers.colors.green(key)}${" ".repeat(
|
|
1046
|
-
width - 12 - key.length,
|
|
1047
|
-
)}`,
|
|
825
|
+
)} ${helpers.colors.green(key)}${" ".repeat(width - 12 - key.length)}`,
|
|
1048
826
|
);
|
|
1049
827
|
}
|
|
1050
|
-
Object.entries(value).forEach(([key, value]) =>
|
|
1051
|
-
printMapItem(
|
|
1052
|
-
|
|
1053
|
-
width,
|
|
1054
|
-
type === "Map" ? key : null,
|
|
1055
|
-
helpers.unescapeSlashes(value),
|
|
1056
|
-
`${indent2} `,
|
|
1057
|
-
),
|
|
1058
|
-
);
|
|
828
|
+
Object.entries(value).forEach(([key, value]) => {
|
|
829
|
+
printMapItem(indent, width, type === "Map" ? key : null, helpers.unescapeSlashes(value), `${indent2} `);
|
|
830
|
+
});
|
|
1059
831
|
} else {
|
|
1060
832
|
if (key.length > width - 12) {
|
|
1061
833
|
console.info(
|
|
@@ -1084,17 +856,15 @@ async function traceWitnetRadonRequestDryRun(request, options) {
|
|
|
1084
856
|
const printResult = (indent, width, resultType, resultValue) => {
|
|
1085
857
|
resultType = extractTypeName(resultType);
|
|
1086
858
|
resultValue =
|
|
1087
|
-
typeof resultValue === "object" || Array.isArray(resultValue)
|
|
1088
|
-
? JSON.stringify(resultValue)
|
|
1089
|
-
: resultValue;
|
|
859
|
+
typeof resultValue === "object" || Array.isArray(resultValue) ? JSON.stringify(resultValue) : resultValue;
|
|
1090
860
|
if (["Map", "Array"].includes(resultType)) {
|
|
1091
861
|
console.info(
|
|
1092
862
|
`${indent} └─ ${helpers.colors.lyellow(`[ ${resultType}${" ".repeat(7 - resultType.length)} ]`)}`,
|
|
1093
863
|
);
|
|
1094
864
|
const obj = JSON.parse(resultValue);
|
|
1095
|
-
Object.entries(obj).forEach(([key, value]) =>
|
|
1096
|
-
printMapItem(indent, width, resultType === "Map" ? key : null, value)
|
|
1097
|
-
);
|
|
865
|
+
Object.entries(obj).forEach(([key, value]) => {
|
|
866
|
+
printMapItem(indent, width, resultType === "Map" ? key : null, value);
|
|
867
|
+
});
|
|
1098
868
|
} else {
|
|
1099
869
|
if (resultType === "Bytes") {
|
|
1100
870
|
resultValue = JSON.parse(resultValue)
|
|
@@ -1103,10 +873,7 @@ async function traceWitnetRadonRequestDryRun(request, options) {
|
|
|
1103
873
|
} else if (resultType === "Boolean") {
|
|
1104
874
|
resultValue = JSON.stringify(resultValue);
|
|
1105
875
|
}
|
|
1106
|
-
const color =
|
|
1107
|
-
resultType.indexOf("Error") > -1
|
|
1108
|
-
? helpers.colors.gray
|
|
1109
|
-
: helpers.colors.lcyan;
|
|
876
|
+
const color = resultType.indexOf("Error") > -1 ? helpers.colors.gray : helpers.colors.lcyan;
|
|
1110
877
|
const typeText =
|
|
1111
878
|
resultType.indexOf("Error") > -1
|
|
1112
879
|
? "\x1b[1;98;41m Error \x1b[0m"
|
|
@@ -1114,9 +881,7 @@ async function traceWitnetRadonRequestDryRun(request, options) {
|
|
|
1114
881
|
const lines = resultValue.match(/.{1,96}/g)?.slice(0, 256) || [""];
|
|
1115
882
|
console.info(`${indent} └─ ${typeText} ${color(lines[0])}`);
|
|
1116
883
|
lines.slice(1).forEach((line) => {
|
|
1117
|
-
console.info(
|
|
1118
|
-
`${indent} ${" ".repeat(resultType.length)}${color(line)}`,
|
|
1119
|
-
);
|
|
884
|
+
console.info(`${indent} ${" ".repeat(resultType.length)}${color(line)}`);
|
|
1120
885
|
});
|
|
1121
886
|
}
|
|
1122
887
|
};
|