@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/inspect.js
CHANGED
|
@@ -1,507 +1,581 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import moment from "moment";
|
|
2
|
+
import { utils, Witnet } from "../../../dist/src/index.js";
|
|
3
|
+
import * as helpers from "../helpers.js";
|
|
3
4
|
|
|
4
|
-
const
|
|
5
|
-
|
|
5
|
+
const {
|
|
6
|
+
cyan,
|
|
7
|
+
gray,
|
|
8
|
+
green,
|
|
9
|
+
lyellow,
|
|
10
|
+
magenta,
|
|
11
|
+
mgreen,
|
|
12
|
+
mmagenta,
|
|
13
|
+
myellow,
|
|
14
|
+
yellow,
|
|
15
|
+
} = helpers.colors;
|
|
6
16
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const DEFAULT_LIMIT = 100
|
|
17
|
+
const _DEFAULT_LIMIT = 100;
|
|
10
18
|
|
|
11
19
|
/// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
12
20
|
/// CLI SUBMODULE CONSTANTS ===========================================================================================
|
|
13
21
|
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
22
|
+
export const envars = {
|
|
23
|
+
WITNET_SDK_PROVIDER_URL:
|
|
24
|
+
"=> Wit/Oracle RPC provider(s) to connect to, if no otherwise specified.",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const flags = {
|
|
28
|
+
provider: {
|
|
29
|
+
hint: "Public Wit/Oracle JSON-RPC provider, other than default.",
|
|
30
|
+
param: "URL",
|
|
31
|
+
},
|
|
32
|
+
reverse: {
|
|
33
|
+
hint: "List most recent data requests first (default: true).",
|
|
34
|
+
},
|
|
35
|
+
verbose: {
|
|
36
|
+
hint: "Outputs validators' nonce and last validation epochs.",
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const router = {
|
|
41
|
+
balance: {
|
|
42
|
+
hint: "Show available Wits on given address.",
|
|
43
|
+
params: "WIT_ADDRESS",
|
|
44
|
+
},
|
|
45
|
+
block: {
|
|
46
|
+
hint: "Get block data given its block hash.",
|
|
47
|
+
params: "BLOCK_HASH",
|
|
48
|
+
},
|
|
49
|
+
dataRequest: {
|
|
50
|
+
hint: "Get query parameters and result to some data request transaction.",
|
|
51
|
+
params: "DR_TX_HASH",
|
|
52
|
+
options: {
|
|
53
|
+
force: {
|
|
54
|
+
hint: "Get data even if the WIT/RPC provider is not synced.",
|
|
55
|
+
},
|
|
56
|
+
mode: {
|
|
57
|
+
hint: "Possible report formats (default: `ethereal`).",
|
|
58
|
+
param: "`ethereal` | `full``",
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
dataRequests: {
|
|
63
|
+
hint: "Search for in-flight or recently solved data request transactions.",
|
|
64
|
+
params: "RAD_BYTECODE | RAD_HASH",
|
|
65
|
+
options: {
|
|
66
|
+
limit: { hint: "Limit output records (default: 100).", param: "LIMIT" },
|
|
67
|
+
offset: {
|
|
68
|
+
hint: "Skips first records as found on server side (default: 0).",
|
|
69
|
+
param: "SKIP",
|
|
70
|
+
},
|
|
71
|
+
mode: {
|
|
72
|
+
hint: "Possible report formats (default: `ethereal`).",
|
|
73
|
+
param: "`ethereal` | `full``",
|
|
74
|
+
},
|
|
75
|
+
since: {
|
|
76
|
+
hint: "Number of past epochs to search for (default: -30240).",
|
|
77
|
+
param: "EPOCH|MINUS_EPOCHS",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
superblock: {
|
|
82
|
+
hint: "Show superblock metadata for given epoch.",
|
|
83
|
+
params: "EPOCH",
|
|
84
|
+
},
|
|
85
|
+
transaction: {
|
|
86
|
+
hint: "Report transaction details given its transaction hash.",
|
|
87
|
+
params: "TX_HASH",
|
|
88
|
+
},
|
|
89
|
+
validators: {
|
|
90
|
+
hint: "List validators treasuring delegated stake from the specified address.",
|
|
91
|
+
params: "WIT_ADDRESS",
|
|
92
|
+
},
|
|
93
|
+
valueTransfer: {
|
|
94
|
+
hint: "Report value transfer details given its transaction hash.",
|
|
95
|
+
params: "VT_TX_HASH",
|
|
96
|
+
options: {
|
|
97
|
+
force: {
|
|
98
|
+
hint: "Get data even if the WIT/RPC provider is not synced.",
|
|
99
|
+
},
|
|
100
|
+
mode: {
|
|
101
|
+
hint: "Possible report formats (default: `full`).",
|
|
102
|
+
param: "`ethereal` | `full` | `simple`",
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
withdrawers: {
|
|
107
|
+
hint: "List withdrawers currently delegating stake to the specified address.",
|
|
108
|
+
params: "WIT_ADDRESS",
|
|
109
|
+
},
|
|
110
|
+
utxos: {
|
|
111
|
+
hint: "List UTXOs available to the specified address.",
|
|
112
|
+
params: "WIT_ADDRESS",
|
|
113
|
+
options: {
|
|
114
|
+
from: {
|
|
115
|
+
hint: "Show only UTXOs that previously belonged to this other address.",
|
|
116
|
+
param: "WIT_ADDRESS",
|
|
117
|
+
},
|
|
118
|
+
"min-value": {
|
|
119
|
+
hint: "Filter out UTXOs with a value smaller than this amount.",
|
|
120
|
+
param: "WITS",
|
|
121
|
+
},
|
|
122
|
+
strategy: {
|
|
123
|
+
hint: "UTXOs listing order: `big-first`, `random`, `small-first` (default: `big-first`).",
|
|
124
|
+
param: "STRATEGY",
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export const subcommands = {
|
|
131
|
+
balance,
|
|
132
|
+
block,
|
|
133
|
+
dataRequest,
|
|
134
|
+
dataRequests,
|
|
135
|
+
superblock,
|
|
136
|
+
transaction,
|
|
137
|
+
validators,
|
|
138
|
+
withdrawers,
|
|
139
|
+
utxos,
|
|
140
|
+
valueTransfer,
|
|
141
|
+
};
|
|
123
142
|
|
|
124
143
|
/// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
125
144
|
/// CLI SUBMODULE COMMANDS ============================================================================================
|
|
126
145
|
|
|
127
|
-
async function balance
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
+
async function balance(options = {}, args = []) {
|
|
147
|
+
if (args.length === 0) {
|
|
148
|
+
throw Error("No WIT_ADDRESS was specified");
|
|
149
|
+
}
|
|
150
|
+
const pkh = args[0];
|
|
151
|
+
const provider = new Witnet.JsonRpcProvider(options?.provider);
|
|
152
|
+
const balance = await provider.getBalance(pkh);
|
|
153
|
+
const records = [];
|
|
154
|
+
records.push([
|
|
155
|
+
Witnet.Coins.fromNanowits(balance.locked).wits,
|
|
156
|
+
Witnet.Coins.fromNanowits(balance.staked).wits,
|
|
157
|
+
Witnet.Coins.fromNanowits(balance.unlocked).wits,
|
|
158
|
+
Witnet.Coins.fromNanowits(
|
|
159
|
+
balance.locked + balance.staked + balance.unlocked,
|
|
160
|
+
).wits,
|
|
161
|
+
]);
|
|
162
|
+
helpers.traceTable(records, {
|
|
163
|
+
headlines: [
|
|
164
|
+
"Locked ($WIT)",
|
|
165
|
+
"Staked ($WIT)",
|
|
166
|
+
"Available ($WIT)",
|
|
167
|
+
"BALANCE ($WIT)",
|
|
168
|
+
],
|
|
169
|
+
humanizers: [
|
|
170
|
+
helpers.commas,
|
|
171
|
+
helpers.commas,
|
|
172
|
+
helpers.commas,
|
|
173
|
+
helpers.commas,
|
|
174
|
+
],
|
|
175
|
+
colors: [gray, yellow, myellow, lyellow],
|
|
176
|
+
});
|
|
146
177
|
}
|
|
147
178
|
|
|
148
|
-
async function block
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
179
|
+
async function block(options = {}, args = []) {
|
|
180
|
+
if (args.length === 0) {
|
|
181
|
+
throw Error("No BLOCK_HASH was specified");
|
|
182
|
+
}
|
|
183
|
+
const blockHash = args[0].startsWith("0x") ? args[0].slice(2) : args[0];
|
|
184
|
+
if (!helpers.isHexString(blockHash)) {
|
|
185
|
+
throw Error("Invalid BLOCK_HASH was provided");
|
|
186
|
+
}
|
|
187
|
+
const provider = await Witnet.JsonRpcProvider.fromEnv(options?.provider);
|
|
188
|
+
const block = await provider.getBlock(blockHash);
|
|
189
|
+
console.info(
|
|
190
|
+
gray(
|
|
191
|
+
JSON.stringify(
|
|
192
|
+
block,
|
|
193
|
+
(key, value) => {
|
|
194
|
+
switch (key) {
|
|
195
|
+
case "bytes":
|
|
196
|
+
case "der":
|
|
197
|
+
case "proof":
|
|
198
|
+
return Array.isArray(value)
|
|
199
|
+
? helpers.toHexString(value, true)
|
|
200
|
+
: value;
|
|
201
|
+
|
|
202
|
+
case "public_key":
|
|
203
|
+
return Array.isArray(value)
|
|
204
|
+
? helpers.toHexString(value, true)
|
|
205
|
+
: typeof value === "object"
|
|
206
|
+
? Witnet.PublicKey.fromProtobuf(value)
|
|
207
|
+
.hash()
|
|
208
|
+
.toBech32(provider.network)
|
|
209
|
+
: value;
|
|
164
210
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}, 2)))
|
|
211
|
+
default:
|
|
212
|
+
return value;
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
2,
|
|
216
|
+
),
|
|
217
|
+
),
|
|
218
|
+
);
|
|
174
219
|
}
|
|
175
220
|
|
|
176
221
|
async function dataRequests(options = {}, [arg]) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
-
|
|
222
|
+
// if (!args || args.length === 0) {
|
|
223
|
+
if (!arg) {
|
|
224
|
+
throw new Error("No RAD_HASH or RAD_RAD_BYTECODE was specified.");
|
|
225
|
+
}
|
|
226
|
+
const provider = new Witnet.JsonRpcProvider(options?.provider);
|
|
227
|
+
// const radHashes = args.map(arg => {
|
|
228
|
+
if (!helpers.isHexString(arg)) {
|
|
229
|
+
throw new Error(`Invalid hex string was provided: '${arg}'`);
|
|
230
|
+
}
|
|
231
|
+
let radHash;
|
|
232
|
+
if (helpers.isHexStringOfLength(arg, 32)) {
|
|
233
|
+
radHash = arg;
|
|
234
|
+
} else {
|
|
235
|
+
const request = Witnet.Radon.RadonRequest.fromBytecode(arg);
|
|
236
|
+
radHash = request.radHash;
|
|
237
|
+
}
|
|
238
|
+
// return radHash
|
|
239
|
+
// })
|
|
240
|
+
// let results = await helpers.prompter(
|
|
241
|
+
// Promise.all(
|
|
242
|
+
// [...new Set(radHashes)].map(radHash => provider.searchDataRequests(radHash, {
|
|
243
|
+
// limit: options?.limit ? parseInt(options.limit) : undefined,
|
|
244
|
+
// offset: options?.offset ? parseInt(options.offset) : undefined,
|
|
245
|
+
// reverse: options?.reverse,
|
|
246
|
+
// }))
|
|
247
|
+
// ).then(results => results
|
|
248
|
+
// .flat()
|
|
249
|
+
// .sort((a, b) => options?.reverse ? b.block_epoch - a.block_epoch : a.block_epoch - b.block_epoch)
|
|
250
|
+
// .slice(options?.offset)
|
|
251
|
+
// .slice(0, options?.limit || DEFAULT_LIMIT)
|
|
252
|
+
// )
|
|
253
|
+
// )
|
|
254
|
+
const results = await helpers.prompter(
|
|
255
|
+
provider.searchDataRequests(radHash, {
|
|
256
|
+
limit: options?.limit ? parseInt(options.limit, 10) : undefined,
|
|
257
|
+
offset: options?.offset ? parseInt(options.offset, 10) : undefined,
|
|
258
|
+
mode: options?.mode,
|
|
259
|
+
reverse: options?.reverse,
|
|
260
|
+
}),
|
|
261
|
+
);
|
|
262
|
+
helpers.traceTable(
|
|
263
|
+
results.map((record) => {
|
|
264
|
+
let result = record?.result.cbor_bytes
|
|
265
|
+
? utils.cbor.decode(record?.result.cbor_bytes, { encoding: "hex" })
|
|
266
|
+
: "";
|
|
267
|
+
const request = Witnet.Radon.RadonRequest.fromBytecode(
|
|
268
|
+
record.query.rad_bytecode,
|
|
269
|
+
);
|
|
270
|
+
const dataType =
|
|
271
|
+
result.constructor.name === "Tagged" ? "RadonError" : request.dataType;
|
|
272
|
+
if (dataType !== "RadonError")
|
|
273
|
+
result = Buffer.from(
|
|
274
|
+
utils.fromHexString(record?.result.cbor_bytes),
|
|
275
|
+
).toString("base64");
|
|
276
|
+
else if (result.constructor.name === "Buffer")
|
|
277
|
+
result = result.toString("base64");
|
|
278
|
+
return [
|
|
279
|
+
record.block_epoch,
|
|
280
|
+
record.hash,
|
|
281
|
+
record.query.witnesses,
|
|
282
|
+
Witnet.Coins.fromPedros(record.query.unitary_reward).toString(2),
|
|
283
|
+
dataType === "RadonError"
|
|
284
|
+
? helpers.colors.mred("RadonError")
|
|
285
|
+
: helpers.colors.mgreen(dataType),
|
|
286
|
+
...(options?.verbose
|
|
287
|
+
? [
|
|
288
|
+
dataType === "RadonError"
|
|
289
|
+
? helpers.colors.red(result)
|
|
290
|
+
: record?.result.finalized
|
|
291
|
+
? helpers.colors.mcyan(result)
|
|
292
|
+
: helpers.colors.cyan(result),
|
|
293
|
+
]
|
|
294
|
+
: [
|
|
295
|
+
record?.result
|
|
296
|
+
? `${record.result.cbor_bytes.length / 2} bytes`
|
|
297
|
+
: "",
|
|
298
|
+
record?.result.timestamp
|
|
299
|
+
? moment.unix(record.result.timestamp).fromNow()
|
|
300
|
+
: "",
|
|
301
|
+
]),
|
|
302
|
+
];
|
|
303
|
+
}),
|
|
304
|
+
{
|
|
305
|
+
headlines: [
|
|
306
|
+
"EPOCH:",
|
|
307
|
+
"DATA REQUEST TRANSACION HASH",
|
|
308
|
+
"witnesses",
|
|
309
|
+
"total fees",
|
|
310
|
+
":data type",
|
|
311
|
+
...(options?.verbose
|
|
312
|
+
? [":DATA REQUEST RESULT"]
|
|
313
|
+
: ["CBOR SIZE:", "DATA FRESHNESS:"]),
|
|
314
|
+
],
|
|
315
|
+
humanizers: [helpers.commas],
|
|
316
|
+
colors: [
|
|
317
|
+
undefined,
|
|
318
|
+
helpers.colors.gray,
|
|
319
|
+
helpers.colors.green,
|
|
320
|
+
helpers.colors.green,
|
|
321
|
+
undefined,
|
|
322
|
+
helpers.colors.cyan,
|
|
323
|
+
helpers.colors.mcyan,
|
|
324
|
+
],
|
|
325
|
+
},
|
|
326
|
+
);
|
|
258
327
|
}
|
|
259
328
|
|
|
260
|
-
async function dataRequest
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
329
|
+
async function dataRequest(options = {}, args = []) {
|
|
330
|
+
if (args.length === 0) {
|
|
331
|
+
throw Error("No DR_TX_HASH was specified");
|
|
332
|
+
}
|
|
333
|
+
const drTxHash = args[0].startsWith("0x") ? args[0].slice(2) : args[0];
|
|
334
|
+
if (!helpers.isHexString(drTxHash)) {
|
|
335
|
+
throw Error("Invalid DR_TX_HASH was provided");
|
|
336
|
+
}
|
|
337
|
+
const provider = new Witnet.JsonRpcProvider(options?.provider);
|
|
269
338
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
339
|
+
const drTxJsonReplacer = (key, value) => {
|
|
340
|
+
switch (key) {
|
|
341
|
+
case "proof":
|
|
342
|
+
case "public_key":
|
|
343
|
+
case "signature":
|
|
344
|
+
case "signatures":
|
|
345
|
+
return undefined;
|
|
277
346
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
347
|
+
case "reveal":
|
|
348
|
+
case "tally":
|
|
349
|
+
if (Array.isArray(value)) {
|
|
350
|
+
const result = utils.cbor.decode(Uint8Array.from(value));
|
|
351
|
+
return Buffer.isBuffer(result) ? utils.toHexString(value) : result;
|
|
352
|
+
}
|
|
284
353
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
354
|
+
default:
|
|
355
|
+
return value;
|
|
356
|
+
}
|
|
357
|
+
};
|
|
289
358
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
359
|
+
const mode = options?.mode || `ethereal`;
|
|
360
|
+
if (!["ethereal", "full"].includes(mode)) {
|
|
361
|
+
throw Error(`Invalid mode value: "${options.mode}"`);
|
|
362
|
+
}
|
|
294
363
|
|
|
295
|
-
|
|
296
|
-
|
|
364
|
+
const report = await provider.getDataRequest(drTxHash, mode, options?.force);
|
|
365
|
+
console.info(JSON.stringify(report, drTxJsonReplacer, 4));
|
|
297
366
|
}
|
|
298
367
|
|
|
299
|
-
async function superblock
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
368
|
+
async function superblock(options = {}, args = []) {
|
|
369
|
+
if (args.length === 0) {
|
|
370
|
+
throw Error("No EPOCH was specified");
|
|
371
|
+
}
|
|
372
|
+
const provider = new Witnet.JsonRpcProvider(options?.provider);
|
|
373
|
+
const superblock = await provider.getSuperblock(args[0]);
|
|
374
|
+
console.info(superblock);
|
|
306
375
|
}
|
|
307
376
|
|
|
308
|
-
async function transaction
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
377
|
+
async function transaction(options = {}, args = []) {
|
|
378
|
+
if (args.length === 0) {
|
|
379
|
+
throw Error("No TX_HASH was specified");
|
|
380
|
+
}
|
|
381
|
+
const txHash = args[0].startsWith("0x") ? args[0].slice(2) : args[0];
|
|
382
|
+
if (!helpers.isHexString(txHash)) {
|
|
383
|
+
throw Error("Invalid TX_HASH was provided");
|
|
384
|
+
}
|
|
385
|
+
const provider = new Witnet.JsonRpcProvider(options?.provider);
|
|
386
|
+
const transaction = await provider.getTransaction(txHash);
|
|
387
|
+
console.info(
|
|
388
|
+
`${yellow(JSON.stringify(transaction, utils.txJsonReplacer, 2))}`,
|
|
389
|
+
);
|
|
321
390
|
}
|
|
322
391
|
|
|
323
|
-
async function utxos
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
392
|
+
async function utxos(options = {}, args = []) {
|
|
393
|
+
if (args.length < 1) {
|
|
394
|
+
throw Error("No WIT_ADDRESS was specified");
|
|
395
|
+
}
|
|
396
|
+
const now = Math.floor(Date.now() / 1000);
|
|
397
|
+
const provider = new Witnet.JsonRpcProvider(options?.provider);
|
|
398
|
+
let utxos = await provider.getUtxos(args[0], {
|
|
399
|
+
minValue: options["min-value"]
|
|
400
|
+
? Witnet.Coins.fromWits(Number(options["min-value"])).pedros
|
|
401
|
+
: undefined,
|
|
402
|
+
fromSigner: options.from,
|
|
403
|
+
});
|
|
404
|
+
let totalBalance = 0n;
|
|
405
|
+
if (!options?.verbose) {
|
|
406
|
+
utxos = utils
|
|
407
|
+
.selectUtxos({ utxos, strategy: options?.strategy || "big-first" })
|
|
408
|
+
.filter((utxo) => utxo.timelock <= now)
|
|
409
|
+
.map((utxo) => {
|
|
410
|
+
totalBalance += utxo.value;
|
|
411
|
+
return [utxo.output_pointer, utxo.value];
|
|
412
|
+
});
|
|
413
|
+
helpers.traceTable(utxos, {
|
|
414
|
+
headlines: [":UTXOs", "Value ($pedros)"],
|
|
415
|
+
humanizers: [undefined, helpers.commas],
|
|
416
|
+
colors: [undefined, myellow],
|
|
417
|
+
});
|
|
418
|
+
} else {
|
|
419
|
+
utxos = utxos.map((utxo) => {
|
|
420
|
+
totalBalance += utxo.value;
|
|
421
|
+
return [
|
|
422
|
+
utxo.output_pointer,
|
|
423
|
+
utxo.timelock > now ? gray(moment.unix(utxo.timelock).fromNow()) : "",
|
|
424
|
+
utxo.timelock > now
|
|
425
|
+
? gray(helpers.commas(utxo.value))
|
|
426
|
+
: myellow(helpers.commas(utxo.value)),
|
|
427
|
+
];
|
|
428
|
+
});
|
|
429
|
+
helpers.traceTable(utxos, {
|
|
430
|
+
headlines: [":UTXOs", "Timelock", "Value ($pedros)"],
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
console.info(
|
|
434
|
+
`^ Showing ${utxos.length} UTXOs: ${lyellow(helpers.whole_wits(totalBalance, 2))}.`,
|
|
435
|
+
);
|
|
364
436
|
}
|
|
365
437
|
|
|
366
|
-
async function validators
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
}
|
|
438
|
+
async function validators(options = {}, args = []) {
|
|
439
|
+
if (args.length === 0) {
|
|
440
|
+
throw Error("No WIT_ADDRESS was specified");
|
|
441
|
+
}
|
|
442
|
+
const provider = new Witnet.JsonRpcProvider(options?.provider);
|
|
443
|
+
const query = {
|
|
444
|
+
filter: { withdrawer: args[0] },
|
|
445
|
+
};
|
|
446
|
+
const records = await provider.stakes(query);
|
|
447
|
+
let nanowits = 0;
|
|
448
|
+
if (records.length > 0) {
|
|
449
|
+
helpers.traceTable(
|
|
450
|
+
records.map((record, index) => {
|
|
451
|
+
nanowits += record.value.coins;
|
|
452
|
+
return [
|
|
453
|
+
1 + index,
|
|
454
|
+
record.key.validator,
|
|
455
|
+
...(options?.verbose
|
|
456
|
+
? [
|
|
457
|
+
record.value.nonce,
|
|
458
|
+
record.value.epochs.witnessing,
|
|
459
|
+
record.value.epochs.mining,
|
|
460
|
+
]
|
|
461
|
+
: []),
|
|
462
|
+
Witnet.Coins.fromNanowits(record.value.coins).wits,
|
|
463
|
+
];
|
|
464
|
+
}),
|
|
465
|
+
{
|
|
466
|
+
headlines: [
|
|
467
|
+
"RANK",
|
|
468
|
+
"VALIDATORS",
|
|
469
|
+
...(options?.verbose ? ["Nonce", "LW_Epoch", "LM_Epoch"] : []),
|
|
470
|
+
"STAKED ($WIT)",
|
|
471
|
+
],
|
|
472
|
+
humanizers: [
|
|
473
|
+
undefined,
|
|
474
|
+
undefined,
|
|
475
|
+
...(options?.verbose
|
|
476
|
+
? [helpers.commas, helpers.commas, helpers.commas]
|
|
477
|
+
: []),
|
|
478
|
+
helpers.commas,
|
|
479
|
+
],
|
|
480
|
+
colors: [
|
|
481
|
+
undefined,
|
|
482
|
+
green,
|
|
483
|
+
...(options?.verbose
|
|
484
|
+
? [undefined, magenta, cyan, myellow]
|
|
485
|
+
: [myellow]),
|
|
486
|
+
],
|
|
487
|
+
},
|
|
488
|
+
);
|
|
489
|
+
console.info(
|
|
490
|
+
`^ ${records.length} validators for withdrawer ${mgreen(
|
|
491
|
+
args[0],
|
|
492
|
+
)}: ${lyellow(helpers.whole_wits(nanowits, 2))}`,
|
|
493
|
+
);
|
|
494
|
+
} else {
|
|
495
|
+
console.info(`> No validators found for withdrawer ${mmagenta(args[0])}.`);
|
|
496
|
+
}
|
|
426
497
|
}
|
|
427
498
|
|
|
428
|
-
async function valueTransfer
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
499
|
+
async function valueTransfer(options = {}, args = []) {
|
|
500
|
+
if (args.length === 0) {
|
|
501
|
+
throw Error("No VT_TX_HASH was specified");
|
|
502
|
+
}
|
|
503
|
+
const txHash = args[0].startsWith("0x") ? args[0].slice(2) : args[0];
|
|
504
|
+
if (!helpers.isHexString(txHash)) {
|
|
505
|
+
throw Error("Invalid VT_TX_HASH was provided");
|
|
506
|
+
}
|
|
507
|
+
const mode = options?.mode || `full`;
|
|
508
|
+
if (!["ethereal", "full", "simple"].includes(mode)) {
|
|
509
|
+
throw Error(`Invalid mode value: "${options.mode}"`);
|
|
510
|
+
}
|
|
511
|
+
const provider = new Witnet.JsonRpcProvider(options?.provider);
|
|
512
|
+
const transaction = await provider.getValueTransfer(
|
|
513
|
+
txHash,
|
|
514
|
+
mode,
|
|
515
|
+
options?.force,
|
|
516
|
+
);
|
|
517
|
+
console.info(
|
|
518
|
+
`${yellow(JSON.stringify(transaction, utils.txJsonReplacer, 2))}`,
|
|
519
|
+
);
|
|
445
520
|
}
|
|
446
521
|
|
|
447
|
-
async function withdrawers
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
}
|
|
522
|
+
async function withdrawers(options = {}, args = []) {
|
|
523
|
+
if (args.length === 0) {
|
|
524
|
+
throw Error("No WIT_ADDRESS was specified");
|
|
525
|
+
}
|
|
526
|
+
const provider = new Witnet.JsonRpcProvider(options?.provider);
|
|
527
|
+
const query = {
|
|
528
|
+
filter: { validator: args[0] },
|
|
529
|
+
};
|
|
530
|
+
const records = await provider.stakes(query);
|
|
531
|
+
let nanowits = 0;
|
|
532
|
+
if (records.length > 0) {
|
|
533
|
+
helpers.traceTable(
|
|
534
|
+
records.map((record, index) => {
|
|
535
|
+
nanowits += record.value.coins;
|
|
536
|
+
return [
|
|
537
|
+
1 + index,
|
|
538
|
+
record.key.withdrawer,
|
|
539
|
+
...(options?.verbose
|
|
540
|
+
? [
|
|
541
|
+
record.value.nonce,
|
|
542
|
+
record.value.epochs.witnessing,
|
|
543
|
+
record.value.epochs.mining,
|
|
544
|
+
]
|
|
545
|
+
: []),
|
|
546
|
+
Witnet.Coins.fromNanowits(record.value.coins).wits,
|
|
547
|
+
];
|
|
548
|
+
}),
|
|
549
|
+
{
|
|
550
|
+
headlines: [
|
|
551
|
+
"RANK",
|
|
552
|
+
"WITHDRAWERS",
|
|
553
|
+
...(options?.verbose ? ["Nonce", "LW_Epoch", "LM_Epoch"] : []),
|
|
554
|
+
"STAKED ($WIT)",
|
|
555
|
+
],
|
|
556
|
+
humanizers: [
|
|
557
|
+
undefined,
|
|
558
|
+
undefined,
|
|
559
|
+
...(options?.verbose
|
|
560
|
+
? [helpers.commas, helpers.commas, helpers.commas]
|
|
561
|
+
: []),
|
|
562
|
+
helpers.commas,
|
|
563
|
+
],
|
|
564
|
+
colors: [
|
|
565
|
+
undefined,
|
|
566
|
+
green,
|
|
567
|
+
...(options?.verbose
|
|
568
|
+
? [undefined, magenta, cyan, myellow]
|
|
569
|
+
: [myellow]),
|
|
570
|
+
],
|
|
571
|
+
},
|
|
572
|
+
);
|
|
573
|
+
console.info(
|
|
574
|
+
`^ ${records.length} withdrawers for validator ${mgreen(
|
|
575
|
+
args[0],
|
|
576
|
+
)}: ${lyellow(helpers.whole_wits(nanowits, 2))}`,
|
|
577
|
+
);
|
|
578
|
+
} else {
|
|
579
|
+
console.info(`> No withdrawers found for validator ${mmagenta(args[0])}.`);
|
|
580
|
+
}
|
|
507
581
|
}
|