@witnet/sdk 1.1.5 → 1.2.1

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