@witnet/sdk 1.2.2 → 1.2.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.
Files changed (53) hide show
  1. package/.env_witnet +2 -1
  2. package/dist/package.json +4 -3
  3. package/dist/src/bin/helpers.js +1 -1
  4. package/dist/src/index.js +1 -1
  5. package/dist/src/lib/crypto/account.js +1 -1
  6. package/dist/src/lib/crypto/coinbase.js +1 -1
  7. package/dist/src/lib/crypto/index.js +1 -1
  8. package/dist/src/lib/crypto/interfaces.js +1 -1
  9. package/dist/src/lib/crypto/payloads/DataRequestPayload.js +1 -1
  10. package/dist/src/lib/crypto/payloads/StakePayload.js +1 -1
  11. package/dist/src/lib/crypto/payloads/UnstakePayload.js +1 -1
  12. package/dist/src/lib/crypto/payloads/ValueTransferPayload.js +1 -1
  13. package/dist/src/lib/crypto/payloads.js +1 -1
  14. package/dist/src/lib/crypto/signer.js +1 -1
  15. package/dist/src/lib/crypto/transmitters/DataRequests.js +1 -1
  16. package/dist/src/lib/crypto/transmitters/StakeDeposits.js +1 -1
  17. package/dist/src/lib/crypto/transmitters/StakeWithdrawals.js +1 -1
  18. package/dist/src/lib/crypto/transmitters/ValueTransfers.js +1 -1
  19. package/dist/src/lib/crypto/transmitters.js +1 -1
  20. package/dist/src/lib/crypto/types.js +1 -1
  21. package/dist/src/lib/crypto/utils.js +1 -1
  22. package/dist/src/lib/crypto/wallet.js +1 -1
  23. package/dist/src/lib/index.js +1 -1
  24. package/dist/src/lib/radon/ccdr/eth.js +1 -1
  25. package/dist/src/lib/radon/ccdr/index.js +1 -1
  26. package/dist/src/lib/radon/ccdr/wit.js +1 -1
  27. package/dist/src/lib/radon/filters.js +1 -1
  28. package/dist/src/lib/radon/index.js +1 -1
  29. package/dist/src/lib/radon/reducers.js +1 -1
  30. package/dist/src/lib/radon/types.js +1 -1
  31. package/dist/src/lib/radon/utils.d.ts.map +1 -1
  32. package/dist/src/lib/radon/utils.js +1 -1
  33. package/dist/src/lib/rest/kermit.d.ts.map +1 -1
  34. package/dist/src/lib/rest/kermit.js +2 -4
  35. package/dist/src/lib/rest/types.js +1 -1
  36. package/dist/src/lib/rpc/index.js +1 -1
  37. package/dist/src/lib/rpc/nodes.js +1 -1
  38. package/dist/src/lib/rpc/provider.js +1 -1
  39. package/dist/src/lib/rpc/types.js +1 -1
  40. package/dist/src/lib/types.js +1 -1
  41. package/dist/src/lib/utils.js +1 -1
  42. package/package.json +4 -3
  43. package/scripts/clean.cjs +21 -21
  44. package/scripts/postinstall.cjs +9 -9
  45. package/src/bin/bots/watcher.cjs +365 -354
  46. package/src/bin/cli/history.cjs +31 -31
  47. package/src/bin/cli/inspect.js +581 -581
  48. package/src/bin/cli/network.js +695 -695
  49. package/src/bin/cli/nodes.js +424 -424
  50. package/src/bin/cli/radon.js +1124 -1122
  51. package/src/bin/cli/wallet.js +1362 -1362
  52. package/src/bin/helpers.js +974 -974
  53. package/src/bin/index.js +328 -328
package/src/bin/index.js CHANGED
@@ -1,329 +1,329 @@
1
1
  #!/usr/bin/env node
