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