@witnet/solidity 3.0.4 → 3.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/LICENSE +2 -2
  2. package/build/contracts/Bech32.json +1 -1
  3. package/build/contracts/Clonable.json +1 -1
  4. package/build/contracts/Context.json +1 -1
  5. package/build/contracts/Create3.json +1 -1
  6. package/build/contracts/ERC165.json +1 -1
  7. package/build/contracts/Escrowable.json +1 -1
  8. package/build/contracts/IChainlinkAggregatorV3.json +1 -1
  9. package/build/contracts/IERC165.json +1 -1
  10. package/build/contracts/IERC20.json +1 -1
  11. package/build/contracts/IERC2362.json +1 -1
  12. package/build/contracts/IPythChainlinkAggregatorV3.json +1 -1
  13. package/build/contracts/IWitAppliance.json +1 -1
  14. package/build/contracts/IWitOracle.json +1 -1
  15. package/build/contracts/IWitOracleAppliance.json +1 -1
  16. package/build/contracts/IWitOracleConsumer.json +1 -1
  17. package/build/contracts/IWitOracleConsumerLegacy.json +1 -1
  18. package/build/contracts/IWitOracleLegacy.json +1 -1
  19. package/build/contracts/IWitOracleQueriable.json +1 -1
  20. package/build/contracts/IWitOracleQueriableConsumer.json +1 -1
  21. package/build/contracts/IWitOracleQueriableEvents.json +1 -1
  22. package/build/contracts/IWitOracleQueriableExperimental.json +1 -1
  23. package/build/contracts/IWitOracleQueriableTrustableReporter.json +1 -1
  24. package/build/contracts/IWitOracleQueriableTrustlessReporter.json +1 -1
  25. package/build/contracts/IWitOracleRadonRegistry.json +1 -1
  26. package/build/contracts/IWitOracleRadonRegistryEvents.json +1 -1
  27. package/build/contracts/IWitOracleRadonRegistryLegacy.json +1 -1
  28. package/build/contracts/IWitOracleRadonRequestFactory.json +1 -1
  29. package/build/contracts/IWitOracleRadonRequestModal.json +1 -1
  30. package/build/contracts/IWitOracleRadonRequestTemplate.json +1 -1
  31. package/build/contracts/IWitOracleRequest.json +1 -1
  32. package/build/contracts/IWitOracleRequestFactory.json +1 -1
  33. package/build/contracts/IWitOracleRequestFactoryEvents.json +1 -1
  34. package/build/contracts/IWitOracleRequestTemplate.json +1 -1
  35. package/build/contracts/IWitOracleTrustableAdmin.json +1 -1
  36. package/build/contracts/IWitOracleTrustless.json +1 -1
  37. package/build/contracts/IWitPriceFeeds.json +1 -1
  38. package/build/contracts/IWitPriceFeedsAdmin.json +1 -1
  39. package/build/contracts/IWitPriceFeedsConsumer.json +1 -1
  40. package/build/contracts/IWitPriceFeedsEvents.json +1 -1
  41. package/build/contracts/IWitPriceFeedsLegacy.json +1 -1
  42. package/build/contracts/IWitPriceFeedsLegacyAdmin.json +1 -1
  43. package/build/contracts/IWitPriceFeedsLegacySolver.json +1 -1
  44. package/build/contracts/IWitPriceFeedsLegacySolverFactory.json +1 -1
  45. package/build/contracts/IWitPriceFeedsTypes.json +1 -1
  46. package/build/contracts/IWitPyth.json +1 -1
  47. package/build/contracts/IWitPythChainlinkAggregator.json +1 -1
  48. package/build/contracts/IWitPythErrors.json +1 -1
  49. package/build/contracts/IWitPythEvents.json +1 -1
  50. package/build/contracts/IWitPythReporter.json +1 -1
  51. package/build/contracts/IWitRandomness.json +1 -1
  52. package/build/contracts/IWitRandomnessAdmin.json +1 -1
  53. package/build/contracts/IWitRandomnessAdminV2.json +1 -1
  54. package/build/contracts/IWitRandomnessConsumer.json +1 -1
  55. package/build/contracts/IWitRandomnessEvents.json +1 -1
  56. package/build/contracts/IWitRandomnessLegacy.json +1 -1
  57. package/build/contracts/IWitRandomnessTypes.json +1 -1
  58. package/build/contracts/Initializable.json +1 -1
  59. package/build/contracts/OVM_GasPriceOracle.json +1 -1
  60. package/build/contracts/Ownable.json +1 -1
  61. package/build/contracts/Ownable2Step.json +1 -1
  62. package/build/contracts/Payable.json +1 -1
  63. package/build/contracts/Proxiable.json +1 -1
  64. package/build/contracts/ReentrancyGuard.json +1 -1
  65. package/build/contracts/Secp256k1.json +1 -1
  66. package/build/contracts/Slices.json +1 -1
  67. package/build/contracts/TestBech32.json +1 -1
  68. package/build/contracts/TestSecp256k1.json +1 -1
  69. package/build/contracts/Upgradeable.json +1 -1
  70. package/build/contracts/UsingWitOracle.json +1 -1
  71. package/build/contracts/UsingWitPriceFeeds.json +1 -1
  72. package/build/contracts/UsingWitRandomness.json +1 -1
  73. package/build/contracts/WitOracle.json +2 -13
  74. package/build/contracts/WitOracleBasePushOnly.json +1 -1
  75. package/build/contracts/WitOracleBasePushOnlyTrustable.json +1 -1
  76. package/build/contracts/WitOracleBasePushOnlyTrustless.json +1 -1
  77. package/build/contracts/WitOracleBasePushOnlyUpgradable.json +1 -1
  78. package/build/contracts/WitOracleBaseQueriable.json +1 -1
  79. package/build/contracts/WitOracleBaseQueriableTrustable.json +1 -1
  80. package/build/contracts/WitOracleBaseQueriableTrustless.json +1 -1
  81. package/build/contracts/WitOracleBaseQueriableUpgradable.json +1 -1
  82. package/build/contracts/WitOracleDataLib.json +2 -254
  83. package/build/contracts/WitOraclePushOnly.json +1 -1
  84. package/build/contracts/WitOracleRadonEncodingLib.json +2 -13
  85. package/build/contracts/WitOracleRadonRegistry.json +2 -13
  86. package/build/contracts/WitOracleRadonRegistryBase.json +1 -1
  87. package/build/contracts/WitOracleRadonRegistryBaseUpgradable.json +1 -1
  88. package/build/contracts/WitOracleRadonRegistryData.json +1 -1
  89. package/build/contracts/WitOracleRadonRegistryDefaultV21.json +1 -1
  90. package/build/contracts/WitOracleRadonRegistryUpgradableDefault.json +2 -17
  91. package/build/contracts/WitOracleRadonRegistryUpgradableNoSha256.json +1 -1
  92. package/build/contracts/WitOracleRadonRegistryUpgradableZkSync.json +1 -1
  93. package/build/contracts/WitOracleRadonRequestFactory.json +2 -13
  94. package/build/contracts/WitOracleRadonRequestFactoryBase.json +1 -1
  95. package/build/contracts/WitOracleRadonRequestFactoryBaseUpgradable.json +1 -1
  96. package/build/contracts/WitOracleRadonRequestFactoryModals.json +2 -13
  97. package/build/contracts/WitOracleRadonRequestFactoryModalsDefault.json +2 -13
  98. package/build/contracts/WitOracleRadonRequestFactoryTemplates.json +2 -13
  99. package/build/contracts/WitOracleRadonRequestFactoryTemplatesDefault.json +2 -13
  100. package/build/contracts/WitOracleRadonRequestFactoryUpgradableConfluxCore.json +1 -1
  101. package/build/contracts/WitOracleRadonRequestFactoryUpgradableDefault.json +2 -13
  102. package/build/contracts/WitOracleResultStatusLib.json +2 -14
  103. package/build/contracts/WitOracleTrustableDefault.json +2 -259
  104. package/build/contracts/WitOracleTrustableExperimental.json +1 -1
  105. package/build/contracts/WitOracleTrustableObscuro.json +1 -1
  106. package/build/contracts/WitOracleTrustableOvm2.json +1 -1
  107. package/build/contracts/WitOracleTrustablePushOnly.json +1 -1
  108. package/build/contracts/WitOracleTrustableReef.json +1 -1
  109. package/build/contracts/WitOracleTrustableZkSync.json +1 -1
  110. package/build/contracts/WitOracleTrustlessDataLib.json +1 -1
  111. package/build/contracts/WitOracleTrustlessDefaultV22.json +1 -1
  112. package/build/contracts/WitOracleTrustlessUpgradableDefault.json +1 -1
  113. package/build/contracts/WitPriceFeeds.json +2 -13
  114. package/build/contracts/WitPriceFeedsDataLib.json +2 -14
  115. package/build/contracts/WitPriceFeedsLegacy.json +2 -8
  116. package/build/contracts/WitPriceFeedsLegacyDataLib.json +2 -84
  117. package/build/contracts/WitPriceFeedsLegacyUpgradable.json +1 -1
  118. package/build/contracts/WitPriceFeedsLegacyUpgradableBypass.json +2 -80
  119. package/build/contracts/WitPriceFeedsSolverBase.json +1 -1
  120. package/build/contracts/WitPriceFeedsV3.json +1 -1
  121. package/build/contracts/WitPriceFeedsV3Upgradable.json +2 -17
  122. package/build/contracts/WitPythChainlinkAggregator.json +1 -1
  123. package/build/contracts/WitRandomness.json +2 -13
  124. package/build/contracts/WitRandomnessLegacy.json +1 -1
  125. package/build/contracts/WitRandomnessV3.json +2 -13
  126. package/build/contracts/WitRngConsumer.json +1 -1
  127. package/build/contracts/Witnet.json +1 -1
  128. package/build/contracts/WitnetBuffer.json +1 -1
  129. package/build/contracts/WitnetCBOR.json +1 -1
  130. package/build/contracts/WitnetDeployer.json +2 -13
  131. package/build/contracts/WitnetDeployerConfluxCore.json +1 -1
  132. package/build/contracts/WitnetDeployerDeferred.json +1 -1
  133. package/build/contracts/WitnetDeployerMeter.json +1 -1
  134. package/build/contracts/WitnetProxy.json +2 -9
  135. package/build/contracts/WitnetUpgradableBase.json +1 -1
  136. package/{migrations → dist/migrations}/addresses.json +1 -25
  137. package/{migrations → dist/migrations}/constructorArgs.json +1 -6
  138. package/dist/migrations/settings/artifacts.d.ts +95 -0
  139. package/dist/migrations/settings/artifacts.d.ts.map +1 -0
  140. package/dist/migrations/settings/artifacts.js +80 -0
  141. package/dist/migrations/settings/networks.d.ts +593 -0
  142. package/dist/migrations/settings/networks.d.ts.map +1 -0
  143. package/dist/migrations/settings/networks.js +593 -0
  144. package/dist/src/bin/helpers.cjs +350 -0
  145. package/dist/src/bin/helpers.d.cts +76 -0
  146. package/dist/src/bin/helpers.d.cts.map +1 -0
  147. package/dist/src/index.d.ts +6 -0
  148. package/dist/src/index.d.ts.map +1 -0
  149. package/dist/src/index.js +33 -0
  150. package/dist/src/lib/types.d.ts +99 -0
  151. package/dist/src/lib/types.d.ts.map +1 -0
  152. package/dist/src/lib/types.js +18 -0
  153. package/dist/src/lib/utils.d.ts +22 -0
  154. package/dist/src/lib/utils.d.ts.map +1 -0
  155. package/dist/src/lib/utils.js +267 -0
  156. package/dist/src/lib/wrappers/ContractWrapper.d.ts +47 -0
  157. package/dist/src/lib/wrappers/ContractWrapper.d.ts.map +1 -0
  158. package/dist/src/lib/wrappers/ContractWrapper.js +81 -0
  159. package/dist/src/lib/wrappers/WitAppliance.d.ts +7 -0
  160. package/dist/src/lib/wrappers/WitAppliance.d.ts.map +1 -0
  161. package/dist/src/lib/wrappers/WitAppliance.js +17 -0
  162. package/dist/src/lib/wrappers/WitArtifact.d.ts +6 -0
  163. package/dist/src/lib/wrappers/WitArtifact.d.ts.map +1 -0
  164. package/dist/src/lib/wrappers/WitArtifact.js +16 -0
  165. package/dist/src/lib/wrappers/WitOracle.d.ts +105 -0
  166. package/dist/src/lib/wrappers/WitOracle.d.ts.map +1 -0
  167. package/dist/src/lib/wrappers/WitOracle.js +217 -0
  168. package/dist/src/lib/wrappers/WitOracleConsumer.d.ts +16 -0
  169. package/dist/src/lib/wrappers/WitOracleConsumer.d.ts.map +1 -0
  170. package/dist/src/lib/wrappers/WitOracleConsumer.js +30 -0
  171. package/dist/src/lib/wrappers/WitOracleRadonRegistry.d.ts +102 -0
  172. package/dist/src/lib/wrappers/WitOracleRadonRegistry.d.ts.map +1 -0
  173. package/dist/src/lib/wrappers/WitOracleRadonRegistry.js +140 -0
  174. package/dist/src/lib/wrappers/WitOracleRadonRequestFactory.d.ts +81 -0
  175. package/dist/src/lib/wrappers/WitOracleRadonRequestFactory.d.ts.map +1 -0
  176. package/dist/src/lib/wrappers/WitOracleRadonRequestFactory.js +257 -0
  177. package/dist/src/lib/wrappers/WitPriceFeeds.d.ts +91 -0
  178. package/dist/src/lib/wrappers/WitPriceFeeds.d.ts.map +1 -0
  179. package/dist/src/lib/wrappers/WitPriceFeeds.js +356 -0
  180. package/dist/src/lib/wrappers/WitPriceFeedsLegacy.d.ts +14 -0
  181. package/dist/src/lib/wrappers/WitPriceFeedsLegacy.d.ts.map +1 -0
  182. package/dist/src/lib/wrappers/WitPriceFeedsLegacy.js +64 -0
  183. package/dist/src/lib/wrappers/WitRandomness.d.ts +55 -0
  184. package/dist/src/lib/wrappers/WitRandomness.d.ts.map +1 -0
  185. package/dist/src/lib/wrappers/WitRandomness.js +165 -0
  186. package/dist/src/lib/wrappers.d.ts +8 -0
  187. package/dist/src/lib/wrappers.d.ts.map +1 -0
  188. package/dist/src/lib/wrappers.js +8 -0
  189. package/package.json +78 -54
  190. package/scripts/clean.cjs +21 -0
  191. package/scripts/eth-create2.cjs +38 -0
  192. package/scripts/eth-create3.cjs +45 -0
  193. package/scripts/postinstall.cjs +9 -0
  194. package/scripts/prepare.cjs +27 -0
  195. package/scripts/vanity2gen.cjs +121 -0
  196. package/scripts/vanity3gen.cjs +84 -0
  197. package/scripts/verify-proxies.cjs +50 -0
  198. package/scripts/verify-truffle.cjs +69 -0
  199. package/scripts/verify.js +95 -0
  200. package/scripts/wof-acls.js +17 -0
  201. package/src/bin/bots/bridge.cjs +0 -0
  202. package/src/bin/bots/randomizer.cjs +290 -0
  203. package/src/bin/bots/reporter.cjs +0 -0
  204. package/src/bin/cli/accounts.cjs +47 -0
  205. package/src/bin/cli/assets.cjs +466 -0
  206. package/src/bin/cli/framework.cjs +100 -0
  207. package/src/bin/cli/gateway.cjs +26 -0
  208. package/src/bin/cli/networks.cjs +63 -0
  209. package/src/bin/cli/priceFeeds.cjs +170 -0
  210. package/src/bin/cli/queries.cjs +217 -0
  211. package/src/bin/cli/randomness.cjs +367 -0
  212. package/src/bin/cli/reports.cjs +272 -0
  213. package/src/bin/cli/wizard.cjs +352 -0
  214. package/src/bin/helpers.cjs +388 -0
  215. package/src/bin/index.cjs +407 -0
  216. package/settings/artifacts.js +0 -71
  217. package/settings/index.js +0 -49
  218. package/settings/networks.js +0 -593
  219. package/settings/solidity.js +0 -11
  220. package/settings/specs.js +0 -102
  221. package/src/index.js +0 -96
  222. package/src/utils.js +0 -305