2
-
3
- /// IMPORTS ===========================================================================================================
4
-
5
- import fs from "node:fs";
6
- import { createRequire } from "node:module";
7
- import os from "node:os";
8
- import path from "node:path";
9
- import axios from "axios";
10
- import dotenv from "dotenv";
11
-
12
- dotenv.config({ quiet: true });
13
- const _require = createRequire(import.meta.url);
14
-
15
- import {
16
- colors,
17
- deleteExtraFlags,
18
- extractFromArgs,
19
- prompt,
20
- showUsage,
21
- showUsageError,
22
- showUsageSubcommand,
23
- showVersion,
24
- toolkitRun,
25
- } from "./helpers.js";
26
-
27
- /// CONSTANTS =======================================================================================================
28
-
29
- const __dirname = import.meta.dirname;
30
-
31
- const version = "2.0.21";
32
- const toolkitDownloadUrlBase = `https://github.com/witnet/witnet-rust/releases/download/${version}/`;
33
- const toolkitDownloadNames = {
34
- win32: (arch) => `witnet_toolkit-${arch}-pc-windows-msvc.exe`,
35
- // TODO: detect armv7
36
- linux: (arch) =>
37
- `witnet_toolkit-${arch}-unknown-linux-gnu${arch === "arm" ? "eabihf" : ""}`,
38
- darwin: (_arch) => `witnet_toolkit-x86_64-apple-darwin`,
39
- };
40
- const toolkitFileNames = {
41
- win32: (arch) => `witnet_toolkit-${version}-${arch}-pc-windows-msvc.exe`,
42
- // TODO: detect armv7
43
- linux: (arch) =>
44
- `witnet_toolkit-${version}-${arch}-unknown-linux-gnu${arch === "arm" ? "eabihf" : ""}`,
45
- darwin: (_arch) => `witnet_toolkit-${version}-x86_64-apple-darwin`,
46
- };
47
- const archsMap = {
48
- arm64: "aarch64",
49
- x64: "x86_64",
50
- };
51
-
52
- /// ENVIRONMENT ACQUISITION =========================================================================================
53
-
54
- const args = process.argv;
55
- const binDir = __dirname;
56
-
57
- const toolkitDirPath = path.resolve(binDir, "../../witnet/");
58
- const platform = guessPlatform();
59
- const arch = guessArch();
60
- const toolkitDownloadName = guessToolkitDownloadName(platform, arch);
61
- const toolkitFileName = guessToolkitFileName(platform, arch);
62
- const toolkitBinPath = guessToolkitBinPath(toolkitDirPath, platform, arch);
63
- const toolkitIsDownloaded = checkToolkitIsDownloaded(toolkitBinPath);
64
-
65
- function guessPlatform() {
66
- return os.platform();
67
- }
68
- function guessArch() {
69
- const rawArch = os.arch();
70
- return archsMap[rawArch] || rawArch;
71
- }
72
- function guessDownloadUrl(toolkitFileName) {
73
- return `${toolkitDownloadUrlBase}${toolkitFileName}`;
74
- }
75
- function guessToolkitDownloadName(platform, arch) {
76
- return (toolkitDownloadNames[platform] || toolkitDownloadNames.linux)(arch);
77
- }
78
- function guessToolkitFileName(platform, arch) {
79
- return (toolkitFileNames[platform] || toolkitFileNames.linux)(arch);
80
- }
81
- function guessToolkitBinPath(toolkitDirPath, platform, arch) {
82
- const fileName = guessToolkitFileName(platform, arch);
83
-
84
- return path.resolve(toolkitDirPath, fileName);
85
- }
86
- function checkToolkitIsDownloaded(toolkitBinPath) {
87
- return fs.existsSync(toolkitBinPath);
88
- }
89
-
90
- /// HELPER FUNCTIONS ================================================================================================
91
-
92
- async function downloadToolkit(
93
- toolkitDownloadName,
94
- _toolkitFileName,
95
- toolkitBinPath,
96
- platform,
97
- arch,
98
- ) {
99
- const downloadUrl = guessDownloadUrl(toolkitDownloadName);
100
- console.info("Downloading", downloadUrl, "into", toolkitBinPath);
101
-
102
- const file = fs.createWriteStream(toolkitBinPath);
103
- axios({
104
- method: "get",
105
- url: downloadUrl,
106
- responseType: "stream",
107
- }).then((response) => {
108
- response.data.pipe(file);
109
- });
110
-
111
- return new Promise((resolve, reject) => {
112
- file.on("finish", () => {
113
- file.close(() => {
114
- if (file.bytesWritten > 1000000) {
115
- fs.chmodSync(toolkitBinPath, 0o755);
116
- resolve();
117
- } else {
118
- reject(`No suitable witnet_toolkit binary found. Maybe your OS (${platform}) or architecture \
119
- (${arch}) are not yet supported. Feel free to complain about it in the Witnet community on Discord: \
120
- https://discord.gg/2rTFYXHmPm `);
121
- }
122
- });
123
- });
124
- const errorHandler = (err) => {
125
- fs.unlink(downloadUrl, () => {
126
- reject(err);
127
- });
128
- };
129
- file.on("error", errorHandler);
130
- });
131
- }
132
-
133
- /// COMMAND HANDLERS ================================================================================================
134
-
135
- async function installCommand(settings) {
136
- if (!settings.checks.toolkitIsDownloaded) {
137
- // Skip confirmation if install is forced
138
- if (!settings.force) {
139
- console.info(
140
- `The witnet_toolkit ${version} native binary hasn't been downloaded yet (this is a requirement).`,
141
- );
142
- const will = await prompt("Do you want to download it now? (Y/n)");
143
- // Abort if not confirmed
144
- if (!["", "y"].includes(will.toLowerCase())) {
145
- console.error("Aborted download of witnet_toolkit native binary.");
146
- return;
147
- }
148
- }
149
-
150
- return forcedInstallCommand(settings);
151
- }
152
- }
153
-
154
- async function forcedInstallCommand(settings) {
155
- if (!fs.existsSync(".env_witnet")) {
156
- fs.cpSync("node_modules/@witnet/sdk/.env_witnet", ".env_witnet");
157
- }
158
- return downloadToolkit(
159
- settings.paths.toolkitDownloadName,
160
- settings.paths.toolkitFileName,
161
- settings.paths.toolkitBinPath,
162
- settings.system.platform,
163
- settings.system.arch,
164
- ).catch((err) => {
165
- console.error("Error updating witnet_toolkit binary:", err);
166
- });
167
- }
168
-
169
- async function versionCommand(settings) {
170
- return fallbackBinaryCommand(settings, ["--version"]);
171
- }
172
-
173
- async function fallbackBinaryCommand(settings, args) {
174
- const toolkitOutput = await toolkitRun(settings, args.slice(1)).catch(
175
- (err) => {
176
- let errorMessage = err.message.split("\n").slice(1).join("\n").trim();
177
- const errorRegex = /.*^error: (?<message>.*)$.*/gm;
178
- const matched = errorRegex.exec(err.message);
179
- if (matched) {
180
- errorMessage = matched.groups.message;
181
- }
182
- console.error(errorMessage || err);
183
- },
184
- );
185
- if (toolkitOutput) console.info(toolkitOutput);
186
- }
187
-
188
- /// PROCESS SETTINGS ===============================================================================================
189
-
190
- const settings = {
191
- paths: {
192
- toolkitBinPath,
193
- toolkitDirPath,
194
- toolkitDownloadName,
195
- toolkitFileName,
196
- },
197
- checks: {
198
- toolkitIsDownloaded,
199
- },
200
- system: {
201
- platform,
202
- arch,
203
- },
204
- };
205
-
206
- if (args.includes("--debug")) {
207
- settings.debug = true;
208
- args.splice(args.indexOf("--debug"), 1);
209
- }
210
-
211
- if (args.includes("--force")) {
212
- settings.force = true;
213
- args.splice(args.indexOf("--force"), 1);
214
- }
215
-
216
- if (args.includes("--help")) {
217
- settings.help = true;
218
- args.splice(args.indexOf("--help"), 1);
219
- }
220
-
221
- if (args.includes("--version")) {
222
- settings.showVersion = true;
223
- args.splice(args.indexOf("--version"), 1);
224
- }
225
-
226
- if (args.includes("--update")) {
227
- settings.update = true;
228
- args.splice(args.indexOf("--update"), 1);
229
- }
230
-
231
- /// MAIN LOGIC ======================================================================================================
232
-
233
- const mainRouter = {
234
- "--": fallbackBinaryCommand,
235
- update: forcedInstallCommand,
236
- install: installCommand,
237
- version: versionCommand,
238
- };
239
-
240
- async function main() {
241
- if (settings.showVersion) {
242
- showVersion();
243
- }
244
- // Run installCommand before anything else, mainly to ensure that the witnet_toolkit binary
245
- // has been downloaded, unless we're intentionally installing or updating the binary.
246
- if (settings.update) {
247
- await forcedInstallCommand(settings);
248
- }
249
- let args = process.argv.slice(2);
250
-
251
- // Allow options and flags to be placed as first argument...
252
- if (args[0]?.startsWith("--") && args[0].length > 2) {
253
- for (let index = 1; index < args.length; index++) {
254
- if (!args[index].startsWith("--")) {
255
- try {
256
- await import(`./cli/${args[index]}.js`);
257
- args = [
258
- args[index],
259
- ...args.slice(0, index).concat(args.slice(index + 1)),
260
- ];
261
- break;
262
- } catch {}
263
- }
264
- }
265
- }
266
-
267
- let flags;
268
- let options;
269
- if (args[0] && mainRouter[args[0]]) {
270
- await mainRouter[args[0]](settings, args.slice(1));
271
- process.exit(0);
272
- } else if (args[0] && !args[0].startsWith("--")) {
273
- try {
274
- const cmd = args[0];
275
- const module = await import(`./cli/${cmd}.js`);
276
- [args, flags] = extractFromArgs(args.slice(1), module?.flags);
277
- if (args?.[0] && module.subcommands && module?.router[args[0]]) {
278
- const subcmd = args[0];
279
- if (settings?.help) {
280
- showUsageSubcommand(cmd, subcmd, module);
281
- } else {
282
- [args, options] = extractFromArgs(args.slice(1), {
283
- ...module.router[subcmd]?.options,
284
- });
285
- args = deleteExtraFlags(args);
286
- await module.subcommands[subcmd](
287
- { ...settings, ...flags, ...options },
288
- args,
289
- ).catch((err) => {
290
- showUsageError(cmd, subcmd, module, err, settings);
291
- });
292
- }
293
- } else {
294
- showUsage(cmd, module);
295
- }
296
- process.exit(0);
297
- } catch (e) {
298
- console.error(`EXCEPTION:\n${e}\n`);
299
- }
300
- }
301
- console.info("USAGE:");
302
- console.info(` ${colors.white("npx witsdk")} [FLAGS] <MODULE>`);
303
- console.info("\nFLAGS:");
304
- console.info(" --debug Outputs stack trace in case of error.");
305
- console.info(" --force Avoids asking the user to confirm operation.");
306
- console.info(" --help Describes command or subcommand usage.");
307
- console.info(" --update Forces update of underlying binaries.");
308
- console.info(
309
- " --version Prints toolkit name and version as first line.",
310
- );
311
- console.info("\nMODULES:");
312
- console.info(
313
- " inspect Inspect public data from the Wit/Oracle blockchain.",
314
- );
315
- console.info(
316
- " network Dynamic information from the Wit/Oracle P2P network.",
317
- );
318
- console.info(
319
- " nodes Interact with your private Wit/Oracle nodes, if reachable.",
320
- );
321
- console.info(
322
- " radon Manage Radon requests and templates within your project.",
323
- );
324
- console.info(
325
- " wallet Simple CLI wallet for spending and staking your Wits.",
326
- );
327
- }
328
-
329
- main();
2
+
3
+ /// IMPORTS ===========================================================================================================
4
+
5
+ import fs from "node:fs";
6
+ import { createRequire } from "node:module";
7
+ import os from "node:os";
8
+ import path from "node:path";
9
+ import axios from "axios";
10
+ import dotenv from "dotenv";
11
+
12
+ dotenv.config({ quiet: true });
13
+ const _require = createRequire(import.meta.url);
14
+
15
+ import {
16
+ colors,
17
+ deleteExtraFlags,
18
+ extractFromArgs,
19
+ prompt,
20
+ showUsage,
21
+ showUsageError,
22
+ showUsageSubcommand,
23
+ showVersion,
24
+ toolkitRun,
25
+ } from "./helpers.js";
26
+
27
+ /// CONSTANTS =======================================================================================================
28
+
29
+ const __dirname = import.meta.dirname;
30
+
31
+ const version = "2.0.21";
32
+ const toolkitDownloadUrlBase = `https://github.com/witnet/witnet-rust/releases/download/${version}/`;
33
+ const toolkitDownloadNames = {
34
+ win32: (arch) => `witnet_toolkit-${arch}-pc-windows-msvc.exe`,
35
+ // TODO: detect armv7
36
+ linux: (arch) =>
37
+ `witnet_toolkit-${arch}-unknown-linux-gnu${arch === "arm" ? "eabihf" : ""}`,
38
+ darwin: (_arch) => `witnet_toolkit-x86_64-apple-darwin`,
39
+ };
40
+ const toolkitFileNames = {
41
+ win32: (arch) => `witnet_toolkit-${version}-${arch}-pc-windows-msvc.exe`,
42
+ // TODO: detect armv7
43
+ linux: (arch) =>
44
+ `witnet_toolkit-${version}-${arch}-unknown-linux-gnu${arch === "arm" ? "eabihf" : ""}`,
45
+ darwin: (_arch) => `witnet_toolkit-${version}-x86_64-apple-darwin`,
46
+ };
47
+ const archsMap = {
48
+ arm64: "aarch64",
49
+ x64: "x86_64",
50
+ };
51
+
52
+ /// ENVIRONMENT ACQUISITION =========================================================================================
53
+
54
+ const args = process.argv;
55
+ const binDir = __dirname;
56
+
57
+ const toolkitDirPath = path.resolve(binDir, "../../witnet/");
58
+ const platform = guessPlatform();
59
+ const arch = guessArch();
60
+ const toolkitDownloadName = guessToolkitDownloadName(platform, arch);
61
+ const toolkitFileName = guessToolkitFileName(platform, arch);
62
+ const toolkitBinPath = guessToolkitBinPath(toolkitDirPath, platform, arch);
63
+ const toolkitIsDownloaded = checkToolkitIsDownloaded(toolkitBinPath);
64
+
65
+ function guessPlatform() {
66
+ return os.platform();
67
+ }
68
+ function guessArch() {
69
+ const rawArch = os.arch();
70
+ return archsMap[rawArch] || rawArch;
71
+ }
72
+ function guessDownloadUrl(toolkitFileName) {
73
+ return `${toolkitDownloadUrlBase}${toolkitFileName}`;
74
+ }
75
+ function guessToolkitDownloadName(platform, arch) {
76
+ return (toolkitDownloadNames[platform] || toolkitDownloadNames.linux)(arch);
77
+ }
78
+ function guessToolkitFileName(platform, arch) {
79
+ return (toolkitFileNames[platform] || toolkitFileNames.linux)(arch);
80
+ }
81
+ function guessToolkitBinPath(toolkitDirPath, platform, arch) {
82
+ const fileName = guessToolkitFileName(platform, arch);
83
+
84
+ return path.resolve(toolkitDirPath, fileName);
85
+ }
86
+ function checkToolkitIsDownloaded(toolkitBinPath) {
87
+ return fs.existsSync(toolkitBinPath);
88
+ }
89
+
90
+ /// HELPER FUNCTIONS ================================================================================================
91
+
92
+ async function downloadToolkit(
93
+ toolkitDownloadName,
94
+ _toolkitFileName,
95
+ toolkitBinPath,
96
+ platform,
97
+ arch,
98
+ ) {
99
+ const downloadUrl = guessDownloadUrl(toolkitDownloadName);
100
+ console.info("Downloading", downloadUrl, "into", toolkitBinPath);
101
+
102
+ const file = fs.createWriteStream(toolkitBinPath);
103
+ axios({
104
+ method: "get",
105
+ url: downloadUrl,
106
+ responseType: "stream",
107
+ }).then((response) => {
108
+ response.data.pipe(file);
109
+ });
110
+
111
+ return new Promise((resolve, reject) => {
112
+ file.on("finish", () => {
113
+ file.close(() => {
114
+ if (file.bytesWritten > 1000000) {
115
+ fs.chmodSync(toolkitBinPath, 0o755);
116
+ resolve();
117
+ } else {
118
+ reject(`No suitable witnet_toolkit binary found. Maybe your OS (${platform}) or architecture \
119
+ (${arch}) are not yet supported. Feel free to complain about it in the Witnet community on Discord: \
120
+ https://discord.gg/2rTFYXHmPm `);
121
+ }
122
+ });
123
+ });
124
+ const errorHandler = (err) => {
125
+ fs.unlink(downloadUrl, () => {
126
+ reject(err);
127
+ });
128
+ };
129
+ file.on("error", errorHandler);
130
+ });
131
+ }
132
+
133
+ /// COMMAND HANDLERS ================================================================================================
134
+
135
+ async function installCommand(settings) {
136
+ if (!settings.checks.toolkitIsDownloaded) {
137
+ // Skip confirmation if install is forced
138
+ if (!settings.force) {
139
+ console.info(
140
+ `The witnet_toolkit ${version} native binary hasn't been downloaded yet (this is a requirement).`,
141
+ );
142
+ const will = await prompt("Do you want to download it now? (Y/n)");
143
+ // Abort if not confirmed
144
+ if (!["", "y"].includes(will.toLowerCase())) {
145
+ console.error("Aborted download of witnet_toolkit native binary.");
146
+ return;
147
+ }
148
+ }
149
+
150
+ return forcedInstallCommand(settings);
151
+ }
152
+ }
153
+
154
+ async function forcedInstallCommand(settings) {
155
+ if (!fs.existsSync(".env_witnet")) {
156
+ fs.cpSync("node_modules/@witnet/sdk/.env_witnet", ".env_witnet");
157
+ }
158
+ return downloadToolkit(
159
+ settings.paths.toolkitDownloadName,
160
+ settings.paths.toolkitFileName,
161
+ settings.paths.toolkitBinPath,
162
+ settings.system.platform,
163
+ settings.system.arch,
164
+ ).catch((err) => {
165
+ console.error("Error updating witnet_toolkit binary:", err);
166
+ });
167
+ }
168
+
169
+ async function versionCommand(settings) {
170
+ return fallbackBinaryCommand(settings, ["--version"]);
171
+ }
172
+
173
+ async function fallbackBinaryCommand(settings, args) {
174
+ const toolkitOutput = await toolkitRun(settings, args.slice(1)).catch(
175
+ (err) => {
176
+ let errorMessage = err.message.split("\n").slice(1).join("\n").trim();
177
+ const errorRegex = /.*^error: (?<message>.*)$.*/gm;
178
+ const matched = errorRegex.exec(err.message);
179
+ if (matched) {
180
+ errorMessage = matched.groups.message;
181
+ }
182
+ console.error(errorMessage || err);
183
+ },
184
+ );
185
+ if (toolkitOutput) console.info(toolkitOutput);
186
+ }
187
+
188
+ /// PROCESS SETTINGS ===============================================================================================
189
+
190
+ const settings = {
191
+ paths: {
192
+ toolkitBinPath,
193
+ toolkitDirPath,
194
+ toolkitDownloadName,
195
+ toolkitFileName,
196
+ },
197
+ checks: {
198
+ toolkitIsDownloaded,
199
+ },
200
+ system: {
201
+ platform,
202
+ arch,
203
+ },
204
+ };
205
+
206
+ if (args.includes("--debug")) {
207
+ settings.debug = true;
208
+ args.splice(args.indexOf("--debug"), 1);
209
+ }
210
+
211
+ if (args.includes("--force")) {
212
+ settings.force = true;
213
+ args.splice(args.indexOf("--force"), 1);
214
+ }
215
+
216
+ if (args.includes("--help")) {
217
+ settings.help = true;
218
+ args.splice(args.indexOf("--help"), 1);
219
+ }
220
+
221
+ if (args.includes("--version")) {
222
+ settings.showVersion = true;
223
+ args.splice(args.indexOf("--version"), 1);
224
+ }
225
+
226
+ if (args.includes("--update")) {
227
+ settings.update = true;
228
+ args.splice(args.indexOf("--update"), 1);
229
+ }
230
+
231
+ /// MAIN LOGIC ======================================================================================================
232
+
233
+ const mainRouter = {
234
+ "--": fallbackBinaryCommand,
235
+ update: forcedInstallCommand,
236
+ install: installCommand,
237
+ version: versionCommand,
238
+ };
239
+
240
+ async function main() {
241
+ if (settings.showVersion) {
242
+ showVersion();
243
+ }
244
+ // Run installCommand before anything else, mainly to ensure that the witnet_toolkit binary
245
+ // has been downloaded, unless we're intentionally installing or updating the binary.
246
+ if (settings.update) {
247
+ await forcedInstallCommand(settings);
248
+ }
249
+ let args = process.argv.slice(2);
250
+
251
+ // Allow options and flags to be placed as first argument...
252
+ if (args[0]?.startsWith("--") && args[0].length > 2) {
253
+ for (let index = 1; index < args.length; index++) {
254
+ if (!args[index].startsWith("--")) {
255
+ try {
256
+ await import(`./cli/${args[index]}.js`);
257
+ args = [
258
+ args[index],
259
+ ...args.slice(0, index).concat(args.slice(index + 1)),
260
+ ];
261
+ break;
262
+ } catch {}
263
+ }
264
+ }
265
+ }
266
+
267
+ let flags;
268
+ let options;
269
+ if (args[0] && mainRouter[args[0]]) {
270
+ await mainRouter[args[0]](settings, args.slice(1));
271
+ process.exit(0);
272
+ } else if (args[0] && !args[0].startsWith("--")) {
273
+ try {
274
+ const cmd = args[0];
275
+ const module = await import(`./cli/${cmd}.js`);
276
+ [args, flags] = extractFromArgs(args.slice(1), module?.flags);
277
+ if (args?.[0] && module.subcommands && module?.router[args[0]]) {
278
+ const subcmd = args[0];
279
+ if (settings?.help) {
280
+ showUsageSubcommand(cmd, subcmd, module);
281
+ } else {
282
+ [args, options] = extractFromArgs(args.slice(1), {
283
+ ...module.router[subcmd]?.options,
284
+ });
285
+ args = deleteExtraFlags(args);
286
+ await module.subcommands[subcmd](
287
+ { ...settings, ...flags, ...options },
288
+ args,
289
+ ).catch((err) => {
290
+ showUsageError(cmd, subcmd, module, err, settings);
291
+ });
292
+ }
293
+ } else {
294
+ showUsage(cmd, module);
295
+ }
296
+ process.exit(0);
297
+ } catch (e) {
298
+ console.error(`EXCEPTION:\n${e}\n`);
299
+ }
300
+ }
301
+ console.info("USAGE:");
302
+ console.info(` ${colors.white("npx witsdk")} [FLAGS] <MODULE>`);
303
+ console.info("\nFLAGS:");
304
+ console.info(" --debug Outputs stack trace in case of error.");
305
+ console.info(" --force Avoids asking the user to confirm operation.");
306
+ console.info(" --help Describes command or subcommand usage.");
307
+ console.info(" --update Forces update of underlying binaries.");
308
+ console.info(
309
+ " --version Prints toolkit name and version as first line.",
310
+ );
311
+ console.info("\nMODULES:");
312
+ console.info(
313
+ " inspect Inspect public data from the Wit/Oracle blockchain.",
314
+ );
315
+ console.info(
316
+ " network Dynamic information from the Wit/Oracle P2P network.",
317
+ );
318
+ console.info(
319
+ " nodes Interact with your private Wit/Oracle nodes, if reachable.",
320
+ );
321
+ console.info(
322
+ " radon Manage Radon requests and templates within your project.",
323
+ );
324
+ console.info(
325
+ " wallet Simple CLI wallet for spending and staking your Wits.",
326
+ );
327
+ }
328
+
329
+ main();