@witnet/sdk 1.1.3 → 1.2.0
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 +13 -1
- package/dist/package.json +31 -24
- package/dist/src/bin/helpers.d.ts +59 -49
- package/dist/src/bin/helpers.d.ts.map +1 -1
- package/dist/src/bin/helpers.js +228 -229
- package/dist/src/index.d.ts +3 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -47
- package/dist/src/lib/crypto/account.d.ts +3 -3
- package/dist/src/lib/crypto/account.d.ts.map +1 -1
- package/dist/src/lib/crypto/account.js +31 -25
- package/dist/src/lib/crypto/coinbase.d.ts +4 -4
- package/dist/src/lib/crypto/coinbase.d.ts.map +1 -1
- package/dist/src/lib/crypto/coinbase.js +8 -13
- package/dist/src/lib/crypto/index.d.ts +7 -7
- package/dist/src/lib/crypto/index.d.ts.map +1 -1
- package/dist/src/lib/crypto/index.js +7 -30
- package/dist/src/lib/crypto/interfaces.d.ts +5 -5
- package/dist/src/lib/crypto/interfaces.d.ts.map +1 -1
- package/dist/src/lib/crypto/interfaces.js +2 -3
- package/dist/src/lib/crypto/payloads/DataRequestPayload.d.ts +5 -5
- package/dist/src/lib/crypto/payloads/DataRequestPayload.d.ts.map +1 -1
- package/dist/src/lib/crypto/payloads/DataRequestPayload.js +107 -95
- package/dist/src/lib/crypto/payloads/StakePayload.d.ts +3 -4
- package/dist/src/lib/crypto/payloads/StakePayload.d.ts.map +1 -1
- package/dist/src/lib/crypto/payloads/StakePayload.js +81 -71
- package/dist/src/lib/crypto/payloads/UnstakePayload.d.ts +4 -5
- package/dist/src/lib/crypto/payloads/UnstakePayload.d.ts.map +1 -1
- package/dist/src/lib/crypto/payloads/UnstakePayload.js +36 -43
- package/dist/src/lib/crypto/payloads/ValueTransferPayload.d.ts +3 -4
- package/dist/src/lib/crypto/payloads/ValueTransferPayload.d.ts.map +1 -1
- package/dist/src/lib/crypto/payloads/ValueTransferPayload.js +46 -48
- package/dist/src/lib/crypto/payloads.d.ts +5 -5
- package/dist/src/lib/crypto/payloads.d.ts.map +1 -1
- package/dist/src/lib/crypto/payloads.js +44 -45
- package/dist/src/lib/crypto/signer.d.ts +3 -3
- package/dist/src/lib/crypto/signer.d.ts.map +1 -1
- package/dist/src/lib/crypto/signer.js +45 -88
- package/dist/src/lib/crypto/transmitters/DataRequests.d.ts +6 -6
- package/dist/src/lib/crypto/transmitters/DataRequests.d.ts.map +1 -1
- package/dist/src/lib/crypto/transmitters/DataRequests.js +6 -10
- package/dist/src/lib/crypto/transmitters/StakeDeposits.d.ts +5 -5
- package/dist/src/lib/crypto/transmitters/StakeDeposits.d.ts.map +1 -1
- package/dist/src/lib/crypto/transmitters/StakeDeposits.js +7 -11
- package/dist/src/lib/crypto/transmitters/StakeWithdrawals.d.ts +6 -7
- package/dist/src/lib/crypto/transmitters/StakeWithdrawals.d.ts.map +1 -1
- package/dist/src/lib/crypto/transmitters/StakeWithdrawals.js +9 -13
- package/dist/src/lib/crypto/transmitters/ValueTransfers.d.ts +5 -5
- package/dist/src/lib/crypto/transmitters/ValueTransfers.d.ts.map +1 -1
- package/dist/src/lib/crypto/transmitters/ValueTransfers.js +6 -10
- package/dist/src/lib/crypto/transmitters.d.ts +6 -6
- package/dist/src/lib/crypto/transmitters.d.ts.map +1 -1
- package/dist/src/lib/crypto/transmitters.js +88 -76
- package/dist/src/lib/crypto/types.d.ts +1 -2
- package/dist/src/lib/crypto/types.d.ts.map +1 -1
- package/dist/src/lib/crypto/types.js +71 -67
- package/dist/src/lib/crypto/utils.d.ts +5 -5
- package/dist/src/lib/crypto/utils.d.ts.map +1 -1
- package/dist/src/lib/crypto/utils.js +48 -66
- package/dist/src/lib/crypto/wallet.d.ts +3 -3
- package/dist/src/lib/crypto/wallet.d.ts.map +1 -1
- package/dist/src/lib/crypto/wallet.js +72 -89
- package/dist/src/lib/index.d.ts +5 -4
- package/dist/src/lib/index.d.ts.map +1 -1
- package/dist/src/lib/index.js +6 -44
- package/dist/src/lib/radon/ccdr/eth.d.ts +1 -1
- package/dist/src/lib/radon/ccdr/eth.d.ts.map +1 -1
- package/dist/src/lib/radon/ccdr/eth.js +95 -83
- package/dist/src/lib/radon/ccdr/index.d.ts +2 -2
- package/dist/src/lib/radon/ccdr/index.d.ts.map +1 -1
- package/dist/src/lib/radon/ccdr/index.js +3 -39
- package/dist/src/lib/radon/ccdr/wit.d.ts +2 -2
- package/dist/src/lib/radon/ccdr/wit.d.ts.map +1 -1
- package/dist/src/lib/radon/ccdr/wit.js +17 -19
- package/dist/src/lib/radon/filters.d.ts.map +1 -1
- package/dist/src/lib/radon/filters.js +23 -19
- package/dist/src/lib/radon/index.d.ts +10 -11
- package/dist/src/lib/radon/index.d.ts.map +1 -1
- package/dist/src/lib/radon/index.js +205 -187
- package/dist/src/lib/radon/reducers.d.ts +2 -2
- package/dist/src/lib/radon/reducers.d.ts.map +1 -1
- package/dist/src/lib/radon/reducers.js +48 -34
- package/dist/src/lib/radon/types.d.ts +2 -2
- package/dist/src/lib/radon/types.d.ts.map +1 -1
- package/dist/src/lib/radon/types.js +80 -110
- package/dist/src/lib/radon/utils.d.ts +3 -3
- package/dist/src/lib/radon/utils.d.ts.map +1 -1
- package/dist/src/lib/radon/utils.js +49 -52
- package/dist/src/lib/rest/kermit.d.ts +20 -0
- package/dist/src/lib/rest/kermit.d.ts.map +1 -0
- package/dist/src/lib/rest/kermit.js +68 -0
- package/dist/src/lib/rest/types.d.ts +5 -0
- package/dist/src/lib/rest/types.d.ts.map +1 -0
- package/dist/src/lib/rest/types.js +2 -0
- package/dist/src/lib/rpc/index.d.ts +2 -2
- package/dist/src/lib/rpc/index.d.ts.map +1 -1
- package/dist/src/lib/rpc/index.js +3 -19
- package/dist/src/lib/rpc/nodes.d.ts +13 -13
- package/dist/src/lib/rpc/nodes.d.ts.map +1 -1
- package/dist/src/lib/rpc/nodes.js +69 -98
- package/dist/src/lib/rpc/provider.d.ts +4 -4
- package/dist/src/lib/rpc/provider.d.ts.map +1 -1
- package/dist/src/lib/rpc/provider.js +111 -125
- package/dist/src/lib/rpc/types.d.ts +2 -2
- package/dist/src/lib/rpc/types.d.ts.map +1 -1
- package/dist/src/lib/rpc/types.js +13 -16
- package/dist/src/lib/types.d.ts +5 -4
- package/dist/src/lib/types.d.ts.map +1 -1
- package/dist/src/lib/types.js +3 -9
- package/dist/src/lib/utils.d.ts +5 -5
- package/dist/src/lib/utils.d.ts.map +1 -1
- package/dist/src/lib/utils.js +40 -99
- package/dist/witnet/assets/index.cjs +6 -0
- package/dist/witnet/assets/index.d.cts +29 -0
- package/dist/witnet/assets/index.d.cts.map +1 -0
- package/dist/witnet/assets/modals/index.cjs +9 -0
- package/dist/witnet/assets/modals/index.d.cts +16 -0
- package/dist/witnet/assets/modals/index.d.cts.map +1 -0
- package/dist/witnet/assets/modals/web3/eth.cjs +23 -0
- package/dist/witnet/assets/modals/web3/eth.d.cts +4 -0
- package/dist/witnet/assets/modals/web3/eth.d.cts.map +1 -0
- package/dist/witnet/assets/modals/web3/ipfs.cjs +18 -0
- package/dist/witnet/assets/modals/web3/ipfs.d.cts +3 -0
- package/dist/witnet/assets/modals/web3/ipfs.d.cts.map +1 -0
- package/dist/witnet/assets/modals/web3/wit.cjs +24 -0
- package/dist/witnet/assets/modals/web3/wit.d.cts +3 -0
- package/dist/witnet/assets/modals/web3/wit.d.cts.map +1 -0
- package/dist/witnet/assets/requests.cjs +43 -0
- package/dist/witnet/assets/requests.d.cts +10 -0
- package/dist/witnet/assets/requests.d.cts.map +1 -0
- package/package.json +31 -24
- package/src/bin/bots/watcher.cjs +354 -0
- package/src/bin/cli/history.cjs +31 -0
- package/src/bin/cli/inspect.js +545 -471
- package/src/bin/cli/network.js +658 -557
- package/src/bin/cli/nodes.js +392 -332
- package/src/bin/cli/radon.js +1071 -844
- package/src/bin/cli/wallet.js +1317 -1074
- package/src/bin/helpers.js +969 -868
- package/src/bin/index.js +329 -0
- package/witnet/assets/_index.cjs +5 -0
- package/witnet/assets/_requests.cjs +25 -0
- package/witnet/assets/_sources.cjs +36 -0
- package/witnet/assets/_templates.cjs +36 -0
- package/witnet/assets/index.cjs +4 -0
- package/witnet/assets/modals/index.cjs +7 -0
- package/witnet/assets/modals/web3/eth.cjs +27 -0
- package/witnet/assets/modals/web3/ipfs.cjs +22 -0
- package/witnet/assets/modals/web3/wit.cjs +28 -0
- package/witnet/assets/requests.cjs +49 -0
- package/witnet/witnet copy.proto +457 -0
- package/witnet/witnet.proto +456 -0
- package/witnet/witnet_toolkit-1.6.7-x86_64-pc-windows-msvc.exe +0 -0
- package/witnet/witnet_toolkit-1.7.1-x86_64-pc-windows-msvc.exe +0 -0
- package/witnet/witnet_toolkit-2.0.0-rc.7-x86_64-pc-windows-msvc.exe +0 -0
- package/witnet/witnet_toolkit-2.0.2-x86_64-pc-windows-msvc.exe +0 -0
- package/witnet/witnet_toolkit-2.0.21-x86_64-pc-windows-msvc.exe +0 -0
- package/witnet/witnet_toolkit-2.0.7-x86_64-pc-windows-msvc.exe +0 -0
- package/witnet/witnet_toolkit-2.0.8-x86_64-pc-windows-msvc.exe +0 -0
- package/dist/witnet/assets/index.d.ts +0 -29
- package/dist/witnet/assets/index.d.ts.map +0 -1
- package/dist/witnet/assets/index.js +0 -6
- package/dist/witnet/assets/modals/index.d.ts +0 -16
- package/dist/witnet/assets/modals/index.d.ts.map +0 -1
- package/dist/witnet/assets/modals/index.js +0 -11
- package/dist/witnet/assets/modals/web3/eth.d.ts +0 -5
- package/dist/witnet/assets/modals/web3/eth.d.ts.map +0 -1
- package/dist/witnet/assets/modals/web3/eth.js +0 -26
- package/dist/witnet/assets/modals/web3/ipfs.d.ts +0 -4
- package/dist/witnet/assets/modals/web3/ipfs.d.ts.map +0 -1
- package/dist/witnet/assets/modals/web3/ipfs.js +0 -18
- package/dist/witnet/assets/modals/web3/wit.d.ts +0 -4
- package/dist/witnet/assets/modals/web3/wit.d.ts.map +0 -1
- package/dist/witnet/assets/modals/web3/wit.js +0 -17
- package/dist/witnet/assets/requests.d.ts +0 -11
- package/dist/witnet/assets/requests.d.ts.map +0 -1
- package/dist/witnet/assets/requests.js +0 -43
- package/src/bin/cli/history.js +0 -31
- package/src/bin/postinstall.js +0 -9
- package/src/bin/toolkit.js +0 -290
- package/witnet/assets/_index.js +0 -8
- package/witnet/assets/_requests.js +0 -25
- package/witnet/assets/_sources.js +0 -36
- package/witnet/assets/_templates.js +0 -36
- package/witnet/assets/index.js +0 -4
- package/witnet/assets/modals/index.js +0 -9
- package/witnet/assets/modals/web3/eth.js +0 -29
- package/witnet/assets/modals/web3/ipfs.js +0 -22
- package/witnet/assets/modals/web3/wit.js +0 -21
- package/witnet/assets/requests.js +0 -49
- /package/witnet/assets/modals/web3/{btc.js → btc.cjs} +0 -0
- /package/witnet/assets/modals/web3/{sol.js → sol.cjs} +0 -0
package/src/bin/cli/nodes.js
CHANGED
|
@@ -1,364 +1,424 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import * as qrcode from "qrcode-terminal";
|
|
2
|
+
import { Witnet } from "../../../dist/src/index.js";
|
|
3
|
+
import {
|
|
4
|
+
colors as _colors,
|
|
5
|
+
commas,
|
|
6
|
+
prompt,
|
|
7
|
+
traceChecklists,
|
|
8
|
+
traceTable,
|
|
9
|
+
} from "../helpers.js";
|
|
4
10
|
|
|
5
|
-
const {
|
|
11
|
+
const {
|
|
12
|
+
cyan,
|
|
13
|
+
gray,
|
|
14
|
+
green,
|
|
15
|
+
red,
|
|
16
|
+
yellow,
|
|
17
|
+
white,
|
|
18
|
+
mcyan,
|
|
19
|
+
mgreen,
|
|
20
|
+
mmagenta,
|
|
21
|
+
mred,
|
|
22
|
+
myellow,
|
|
23
|
+
lcyan,
|
|
24
|
+
lgreen,
|
|
25
|
+
lmagenta,
|
|
26
|
+
lyellow,
|
|
27
|
+
} = _colors;
|
|
6
28
|
|
|
7
29
|
/// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
8
30
|
/// CLI SUBMODULE CONSTANTS ===========================================================================================
|
|
9
31
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
32
|
+
export const envars = {
|
|
33
|
+
WITNET_TOOLKIT_FARM_NODES:
|
|
34
|
+
"=> URLs to your own nodes' HTTP/JSON private endpoints, if no otherwise specified.",
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const flags = {
|
|
38
|
+
nodes: {
|
|
39
|
+
hint: "Private URLs to your node's HTTP/JSON endpoints, other than default.",
|
|
40
|
+
param: "JSON_HTTP_URL[;..]",
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const router = {
|
|
45
|
+
authorize: {
|
|
46
|
+
hint: "Generate stake authorization codes for given withdrawer.",
|
|
47
|
+
params: "WITHDRAWER",
|
|
48
|
+
options: {
|
|
49
|
+
qrcodes: {
|
|
50
|
+
hint: "Print authorization QR codes, scannable from myWitWallet.",
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
balance: {
|
|
55
|
+
hint: "List endpoints that connect to your nodes, addresses and available balances.",
|
|
56
|
+
},
|
|
57
|
+
masterKeys: {
|
|
58
|
+
hint: "Export nodes' master keys.",
|
|
59
|
+
},
|
|
60
|
+
publicKeys: {
|
|
61
|
+
hint: "Export nodes' public keys.",
|
|
62
|
+
},
|
|
63
|
+
peers: {
|
|
64
|
+
hint: "List and manage node farm's peers.",
|
|
65
|
+
options: {
|
|
66
|
+
add: {
|
|
67
|
+
hint: "Add new peer addresses for the nodes to try to connect to.",
|
|
68
|
+
param: "P2P_IP:PORT[;..]",
|
|
69
|
+
},
|
|
70
|
+
"clear-buckets": {
|
|
71
|
+
hint: "Clear out all peering buckets.",
|
|
72
|
+
},
|
|
73
|
+
reset: {
|
|
74
|
+
hint: "Clear all peers from the buckets and initialize to those in config.",
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
rankings: {
|
|
79
|
+
hint: "Sort identities by their current mining power ranking.",
|
|
80
|
+
options: {
|
|
81
|
+
witnessing: { hint: "Sort by witnessing power ranking instead." },
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
rewind: {
|
|
85
|
+
hint: "Rewind blockchain state on farm nodes to this epoch.",
|
|
86
|
+
params: "EPOCH",
|
|
87
|
+
},
|
|
88
|
+
stats: {
|
|
89
|
+
hint: "Report farm stats.",
|
|
90
|
+
},
|
|
91
|
+
syncStatus: {
|
|
92
|
+
hint: "Report current sync status for every node in the farm.",
|
|
93
|
+
},
|
|
94
|
+
withdrawers: {
|
|
95
|
+
hint: "List withdrawers and stake entries currently delegating to the farm nodes.",
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const subcommands = {
|
|
100
|
+
addresses,
|
|
101
|
+
authorize,
|
|
102
|
+
balance,
|
|
103
|
+
masterKeys,
|
|
104
|
+
publicKeys,
|
|
105
|
+
peers,
|
|
106
|
+
rankings,
|
|
107
|
+
rewind,
|
|
108
|
+
stats,
|
|
109
|
+
syncStatus,
|
|
110
|
+
withdrawers,
|
|
111
|
+
};
|
|
88
112
|
|
|
89
113
|
/// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
90
114
|
/// CLI SUBMODULE COMMANDS ============================================================================================
|
|
91
115
|
|
|
92
|
-
async function _initializeFarm
|
|
93
|
-
|
|
116
|
+
async function _initializeFarm(options = {}) {
|
|
117
|
+
return new Witnet.JsonRpcNodeFarm(options?.nodes);
|
|
94
118
|
}
|
|
95
119
|
|
|
96
|
-
async function addresses
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
120
|
+
async function addresses(options = {}) {
|
|
121
|
+
const farm = await _initializeFarm(options);
|
|
122
|
+
const addresses = Object.entries(await farm.addresses());
|
|
123
|
+
if (addresses.length === 1 && !(addresses[0][1] instanceof Error)) {
|
|
124
|
+
console.info(lcyan(addresses[0][1]));
|
|
125
|
+
qrcode.generate(addresses[0][1]);
|
|
126
|
+
} else {
|
|
127
|
+
traceTable(
|
|
128
|
+
addresses.map(([url, pkh]) => [
|
|
129
|
+
pkh instanceof Error ? red(url) : mcyan(url),
|
|
130
|
+
pkh instanceof Error ? red(pkh) : lcyan(pkh),
|
|
131
|
+
]),
|
|
132
|
+
{
|
|
133
|
+
headlines: ["NODES", ":Public Key Hash"],
|
|
134
|
+
},
|
|
135
|
+
);
|
|
136
|
+
}
|
|
112
137
|
}
|
|
113
138
|
|
|
114
|
-
async function authorize
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
139
|
+
async function authorize(options = {}, args = []) {
|
|
140
|
+
if (args.length === 0) {
|
|
141
|
+
throw Error("Withdrawer address must be specified");
|
|
142
|
+
} else {
|
|
143
|
+
Witnet.PublicKeyHash.fromBech32(args[0]);
|
|
144
|
+
const farm = await _initializeFarm(options);
|
|
145
|
+
const authcodes = await farm.authorizeStakes(args[0].toLowerCase());
|
|
146
|
+
Object.entries(authcodes).forEach(([url, [validator, authcode]]) => {
|
|
147
|
+
if (url instanceof Error) {
|
|
148
|
+
console.error(url);
|
|
149
|
+
} else if (validator instanceof Error) {
|
|
150
|
+
console.error("Endpoint:", url);
|
|
151
|
+
console.error(validator);
|
|
152
|
+
} else if (authcode instanceof Error) {
|
|
153
|
+
console.info("Validator address: ", mcyan(validator));
|
|
154
|
+
console.error(authcode);
|
|
155
|
+
} else {
|
|
156
|
+
console.info("Validator address: ", mcyan(validator));
|
|
157
|
+
console.info(`${white(authcode)}`);
|
|
158
|
+
if (options?.qrcodes) generate(authcode);
|
|
159
|
+
}
|
|
160
|
+
console.info();
|
|
161
|
+
});
|
|
162
|
+
if (options?.qrcodes) {
|
|
163
|
+
console.info("=".repeat(102));
|
|
164
|
+
console.info("^ Withdrawer address:", lmagenta(args[0].toLowerCase()));
|
|
165
|
+
} else {
|
|
166
|
+
console.info("Withdrawer address:", lmagenta(args[0].toLowerCase()));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
144
169
|
}
|
|
145
170
|
|
|
146
|
-
async function balance
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
171
|
+
async function balance(options = {}) {
|
|
172
|
+
const farm = await _initializeFarm(options);
|
|
173
|
+
const balances = await farm.balances();
|
|
174
|
+
traceTable(
|
|
175
|
+
Object.entries(balances).map(([url, [pkh, balance]]) => [
|
|
176
|
+
pkh instanceof Error ? red(url) : mcyan(url),
|
|
177
|
+
pkh instanceof Error ? red(pkh) : lcyan(pkh),
|
|
178
|
+
...(balance instanceof Error
|
|
179
|
+
? new Array(4).fill(gray("n/a"))
|
|
180
|
+
: [
|
|
181
|
+
gray(Witnet.Coins.fromNanowits(balance.locked).wits),
|
|
182
|
+
yellow(Witnet.Coins.fromNanowits(balance.staked).wits),
|
|
183
|
+
myellow(Witnet.Coins.fromNanowits(balance.unlocked).wits),
|
|
184
|
+
lyellow(
|
|
185
|
+
Witnet.Coins.fromNanowits(
|
|
186
|
+
balance.locked + balance.staked + balance.unlocked,
|
|
187
|
+
).wits,
|
|
188
|
+
),
|
|
189
|
+
]),
|
|
190
|
+
]),
|
|
191
|
+
{
|
|
192
|
+
headlines: [
|
|
193
|
+
"NODES",
|
|
194
|
+
":Validator address",
|
|
195
|
+
"Locked ($WIT)",
|
|
196
|
+
"Staked ($WIT)",
|
|
197
|
+
"Available ($WIT)",
|
|
198
|
+
"BALANCE ($WIT)",
|
|
199
|
+
],
|
|
200
|
+
humanizers: [undefined, undefined, commas, commas, commas, commas],
|
|
201
|
+
maxColumnWidth: 48,
|
|
202
|
+
},
|
|
203
|
+
);
|
|
168
204
|
}
|
|
169
205
|
|
|
170
|
-
async function masterKeys
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
206
|
+
async function masterKeys(options = {}) {
|
|
207
|
+
const farm = await _initializeFarm(options);
|
|
208
|
+
const masterKeys = await farm.masterKeys();
|
|
209
|
+
traceTable(
|
|
210
|
+
Object.entries(masterKeys).map(([, [pkh, masterKey]]) => [
|
|
211
|
+
// pkh instanceof Error ? cyan(url) : mcyan(url),
|
|
212
|
+
pkh instanceof Error ? red(pkh) : mcyan(pkh),
|
|
213
|
+
masterKey instanceof Error ? mred(masterKey) : cyan(masterKey),
|
|
214
|
+
]),
|
|
215
|
+
{
|
|
216
|
+
headlines: [":Public key hash", "Secret key"],
|
|
217
|
+
maxColumnWidth: 120,
|
|
218
|
+
},
|
|
219
|
+
);
|
|
183
220
|
}
|
|
184
221
|
|
|
185
|
-
async function peers
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
222
|
+
async function peers(options = {}) {
|
|
223
|
+
const farm = await _initializeFarm(options);
|
|
224
|
+
const checklists = {};
|
|
225
|
+
if (options.reset) {
|
|
226
|
+
checklists["Reset peers"] = await farm.initializePeers();
|
|
227
|
+
} else if (options["clear-buckets"]) {
|
|
228
|
+
checklists["Clear buckets"] = await farm.clearPeers();
|
|
229
|
+
}
|
|
230
|
+
if (options.add) {
|
|
231
|
+
const morePeers = options.add.replaceAll(",", ";").split(";");
|
|
232
|
+
checklists["Add peers"] = await farm.addPeers(morePeers);
|
|
233
|
+
}
|
|
234
|
+
traceChecklists(checklists);
|
|
235
|
+
const peers = await farm.peers();
|
|
236
|
+
if (peers.length > 0) {
|
|
237
|
+
console.log(peers);
|
|
238
|
+
}
|
|
202
239
|
}
|
|
203
240
|
|
|
204
|
-
async function publicKeys
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
241
|
+
async function publicKeys(options = {}) {
|
|
242
|
+
const farm = await _initializeFarm(options);
|
|
243
|
+
const publicKeys = await farm.publicKeys();
|
|
244
|
+
traceTable(
|
|
245
|
+
Object.entries(publicKeys).map(([, [pkh, publicKey]]) => [
|
|
246
|
+
pkh instanceof Error ? red(pkh) : mcyan(pkh),
|
|
247
|
+
publicKey instanceof Error
|
|
248
|
+
? mred(publicKey.toString())
|
|
249
|
+
: cyan(publicKey.toString()),
|
|
250
|
+
]),
|
|
251
|
+
{
|
|
252
|
+
headlines: [":Public key hash", "Public key"],
|
|
253
|
+
maxColumnWidth: 120,
|
|
254
|
+
},
|
|
255
|
+
);
|
|
216
256
|
}
|
|
217
257
|
|
|
218
|
-
async function rankings
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
console.info("> No nodes currently available to interact with.")
|
|
268
|
-
}
|
|
258
|
+
async function rankings(options = {}) {
|
|
259
|
+
const farm = await _initializeFarm(options);
|
|
260
|
+
const addresses = Object.entries(await farm.addresses());
|
|
261
|
+
const validators = [];
|
|
262
|
+
let provider;
|
|
263
|
+
addresses.forEach(([url, pkh]) => {
|
|
264
|
+
if (pkh instanceof Error) {
|
|
265
|
+
console.error(`> Skipping node ${url}: ${pkh}`);
|
|
266
|
+
} else {
|
|
267
|
+
if (!provider) provider = new Witnet.JsonRpcProvider(url);
|
|
268
|
+
validators.push(pkh);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
if (validators.length > 0 && provider) {
|
|
272
|
+
const query = {
|
|
273
|
+
distinct: true,
|
|
274
|
+
orderBy: options?.witnessing ? "witnessing" : "mining",
|
|
275
|
+
};
|
|
276
|
+
const capability = query.orderBy.toUpperCase();
|
|
277
|
+
const records = await provider.powers(query);
|
|
278
|
+
if (records.length > 0) {
|
|
279
|
+
traceTable(
|
|
280
|
+
records
|
|
281
|
+
.filter((record) => validators.includes(record.validator))
|
|
282
|
+
.map(({ power, ranking, validator, withdrawer }) => [
|
|
283
|
+
validator,
|
|
284
|
+
withdrawer,
|
|
285
|
+
power,
|
|
286
|
+
ranking,
|
|
287
|
+
]),
|
|
288
|
+
{
|
|
289
|
+
headlines: [
|
|
290
|
+
"VALIDATORS",
|
|
291
|
+
"Withdrawer",
|
|
292
|
+
`${capability} POWER`,
|
|
293
|
+
"G_RANK",
|
|
294
|
+
],
|
|
295
|
+
humanizers: [undefined, undefined, commas, commas],
|
|
296
|
+
colors: [lcyan, mmagenta, green, lgreen],
|
|
297
|
+
},
|
|
298
|
+
);
|
|
299
|
+
} else {
|
|
300
|
+
console.info(
|
|
301
|
+
`> No ${capability} power is currently treasured on the farm.`,
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
} else {
|
|
305
|
+
console.info("> No nodes currently available to interact with.");
|
|
306
|
+
}
|
|
269
307
|
}
|
|
270
308
|
|
|
271
|
-
async function rewind
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
309
|
+
async function rewind(options = {}, args = []) {
|
|
310
|
+
if (!args || args.length === 0) {
|
|
311
|
+
throw Error("No rewind epoch was provided");
|
|
312
|
+
}
|
|
313
|
+
if (!options?.force) {
|
|
314
|
+
const will = await prompt(
|
|
315
|
+
"Rewinding will reset some stats. Do you want to proceed anyways? (y/N)",
|
|
316
|
+
);
|
|
317
|
+
// Abort if not confirmed
|
|
318
|
+
if (!["y"].includes(will.toLowerCase())) {
|
|
319
|
+
console.error("Aborted by user.");
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
const farm = await _initializeFarm(options);
|
|
324
|
+
const epoch = parseInt(args[0], 10);
|
|
325
|
+
traceChecklists({
|
|
326
|
+
"Rewind chain": await farm.rewind(epoch),
|
|
327
|
+
});
|
|
328
|
+
syncStatus(options);
|
|
289
329
|
}
|
|
290
330
|
|
|
291
|
-
async function stats
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
331
|
+
async function stats(options = {}) {
|
|
332
|
+
const farm = await _initializeFarm(options);
|
|
333
|
+
const stats = await farm.stats();
|
|
334
|
+
traceTable(
|
|
335
|
+
Object.entries(stats).map(([url, stats]) => [
|
|
336
|
+
...(stats instanceof Error
|
|
337
|
+
? [
|
|
338
|
+
red(url),
|
|
339
|
+
gray("n/a"),
|
|
340
|
+
gray("n/a"),
|
|
341
|
+
gray("n/a"),
|
|
342
|
+
gray("n/a"),
|
|
343
|
+
gray("n/a"),
|
|
344
|
+
gray("n/a"),
|
|
345
|
+
]
|
|
346
|
+
: [
|
|
347
|
+
mcyan(url),
|
|
348
|
+
stats.block_mined_count,
|
|
349
|
+
stats.commits_count,
|
|
350
|
+
(stats.block_mined_count / stats.block_proposed_count).toFixed(3),
|
|
351
|
+
(stats.commits_count / stats.commits_proposed_count).toFixed(3),
|
|
352
|
+
(
|
|
353
|
+
(stats.dr_eligibility_count - stats.commits_proposed_count) /
|
|
354
|
+
stats.dr_eligibility_count
|
|
355
|
+
).toFixed(3),
|
|
356
|
+
(stats.slashed_count / stats.commits_count).toFixed(3),
|
|
357
|
+
]),
|
|
358
|
+
]),
|
|
359
|
+
{
|
|
360
|
+
headlines: [
|
|
361
|
+
"NODES",
|
|
362
|
+
"Mined blocks",
|
|
363
|
+
"Witnessed DRs",
|
|
364
|
+
"M_Acceptancy",
|
|
365
|
+
"W_Acceptancy",
|
|
366
|
+
"W_Reluctancy",
|
|
367
|
+
"W_Falsity",
|
|
368
|
+
],
|
|
369
|
+
humanizers: [undefined, commas, commas, undefined, undefined, undefined],
|
|
370
|
+
},
|
|
371
|
+
);
|
|
321
372
|
}
|
|
322
373
|
|
|
323
|
-
async function syncStatus
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
374
|
+
async function syncStatus(options) {
|
|
375
|
+
const farm = await _initializeFarm(options);
|
|
376
|
+
const syncStatus = await farm.syncStatus();
|
|
377
|
+
traceTable(
|
|
378
|
+
Object.entries(syncStatus).map(([url, status]) => [
|
|
379
|
+
status instanceof Error ? red(url) : mcyan(url),
|
|
380
|
+
...(status instanceof Error
|
|
381
|
+
? [red(status), "", "", ""]
|
|
382
|
+
: [
|
|
383
|
+
status.node_state.trim() === "Synced"
|
|
384
|
+
? mgreen(status.node_state)
|
|
385
|
+
: myellow(status.node_state),
|
|
386
|
+
status.current_epoch,
|
|
387
|
+
status.chain_beacon.checkpoint,
|
|
388
|
+
status.chain_beacon.hashPrevBlock,
|
|
389
|
+
]),
|
|
390
|
+
]),
|
|
391
|
+
{
|
|
392
|
+
headlines: [
|
|
393
|
+
":NODES",
|
|
394
|
+
":Status",
|
|
395
|
+
"Current epoch",
|
|
396
|
+
"Checkpoint epoch",
|
|
397
|
+
":Checkpoint block hash",
|
|
398
|
+
],
|
|
399
|
+
humanizers: [undefined, undefined, commas, commas],
|
|
400
|
+
colors: [undefined, undefined, white, undefined, gray], // gray, gray ],
|
|
401
|
+
},
|
|
402
|
+
);
|
|
343
403
|
}
|
|
344
404
|
|
|
345
|
-
async function withdrawers
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
405
|
+
async function withdrawers(options = {}) {
|
|
406
|
+
const farm = await _initializeFarm(options);
|
|
407
|
+
const records = await farm.withdrawers();
|
|
408
|
+
if (records && Object.keys(records).length > 0) {
|
|
409
|
+
traceTable(
|
|
410
|
+
Object.entries(records).map(([withdrawer, [coins, nonce]]) => [
|
|
411
|
+
withdrawer,
|
|
412
|
+
nonce,
|
|
413
|
+
Witnet.Coins.fromNanowits(coins).wits,
|
|
414
|
+
]),
|
|
415
|
+
{
|
|
416
|
+
headlines: ["WITHDRAWERS", "Latest nonce", "Total staked ($WIT)"],
|
|
417
|
+
humanizers: [undefined, commas, commas],
|
|
418
|
+
colors: [mmagenta, undefined, myellow],
|
|
419
|
+
},
|
|
420
|
+
);
|
|
421
|
+
} else {
|
|
422
|
+
console.info("> No withdrawers delegating on the farm at the moment.");
|
|
423
|
+
}
|
|
364
424
|
}
|