@witnet/sdk 1.0.4 → 1.0.5

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 (211) hide show
  1. package/.env_witnet +6 -6
  2. package/LICENSE +21 -21
  3. package/README.md +103 -103
  4. package/dist/package.json +3 -4
  5. package/dist/src/bin/helpers.js +1 -1
  6. package/dist/src/index.js +1 -1
  7. package/dist/src/lib/crypto/account.d.ts +3 -1
  8. package/dist/src/lib/crypto/account.d.ts.map +1 -1
  9. package/dist/src/lib/crypto/account.js +7 -1
  10. package/dist/src/lib/crypto/coinbase.js +1 -1
  11. package/dist/src/lib/crypto/index.js +1 -1
  12. package/dist/src/lib/crypto/interfaces.d.ts +2 -0
  13. package/dist/src/lib/crypto/interfaces.d.ts.map +1 -1
  14. package/dist/src/lib/crypto/interfaces.js +1 -1
  15. package/dist/src/lib/crypto/payloads/DataRequestPayload.js +1 -1
  16. package/dist/src/lib/crypto/payloads/StakePayload.js +1 -1
  17. package/dist/src/lib/crypto/payloads/UnstakePayload.js +1 -1
  18. package/dist/src/lib/crypto/payloads/ValueTransferPayload.js +1 -1
  19. package/dist/src/lib/crypto/payloads.d.ts.map +1 -1
  20. package/dist/src/lib/crypto/payloads.js +12 -1
  21. package/dist/src/lib/crypto/signer.d.ts +1 -0
  22. package/dist/src/lib/crypto/signer.d.ts.map +1 -1
  23. package/dist/src/lib/crypto/signer.js +18 -1
  24. package/dist/src/lib/crypto/transmitters/DataRequests.js +1 -1
  25. package/dist/src/lib/crypto/transmitters/StakeDeposits.js +1 -1
  26. package/dist/src/lib/crypto/transmitters/StakeWithdrawals.js +1 -1
  27. package/dist/src/lib/crypto/transmitters/ValueTransfers.js +1 -1
  28. package/dist/src/lib/crypto/transmitters.js +4 -4
  29. package/dist/src/lib/crypto/types.d.ts.map +1 -1
  30. package/dist/src/lib/crypto/types.js +2 -1
  31. package/dist/src/lib/crypto/utils.js +1 -1
  32. package/dist/src/lib/crypto/wallet.d.ts +3 -1
  33. package/dist/src/lib/crypto/wallet.d.ts.map +1 -1
  34. package/dist/src/lib/crypto/wallet.js +10 -1
  35. package/dist/src/lib/index.js +1 -1
  36. package/dist/src/lib/radon/ccdr/eth.js +1 -1
  37. package/dist/src/lib/radon/ccdr/index.js +1 -1
  38. package/dist/src/lib/radon/ccdr/wit.js +1 -1
  39. package/dist/src/lib/radon/filters.js +1 -1
  40. package/dist/src/lib/radon/index.js +1 -1
  41. package/dist/src/lib/radon/reducers.js +1 -1
  42. package/dist/src/lib/radon/types.js +1 -1
  43. package/dist/src/lib/radon/utils.js +1 -1
  44. package/dist/src/lib/rpc/index.js +1 -1
  45. package/dist/src/lib/rpc/nodes.js +1 -1
  46. package/dist/src/lib/rpc/provider.js +1 -1
  47. package/dist/src/lib/rpc/types.d.ts +6 -4
  48. package/dist/src/lib/rpc/types.d.ts.map +1 -1
  49. package/dist/src/lib/rpc/types.js +1 -1
  50. package/dist/src/lib/types.d.ts +0 -1
  51. package/dist/src/lib/types.d.ts.map +1 -1
  52. package/dist/src/lib/types.js +1 -1
  53. package/dist/src/lib/utils.js +1 -1
  54. package/dist/witnet/assets/index.js +1 -1
  55. package/dist/witnet/assets/modals/index.js +1 -1
  56. package/dist/witnet/assets/modals/web3/eth.js +1 -1
  57. package/dist/witnet/assets/modals/web3/ipfs.js +1 -1
  58. package/dist/witnet/assets/modals/web3/wit.js +1 -1
  59. package/dist/witnet/assets/requests.js +1 -1
  60. package/package.json +3 -4
  61. package/src/bin/cli/history.js +31 -31
  62. package/src/bin/cli/inspect.js +405 -405
  63. package/src/bin/cli/network.js +594 -594
  64. package/src/bin/cli/nodes.js +364 -364
  65. package/src/bin/cli/radon.js +817 -815
  66. package/src/bin/cli/wallet.js +1121 -1117
  67. package/src/bin/helpers.js +840 -840
  68. package/src/bin/postinstall.js +9 -9
  69. package/src/bin/toolkit.js +295 -295
  70. package/witnet/assets/_index.js +8 -8
  71. package/witnet/assets/_requests.js +25 -25
  72. package/witnet/assets/_sources.js +36 -36
  73. package/witnet/assets/_templates.js +36 -36
  74. package/witnet/assets/index.js +4 -4
  75. package/witnet/assets/modals/index.js +9 -9
  76. package/witnet/assets/modals/web3/eth.js +29 -29
  77. package/witnet/assets/modals/web3/ipfs.js +19 -19
  78. package/witnet/assets/modals/web3/wit.js +21 -21
  79. package/witnet/assets/requests.js +95 -95
  80. package/dist/bin/helpers.d.ts +0 -88
  81. package/dist/bin/helpers.d.ts.map +0 -1
  82. package/dist/bin/helpers.js +0 -866
  83. package/dist/index.d.ts +0 -4
  84. package/dist/index.d.ts.map +0 -1
  85. package/dist/index.js +0 -42
  86. package/dist/lib/crypto/account.d.ts +0 -18
  87. package/dist/lib/crypto/account.d.ts.map +0 -1
  88. package/dist/lib/crypto/account.js +0 -152
  89. package/dist/lib/crypto/coinbase.d.ts +0 -9
  90. package/dist/lib/crypto/coinbase.d.ts.map +0 -1
  91. package/dist/lib/crypto/coinbase.js +0 -39
  92. package/dist/lib/crypto/index.d.ts +0 -7
  93. package/dist/lib/crypto/index.d.ts.map +0 -1
  94. package/dist/lib/crypto/index.js +0 -28
  95. package/dist/lib/crypto/interfaces.d.ts +0 -80
  96. package/dist/lib/crypto/interfaces.d.ts.map +0 -1
  97. package/dist/lib/crypto/interfaces.js +0 -3
  98. package/dist/lib/crypto/payloads/DataRequestPayload.d.ts +0 -47
  99. package/dist/lib/crypto/payloads/DataRequestPayload.d.ts.map +0 -1
  100. package/dist/lib/crypto/payloads/DataRequestPayload.js +0 -384
  101. package/dist/lib/crypto/payloads/StakePayload.d.ts +0 -27
  102. package/dist/lib/crypto/payloads/StakePayload.d.ts.map +0 -1
  103. package/dist/lib/crypto/payloads/StakePayload.js +0 -184
  104. package/dist/lib/crypto/payloads/UnstakePayload.d.ts +0 -35
  105. package/dist/lib/crypto/payloads/UnstakePayload.d.ts.map +0 -1
  106. package/dist/lib/crypto/payloads/UnstakePayload.js +0 -244
  107. package/dist/lib/crypto/payloads/ValueTransferPayload.d.ts +0 -24
  108. package/dist/lib/crypto/payloads/ValueTransferPayload.d.ts.map +0 -1
  109. package/dist/lib/crypto/payloads/ValueTransferPayload.js +0 -182
  110. package/dist/lib/crypto/payloads.d.ts +0 -54
  111. package/dist/lib/crypto/payloads.d.ts.map +0 -1
  112. package/dist/lib/crypto/payloads.js +0 -224
  113. package/dist/lib/crypto/signer.d.ts +0 -26
  114. package/dist/lib/crypto/signer.d.ts.map +0 -1
  115. package/dist/lib/crypto/signer.js +0 -299
  116. package/dist/lib/crypto/transmitters/DataRequests.d.ts +0 -14
  117. package/dist/lib/crypto/transmitters/DataRequests.d.ts.map +0 -1
  118. package/dist/lib/crypto/transmitters/DataRequests.js +0 -62
  119. package/dist/lib/crypto/transmitters/StakeDeposits.d.ts +0 -11
  120. package/dist/lib/crypto/transmitters/StakeDeposits.d.ts.map +0 -1
  121. package/dist/lib/crypto/transmitters/StakeDeposits.js +0 -48
  122. package/dist/lib/crypto/transmitters/StakeWithdrawals.d.ts +0 -17
  123. package/dist/lib/crypto/transmitters/StakeWithdrawals.d.ts.map +0 -1
  124. package/dist/lib/crypto/transmitters/StakeWithdrawals.js +0 -115
  125. package/dist/lib/crypto/transmitters/ValueTransfers.d.ts +0 -10
  126. package/dist/lib/crypto/transmitters/ValueTransfers.d.ts.map +0 -1
  127. package/dist/lib/crypto/transmitters/ValueTransfers.js +0 -47
  128. package/dist/lib/crypto/transmitters.d.ts +0 -46
  129. package/dist/lib/crypto/transmitters.d.ts.map +0 -1
  130. package/dist/lib/crypto/transmitters.js +0 -506
  131. package/dist/lib/crypto/types.d.ts +0 -127
  132. package/dist/lib/crypto/types.d.ts.map +0 -1
  133. package/dist/lib/crypto/types.js +0 -261
  134. package/dist/lib/crypto/utils.d.ts +0 -10
  135. package/dist/lib/crypto/utils.d.ts.map +0 -1
  136. package/dist/lib/crypto/utils.js +0 -97
  137. package/dist/lib/crypto/wallet.d.ts +0 -26
  138. package/dist/lib/crypto/wallet.d.ts.map +0 -1
  139. package/dist/lib/crypto/wallet.js +0 -327
  140. package/dist/lib/helpers.d.ts +0 -90
  141. package/dist/lib/helpers.d.ts.map +0 -1
  142. package/dist/lib/helpers.js +0 -1031
  143. package/dist/lib/index.d.ts +0 -5
  144. package/dist/lib/index.d.ts.map +0 -1
  145. package/dist/lib/index.js +0 -21
  146. package/dist/lib/radon/artifacts.d.ts +0 -55
  147. package/dist/lib/radon/artifacts.d.ts.map +0 -1
  148. package/dist/lib/radon/artifacts.js +0 -347
  149. package/dist/lib/radon/ccdr/eth.d.ts +0 -100
  150. package/dist/lib/radon/ccdr/eth.d.ts.map +0 -1
  151. package/dist/lib/radon/ccdr/eth.js +0 -237
  152. package/dist/lib/radon/ccdr/index.d.ts +0 -34
  153. package/dist/lib/radon/ccdr/index.d.ts.map +0 -1
  154. package/dist/lib/radon/ccdr/index.js +0 -63
  155. package/dist/lib/radon/ccdr/wit.d.ts +0 -29
  156. package/dist/lib/radon/ccdr/wit.d.ts.map +0 -1
  157. package/dist/lib/radon/ccdr/wit.js +0 -60
  158. package/dist/lib/radon/filters.d.ts +0 -14
  159. package/dist/lib/radon/filters.d.ts.map +0 -1
  160. package/dist/lib/radon/filters.js +0 -47
  161. package/dist/lib/radon/index.d.ts +0 -36
  162. package/dist/lib/radon/index.d.ts.map +0 -1
  163. package/dist/lib/radon/index.js +0 -154
  164. package/dist/lib/radon/reducers.d.ts +0 -29
  165. package/dist/lib/radon/reducers.d.ts.map +0 -1
  166. package/dist/lib/radon/reducers.js +0 -101
  167. package/dist/lib/radon/retrievals.d.ts +0 -120
  168. package/dist/lib/radon/retrievals.d.ts.map +0 -1
  169. package/dist/lib/radon/retrievals.js +0 -358
  170. package/dist/lib/radon/sources.d.ts +0 -102
  171. package/dist/lib/radon/sources.d.ts.map +0 -1
  172. package/dist/lib/radon/sources.js +0 -294
  173. package/dist/lib/radon/types.d.ts +0 -521
  174. package/dist/lib/radon/types.d.ts.map +0 -1
  175. package/dist/lib/radon/types.js +0 -1066
  176. package/dist/lib/radon/utils.d.ts +0 -55
  177. package/dist/lib/radon/utils.d.ts.map +0 -1
  178. package/dist/lib/radon/utils.js +0 -181
  179. package/dist/lib/rpc/farm.d.ts +0 -66
  180. package/dist/lib/rpc/farm.d.ts.map +0 -1
  181. package/dist/lib/rpc/farm.js +0 -808
  182. package/dist/lib/rpc/index.d.ts +0 -3
  183. package/dist/lib/rpc/index.d.ts.map +0 -1
  184. package/dist/lib/rpc/index.js +0 -19
  185. package/dist/lib/rpc/node.d.ts +0 -38
  186. package/dist/lib/rpc/node.d.ts.map +0 -1
  187. package/dist/lib/rpc/node.js +0 -335
  188. package/dist/lib/rpc/nodes.d.ts +0 -40
  189. package/dist/lib/rpc/nodes.d.ts.map +0 -1
  190. package/dist/lib/rpc/nodes.js +0 -531
  191. package/dist/lib/rpc/provider.d.ts +0 -72
  192. package/dist/lib/rpc/provider.d.ts.map +0 -1
  193. package/dist/lib/rpc/provider.js +0 -402
  194. package/dist/lib/rpc/reporter.d.ts +0 -18
  195. package/dist/lib/rpc/reporter.d.ts.map +0 -1
  196. package/dist/lib/rpc/reporter.js +0 -99
  197. package/dist/lib/rpc/types.d.ts +0 -396
  198. package/dist/lib/rpc/types.d.ts.map +0 -1
  199. package/dist/lib/rpc/types.js +0 -81
  200. package/dist/lib/rpc/wallet.d.ts +0 -72
  201. package/dist/lib/rpc/wallet.d.ts.map +0 -1
  202. package/dist/lib/rpc/wallet.js +0 -41
  203. package/dist/lib/types.d.ts +0 -19
  204. package/dist/lib/types.d.ts.map +0 -1
  205. package/dist/lib/types.js +0 -7
  206. package/dist/lib/utils.d.ts +0 -5
  207. package/dist/lib/utils.d.ts.map +0 -1
  208. package/dist/lib/utils.js +0 -51
  209. package/dist/src/lib/rpc/reporter.d.ts +0 -17
  210. package/dist/src/lib/rpc/reporter.d.ts.map +0 -1
  211. package/dist/src/lib/rpc/reporter.js +0 -27
