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