@@ -0,0 +1,388 @@
1
+ const fs = require("node:fs")
2
+ const merge = require("lodash.merge")
3
+
4
+ const addresses = require("../../migrations/addresses.json")
5
+ const artifacts = require("../../migrations/settings/artifacts.js").default
6
+ const constructorArgs = require("../../migrations/constructorArgs.json")
7
+
8
+ const DEFAULT_BATCH_SIZE = 64
9
+ const DEFAULT_LIMIT = 64
10
+ const DEFAULT_SINCE = -5000
11
+ const WITNET_SDK_RADON_ASSETS_PATH =
12
+ process.env.WITNET_SDK_RADON_ASSETS_PATH || "../../../../witnet/assets"
13
+
14
+ const isModuleInitialized = fs.existsSync("./witnet/assets/index.cjs")
15
+
16
+ function* chunks(arr, n) {
17
+ for (let i = 0; i < arr.length; i += n) {
18
+ yield arr.slice(i, i + n)
19
+ }
20
+ }
21
+
22
+ const colors = {
23
+ blue: (str) => `\x1b[34m${str}\x1b[0m`,
24
+ cyan: (str) => `\x1b[36m${str}\x1b[0m`,
25
+ gray: (str) => `\x1b[90m${str}\x1b[0m`,
26
+ green: (str) => `\x1b[32m${str}\x1b[0m`,
27
+ magenta: (str) => `\x1b[0;35m${str}\x1b[0m`,
28
+ red: (str) => `\x1b[31m${str}\x1b[0m`,
29
+ yellow: (str) => `\x1b[33m${str}\x1b[0m`,
30
+ white: (str) => `\x1b[0;38m${str}\x1b[0m`,
31
+ lblue: (str) => `\x1b[1;94m${str}\x1b[0m`,
32
+ lcyan: (str) => `\x1b[1;96m${str}\x1b[0m`,
33
+ lgreen: (str) => `\x1b[1;92m${str}\x1b[0m`,
34
+ lmagenta: (str) => `\x1b[1;95m${str}\x1b[0m`,
35
+ lwhite: (str) => `\x1b[0;1;98m${str}\x1b[0m`,
36
+ lyellow: (str) => `\x1b[1;93m${str}\x1b[0m`,
37
+ mblue: (str) => `\x1b[94m${str}\x1b[0m`,
38
+ mcyan: (str) => `\x1b[96m${str}\x1b[0m`,
39
+ mgreen: (str) => `\x1b[92m${str}\x1b[0m`,
40
+ mmagenta: (str) => `\x1b[0;95m${str}\x1b[0m`,
41
+ mred: (str) => `\x1b[91m${str}\x1b[0m`,
42
+ myellow: (str) => `\x1b[93m${str}\x1b[0m`,
43
+ }
44
+
45
+ const colorstrip = (str) =>
46
+ str.replace(
47
+ /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
48
+ "",
49
+ )
50
+
51
+ const commas = (number) => {
52
+ const parts = number?.toString().split(".") || [""]
53
+ const result =
54
+ parts.length <= 1
55
+ ? `${parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",")}`
56
+ : `${parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",")}.${parts[1]}`
57
+ return result
58
+ }
59
+
60
+ function deleteExtraFlags(args) {
61
+ const deleted = []
62
+ return [
63
+ args?.filter((arg) => {
64
+ if (arg.startsWith("--")) {
65
+ deleted.push(arg.slice(2))
66
+ return false
67
+ } else {
68
+ return true
69
+ }
70
+ }),
71
+ deleted,
72
+ ]
73
+ }
74
+
75
+ function extractFlagsFromArgs(args, flags) {
76
+ const curated = {}
77
+ if (args && Array.isArray(args) && flags) {
78
+ flags.forEach((flag) => {
79
+ const index = args.indexOf(`--${flag}`)
80
+ if (index >= 0) {
81
+ curated[flag] = true
82
+ args.splice(index, 1)
83
+ }
84
+ })
85
+ }
86
+ return [args || [], curated]
87
+ }
88
+
89
+ function extractOptionsFromArgs(args, options) {
90
+ const curated = {}
91
+ if (args && Array.isArray(args) && options) {
92
+ options.forEach((option) => {
93
+ const index = args.indexOf(`--${option}`)
94
+ if (index >= 0) {
95
+ curated[option] = args[index]
96
+ if (!args[index + 1] || args[index + 1].startsWith("--")) {
97
+ args.splice(index, 1)
98
+ curated[option] = undefined
99
+ } else {
100
+ curated[option] = args[index + 1]
101
+ args.splice(index, 2)
102
+ }
103
+ }
104
+ })
105
+ }
106
+ return [args || [], curated]
107
+ }
108
+
109
+ function flattenObject(ob) {
110
+ const toReturn = {}
111
+ for (const i in ob) {
112
+ if (!Object.hasOwn(ob, i)) continue
113
+ if (typeof ob[i] === "object" && ob[i] !== null) {
114
+ const flatObject = flattenObject(ob[i])
115
+ for (const x in flatObject) {
116
+ if (!Object.hasOwn(flatObject, x)) continue
117
+ toReturn[`${i}.${x}`] = flatObject[x]
118
+ }
119
+ } else {
120
+ toReturn[i] = ob[i]
121
+ }
122
+ }
123
+ return toReturn
124
+ }
125
+
126
+ function getNetworkAddresses(network) {
127
+ let res = addresses?.default
128
+ getNetworkTagsFromString(network).forEach((net) => {
129
+ res = merge(res, addresses[net])
130
+ })
131
+ return merge(
132
+ res,
133
+ fs.existsSync(`${WITNET_SDK_RADON_ASSETS_PATH}/../addresses.json`)
134
+ ? require(`${WITNET_SDK_RADON_ASSETS_PATH}/../addresses.json`)[
135
+ network.toLowerCase()
136
+ ]
137
+ : {},
138
+ )
139
+ }
140
+
141
+ function getNetworkArtifacts(network) {
142
+ let res = artifacts?.default
143
+ getNetworkTagsFromString(network).forEach((net) => {
144
+ res = merge(res, artifacts[net])
145
+ })
146
+ return res
147
+ }
148
+
149
+ function getNetworkConstructorArgs(network) {
150
+ let res = {}
151
+ getNetworkTagsFromString(network).forEach((net) => {
152
+ res = merge(res, constructorArgs[net])
153
+ })
154
+ return res
155
+ }
156
+
157
+ function getNetworkTagsFromString(network) {
158
+ network = network ? network.toLowerCase() : "development"
159
+ const tags = []
160
+ const parts = network.split(":")
161
+ for (let ix = 0; ix < parts.length; ix++) {
162
+ tags.push(parts.slice(0, ix + 1).join(":"))
163
+ }
164
+ return tags
165
+ }
166
+
167
+ function importRadonAssets(options) {
168
+ const assets = options?.legacy ? {} : require("@witnet/sdk/assets")
169
+ return isModuleInitialized &&
170
+ fs.existsSync(`${WITNET_SDK_RADON_ASSETS_PATH}/index.cjs`)
171
+ ? merge(assets, require(`${WITNET_SDK_RADON_ASSETS_PATH}/index.cjs`))
172
+ : assets
173
+ }
174
+
175
+ function orderKeys(obj) {
176
+ const keys = Object.keys(obj).sort(function keyOrder(k1, k2) {
177
+ if (k1 < k2) return -1
178
+ else if (k1 > k2) return +1
179
+ else return 0
180
+ })
181
+ let i
182
+ const after = {}
183
+ for (i = 0; i < keys.length; i++) {
184
+ after[keys[i]] = obj[keys[i]]
185
+ delete obj[keys[i]]
186
+ }
187
+ for (i = 0; i < keys.length; i++) {
188
+ obj[keys[i]] = after[keys[i]]
189
+ }
190
+ return obj
191
+ }
192
+
193
+ function prompter(promise) {
194
+ const loading = (() => {
195
+ const h = ["|", "/", "-", "\\"]
196
+ let i = 0
197
+ return setInterval(() => {
198
+ i = i > 3 ? 0 : i
199
+ process.stdout.write(`\b\b${h[i]} `)
200
+ i++
201
+ }, 50)
202
+ })()
203
+ return promise.then((result) => {
204
+ clearInterval(loading)
205
+ process.stdout.write("\b\b")
206
+ return result
207
+ })
208
+ }
209
+
210
+ function readWitnetJsonFiles(...filenames) {
211
+ return Object.fromEntries(
212
+ filenames.map((key) => {
213
+ const filepath = `./witnet/${key}.json`
214
+ return [
215
+ key,
216
+ fs.existsSync(filepath) ? JSON.parse(fs.readFileSync(filepath)) : {},
217
+ ]
218
+ }),
219
+ )
220
+ }
221
+
222
+ function saveWitnetJsonFiles(data) {
223
+ Object.entries(data).forEach(([key, obj]) => {
224
+ const filepath = `./witnet/${key}.json`
225
+ if (!fs.existsSync(filepath)) fs.writeFileSync(filepath, "{}")
226
+ const json = merge(JSON.parse(fs.readFileSync(filepath)), obj)
227
+ fs.writeFileSync(filepath, JSON.stringify(json, null, 4), { flag: "w+" })
228
+ })
229
+ }
230
+
231
+ function supportedNetworks(ecosystem) {
232
+ const networks = require("../../migrations/settings/networks.js").default
233
+ return Object.fromEntries(
234
+ Object.keys(constructorArgs)
235
+ .sort()
236
+ .filter(
237
+ (network) =>
238
+ network.indexOf(":") >= 0 &&
239
+ (!ecosystem || network.startsWith(ecosystem.toLowerCase())),
240
+ )
241
+ .map((network) => {
242
+ return [
243
+ network,
244
+ {
245
+ mainnet: networks[network]?.mainnet || false,
246
+ network_id: networks[network].network_id,
247
+ port: networks[network].port,
248
+ symbol: networks[network]?.symbol || "ETH",
249
+ verified: networks[network]?.verify?.explorerUrl,
250
+ },
251
+ ]
252
+ }),
253
+ )
254
+ }
255
+
256
+ function supportsNetwork(network) {
257
+ return network && Object.keys(constructorArgs).includes(network.toLowerCase())
258
+ }
259
+
260
+ function traceHeader(header, color = colors.white, indent = "") {
261
+ console.info(`${indent}┌─${"─".repeat(header.length)}─┐`)
262
+ console.info(`${indent}│ ${color(header)} │`)
263
+ console.info(`${indent}└─${"─".repeat(header.length)}─┘`)
264
+ }
265
+
266
+ function traceTable(records, options) {
267
+ const stringify = (data, humanizers, index) =>
268
+ humanizers?.[index]
269
+ ? humanizers[index](data).toString()
270
+ : (data?.toString() ?? "")
271
+ const reduceMax = (numbers) =>
272
+ numbers.reduce((curr, prev) => Math.max(curr, prev), 0)
273
+ if (!options) options = {}
274
+ const indent = options?.indent || ""
275
+ const numColumns = reduceMax(records.map((record) => record?.length || 1))
276
+ const maxColumnWidth = options?.maxColumnWidth || 80
277
+ const table = transpose(records, numColumns)
278
+ options.widths =
279
+ options?.widths ||
280
+ table.map((column, index) => {
281
+ let maxWidth = reduceMax(
282
+ column.map(
283
+ (field) =>
284
+ colorstrip(stringify(field, options?.humanizers, index)).length,
285
+ ),
286
+ )
287
+ if (options?.headlines?.[index]) {
288
+ maxWidth = Math.max(
289
+ maxWidth,
290
+ colorstrip(options.headlines[index].replaceAll(":", "")).length,
291
+ )
292
+ }
293
+ return Math.min(maxWidth, maxColumnWidth)
294
+ })
295
+ let headline = options.widths.map((maxWidth) => "─".repeat(maxWidth))
296
+ console.info(`${indent}┌─${headline.join("─┬─")}─┐`)
297
+ if (options?.headlines) {
298
+ headline = options.widths.map((maxWidth, index) => {
299
+ const caption = options.headlines[index].replaceAll(":", "")
300
+ const captionLength = colorstrip(caption).length
301
+ return `${colors.white(caption)}${" ".repeat(maxWidth - captionLength)}`
302
+ })
303
+ console.info(`${indent}│ ${headline.join(" │ ")} │`)
304
+ headline = options.widths.map((maxWidth) => "─".repeat(maxWidth))
305
+ console.info(`${indent}├─${headline.join("─┼─")}─┤`)
306
+ }
307
+ for (let i = 0; i < records.length; i++) {
308
+ let line = ""
309
+ for (let j = 0; j < numColumns; j++) {
310
+ let data = table[j][i]
311
+ let color
312
+ if (options?.colors?.[j]) {
313
+ color = options.colors[j]
314
+ } else {
315
+ color =
316
+ typeof data === "string"
317
+ ? colors.green
318
+ : Number(data) === data && data % 1 !== 0 // is float number?
319
+ ? colors.yellow
320
+ : (x) => x
321
+ }
322
+ data = stringify(data, options?.humanizers, j)
323
+ if (colorstrip(data).length > maxColumnWidth) {
324
+ while (colorstrip(data).length > maxColumnWidth - 3) {
325
+ data = data.slice(0, -1)
326
+ }
327
+ data += "..."
328
+ }
329
+ const dataLength = colorstrip(data).length
330
+ if (options?.headlines && options.headlines[j][0] === ":") {
331
+ data = `${color(data)}${" ".repeat(options.widths[j] - dataLength)}`
332
+ } else {
333
+ data = `${" ".repeat(options.widths[j] - dataLength)}${color(data)}`
334
+ }
335
+ line += `│ ${data} `
336
+ }
337
+ console.info(`${indent}${line}│`)
338
+ }
339
+ headline = options.widths.map((maxWidth) => "─".repeat(maxWidth))
340
+ console.info(`${indent}└─${headline.join("─┴─")}─┘`)
341
+ }
342
+
343
+ function transpose(records, numColumns) {
344
+ const columns = []
345
+ for (let index = 0; index < numColumns; index++) {
346
+ columns.push(records.map((row) => row[index]))
347
+ }
348
+ return columns
349
+ }
350
+
351
+ function traceData(header, data, width, color) {
352
+ process.stdout.write(header)
353
+ if (color) process.stdout.write(color)
354
+ for (let ix = 0; ix < data.length / width; ix++) {
355
+ if (ix > 0) process.stdout.write(" ".repeat(header.length))
356
+ process.stdout.write(data.slice(width * ix, width * (ix + 1)))
357
+ process.stdout.write("\n")
358
+ }
359
+ if (color) process.stdout.write("\x1b[0m")
360
+ }
361
+
362
+ module.exports = {
363
+ DEFAULT_BATCH_SIZE,
364
+ DEFAULT_LIMIT,
365
+ DEFAULT_SINCE,
366
+ colors,
367
+ chunks,
368
+ deleteExtraFlags,
369
+ extractFlagsFromArgs,
370
+ extractOptionsFromArgs,
371
+ flattenObject,
372
+ orderKeys,
373
+ traceData,
374
+ traceHeader,
375
+ getNetworkAddresses,
376
+ getNetworkArtifacts,
377
+ getNetworkConstructorArgs,
378
+ getNetworkTagsFromString,
379
+ supportedNetworks,
380
+ supportsNetwork,
381
+ importRadonAssets,
382
+ readWitnetJsonFiles,
383
+ saveWitnetJsonFiles,
384
+ traceTable,
385
+ commas,
386
+ colorstrip,
387
+ prompter,
388
+ }