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