@witnet/sdk 1.1.5 → 1.2.0

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