@@ -1,594 +1,594 @@
1
- const helpers = require("../helpers")
2
- const { Witnet } = require("../../../dist/src")
3
-
4
- const FLAGS_LIMIT_MAX = 2048
5
- const FLAGS_LIMIT_DEFAULT = 64
6
- const OPTIONS_DEFAULT_SINCE = -2048
7
-
8
- const { cyan, white, gray, green, lcyan, lyellow, mgreen, mred, myellow, yellow } = helpers.colors
9
-
10
- /// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11
- /// CLI SUBMODULE CONSTANTS ===========================================================================================
12
-
13
- module.exports = {
14
- envars: {
15
- WITNET_SDK_PROVIDER_URL: "=> Wit/Oracle RPC provider(s) to connect to, if no otherwise specified.",
16
- },
17
- flags: {
18
- limit: {
19
- hint: "Limits number of output records (default: 64).",
20
- param: "LIMIT",
21
- },
22
- offset: {
23
- hint: "Skips first records as found on server side (default: 0).",
24
- param: "SKIP",
25
- },
26
- provider: {
27
- hint: "Public Wit/Oracle JSON-RPC provider, other than default.",
28
- param: "PROVIDER_URL",
29
- },
30
- verbose: {
31
- hint: "Outputs detailed information.",
32
- },
33
- },
34
- router: {
35
- blocks: {
36
- hint: "List recently validated blocks.",
37
- options: {
38
- since: {
39
- hint: "Since the specified epoch (default: -<LIMIT>-2).",
40
- param: "EPOCH|MINUS_EPOCHS",
41
- },
42
- },
43
- },
44
- constants: {
45
- hint: "Show network's consensus constants.",
46
- },
47
- fees: {
48
- hint: "Estimate transaction fees based on recent network activity.",
49
- params: "\"vtt\" | \"drt\" | \"st\" | \"ut\"",
50
- options: {
51
- eti: {
52
- hint: "Expected time before inclusion (default: 60 seconds).",
53
- param: "ETI_SECONDS",
54
- },
55
- weight: {
56
- hint: "Assuming this transaction weight (default: 1).",
57
- param: "TX_WEIGHT",
58
- },
59
- },
60
- },
61
- holders: {
62
- hint: "List identities holding Wits within the specified range.",
63
- options: {
64
- "min-balance": {
65
- hint: "Having at least this amount of unlocked Wits (default: 1 Wit).",
66
- param: "WITS",
67
- },
68
- "max-balance": {
69
- hint: "Having at most this amount of unlocked Wits.",
70
- param: "WITS",
71
- },
72
- },
73
- },
74
- knownPeers: {
75
- hint: "Get a full list of peers as known by the Wit/Oracle RPC provider(s).",
76
- },
77
- mempool: {
78
- hint: "Dump current transactions mempool.",
79
- params: "[\"vtt\" | \"drt\" | \"st\" | \"ut\"]",
80
- options: {
81
- count: { hint: "Just count the number of entries (ignoring limit)." },
82
- offset: {
83
- hint: "Skips first matching entries (default: 0).",
84
- param: "OFFSET",
85
- },
86
- },
87
- },
88
- powers: {
89
- hint: "List validation identities ordered by their current mining power.",
90
- options: {
91
- distinct: { hint: "Include only the first appearance per validator." },
92
- witnessing: { hint: "Order by witnessing power instead." },
93
- },
94
- },
95
- provider: {
96
- hint: "Show the underlying Wit/RPC provider and network id being used.",
97
- },
98
- senate: {
99
- hint: "List distinct identities that have lately validated at least one block.",
100
- options: {
101
- since: {
102
- hint: "Since the specified epoch (default: -2048).",
103
- param: "MINUS_EPOCHS",
104
- },
105
- },
106
- },
107
- stakes: {
108
- hint: "List active stake entries at present time.",
109
- options: {
110
- validator: { hint: "Filter by validator address.", param: "WIT_ADDRESS" },
111
- withdrawer: { hint: "Filter by withdrawer address.", param: "WIT_ADDRESS" },
112
- },
113
- },
114
- "stats*": {
115
- hint: "Report network stats.",
116
- },
117
- status: {
118
- hint: "Report the sync status of the network's Wit/Oracle RPC provider being used.",
119
- },
120
- supplyInfo: {
121
- hint: "Get network's Wit supply information.",
122
- },
123
- versions: {
124
- hint: "List known protocol versions and which one is currently live.",
125
- },
126
- wips: {
127
- hint: "Show currently activated WIPs on the network.",
128
- options: {
129
- pending: { hint: "Only shows pending upgrades, if any." },
130
- },
131
- },
132
- },
133
- subcommands: {
134
- blocks,
135
- constants,
136
- holders,
137
- knownPeers,
138
- mempool,
139
- fees: priorities,
140
- powers,
141
- provider,
142
- senate,
143
- stakes,
144
- supplyInfo,
145
- status: syncStatus,
146
- versions,
147
- wips,
148
- },
149
- }
150
-
151
- /// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
152
- /// CLI SUBMODULE COMMANDS ============================================================================================
153
-
154
- async function blocks (options = {}) {
155
- options.limit = Math.min(parseInt(options.limit) || FLAGS_LIMIT_DEFAULT, FLAGS_LIMIT_MAX)
156
- const provider = new Witnet.JsonRpcProvider(options?.provider)
157
- // todo: use prompter?
158
- const records = await provider.blocks(parseInt(options?.since) || -options.limit - 2, options.limit)
159
- if (records.length > 0) {
160
- helpers.traceTable(
161
- records.slice(0, options.limit).map(record => [
162
- record[0],
163
- record[1],
164
- ]), {
165
- headlines: ["EPOCH", "BLOCK HASHES"],
166
- humanizers: [helpers.commas],
167
- colors: [, helpers.colors.gray],
168
- })
169
- console.info(`^ Listed ${records.length} blocks for a range of ${options.limit} epochs.`)
170
- } else {
171
- console.info(
172
- `> No blocks found in specified range (since: ${
173
- options?.since || -options.limit
174
- }, limit: ${
175
- options.limit
176
- }).`
177
- )
178
- }
179
- }
180
-
181
- async function constants (options = {}) {
182
- const provider = new Witnet.JsonRpcProvider(options?.provider)
183
- console.info(await provider.constants())
184
- }
185
-
186
- async function holders (options = {}) {
187
- options.limit = Math.min(parseInt(options.limit) || FLAGS_LIMIT_DEFAULT, FLAGS_LIMIT_MAX)
188
- const provider = new Witnet.JsonRpcProvider(options?.provider)
189
- const records = Object.entries(await helpers.prompter(provider.holders(
190
- options["min-balance"] ? options["min-balance"] * 10 ** 9 : 1000000,
191
- options["max-balance"] ? options["max-balance"] * 10 ** 9 : null,
192
- )))
193
- const totalRecords = records.length
194
- helpers.traceTable(
195
- records.slice(0, options.limit).map(([address, balance], index) => [
196
- index + 1,
197
- address,
198
- ...(options?.verbose
199
- ? [
200
- Witnet.Coins.fromNanowits(balance.locked).wits,
201
- Witnet.Coins.fromNanowits(balance.staked).wits,
202
- Witnet.Coins.fromNanowits(balance.unlocked).wits,
203
- ]
204
- : []),
205
- Witnet.Coins.fromNanowits(balance.locked + balance.staked + balance.unlocked).wits,
206
- ]), {
207
- headlines: [
208
- "RANK", "HOLDERS",
209
- ...(options?.verbose
210
- ? [
211
- "Locked ($WIT)",
212
- "Staked ($WIT)",
213
- "Available ($WIT)",
214
- ]
215
- : []),
216
- "BALANCE ($WIT)",
217
- ],
218
- humanizers: [,, helpers.commas, helpers.commas, helpers.commas, helpers.commas],
219
- colors: [
220
- , mgreen,
221
- ...(options?.verbose
222
- ? [
223
- gray,
224
- yellow,
225
- myellow,
226
- ]
227
- : []),
228
- lyellow,
229
- ],
230
- }
231
- )
232
- if (options.limit < totalRecords) {
233
- console.info(`^ Listed ${Math.min(options.limit, totalRecords)} out of ${totalRecords} records.`)
234
- }
235
- }
236
-
237
- async function knownPeers (options = {}) {
238
- if (!options) options = {}
239
- options.limit = parseInt(options.limit) || FLAGS_LIMIT_DEFAULT
240
- const provider = new Witnet.JsonRpcProvider(options?.provider)
241
- const knownPeers = await provider.knownPeers()
242
- console.info(knownPeers)
243
- }
244
-
245
- async function mempool (options = {}) {
246
- const provider = new Witnet.JsonRpcProvider(options?.provider)
247
- console.info(await provider.mempool())
248
- }
249
-
250
- async function powers (options = {}) {
251
- const provider = new Witnet.JsonRpcProvider(options?.provider)
252
- const query = {
253
- distinct: options?.distinct || false,
254
- limit: parseInt(options.limit) || FLAGS_LIMIT_DEFAULT,
255
- offset: parseInt(options?.offset) || 0,
256
- orderBy: options?.witnessing ? "witnessing" : "mining",
257
- }
258
- const records = await provider.powers(query)
259
- if (records.length > 0) {
260
- helpers.traceTable(
261
- records.map(record => [
262
- record.ranking,
263
- record.validator,
264
- ...(options?.verbose ? [record.withdrawer] : []),
265
- record.power,
266
- ]), {
267
- headlines: [
268
- "G_RANK",
269
- "VALIDATORS",
270
- ...(options?.verbose ? ["Withdrawer"] : []),
271
- `${query.orderBy.toUpperCase()} POWER`,
272
- ],
273
- colors: [
274
- ,
275
- helpers.colors.green,
276
- ...(options?.verbose ? [helpers.colors.mgreen] : []),
277
- query.orderBy === "mining" ? helpers.colors.mcyan : helpers.colors.mmagenta,
278
- ],
279
- humanizers: [
280
- helpers.commas,,
281
- ...(options?.verbose ? [, helpers.commas] : [helpers.commas]),
282
- ],
283
- },
284
- )
285
- if (records.length === query.limit || query.offset === 0) {
286
- console.info(`^ Listed ${records.length} records.`)
287
- } else if (query.offset !== 0) {
288
- console.info(`^ Listed ${records.length} out of ${records.length + query.offset} records.`)
289
- }
290
- } else {
291
- if (query.offset === 0) {
292
- console.info("> No records found.")
293
- } else {
294
- console.info(`> No as many as ${query.offset + 1} records exist.`)
295
- }
296
- }
297
- }
298
-
299
- async function priorities (options = {}) {
300
- const provider = new Witnet.JsonRpcProvider(options?.provider)
301
- console.info(await provider.priorities())
302
- }
303
-
304
- async function provider (options = {}) {
305
- const provider = await Witnet.JsonRpcProvider.fromEnv(options?.provider)
306
- console.info(`> Witnet RPC provider: ${white(provider.endpoints)}`)
307
- console.info(`> Witnet environment: ${
308
- provider.networkId === 40941
309
- ? lcyan("MAINNET")
310
- : (provider.network === "testnet" ? cyan("TESTNET") : mred("Unknown"))
311
- }`)
312
- console.info(`> Witnet network id: ${green("0x" + provider.networkId.toString(16).toUpperCase())}`)
313
- }
314
-
315
- async function senate (options = {}) {
316
- const provider = new Witnet.JsonRpcProvider(options?.provider)
317
- const params = {
318
- distinct: true,
319
- limit: Math.min(parseInt(options.limit) || FLAGS_LIMIT_DEFAULT, FLAGS_LIMIT_MAX),
320
- offset: parseInt(options?.offset || 0),
321
- order: { by: "mining" },
322
- since: -Math.abs(parseInt(options?.since) || OPTIONS_DEFAULT_SINCE) - 1,
323
- }
324
- const records = await provider.stakes({ params }) // todo: use prompter?
325
- if (records.length > 0) {
326
- helpers.traceTable(
327
- records
328
- .map((record, index) => [
329
- ...(options?.verbose
330
- ? [
331
- index + 1,
332
- record.key.validator,
333
- record.value.nonce,
334
- record.value.epochs.witnessing,
335
- ]
336
- : [
337
- record.key.validator,
338
- ]),
339
- record.value.epochs.mining,
340
- ])
341
- , {
342
- headlines: [
343
- ...(options?.verbose
344
- ? [
345
- "INDEX",
346
- `Superblock Voting Committee ${params.since + 1}`,
347
- "Nonce",
348
- "LW_Epoch",
349
- ]
350
- : [
351
- `Superblock Voting Committee ${params.since + 1}`,
352
- ]),
353
- "LM_Epoch",
354
- ],
355
- humanizers: [
356
- ...(options?.verbose
357
- ? [
358
- helpers.commas,, helpers.commas, helpers.commas, helpers.commas,
359
- ]
360
- : [
361
- , helpers.commas, helpers.commas, helpers.commas,
362
- ]),
363
- ],
364
- colors: [
365
- ...(options?.verbose
366
- ? [
367
- ,,, helpers.colors.magenta, helpers.colors.mcyan,
368
- ]
369
- : [
370
- , helpers.colors.mcyan,
371
- ]),
372
- ],
373
- }
374
- )
375
- if (records.length < params.limit) {
376
- if (params.offset === 0) {
377
- console.info(`^ Only ${records.length} qualified members out of ${params.limit} seats.`)
378
- } else {
379
- console.info(`^ Listed ${records.length} out of ${records.length + params.offset} members.`)
380
- }
381
- } else {
382
- console.info(`^ Listed ${records.length} members.`)
383
- }
384
- } else {
385
- if (params.offset === 0) {
386
- console.info("No qualified members found.")
387
- } else {
388
- console.info(`No as many as ${params.offset} qualified members exist.`)
389
- }
390
- }
391
- }
392
-
393
- async function stakes (options = {}) {
394
- const provider = new Witnet.JsonRpcProvider(options?.provider)
395
- const query = {
396
- params: {
397
- limit: Math.min(parseInt(options.limit) || FLAGS_LIMIT_DEFAULT, FLAGS_LIMIT_MAX),
398
- offset: parseInt(options?.offset || 0),
399
- },
400
- }
401
- if (options?.validator) query.filter = { validator: options.validator }
402
- if (options?.withdrawer) query.filter = { ...query.filter, withdrawer: options.withdrawer }
403
- const records = await provider.stakes(query) // todo: use prompter?
404
- if (records.length > 0) {
405
- helpers.traceTable(
406
- records
407
- .map((record, index) => [
408
- 1 + index + query.params.offset,
409
- record.key.withdrawer,
410
- record.key.validator,
411
- ...(
412
- options?.verbose
413
- ? [record.value.nonce, record.value.epochs.witnessing, record.value.epochs.mining]
414
- : []
415
- ),
416
- Witnet.Coins.fromNanowits(record.value.coins).wits,
417
- ]),
418
- {
419
- headlines: [
420
- options?.validator || options?.withdrawer ? "RANK" : "G_RANK",
421
- "STAKERS",
422
- "Validator",
423
- ...(
424
- options?.verbose
425
- ? ["Nonce", "LW_Epoch", "LM_Epoch"]
426
- : []
427
- ),
428
- "STAKED ($WIT)",
429
- ],
430
- humanizers: [
431
- ,,, ...(
432
- options?.verbose
433
- ? [helpers.commas, helpers.commas, helpers.commas]
434
- : []
435
- ),
436
- (x) => helpers.commas(Math.floor(parseFloat(x))),
437
- ],
438
- colors: [
439
- , helpers.colors.mgreen,, ...(
440
- options?.verbose
441
- ? [, helpers.colors.magenta, helpers.colors.cyan]
442
- : []
443
- ),
444
- helpers.colors.myellow,
445
- ],
446
- },
447
- )
448
- if (records.length === query.params.limit || query.params.offset === 0) {
449
- console.info(`^ Listed ${records.length} records.`)
450
- } else if (query.params.offset !== 0) {
451
- console.info(`^ Listed ${records.length} out of ${records.length + query.params.offset} records.`)
452
- }
453
- } else {
454
- if (query.params.offset === 0) {
455
- console.info("> No records found.")
456
- } else {
457
- console.info(`> No as many as ${query.params.offset + 1} records exist.`)
458
- }
459
- }
460
- }
461
-
462
- async function supplyInfo (options = {}) {
463
- const reporter = new Witnet.JsonRpcProvider(options?.provider || process.env.WITNET_SDK_PROVIDER_URL)
464
- const data = await reporter.supplyInfo()
465
- console.info(`> Supply info at epoch ${helpers.colors.white(helpers.commas(data.epoch))}:`)
466
- const records = []
467
- records.push(["Minted blocks", helpers.toFixedTrunc(100 * data.blocks_minted / (data.epoch - 1), 1) + " %"])
468
- records.push(["Minted rewards", helpers.whole_wits(data.blocks_minted_reward, 2)])
469
- if (data.burnt_supply) {
470
- records.push(["Burnt supply", helpers.whole_wits(data.burnt_supply, 2)])
471
- };
472
- if (data.current_locked_supply) {
473
- records.push(["Locked supply", helpers.whole_wits(data.current_locked_supply, 2)])
474
- }
475
- if (data.current_staked_supply) {
476
- records.push(["Staked supply", helpers.whole_wits(data.current_staked_supply, 2)])
477
- }
478
- records.push(["Circulating supply", helpers.whole_wits(data.current_unlocked_supply, 2)])
479
- helpers.traceTable(records, {
480
- headlines: [":KPI", "VALUE"],
481
- colors: [helpers.colors.mgreen, helpers.colors.myellow],
482
- })
483
- }
484
-
485
- async function syncStatus (options = {}) {
486
- const provider = await Witnet.JsonRpcProvider.fromEnv(options?.provider)
487
- const syncStatus = await provider.syncStatus()
488
- helpers.traceTable(
489
- [[
490
- provider.network === "mainnet" ? "Mainnet" : `Testnet (${provider.networkId.toString(16).toUpperCase()})`,
491
- syncStatus.node_state || "",
492
- syncStatus.current_epoch,
493
- syncStatus.chain_beacon.checkpoint,
494
- syncStatus.chain_beacon.hashPrevBlock,
495
- ]], {
496
- headlines: [
497
- "NETWORK",
498
- ":STATUS",
499
- "Current epoch",
500
- "Checkpoint epoch",
501
- "Checkpoint block hash",
502
- ],
503
- humanizers: [,, helpers.commas, helpers.commas],
504
- colors: [helpers.colors.mgreen, helpers.colors.lgreen, helpers.colors.white,, helpers.colors.gray],
505
- },
506
- )
507
- }
508
-
509
- async function versions (options = {}) {
510
- const provider = new Witnet.JsonRpcProvider(options?.provider)
511
- const protocolInfo = await provider.protocolInfo()
512
- if (
513
- protocolInfo?.all_checkpoints_periods &&
514
- protocolInfo?.all_versions?.efv &&
515
- Object.keys(protocolInfo.all_versions.efv).length > 0
516
- ) {
517
- const records = Object.fromEntries(
518
- Object.entries(protocolInfo.all_checkpoints_periods)
519
- .sort(([a], [b]) => b - a)
520
- .map(([version, period]) => [version, { period }])
521
- )
522
- Object.entries(protocolInfo.all_versions.efv).forEach(([key, epoch]) => {
523
- if (records[key]) records[key].epoch = epoch
524
- })
525
- helpers.traceTable(
526
- Object.entries(records).map(([key, props]) => [
527
- key === "V1_7" ? "V1_0" : key,
528
- props?.epoch,
529
- props?.period,
530
- ]), {
531
- headlines: [
532
- ":Version",
533
- "Activation epoch",
534
- ":Block time (secs)",
535
- ],
536
- humanizers: [, helpers.commas],
537
- colors: [helpers.colors.mgreen, helpers.colors.white, helpers.colors.normal],
538
- })
539
- }
540
- console.info(`Current protocol version is ${helpers.colors.mgreen(protocolInfo.current_version)}.`)
541
- }
542
-
543
- async function wips (options = {}) {
544
- const provider = new Witnet.JsonRpcProvider(options?.provider)
545
- const wips = await provider.wips()
546
- if (!options?.pending) {
547
- // console.info(`> Active WIP upgrades at epoch ${helpers.colors.white(helpers.commas(wips.epoch))}:`)
548
- const active_upgrades = Object.entries(wips.active_upgrades).map(([wip, epoch]) => [
549
- wip,
550
- epoch,
551
- ])
552
- helpers.traceTable(active_upgrades, {
553
- headlines: [":WIP", "Activation epoch"],
554
- humanizers: [, helpers.commas],
555
- colors: [helpers.colors.mcyan, helpers.colors.white],
556
- })
557
- }
558
- if (wips.pending_upgrades || options?.pending) {
559
- if (wips.pending_upgrades.length === 0) {
560
- console.info(`> No pending WIP upgrades at epoch ${helpers.colors.white(helpers.commas(wips.epoch))}.`)
561
- } else {
562
- console.info(`Pending WIP upgrades at epoch ${helpers.colors.white(helpers.commas(wips.epoch))}:`)
563
- const pending_upgrades = wips.pending_upgrades.map(upgrade => {
564
- return [
565
- upgrade.wip,
566
- upgrade.bit,
567
- upgrade.init,
568
- upgrade.votes,
569
- upgrade.period,
570
- // upgrade.end,
571
- ]
572
- })
573
- helpers.traceTable(pending_upgrades, {
574
- headlines: [
575
- ":WIP",
576
- "WIP_BIT",
577
- "From epoch",
578
- "Aye votes",
579
- "Duration",
580
- // "Deadline",
581
- ],
582
- humanizers: [,, helpers.commas, helpers.commas, helpers.commas, helpers.commas],
583
- colors: [
584
- helpers.colors.lcyan,
585
- helpers.colors.mcyan,
586
- helpers.colors.white,
587
- helpers.colors.myellow,
588
- helpers.colors.mgreen,
589
- // helpers.colors.myellow,
590
- ],
591
- })
592
- }
593
- }
594
- }
1
+ const helpers = require("../helpers")
2
+ const { Witnet } = require("../../../dist/src")
3
+
4
+ const FLAGS_LIMIT_MAX = 2048
5
+ const FLAGS_LIMIT_DEFAULT = 64
6
+ const OPTIONS_DEFAULT_SINCE = -2048
7
+
8
+ const { cyan, white, gray, green, lcyan, lyellow, mgreen, mred, myellow, yellow } = helpers.colors
9
+
10
+ /// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11
+ /// CLI SUBMODULE CONSTANTS ===========================================================================================
12
+
13
+ module.exports = {
14
+ envars: {
15
+ WITNET_SDK_PROVIDER_URL: "=> Wit/Oracle RPC provider(s) to connect to, if no otherwise specified.",
16
+ },
17
+ flags: {
18
+ limit: {
19
+ hint: "Limits number of output records (default: 64).",
20
+ param: "LIMIT",
21
+ },
22
+ offset: {
23
+ hint: "Skips first records as found on server side (default: 0).",
24
+ param: "SKIP",
25
+ },
26
+ provider: {
27
+ hint: "Public Wit/Oracle JSON-RPC provider, other than default.",
28
+ param: "PROVIDER_URL",
29
+ },
30
+ verbose: {
31
+ hint: "Outputs detailed information.",
32
+ },
33
+ },
34
+ router: {
35
+ blocks: {
36
+ hint: "List recently validated blocks.",
37
+ options: {
38
+ since: {
39
+ hint: "Since the specified epoch (default: -<LIMIT>-2).",
40
+ param: "EPOCH|MINUS_EPOCHS",
41
+ },
42
+ },
43
+ },
44
+ constants: {
45
+ hint: "Show network's consensus constants.",
46
+ },
47
+ fees: {
48
+ hint: "Estimate transaction fees based on recent network activity.",
49
+ params: "\"vtt\" | \"drt\" | \"st\" | \"ut\"",
50
+ options: {
51
+ eti: {
52
+ hint: "Expected time before inclusion (default: 60 seconds).",
53
+ param: "ETI_SECONDS",
54
+ },
55
+ weight: {
56
+ hint: "Assuming this transaction weight (default: 1).",
57
+ param: "TX_WEIGHT",
58
+ },
59
+ },
60
+ },
61
+ holders: {
62
+ hint: "List identities holding Wits within the specified range.",
63
+ options: {
64
+ "min-balance": {
65
+ hint: "Having at least this amount of unlocked Wits (default: 1 Wit).",
66
+ param: "WITS",
67
+ },
68
+ "max-balance": {
69
+ hint: "Having at most this amount of unlocked Wits.",
70
+ param: "WITS",
71
+ },
72
+ },
73
+ },
74
+ knownPeers: {
75
+ hint: "Get a full list of peers as known by the Wit/Oracle RPC provider(s).",
76
+ },
77
+ mempool: {
78
+ hint: "Dump current transactions mempool.",
79
+ params: "[\"vtt\" | \"drt\" | \"st\" | \"ut\"]",
80
+ options: {
81
+ count: { hint: "Just count the number of entries (ignoring limit)." },
82
+ offset: {
83
+ hint: "Skips first matching entries (default: 0).",
84
+ param: "OFFSET",
85
+ },
86
+ },
87
+ },
88
+ powers: {
89
+ hint: "List validation identities ordered by their current mining power.",
90
+ options: {
91
+ distinct: { hint: "Include only the first appearance per validator." },
92
+ witnessing: { hint: "Order by witnessing power instead." },
93
+ },
94
+ },
95
+ provider: {
96
+ hint: "Show the underlying Wit/RPC provider and network id being used.",
97
+ },
98
+ senate: {
99
+ hint: "List distinct identities that have lately validated at least one block.",
100
+ options: {
101
+ since: {
102
+ hint: "Since the specified epoch (default: -2048).",
103
+ param: "MINUS_EPOCHS",
104
+ },
105
+ },
106
+ },
107
+ stakes: {
108
+ hint: "List active stake entries at present time.",
109
+ options: {
110
+ validator: { hint: "Filter by validator address.", param: "WIT_ADDRESS" },
111
+ withdrawer: { hint: "Filter by withdrawer address.", param: "WIT_ADDRESS" },
112
+ },
113
+ },
114
+ "stats*": {
115
+ hint: "Report network stats.",
116
+ },
117
+ status: {
118
+ hint: "Report the sync status of the network's Wit/Oracle RPC provider being used.",
119
+ },
120
+ supplyInfo: {
121
+ hint: "Get network's Wit supply information.",
122
+ },
123
+ versions: {
124
+ hint: "List known protocol versions and which one is currently live.",
125
+ },
126
+ wips: {
127
+ hint: "Show currently activated WIPs on the network.",
128
+ options: {
129
+ pending: { hint: "Only shows pending upgrades, if any." },
130
+ },
131
+ },
132
+ },
133
+ subcommands: {
134
+ blocks,
135
+ constants,
136
+ holders,
137
+ knownPeers,
138
+ mempool,
139
+ fees: priorities,
140
+ powers,
141
+ provider,
142
+ senate,
143
+ stakes,
144
+ supplyInfo,
145
+ status: syncStatus,
146
+ versions,
147
+ wips,
148
+ },
149
+ }
150
+
151
+ /// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
152
+ /// CLI SUBMODULE COMMANDS ============================================================================================
153
+
154
+ async function blocks (options = {}) {
155
+ options.limit = Math.min(parseInt(options.limit) || FLAGS_LIMIT_DEFAULT, FLAGS_LIMIT_MAX)
156
+ const provider = new Witnet.JsonRpcProvider(options?.provider)
157
+ // todo: use prompter?
158
+ const records = await provider.blocks(parseInt(options?.since) || -options.limit - 2, options.limit)
159
+ if (records.length > 0) {
160
+ helpers.traceTable(
161
+ records.slice(0, options.limit).map(record => [
162
+ record[0],
163
+ record[1],
164
+ ]), {
165
+ headlines: ["EPOCH", "BLOCK HASHES"],
166
+ humanizers: [helpers.commas],
167
+ colors: [, helpers.colors.gray],
168
+ })
169
+ console.info(`^ Listed ${records.length} blocks for a range of ${options.limit} epochs.`)
170
+ } else {
171
+ console.info(
172
+ `> No blocks found in specified range (since: ${
173
+ options?.since || -options.limit
174
+ }, limit: ${
175
+ options.limit
176
+ }).`
177
+ )
178
+ }
179
+ }
180
+
181
+ async function constants (options = {}) {
182
+ const provider = new Witnet.JsonRpcProvider(options?.provider)
183
+ console.info(await provider.constants())
184
+ }
185
+
186
+ async function holders (options = {}) {
187
+ options.limit = Math.min(parseInt(options.limit) || FLAGS_LIMIT_DEFAULT, FLAGS_LIMIT_MAX)
188
+ const provider = new Witnet.JsonRpcProvider(options?.provider)
189
+ const records = Object.entries(await helpers.prompter(provider.holders(
190
+ options["min-balance"] ? options["min-balance"] * 10 ** 9 : 1000000,
191
+ options["max-balance"] ? options["max-balance"] * 10 ** 9 : null,
192
+ )))
193
+ const totalRecords = records.length
194
+ helpers.traceTable(
195
+ records.slice(0, options.limit).map(([address, balance], index) => [
196
+ index + 1,
197
+ address,
198
+ ...(options?.verbose
199
+ ? [
200
+ Witnet.Coins.fromNanowits(balance.locked).wits,
201
+ Witnet.Coins.fromNanowits(balance.staked).wits,
202
+ Witnet.Coins.fromNanowits(balance.unlocked).wits,
203
+ ]
204
+ : []),
205
+ Witnet.Coins.fromNanowits(balance.locked + balance.staked + balance.unlocked).wits,
206
+ ]), {
207
+ headlines: [
208
+ "RANK", "HOLDERS",
209
+ ...(options?.verbose
210
+ ? [
211
+ "Locked ($WIT)",
212
+ "Staked ($WIT)",
213
+ "Available ($WIT)",
214
+ ]
215
+ : []),
216
+ "BALANCE ($WIT)",
217
+ ],
218
+ humanizers: [,, helpers.commas, helpers.commas, helpers.commas, helpers.commas],
219
+ colors: [
220
+ , mgreen,
221
+ ...(options?.verbose
222
+ ? [
223
+ gray,
224
+ yellow,
225
+ myellow,
226
+ ]
227
+ : []),
228
+ lyellow,
229
+ ],
230
+ }
231
+ )
232
+ if (options.limit < totalRecords) {
233
+ console.info(`^ Listed ${Math.min(options.limit, totalRecords)} out of ${totalRecords} records.`)
234
+ }
235
+ }
236
+
237
+ async function knownPeers (options = {}) {
238
+ if (!options) options = {}
239
+ options.limit = parseInt(options.limit) || FLAGS_LIMIT_DEFAULT
240
+ const provider = new Witnet.JsonRpcProvider(options?.provider)
241
+ const knownPeers = await provider.knownPeers()
242
+ console.info(knownPeers)
243
+ }
244
+
245
+ async function mempool (options = {}) {
246
+ const provider = new Witnet.JsonRpcProvider(options?.provider)
247
+ console.info(await provider.mempool())
248
+ }
249
+
250
+ async function powers (options = {}) {
251
+ const provider = new Witnet.JsonRpcProvider(options?.provider)
252
+ const query = {
253
+ distinct: options?.distinct || false,
254
+ limit: parseInt(options.limit) || FLAGS_LIMIT_DEFAULT,
255
+ offset: parseInt(options?.offset) || 0,
256
+ orderBy: options?.witnessing ? "witnessing" : "mining",
257
+ }
258
+ const records = await provider.powers(query)
259
+ if (records.length > 0) {
260
+ helpers.traceTable(
261
+ records.map(record => [
262
+ record.ranking,
263
+ record.validator,
264
+ ...(options?.verbose ? [record.withdrawer] : []),
265
+ record.power,
266
+ ]), {
267
+ headlines: [
268
+ "G_RANK",
269
+ "VALIDATORS",
270
+ ...(options?.verbose ? ["Withdrawer"] : []),
271
+ `${query.orderBy.toUpperCase()} POWER`,
272
+ ],
273
+ colors: [
274
+ ,
275
+ helpers.colors.green,
276
+ ...(options?.verbose ? [helpers.colors.mgreen] : []),
277
+ query.orderBy === "mining" ? helpers.colors.mcyan : helpers.colors.mmagenta,
278
+ ],
279
+ humanizers: [
280
+ helpers.commas,,
281
+ ...(options?.verbose ? [, helpers.commas] : [helpers.commas]),
282
+ ],
283
+ },
284
+ )
285
+ if (records.length === query.limit || query.offset === 0) {
286
+ console.info(`^ Listed ${records.length} records.`)
287
+ } else if (query.offset !== 0) {
288
+ console.info(`^ Listed ${records.length} out of ${records.length + query.offset} records.`)
289
+ }
290
+ } else {
291
+ if (query.offset === 0) {
292
+ console.info("> No records found.")
293
+ } else {
294
+ console.info(`> No as many as ${query.offset + 1} records exist.`)
295
+ }
296
+ }
297
+ }
298
+
299
+ async function priorities (options = {}) {
300
+ const provider = new Witnet.JsonRpcProvider(options?.provider)
301
+ console.info(await provider.priorities())
302
+ }
303
+
304
+ async function provider (options = {}) {
305
+ const provider = await Witnet.JsonRpcProvider.fromEnv(options?.provider)
306
+ console.info(`> Witnet RPC provider: ${white(provider.endpoints)}`)
307
+ console.info(`> Witnet environment: ${
308
+ provider.networkId === 40941
309
+ ? lcyan("MAINNET")
310
+ : (provider.network === "testnet" ? cyan("TESTNET") : mred("Unknown"))
311
+ }`)
312
+ console.info(`> Witnet network id: ${green("0x" + provider.networkId.toString(16).toUpperCase())}`)
313
+ }
314
+
315
+ async function senate (options = {}) {
316
+ const provider = new Witnet.JsonRpcProvider(options?.provider)
317
+ const params = {
318
+ distinct: true,
319
+ limit: Math.min(parseInt(options.limit) || FLAGS_LIMIT_DEFAULT, FLAGS_LIMIT_MAX),
320
+ offset: parseInt(options?.offset || 0),
321
+ order: { by: "mining" },
322
+ since: -Math.abs(parseInt(options?.since) || OPTIONS_DEFAULT_SINCE) - 1,
323
+ }
324
+ const records = await provider.stakes({ params }) // todo: use prompter?
325
+ if (records.length > 0) {
326
+ helpers.traceTable(
327
+ records
328
+ .map((record, index) => [
329
+ ...(options?.verbose
330
+ ? [
331
+ index + 1,
332
+ record.key.validator,
333
+ record.value.nonce,
334
+ record.value.epochs.witnessing,
335
+ ]
336
+ : [
337
+ record.key.validator,
338
+ ]),
339
+ record.value.epochs.mining,
340
+ ])
341
+ , {
342
+ headlines: [
343
+ ...(options?.verbose
344
+ ? [
345
+ "INDEX",
346
+ `Superblock Voting Committee ${params.since + 1}`,
347
+ "Nonce",
348
+ "LW_Epoch",
349
+ ]
350
+ : [
351
+ `Superblock Voting Committee ${params.since + 1}`,
352
+ ]),
353
+ "LM_Epoch",
354
+ ],
355
+ humanizers: [
356
+ ...(options?.verbose
357
+ ? [
358
+ helpers.commas,, helpers.commas, helpers.commas, helpers.commas,
359
+ ]
360
+ : [
361
+ , helpers.commas, helpers.commas, helpers.commas,
362
+ ]),
363
+ ],
364
+ colors: [
365
+ ...(options?.verbose
366
+ ? [
367
+ ,,, helpers.colors.magenta, helpers.colors.mcyan,
368
+ ]
369
+ : [
370
+ , helpers.colors.mcyan,
371
+ ]),
372
+ ],
373
+ }
374
+ )
375
+ if (records.length < params.limit) {
376
+ if (params.offset === 0) {
377
+ console.info(`^ Only ${records.length} qualified members out of ${params.limit} seats.`)
378
+ } else {
379
+ console.info(`^ Listed ${records.length} out of ${records.length + params.offset} members.`)
380
+ }
381
+ } else {
382
+ console.info(`^ Listed ${records.length} members.`)
383
+ }
384
+ } else {
385
+ if (params.offset === 0) {
386
+ console.info("No qualified members found.")
387
+ } else {
388
+ console.info(`No as many as ${params.offset} qualified members exist.`)
389
+ }
390
+ }
391
+ }
392
+
393
+ async function stakes (options = {}) {
394
+ const provider = new Witnet.JsonRpcProvider(options?.provider)
395
+ const query = {
396
+ params: {
397
+ limit: Math.min(parseInt(options.limit) || FLAGS_LIMIT_DEFAULT, FLAGS_LIMIT_MAX),
398
+ offset: parseInt(options?.offset || 0),
399
+ },
400
+ }
401
+ if (options?.validator) query.filter = { validator: options.validator }
402
+ if (options?.withdrawer) query.filter = { ...query.filter, withdrawer: options.withdrawer }
403
+ const records = await provider.stakes(query) // todo: use prompter?
404
+ if (records.length > 0) {
405
+ helpers.traceTable(
406
+ records
407
+ .map((record, index) => [
408
+ 1 + index + query.params.offset,
409
+ record.key.withdrawer,
410
+ record.key.validator,
411
+ ...(
412
+ options?.verbose
413
+ ? [record.value.nonce, record.value.epochs.witnessing, record.value.epochs.mining]
414
+ : []
415
+ ),
416
+ Witnet.Coins.fromNanowits(record.value.coins).wits,
417
+ ]),
418
+ {
419
+ headlines: [
420
+ options?.validator || options?.withdrawer ? "RANK" : "G_RANK",
421
+ "STAKERS",
422
+ "Validator",
423
+ ...(
424
+ options?.verbose
425
+ ? ["Nonce", "LW_Epoch", "LM_Epoch"]
426
+ : []
427
+ ),
428
+ "STAKED ($WIT)",
429
+ ],
430
+ humanizers: [
431
+ ,,, ...(
432
+ options?.verbose
433
+ ? [helpers.commas, helpers.commas, helpers.commas]
434
+ : []
435
+ ),
436
+ (x) => helpers.commas(Math.floor(parseFloat(x))),
437
+ ],
438
+ colors: [
439
+ , helpers.colors.mgreen,, ...(
440
+ options?.verbose
441
+ ? [, helpers.colors.magenta, helpers.colors.cyan]
442
+ : []
443
+ ),
444
+ helpers.colors.myellow,
445
+ ],
446
+ },
447
+ )
448
+ if (records.length === query.params.limit || query.params.offset === 0) {
449
+ console.info(`^ Listed ${records.length} records.`)
450
+ } else if (query.params.offset !== 0) {
451
+ console.info(`^ Listed ${records.length} out of ${records.length + query.params.offset} records.`)
452
+ }
453
+ } else {
454
+ if (query.params.offset === 0) {
455
+ console.info("> No records found.")
456
+ } else {
457
+ console.info(`> No as many as ${query.params.offset + 1} records exist.`)
458
+ }
459
+ }
460
+ }
461
+
462
+ async function supplyInfo (options = {}) {
463
+ const reporter = new Witnet.JsonRpcProvider(options?.provider || process.env.WITNET_SDK_PROVIDER_URL)
464
+ const data = await reporter.supplyInfo()
465
+ console.info(`> Supply info at epoch ${helpers.colors.white(helpers.commas(data.epoch))}:`)
466
+ const records = []
467
+ records.push(["Minted blocks", helpers.toFixedTrunc(100 * data.blocks_minted / (data.epoch - 1), 1) + " %"])
468
+ records.push(["Minted rewards", helpers.whole_wits(data.blocks_minted_reward, 2)])
469
+ if (data.burnt_supply) {
470
+ records.push(["Burnt supply", helpers.whole_wits(data.burnt_supply, 2)])
471
+ };
472
+ if (data.current_locked_supply) {
473
+ records.push(["Locked supply", helpers.whole_wits(data.current_locked_supply, 2)])
474
+ }
475
+ if (data.current_staked_supply) {
476
+ records.push(["Staked supply", helpers.whole_wits(data.current_staked_supply, 2)])
477
+ }
478
+ records.push(["Circulating supply", helpers.whole_wits(data.current_unlocked_supply, 2)])
479
+ helpers.traceTable(records, {
480
+ headlines: [":KPI", "VALUE"],
481
+ colors: [helpers.colors.mgreen, helpers.colors.myellow],
482
+ })
483
+ }
484
+
485
+ async function syncStatus (options = {}) {
486
+ const provider = await Witnet.JsonRpcProvider.fromEnv(options?.provider)
487
+ const syncStatus = await provider.syncStatus()
488
+ helpers.traceTable(
489
+ [[
490
+ provider.network === "mainnet" ? "Mainnet" : `Testnet (${provider.networkId.toString(16).toUpperCase()})`,
491
+ syncStatus.node_state || "",
492
+ syncStatus.current_epoch,
493
+ syncStatus.chain_beacon.checkpoint,
494
+ syncStatus.chain_beacon.hashPrevBlock,
495
+ ]], {
496
+ headlines: [
497
+ "NETWORK",
498
+ ":STATUS",
499
+ "Current epoch",
500
+ "Checkpoint epoch",
501
+ "Checkpoint block hash",
502
+ ],
503
+ humanizers: [,, helpers.commas, helpers.commas],
504
+ colors: [helpers.colors.mgreen, helpers.colors.lgreen, helpers.colors.white,, helpers.colors.gray],
505
+ },
506
+ )
507
+ }
508
+
509
+ async function versions (options = {}) {
510
+ const provider = new Witnet.JsonRpcProvider(options?.provider)
511
+ const protocolInfo = await provider.protocolInfo()
512
+ if (
513
+ protocolInfo?.all_checkpoints_periods &&
514
+ protocolInfo?.all_versions?.efv &&
515
+ Object.keys(protocolInfo.all_versions.efv).length > 0
516
+ ) {
517
+ const records = Object.fromEntries(
518
+ Object.entries(protocolInfo.all_checkpoints_periods)
519
+ .sort(([a], [b]) => b - a)
520
+ .map(([version, period]) => [version, { period }])
521
+ )
522
+ Object.entries(protocolInfo.all_versions.efv).forEach(([key, epoch]) => {
523
+ if (records[key]) records[key].epoch = epoch
524
+ })
525
+ helpers.traceTable(
526
+ Object.entries(records).map(([key, props]) => [
527
+ key === "V1_7" ? "V1_0" : key,
528
+ props?.epoch,
529
+ props?.period,
530
+ ]), {
531
+ headlines: [
532
+ ":Version",
533
+ "Activation epoch",
534
+ ":Block time (secs)",
535
+ ],
536
+ humanizers: [, helpers.commas],
537
+ colors: [helpers.colors.mgreen, helpers.colors.white, helpers.colors.normal],
538
+ })
539
+ }
540
+ console.info(`Current protocol version is ${helpers.colors.mgreen(protocolInfo.current_version)}.`)
541
+ }
542
+
543
+ async function wips (options = {}) {
544
+ const provider = new Witnet.JsonRpcProvider(options?.provider)
545
+ const wips = await provider.wips()
546
+ if (!options?.pending) {
547
+ // console.info(`> Active WIP upgrades at epoch ${helpers.colors.white(helpers.commas(wips.epoch))}:`)
548
+ const active_upgrades = Object.entries(wips.active_upgrades).map(([wip, epoch]) => [
549
+ wip,
550
+ epoch,
551
+ ])
552
+ helpers.traceTable(active_upgrades, {
553
+ headlines: [":WIP", "Activation epoch"],
554
+ humanizers: [, helpers.commas],
555
+ colors: [helpers.colors.mcyan, helpers.colors.white],
556
+ })
557
+ }
558
+ if (wips.pending_upgrades || options?.pending) {
559
+ if (wips.pending_upgrades.length === 0) {
560
+ console.info(`> No pending WIP upgrades at epoch ${helpers.colors.white(helpers.commas(wips.epoch))}.`)
561
+ } else {
562
+ console.info(`Pending WIP upgrades at epoch ${helpers.colors.white(helpers.commas(wips.epoch))}:`)
563
+ const pending_upgrades = wips.pending_upgrades.map(upgrade => {
564
+ return [
565
+ upgrade.wip,
566
+ upgrade.bit,
567
+ upgrade.init,
568
+ upgrade.votes,
569
+ upgrade.period,
570
+ // upgrade.end,
571
+ ]
572
+ })
573
+ helpers.traceTable(pending_upgrades, {
574
+ headlines: [
575
+ ":WIP",
576
+ "WIP_BIT",
577
+ "From epoch",
578
+ "Aye votes",
579
+ "Duration",
580
+ // "Deadline",
581
+ ],
582
+ humanizers: [,, helpers.commas, helpers.commas, helpers.commas, helpers.commas],
583
+ colors: [
584
+ helpers.colors.lcyan,
585
+ helpers.colors.mcyan,
586
+ helpers.colors.white,
587
+ helpers.colors.myellow,
588
+ helpers.colors.mgreen,
589
+ // helpers.colors.myellow,
590
+ ],
591
+ })
592
+ }
593
+ }
594
+ }