tronwb 6.0.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 (318) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +201 -0
  3. package/dist/TronWeb.js +3 -0
  4. package/dist/TronWeb.js.LICENSE.txt +12 -0
  5. package/dist/TronWeb.js.map +1 -0
  6. package/dist/TronWeb.node.js +2 -0
  7. package/dist/TronWeb.node.js.map +1 -0
  8. package/kj9btptx.cjs +1 -0
  9. package/lib/commonjs/index.d.ts +64 -0
  10. package/lib/commonjs/index.js +37 -0
  11. package/lib/commonjs/index.js.map +1 -0
  12. package/lib/commonjs/lib/TransactionBuilder/TransactionBuilder.d.ts +127 -0
  13. package/lib/commonjs/lib/TransactionBuilder/TransactionBuilder.js +1771 -0
  14. package/lib/commonjs/lib/TransactionBuilder/TransactionBuilder.js.map +1 -0
  15. package/lib/commonjs/lib/TransactionBuilder/helper.d.ts +28 -0
  16. package/lib/commonjs/lib/TransactionBuilder/helper.js +122 -0
  17. package/lib/commonjs/lib/TransactionBuilder/helper.js.map +1 -0
  18. package/lib/commonjs/lib/contract/index.d.ts +29 -0
  19. package/lib/commonjs/lib/contract/index.js +124 -0
  20. package/lib/commonjs/lib/contract/index.js.map +1 -0
  21. package/lib/commonjs/lib/contract/method.d.ts +50 -0
  22. package/lib/commonjs/lib/contract/method.js +238 -0
  23. package/lib/commonjs/lib/contract/method.js.map +1 -0
  24. package/lib/commonjs/lib/event.d.ts +85 -0
  25. package/lib/commonjs/lib/event.js +137 -0
  26. package/lib/commonjs/lib/event.js.map +1 -0
  27. package/lib/commonjs/lib/plugin.d.ts +28 -0
  28. package/lib/commonjs/lib/plugin.js +84 -0
  29. package/lib/commonjs/lib/plugin.js.map +1 -0
  30. package/lib/commonjs/lib/providers/HttpProvider.d.ts +15 -0
  31. package/lib/commonjs/lib/providers/HttpProvider.js +63 -0
  32. package/lib/commonjs/lib/providers/HttpProvider.js.map +1 -0
  33. package/lib/commonjs/lib/providers/index.d.ts +6 -0
  34. package/lib/commonjs/lib/providers/index.js +8 -0
  35. package/lib/commonjs/lib/providers/index.js.map +1 -0
  36. package/lib/commonjs/lib/trx.d.ts +315 -0
  37. package/lib/commonjs/lib/trx.js +965 -0
  38. package/lib/commonjs/lib/trx.js.map +1 -0
  39. package/lib/commonjs/package.json +1 -0
  40. package/lib/commonjs/paramValidator/index.d.ts +19 -0
  41. package/lib/commonjs/paramValidator/index.js +110 -0
  42. package/lib/commonjs/paramValidator/index.js.map +1 -0
  43. package/lib/commonjs/protocol/core/Tron_pb.cjs +7524 -0
  44. package/lib/commonjs/protocol/core/contract/account_contract_pb.cjs +961 -0
  45. package/lib/commonjs/protocol/core/contract/asset_issue_contract_pb.cjs +2196 -0
  46. package/lib/commonjs/protocol/core/contract/balance_contract_pb.cjs +3826 -0
  47. package/lib/commonjs/protocol/core/contract/common_pb.cjs +34 -0
  48. package/lib/commonjs/protocol/core/contract/exchange_contract_pb.cjs +1268 -0
  49. package/lib/commonjs/protocol/core/contract/proposal_contract_pb.cjs +675 -0
  50. package/lib/commonjs/protocol/core/contract/smart_contract_pb.cjs +2960 -0
  51. package/lib/commonjs/protocol/core/contract/storage_contract_pb.cjs +848 -0
  52. package/lib/commonjs/protocol/core/contract/vote_asset_contract_pb.cjs +340 -0
  53. package/lib/commonjs/protocol/core/contract/witness_contract_pb.cjs +956 -0
  54. package/lib/commonjs/tronweb.d.ts +111 -0
  55. package/lib/commonjs/tronweb.js +365 -0
  56. package/lib/commonjs/tronweb.js.map +1 -0
  57. package/lib/commonjs/types/ABI.d.ts +59 -0
  58. package/lib/commonjs/types/ABI.js +3 -0
  59. package/lib/commonjs/types/ABI.js.map +1 -0
  60. package/lib/commonjs/types/APIResponse.d.ts +31 -0
  61. package/lib/commonjs/types/APIResponse.js +3 -0
  62. package/lib/commonjs/types/APIResponse.js.map +1 -0
  63. package/lib/commonjs/types/Contract.d.ts +287 -0
  64. package/lib/commonjs/types/Contract.js +63 -0
  65. package/lib/commonjs/types/Contract.js.map +1 -0
  66. package/lib/commonjs/types/Providers.d.ts +8 -0
  67. package/lib/commonjs/types/Providers.js +3 -0
  68. package/lib/commonjs/types/Providers.js.map +1 -0
  69. package/lib/commonjs/types/Transaction.d.ts +65 -0
  70. package/lib/commonjs/types/Transaction.js +3 -0
  71. package/lib/commonjs/types/Transaction.js.map +1 -0
  72. package/lib/commonjs/types/TransactionBuilder.d.ts +270 -0
  73. package/lib/commonjs/types/TransactionBuilder.js +3 -0
  74. package/lib/commonjs/types/TransactionBuilder.js.map +1 -0
  75. package/lib/commonjs/types/TronWeb.d.ts +20 -0
  76. package/lib/commonjs/types/TronWeb.js +3 -0
  77. package/lib/commonjs/types/TronWeb.js.map +1 -0
  78. package/lib/commonjs/types/Trx.d.ts +263 -0
  79. package/lib/commonjs/types/Trx.js +42 -0
  80. package/lib/commonjs/types/Trx.js.map +1 -0
  81. package/lib/commonjs/types/UtilsTypes.d.ts +23 -0
  82. package/lib/commonjs/types/UtilsTypes.js +3 -0
  83. package/lib/commonjs/types/UtilsTypes.js.map +1 -0
  84. package/lib/commonjs/types/index.d.ts +9 -0
  85. package/lib/commonjs/types/index.js +13 -0
  86. package/lib/commonjs/types/index.js.map +1 -0
  87. package/lib/commonjs/utils/abi.d.ts +5 -0
  88. package/lib/commonjs/utils/abi.js +251 -0
  89. package/lib/commonjs/utils/abi.js.map +1 -0
  90. package/lib/commonjs/utils/accounts.d.ts +22 -0
  91. package/lib/commonjs/utils/accounts.js +51 -0
  92. package/lib/commonjs/utils/accounts.js.map +1 -0
  93. package/lib/commonjs/utils/address.d.ts +12 -0
  94. package/lib/commonjs/utils/address.js +91 -0
  95. package/lib/commonjs/utils/address.js.map +1 -0
  96. package/lib/commonjs/utils/base58.d.ts +3 -0
  97. package/lib/commonjs/utils/base58.js +68 -0
  98. package/lib/commonjs/utils/base58.js.map +1 -0
  99. package/lib/commonjs/utils/base64.d.ts +10 -0
  100. package/lib/commonjs/utils/base64.js +173 -0
  101. package/lib/commonjs/utils/base64.js.map +1 -0
  102. package/lib/commonjs/utils/bytes.d.ts +7 -0
  103. package/lib/commonjs/utils/bytes.js +61 -0
  104. package/lib/commonjs/utils/bytes.js.map +1 -0
  105. package/lib/commonjs/utils/code.d.ts +12 -0
  106. package/lib/commonjs/utils/code.js +166 -0
  107. package/lib/commonjs/utils/code.js.map +1 -0
  108. package/lib/commonjs/utils/crypto.d.ts +25 -0
  109. package/lib/commonjs/utils/crypto.js +222 -0
  110. package/lib/commonjs/utils/crypto.js.map +1 -0
  111. package/lib/commonjs/utils/ethersUtils.d.ts +14 -0
  112. package/lib/commonjs/utils/ethersUtils.js +39 -0
  113. package/lib/commonjs/utils/ethersUtils.js.map +1 -0
  114. package/lib/commonjs/utils/fragments.d.ts +465 -0
  115. package/lib/commonjs/utils/fragments.js +1342 -0
  116. package/lib/commonjs/utils/fragments.js.map +1 -0
  117. package/lib/commonjs/utils/help.d.ts +8 -0
  118. package/lib/commonjs/utils/help.js +61 -0
  119. package/lib/commonjs/utils/help.js.map +1 -0
  120. package/lib/commonjs/utils/index.d.ts +56 -0
  121. package/lib/commonjs/utils/index.js +43 -0
  122. package/lib/commonjs/utils/index.js.map +1 -0
  123. package/lib/commonjs/utils/interface.d.ts +381 -0
  124. package/lib/commonjs/utils/interface.js +1121 -0
  125. package/lib/commonjs/utils/interface.js.map +1 -0
  126. package/lib/commonjs/utils/message.d.ts +4 -0
  127. package/lib/commonjs/utils/message.js +38 -0
  128. package/lib/commonjs/utils/message.js.map +1 -0
  129. package/lib/commonjs/utils/transaction.d.ts +17 -0
  130. package/lib/commonjs/utils/transaction.js +678 -0
  131. package/lib/commonjs/utils/transaction.js.map +1 -0
  132. package/lib/commonjs/utils/typedData.d.ts +148 -0
  133. package/lib/commonjs/utils/typedData.js +498 -0
  134. package/lib/commonjs/utils/typedData.js.map +1 -0
  135. package/lib/commonjs/utils/validations.d.ts +22 -0
  136. package/lib/commonjs/utils/validations.js +128 -0
  137. package/lib/commonjs/utils/validations.js.map +1 -0
  138. package/lib/esm/index.d.ts +64 -0
  139. package/lib/esm/index.js +33 -0
  140. package/lib/esm/index.js.map +1 -0
  141. package/lib/esm/lib/TransactionBuilder/TransactionBuilder.d.ts +127 -0
  142. package/lib/esm/lib/TransactionBuilder/TransactionBuilder.js +1767 -0
  143. package/lib/esm/lib/TransactionBuilder/TransactionBuilder.js.map +1 -0
  144. package/lib/esm/lib/TransactionBuilder/helper.d.ts +28 -0
  145. package/lib/esm/lib/TransactionBuilder/helper.js +112 -0
  146. package/lib/esm/lib/TransactionBuilder/helper.js.map +1 -0
  147. package/lib/esm/lib/contract/index.d.ts +29 -0
  148. package/lib/esm/lib/contract/index.js +118 -0
  149. package/lib/esm/lib/contract/index.js.map +1 -0
  150. package/lib/esm/lib/contract/method.d.ts +50 -0
  151. package/lib/esm/lib/contract/method.js +233 -0
  152. package/lib/esm/lib/contract/method.js.map +1 -0
  153. package/lib/esm/lib/event.d.ts +85 -0
  154. package/lib/esm/lib/event.js +132 -0
  155. package/lib/esm/lib/event.js.map +1 -0
  156. package/lib/esm/lib/plugin.d.ts +28 -0
  157. package/lib/esm/lib/plugin.js +79 -0
  158. package/lib/esm/lib/plugin.js.map +1 -0
  159. package/lib/esm/lib/providers/HttpProvider.d.ts +15 -0
  160. package/lib/esm/lib/providers/HttpProvider.js +59 -0
  161. package/lib/esm/lib/providers/HttpProvider.js.map +1 -0
  162. package/lib/esm/lib/providers/index.d.ts +6 -0
  163. package/lib/esm/lib/providers/index.js +4 -0
  164. package/lib/esm/lib/providers/index.js.map +1 -0
  165. package/lib/esm/lib/trx.d.ts +315 -0
  166. package/lib/esm/lib/trx.js +960 -0
  167. package/lib/esm/lib/trx.js.map +1 -0
  168. package/lib/esm/package.json +1 -0
  169. package/lib/esm/paramValidator/index.d.ts +19 -0
  170. package/lib/esm/paramValidator/index.js +106 -0
  171. package/lib/esm/paramValidator/index.js.map +1 -0
  172. package/lib/esm/protocol/core/Tron_pb.cjs +7524 -0
  173. package/lib/esm/protocol/core/contract/account_contract_pb.cjs +961 -0
  174. package/lib/esm/protocol/core/contract/asset_issue_contract_pb.cjs +2196 -0
  175. package/lib/esm/protocol/core/contract/balance_contract_pb.cjs +3826 -0
  176. package/lib/esm/protocol/core/contract/common_pb.cjs +34 -0
  177. package/lib/esm/protocol/core/contract/exchange_contract_pb.cjs +1268 -0
  178. package/lib/esm/protocol/core/contract/proposal_contract_pb.cjs +675 -0
  179. package/lib/esm/protocol/core/contract/smart_contract_pb.cjs +2960 -0
  180. package/lib/esm/protocol/core/contract/storage_contract_pb.cjs +848 -0
  181. package/lib/esm/protocol/core/contract/vote_asset_contract_pb.cjs +340 -0
  182. package/lib/esm/protocol/core/contract/witness_contract_pb.cjs +956 -0
  183. package/lib/esm/tronweb.d.ts +111 -0
  184. package/lib/esm/tronweb.js +360 -0
  185. package/lib/esm/tronweb.js.map +1 -0
  186. package/lib/esm/types/ABI.d.ts +59 -0
  187. package/lib/esm/types/ABI.js +2 -0
  188. package/lib/esm/types/ABI.js.map +1 -0
  189. package/lib/esm/types/APIResponse.d.ts +31 -0
  190. package/lib/esm/types/APIResponse.js +2 -0
  191. package/lib/esm/types/APIResponse.js.map +1 -0
  192. package/lib/esm/types/Contract.d.ts +287 -0
  193. package/lib/esm/types/Contract.js +60 -0
  194. package/lib/esm/types/Contract.js.map +1 -0
  195. package/lib/esm/types/Providers.d.ts +8 -0
  196. package/lib/esm/types/Providers.js +2 -0
  197. package/lib/esm/types/Providers.js.map +1 -0
  198. package/lib/esm/types/Transaction.d.ts +65 -0
  199. package/lib/esm/types/Transaction.js +2 -0
  200. package/lib/esm/types/Transaction.js.map +1 -0
  201. package/lib/esm/types/TransactionBuilder.d.ts +270 -0
  202. package/lib/esm/types/TransactionBuilder.js +2 -0
  203. package/lib/esm/types/TransactionBuilder.js.map +1 -0
  204. package/lib/esm/types/TronWeb.d.ts +20 -0
  205. package/lib/esm/types/TronWeb.js +2 -0
  206. package/lib/esm/types/TronWeb.js.map +1 -0
  207. package/lib/esm/types/Trx.d.ts +263 -0
  208. package/lib/esm/types/Trx.js +39 -0
  209. package/lib/esm/types/Trx.js.map +1 -0
  210. package/lib/esm/types/UtilsTypes.d.ts +23 -0
  211. package/lib/esm/types/UtilsTypes.js +2 -0
  212. package/lib/esm/types/UtilsTypes.js.map +1 -0
  213. package/lib/esm/types/index.d.ts +9 -0
  214. package/lib/esm/types/index.js +10 -0
  215. package/lib/esm/types/index.js.map +1 -0
  216. package/lib/esm/utils/abi.d.ts +5 -0
  217. package/lib/esm/utils/abi.js +245 -0
  218. package/lib/esm/utils/abi.js.map +1 -0
  219. package/lib/esm/utils/accounts.d.ts +22 -0
  220. package/lib/esm/utils/accounts.js +46 -0
  221. package/lib/esm/utils/accounts.js.map +1 -0
  222. package/lib/esm/utils/address.d.ts +12 -0
  223. package/lib/esm/utils/address.js +82 -0
  224. package/lib/esm/utils/address.js.map +1 -0
  225. package/lib/esm/utils/base58.d.ts +3 -0
  226. package/lib/esm/utils/base58.js +64 -0
  227. package/lib/esm/utils/base58.js.map +1 -0
  228. package/lib/esm/utils/base64.d.ts +10 -0
  229. package/lib/esm/utils/base64.js +169 -0
  230. package/lib/esm/utils/base64.js.map +1 -0
  231. package/lib/esm/utils/bytes.d.ts +7 -0
  232. package/lib/esm/utils/bytes.js +53 -0
  233. package/lib/esm/utils/bytes.js.map +1 -0
  234. package/lib/esm/utils/code.d.ts +12 -0
  235. package/lib/esm/utils/code.js +149 -0
  236. package/lib/esm/utils/code.js.map +1 -0
  237. package/lib/esm/utils/crypto.d.ts +25 -0
  238. package/lib/esm/utils/crypto.js +198 -0
  239. package/lib/esm/utils/crypto.js.map +1 -0
  240. package/lib/esm/utils/ethersUtils.d.ts +14 -0
  241. package/lib/esm/utils/ethersUtils.js +17 -0
  242. package/lib/esm/utils/ethersUtils.js.map +1 -0
  243. package/lib/esm/utils/fragments.d.ts +465 -0
  244. package/lib/esm/utils/fragments.js +1330 -0
  245. package/lib/esm/utils/fragments.js.map +1 -0
  246. package/lib/esm/utils/help.d.ts +8 -0
  247. package/lib/esm/utils/help.js +51 -0
  248. package/lib/esm/utils/help.js.map +1 -0
  249. package/lib/esm/utils/index.d.ts +56 -0
  250. package/lib/esm/utils/index.js +40 -0
  251. package/lib/esm/utils/index.js.map +1 -0
  252. package/lib/esm/utils/interface.d.ts +381 -0
  253. package/lib/esm/utils/interface.js +1112 -0
  254. package/lib/esm/utils/interface.js.map +1 -0
  255. package/lib/esm/utils/message.d.ts +4 -0
  256. package/lib/esm/utils/message.js +32 -0
  257. package/lib/esm/utils/message.js.map +1 -0
  258. package/lib/esm/utils/transaction.d.ts +17 -0
  259. package/lib/esm/utils/transaction.js +669 -0
  260. package/lib/esm/utils/transaction.js.map +1 -0
  261. package/lib/esm/utils/typedData.d.ts +148 -0
  262. package/lib/esm/utils/typedData.js +493 -0
  263. package/lib/esm/utils/typedData.js.map +1 -0
  264. package/lib/esm/utils/validations.d.ts +22 -0
  265. package/lib/esm/utils/validations.js +108 -0
  266. package/lib/esm/utils/validations.js.map +1 -0
  267. package/package.json +110 -0
  268. package/src/index.ts +42 -0
  269. package/src/lib/TransactionBuilder/TransactionBuilder.ts +2272 -0
  270. package/src/lib/TransactionBuilder/helper.ts +139 -0
  271. package/src/lib/contract/index.ts +151 -0
  272. package/src/lib/contract/method.ts +336 -0
  273. package/src/lib/event.ts +248 -0
  274. package/src/lib/plugin.ts +102 -0
  275. package/src/lib/providers/HttpProvider.ts +66 -0
  276. package/src/lib/providers/index.ts +6 -0
  277. package/src/lib/trx.ts +1463 -0
  278. package/src/paramValidator/index.ts +136 -0
  279. package/src/protocol/core/Tron_pb.cjs +7524 -0
  280. package/src/protocol/core/contract/account_contract_pb.cjs +961 -0
  281. package/src/protocol/core/contract/asset_issue_contract_pb.cjs +2196 -0
  282. package/src/protocol/core/contract/balance_contract_pb.cjs +3826 -0
  283. package/src/protocol/core/contract/common_pb.cjs +34 -0
  284. package/src/protocol/core/contract/exchange_contract_pb.cjs +1268 -0
  285. package/src/protocol/core/contract/proposal_contract_pb.cjs +675 -0
  286. package/src/protocol/core/contract/smart_contract_pb.cjs +2960 -0
  287. package/src/protocol/core/contract/storage_contract_pb.cjs +848 -0
  288. package/src/protocol/core/contract/vote_asset_contract_pb.cjs +340 -0
  289. package/src/protocol/core/contract/witness_contract_pb.cjs +956 -0
  290. package/src/tronweb.ts +437 -0
  291. package/src/types/ABI.ts +82 -0
  292. package/src/types/APIResponse.ts +34 -0
  293. package/src/types/Contract.ts +352 -0
  294. package/src/types/Providers.ts +7 -0
  295. package/src/types/Transaction.ts +70 -0
  296. package/src/types/TransactionBuilder.ts +281 -0
  297. package/src/types/TronWeb.ts +23 -0
  298. package/src/types/Trx.ts +285 -0
  299. package/src/types/UtilsTypes.ts +25 -0
  300. package/src/types/index.ts +9 -0
  301. package/src/types/interface.d.ts +1 -0
  302. package/src/utils/abi.ts +257 -0
  303. package/src/utils/accounts.ts +60 -0
  304. package/src/utils/address.ts +89 -0
  305. package/src/utils/base58.ts +78 -0
  306. package/src/utils/base64.ts +200 -0
  307. package/src/utils/bytes.ts +68 -0
  308. package/src/utils/code.ts +172 -0
  309. package/src/utils/crypto.ts +264 -0
  310. package/src/utils/ethersUtils.ts +60 -0
  311. package/src/utils/fragments.ts +1738 -0
  312. package/src/utils/help.ts +59 -0
  313. package/src/utils/index.ts +42 -0
  314. package/src/utils/interface.ts +1362 -0
  315. package/src/utils/message.ts +38 -0
  316. package/src/utils/transaction.ts +991 -0
  317. package/src/utils/typedData.ts +688 -0
  318. package/src/utils/validations.ts +130 -0
@@ -0,0 +1,1362 @@
1
+ /**
2
+ * The Interface class is a low-level class that accepts an
3
+ * ABI and provides all the necessary functionality to encode
4
+ * and decode paramaters to and results from methods, events
5
+ * and errors.
6
+ *
7
+ * It also provides several convenience methods to automatically
8
+ * search and find matching transactions and events to parse them.
9
+ *
10
+ * @_subsection api/abi:Interfaces [interfaces]
11
+ */
12
+
13
+ import { keccak256 } from 'ethers';
14
+ import { id } from 'ethers';
15
+ import {
16
+ concat,
17
+ dataSlice,
18
+ getBigInt,
19
+ getBytes,
20
+ getBytesCopy,
21
+ hexlify,
22
+ zeroPadValue,
23
+ isHexString,
24
+ defineProperties,
25
+ assertArgument,
26
+ toBeHex,
27
+ assert,
28
+ } from 'ethers';
29
+
30
+ import { AbiCoder } from 'ethers';
31
+ import { checkResultErrors, Result } from 'ethers';
32
+ import {
33
+ ConstructorFragment,
34
+ ErrorFragment,
35
+ EventFragment,
36
+ FallbackFragment,
37
+ Fragment,
38
+ FunctionFragment,
39
+ ParamType,
40
+ } from './fragments.js';
41
+ import { Typed } from 'ethers';
42
+
43
+ import type { BigNumberish, BytesLike, CallExceptionError, CallExceptionTransaction } from 'ethers';
44
+
45
+ import type { JsonFragment } from 'ethers';
46
+
47
+ export { checkResultErrors, Result };
48
+
49
+ /**
50
+ * When using the [[Interface-parseLog]] to automatically match a Log to its event
51
+ * for parsing, a **LogDescription** is returned.
52
+ */
53
+ export class LogDescription {
54
+ /**
55
+ * The matching fragment for the ``topic0``.
56
+ */
57
+ readonly fragment!: EventFragment;
58
+
59
+ /**
60
+ * The name of the Event.
61
+ */
62
+ readonly name!: string;
63
+
64
+ /**
65
+ * The full Event signature.
66
+ */
67
+ readonly signature!: string;
68
+
69
+ /**
70
+ * The topic hash for the Event.
71
+ */
72
+ readonly topic!: string;
73
+
74
+ /**
75
+ * The arguments passed into the Event with ``emit``.
76
+ */
77
+ readonly args!: Result;
78
+
79
+ /**
80
+ * @_ignore:
81
+ */
82
+ constructor(fragment: EventFragment, topic: string, args: Result) {
83
+ const name = fragment.name,
84
+ signature = fragment.format();
85
+ defineProperties<LogDescription>(this, {
86
+ fragment,
87
+ name,
88
+ signature,
89
+ topic,
90
+ args,
91
+ });
92
+ }
93
+ }
94
+
95
+ /**
96
+ * When using the [[Interface-parseTransaction]] to automatically match
97
+ * a transaction data to its function for parsing,
98
+ * a **TransactionDescription** is returned.
99
+ */
100
+ export class TransactionDescription {
101
+ /**
102
+ * The matching fragment from the transaction ``data``.
103
+ */
104
+ readonly fragment!: FunctionFragment;
105
+
106
+ /**
107
+ * The name of the Function from the transaction ``data``.
108
+ */
109
+ readonly name!: string;
110
+
111
+ /**
112
+ * The arguments passed to the Function from the transaction ``data``.
113
+ */
114
+ readonly args!: Result;
115
+
116
+ /**
117
+ * The full Function signature from the transaction ``data``.
118
+ */
119
+ readonly signature!: string;
120
+
121
+ /**
122
+ * The selector for the Function from the transaction ``data``.
123
+ */
124
+ readonly selector!: string;
125
+
126
+ /**
127
+ * The ``value`` (in wei) from the transaction.
128
+ */
129
+ readonly value!: bigint;
130
+
131
+ /**
132
+ * @_ignore:
133
+ */
134
+ constructor(fragment: FunctionFragment, selector: string, args: Result, value: bigint) {
135
+ const name = fragment.name,
136
+ signature = fragment.format();
137
+ defineProperties<TransactionDescription>(this, {
138
+ fragment,
139
+ name,
140
+ args,
141
+ signature,
142
+ selector,
143
+ value,
144
+ });
145
+ }
146
+ }
147
+
148
+ /**
149
+ * When using the [[Interface-parseError]] to automatically match an
150
+ * error for a call result for parsing, an **ErrorDescription** is returned.
151
+ */
152
+ export class ErrorDescription {
153
+ /**
154
+ * The matching fragment.
155
+ */
156
+ readonly fragment!: ErrorFragment;
157
+
158
+ /**
159
+ * The name of the Error.
160
+ */
161
+ readonly name!: string;
162
+
163
+ /**
164
+ * The arguments passed to the Error with ``revert``.
165
+ */
166
+ readonly args!: Result;
167
+
168
+ /**
169
+ * The full Error signature.
170
+ */
171
+ readonly signature!: string;
172
+
173
+ /**
174
+ * The selector for the Error.
175
+ */
176
+ readonly selector!: string;
177
+
178
+ /**
179
+ * @_ignore:
180
+ */
181
+ constructor(fragment: ErrorFragment, selector: string, args: Result) {
182
+ const name = fragment.name,
183
+ signature = fragment.format();
184
+ defineProperties<ErrorDescription>(this, {
185
+ fragment,
186
+ name,
187
+ args,
188
+ signature,
189
+ selector,
190
+ });
191
+ }
192
+ }
193
+
194
+ /**
195
+ * An **Indexed** is used as a value when a value that does not
196
+ * fit within a topic (i.e. not a fixed-length, 32-byte type). It
197
+ * is the ``keccak256`` of the value, and used for types such as
198
+ * arrays, tuples, bytes and strings.
199
+ */
200
+ export class Indexed {
201
+ /**
202
+ * The ``keccak256`` of the value logged.
203
+ */
204
+ readonly hash!: null | string;
205
+
206
+ /**
207
+ * @_ignore:
208
+ */
209
+ readonly _isIndexed!: boolean;
210
+
211
+ /**
212
+ * Returns ``true`` if %%value%% is an **Indexed**.
213
+ *
214
+ * This provides a Type Guard for property access.
215
+ */
216
+ static isIndexed(value: any): value is Indexed {
217
+ return !!(value && value._isIndexed);
218
+ }
219
+
220
+ /**
221
+ * @_ignore:
222
+ */
223
+ constructor(hash: null | string) {
224
+ defineProperties<Indexed>(this, { hash, _isIndexed: true });
225
+ }
226
+ }
227
+
228
+ type ErrorInfo = {
229
+ signature: string;
230
+ inputs: Array<string>;
231
+ name: string;
232
+ reason: (...args: Array<any>) => string;
233
+ };
234
+
235
+ // https://docs.soliditylang.org/en/v0.8.13/control-structures.html?highlight=panic#panic-via-assert-and-error-via-require
236
+ const PanicReasons: Record<string, string> = {
237
+ '0': 'generic panic',
238
+ '1': 'assert(false)',
239
+ '17': 'arithmetic overflow',
240
+ '18': 'division or modulo by zero',
241
+ '33': 'enum overflow',
242
+ '34': 'invalid encoded storage byte array accessed',
243
+ '49': 'out-of-bounds array access; popping on an empty array',
244
+ '50': 'out-of-bounds access of an array or bytesN',
245
+ '65': 'out of memory',
246
+ '81': 'uninitialized function',
247
+ };
248
+
249
+ const BuiltinErrors: Record<string, ErrorInfo> = {
250
+ '0x08c379a0': {
251
+ signature: 'Error(string)',
252
+ name: 'Error',
253
+ inputs: ['string'],
254
+ reason: (message: string) => {
255
+ return `reverted with reason string ${JSON.stringify(message)}`;
256
+ },
257
+ },
258
+ '0x4e487b71': {
259
+ signature: 'Panic(uint256)',
260
+ name: 'Panic',
261
+ inputs: ['uint256'],
262
+ reason: (code: bigint) => {
263
+ let reason = 'unknown panic code';
264
+ if (code >= 0 && code <= 0xff && PanicReasons[code.toString()]) {
265
+ reason = PanicReasons[code.toString()];
266
+ }
267
+ return `reverted with panic code 0x${code.toString(16)} (${reason})`;
268
+ },
269
+ },
270
+ };
271
+
272
+ /*
273
+ function wrapAccessError(property: string, error: Error): Error {
274
+ const wrap = new Error(`deferred error during ABI decoding triggered accessing ${ property }`);
275
+ (<any>wrap).error = error;
276
+ return wrap;
277
+ }
278
+ */
279
+ /*
280
+ function checkNames(fragment: Fragment, type: "input" | "output", params: Array<ParamType>): void {
281
+ params.reduce((accum, param) => {
282
+ if (param.name) {
283
+ if (accum[param.name]) {
284
+ logger.throwArgumentError(`duplicate ${ type } parameter ${ JSON.stringify(param.name) } in ${ fragment.format("full") }`, "fragment", fragment);
285
+ }
286
+ accum[param.name] = true;
287
+ }
288
+ return accum;
289
+ }, <{ [ name: string ]: boolean }>{ });
290
+ }
291
+ */
292
+
293
+ /**
294
+ * An **InterfaceAbi** may be any supported ABI format.
295
+ *
296
+ * A string is expected to be a JSON string, which will be parsed
297
+ * using ``JSON.parse``. This means that the value **must** be a valid
298
+ * JSON string, with no stray commas, etc.
299
+ *
300
+ * An array may contain any combination of:
301
+ * - Human-Readable fragments
302
+ * - Parsed JSON fragment
303
+ * - [[Fragment]] instances
304
+ *
305
+ * A **Human-Readable Fragment** is a string which resembles a Solidity
306
+ * signature and is introduced in [this blog entry](link-ricmoo-humanreadableabi).
307
+ * For example, ``function balanceOf(address) view returns (uint)``.
308
+ *
309
+ * A **Parsed JSON Fragment** is a JavaScript Object desribed in the
310
+ * [Solidity documentation](link-solc-jsonabi).
311
+ */
312
+ export type InterfaceAbi = string | ReadonlyArray<Fragment | JsonFragment | string>;
313
+
314
+ /**
315
+ * An Interface abstracts many of the low-level details for
316
+ * encoding and decoding the data on the blockchain.
317
+ *
318
+ * An ABI provides information on how to encode data to send to
319
+ * a Contract, how to decode the results and events and how to
320
+ * interpret revert errors.
321
+ *
322
+ * The ABI can be specified by [any supported format](InterfaceAbi).
323
+ */
324
+ export class Interface {
325
+ /**
326
+ * All the Contract ABI members (i.e. methods, events, errors, etc).
327
+ */
328
+ readonly fragments!: ReadonlyArray<Fragment>;
329
+
330
+ /**
331
+ * The Contract constructor.
332
+ */
333
+ readonly deploy!: ConstructorFragment;
334
+
335
+ /**
336
+ * The Fallback method, if any.
337
+ */
338
+ readonly fallback!: null | FallbackFragment;
339
+
340
+ /**
341
+ * If receiving ether is supported.
342
+ */
343
+ readonly receive!: boolean;
344
+
345
+ #errors: Map<string, ErrorFragment>;
346
+ #events: Map<string, EventFragment>;
347
+ #functions: Map<string, FunctionFragment>;
348
+ // #structs: Map<string, StructFragment>;
349
+
350
+ #abiCoder: AbiCoder;
351
+
352
+ /**
353
+ * Create a new Interface for the %%fragments%%.
354
+ */
355
+ constructor(fragments: InterfaceAbi) {
356
+ let abi: ReadonlyArray<Fragment | JsonFragment | string> = [];
357
+ if (typeof fragments === 'string') {
358
+ abi = JSON.parse(fragments);
359
+ } else {
360
+ abi = fragments;
361
+ }
362
+
363
+ this.#functions = new Map();
364
+ this.#errors = new Map();
365
+ this.#events = new Map();
366
+ // this.#structs = new Map();
367
+
368
+ const frags: Array<Fragment> = [];
369
+ for (const a of abi) {
370
+ try {
371
+ frags.push(Fragment.from(a));
372
+ } catch (error) {
373
+ console.log('EE', error);
374
+ }
375
+ }
376
+
377
+ defineProperties<Interface>(this, {
378
+ fragments: Object.freeze(frags),
379
+ });
380
+
381
+ let fallback: null | FallbackFragment = null;
382
+ let receive = false;
383
+
384
+ this.#abiCoder = this.getAbiCoder();
385
+
386
+ // Add all fragments by their signature
387
+ this.fragments.forEach((fragment, index) => {
388
+ let bucket: Map<string, Fragment>;
389
+ switch (fragment.type) {
390
+ case 'constructor':
391
+ if (this.deploy) {
392
+ console.log('duplicate definition - constructor');
393
+ return;
394
+ }
395
+ //checkNames(fragment, "input", fragment.inputs);
396
+ defineProperties<Interface>(this, {
397
+ deploy: <ConstructorFragment>fragment,
398
+ });
399
+ return;
400
+
401
+ case 'fallback':
402
+ if (fragment.inputs.length === 0) {
403
+ receive = true;
404
+ } else {
405
+ assertArgument(
406
+ !fallback || (<FallbackFragment>fragment).payable !== fallback.payable,
407
+ 'conflicting fallback fragments',
408
+ `fragments[${index}]`,
409
+ fragment
410
+ );
411
+ fallback = <FallbackFragment>fragment;
412
+ receive = fallback.payable;
413
+ }
414
+ return;
415
+
416
+ case 'function':
417
+ //checkNames(fragment, "input", fragment.inputs);
418
+ //checkNames(fragment, "output", (<FunctionFragment>fragment).outputs);
419
+ bucket = this.#functions;
420
+ break;
421
+
422
+ case 'event':
423
+ //checkNames(fragment, "input", fragment.inputs);
424
+ bucket = this.#events;
425
+ break;
426
+
427
+ case 'error':
428
+ bucket = this.#errors;
429
+ break;
430
+
431
+ default:
432
+ return;
433
+ }
434
+
435
+ // Two identical entries; ignore it
436
+ const signature = fragment.format();
437
+ if (bucket.has(signature)) {
438
+ return;
439
+ }
440
+
441
+ bucket.set(signature, fragment);
442
+ });
443
+
444
+ // If we do not have a constructor add a default
445
+ if (!this.deploy) {
446
+ defineProperties<Interface>(this, {
447
+ deploy: ConstructorFragment.from('constructor()'),
448
+ });
449
+ }
450
+
451
+ defineProperties<Interface>(this, { fallback, receive });
452
+ }
453
+
454
+ /**
455
+ * Returns the entire Human-Readable ABI, as an array of
456
+ * signatures, optionally as %%minimal%% strings, which
457
+ * removes parameter names and unneceesary spaces.
458
+ */
459
+ format(minimal?: boolean): Array<string> {
460
+ const format = minimal ? 'minimal' : 'full';
461
+ const abi = this.fragments.map((f) => f.format(format));
462
+ return abi;
463
+ }
464
+
465
+ /**
466
+ * Return the JSON-encoded ABI. This is the format Solidiy
467
+ * returns.
468
+ */
469
+ formatJson(): string {
470
+ const abi = this.fragments.map((f) => f.format('json'));
471
+
472
+ // We need to re-bundle the JSON fragments a bit
473
+ return JSON.stringify(abi.map((j) => JSON.parse(j)));
474
+ }
475
+
476
+ /**
477
+ * The ABI coder that will be used to encode and decode binary
478
+ * data.
479
+ */
480
+ getAbiCoder(): AbiCoder {
481
+ return AbiCoder.defaultAbiCoder();
482
+ }
483
+
484
+ // Find a function definition by any means necessary (unless it is ambiguous)
485
+ #getFunction(key: string, values: null | Array<any | Typed>, forceUnique: boolean): null | FunctionFragment {
486
+ // Selector
487
+ if (isHexString(key)) {
488
+ const selector = key.toLowerCase();
489
+ for (const fragment of this.#functions.values()) {
490
+ if (selector === fragment.selector) {
491
+ return fragment;
492
+ }
493
+ }
494
+ return null;
495
+ }
496
+
497
+ // It is a bare name, look up the function (will return null if ambiguous)
498
+ if (key.indexOf('(') === -1) {
499
+ const matching: Array<FunctionFragment> = [];
500
+ for (const [name, fragment] of this.#functions) {
501
+ if (name.split('(' /* fix:) */)[0] === key) {
502
+ matching.push(fragment);
503
+ }
504
+ }
505
+
506
+ if (values) {
507
+ const lastValue = values.length > 0 ? values[values.length - 1] : null;
508
+
509
+ let valueLength = values.length;
510
+ let allowOptions = true;
511
+ if (Typed.isTyped(lastValue) && lastValue.type === 'overrides') {
512
+ allowOptions = false;
513
+ valueLength--;
514
+ }
515
+
516
+ // Remove all matches that don't have a compatible length. The args
517
+ // may contain an overrides, so the match may have n or n - 1 parameters
518
+ for (let i = matching.length - 1; i >= 0; i--) {
519
+ const inputs = matching[i].inputs.length;
520
+ if (inputs !== valueLength && (!allowOptions || inputs !== valueLength - 1)) {
521
+ matching.splice(i, 1);
522
+ }
523
+ }
524
+
525
+ // Remove all matches that don't match the Typed signature
526
+ for (let i = matching.length - 1; i >= 0; i--) {
527
+ const inputs = matching[i].inputs;
528
+ for (let j = 0; j < values.length; j++) {
529
+ // Not a typed value
530
+ if (!Typed.isTyped(values[j])) {
531
+ continue;
532
+ }
533
+
534
+ // We are past the inputs
535
+ if (j >= inputs.length) {
536
+ if (values[j].type === 'overrides') {
537
+ continue;
538
+ }
539
+ matching.splice(i, 1);
540
+ break;
541
+ }
542
+
543
+ // Make sure the value type matches the input type
544
+ if (values[j].type !== inputs[j].baseType) {
545
+ matching.splice(i, 1);
546
+ break;
547
+ }
548
+ }
549
+ }
550
+ }
551
+
552
+ // We found a single matching signature with an overrides, but the
553
+ // last value is something that cannot possibly be an options
554
+ if (matching.length === 1 && values && values.length !== matching[0].inputs.length) {
555
+ const lastArg = values[values.length - 1];
556
+ if (lastArg == null || Array.isArray(lastArg) || typeof lastArg !== 'object') {
557
+ matching.splice(0, 1);
558
+ }
559
+ }
560
+
561
+ if (matching.length === 0) {
562
+ return null;
563
+ }
564
+
565
+ if (matching.length > 1 && forceUnique) {
566
+ const matchStr = matching.map((m) => JSON.stringify(m.format())).join(', ');
567
+ assertArgument(false, `ambiguous function description (i.e. matches ${matchStr})`, 'key', key);
568
+ }
569
+
570
+ return matching[0];
571
+ }
572
+
573
+ // Normalize the signature and lookup the function
574
+ const result = this.#functions.get(FunctionFragment.from(key).format());
575
+ if (result) {
576
+ return result;
577
+ }
578
+
579
+ return null;
580
+ }
581
+
582
+ /**
583
+ * Get the function name for %%key%%, which may be a function selector,
584
+ * function name or function signature that belongs to the ABI.
585
+ */
586
+ getFunctionName(key: string): string {
587
+ const fragment = this.#getFunction(key, null, false);
588
+ assertArgument(fragment, 'no matching function', 'key', key);
589
+ return fragment.name;
590
+ }
591
+
592
+ /**
593
+ * Returns true if %%key%% (a function selector, function name or
594
+ * function signature) is present in the ABI.
595
+ *
596
+ * In the case of a function name, the name may be ambiguous, so
597
+ * accessing the [[FunctionFragment]] may require refinement.
598
+ */
599
+ hasFunction(key: string): boolean {
600
+ return !!this.#getFunction(key, null, false);
601
+ }
602
+
603
+ /**
604
+ * Get the [[FunctionFragment]] for %%key%%, which may be a function
605
+ * selector, function name or function signature that belongs to the ABI.
606
+ *
607
+ * If %%values%% is provided, it will use the Typed API to handle
608
+ * ambiguous cases where multiple functions match by name.
609
+ *
610
+ * If the %%key%% and %%values%% do not refine to a single function in
611
+ * the ABI, this will throw.
612
+ */
613
+ getFunction(key: string, values?: Array<any | Typed>): null | FunctionFragment {
614
+ return this.#getFunction(key, values || null, true);
615
+ }
616
+
617
+ /**
618
+ * Iterate over all functions, calling %%callback%%, sorted by their name.
619
+ */
620
+ forEachFunction(callback: (func: FunctionFragment, index: number) => void): void {
621
+ const names = Array.from(this.#functions.keys());
622
+ names.sort((a, b) => a.localeCompare(b));
623
+ for (let i = 0; i < names.length; i++) {
624
+ const name = names[i];
625
+ callback(<FunctionFragment>this.#functions.get(name), i);
626
+ }
627
+ }
628
+
629
+ // Find an event definition by any means necessary (unless it is ambiguous)
630
+ #getEvent(key: string, values: null | Array<null | any | Typed>, forceUnique: boolean): null | EventFragment {
631
+ // EventTopic
632
+ if (isHexString(key)) {
633
+ const eventTopic = key.toLowerCase();
634
+ for (const fragment of this.#events.values()) {
635
+ if (eventTopic === fragment.topicHash) {
636
+ return fragment;
637
+ }
638
+ }
639
+ return null;
640
+ }
641
+
642
+ // It is a bare name, look up the function (will return null if ambiguous)
643
+ if (key.indexOf('(') === -1) {
644
+ const matching: EventFragment[] = [];
645
+ for (const [name, fragment] of this.#events) {
646
+ if (name.split('(' /* fix:) */)[0] === key) {
647
+ matching.push(fragment);
648
+ }
649
+ }
650
+
651
+ if (values) {
652
+ // Remove all matches that don't have a compatible length.
653
+ for (let i = matching.length - 1; i >= 0; i--) {
654
+ if (matching[i].inputs.length < values.length) {
655
+ matching.splice(i, 1);
656
+ }
657
+ }
658
+
659
+ // Remove all matches that don't match the Typed signature
660
+ for (let i = matching.length - 1; i >= 0; i--) {
661
+ const inputs = matching[i].inputs;
662
+ for (let j = 0; j < values.length; j++) {
663
+ // Not a typed value
664
+ if (!Typed.isTyped(values[j])) {
665
+ continue;
666
+ }
667
+
668
+ // Make sure the value type matches the input type
669
+ if (values[j].type !== inputs[j].baseType) {
670
+ matching.splice(i, 1);
671
+ break;
672
+ }
673
+ }
674
+ }
675
+ }
676
+
677
+ if (matching.length === 0) {
678
+ return null;
679
+ }
680
+
681
+ if (matching.length > 1 && forceUnique) {
682
+ const matchStr = matching.map((m) => JSON.stringify(m.format())).join(', ');
683
+ assertArgument(false, `ambiguous event description (i.e. matches ${matchStr})`, 'key', key);
684
+ }
685
+
686
+ return matching[0];
687
+ }
688
+
689
+ // Normalize the signature and lookup the function
690
+ const result = this.#events.get(EventFragment.from(key).format());
691
+ if (result) {
692
+ return result;
693
+ }
694
+
695
+ return null;
696
+ }
697
+
698
+ /**
699
+ * Get the event name for %%key%%, which may be a topic hash,
700
+ * event name or event signature that belongs to the ABI.
701
+ */
702
+ getEventName(key: string): string {
703
+ const fragment = this.#getEvent(key, null, false);
704
+ assertArgument(fragment, 'no matching event', 'key', key);
705
+
706
+ return fragment.name;
707
+ }
708
+
709
+ /**
710
+ * Returns true if %%key%% (an event topic hash, event name or
711
+ * event signature) is present in the ABI.
712
+ *
713
+ * In the case of an event name, the name may be ambiguous, so
714
+ * accessing the [[EventFragment]] may require refinement.
715
+ */
716
+ hasEvent(key: string): boolean {
717
+ return !!this.#getEvent(key, null, false);
718
+ }
719
+
720
+ /**
721
+ * Get the [[EventFragment]] for %%key%%, which may be a topic hash,
722
+ * event name or event signature that belongs to the ABI.
723
+ *
724
+ * If %%values%% is provided, it will use the Typed API to handle
725
+ * ambiguous cases where multiple events match by name.
726
+ *
727
+ * If the %%key%% and %%values%% do not refine to a single event in
728
+ * the ABI, this will throw.
729
+ */
730
+ getEvent(key: string, values?: Array<any | Typed>): null | EventFragment {
731
+ return this.#getEvent(key, values || null, true);
732
+ }
733
+
734
+ /**
735
+ * Iterate over all events, calling %%callback%%, sorted by their name.
736
+ */
737
+ forEachEvent(callback: (func: EventFragment, index: number) => void): void {
738
+ const names = Array.from(this.#events.keys());
739
+ names.sort((a, b) => a.localeCompare(b));
740
+ for (let i = 0; i < names.length; i++) {
741
+ const name = names[i];
742
+ callback(<EventFragment>this.#events.get(name), i);
743
+ }
744
+ }
745
+
746
+ /**
747
+ * Get the [[ErrorFragment]] for %%key%%, which may be an error
748
+ * selector, error name or error signature that belongs to the ABI.
749
+ *
750
+ * If %%values%% is provided, it will use the Typed API to handle
751
+ * ambiguous cases where multiple errors match by name.
752
+ *
753
+ * If the %%key%% and %%values%% do not refine to a single error in
754
+ * the ABI, this will throw.
755
+ */
756
+ getError(key: string, values?: Array<any | Typed>): null | ErrorFragment {
757
+ if (isHexString(key)) {
758
+ const selector = key.toLowerCase();
759
+
760
+ if (BuiltinErrors[selector]) {
761
+ return ErrorFragment.from(BuiltinErrors[selector].signature);
762
+ }
763
+
764
+ for (const fragment of this.#errors.values()) {
765
+ if (selector === fragment.selector) {
766
+ return fragment;
767
+ }
768
+ }
769
+
770
+ return null;
771
+ }
772
+
773
+ // It is a bare name, look up the function (will return null if ambiguous)
774
+ if (key.indexOf('(') === -1) {
775
+ const matching: ErrorFragment[] = [];
776
+ for (const [name, fragment] of this.#errors) {
777
+ if (name.split('(' /* fix:) */)[0] === key) {
778
+ matching.push(fragment);
779
+ }
780
+ }
781
+
782
+ if (matching.length === 0) {
783
+ if (key === 'Error') {
784
+ return ErrorFragment.from('error Error(string)');
785
+ }
786
+ if (key === 'Panic') {
787
+ return ErrorFragment.from('error Panic(uint256)');
788
+ }
789
+ return null;
790
+ } else if (matching.length > 1) {
791
+ const matchStr = matching.map((m) => JSON.stringify(m.format())).join(', ');
792
+ assertArgument(false, `ambiguous error description (i.e. ${matchStr})`, 'name', key);
793
+ }
794
+
795
+ return matching[0];
796
+ }
797
+
798
+ // Normalize the signature and lookup the function
799
+ key = ErrorFragment.from(key).format();
800
+ if (key === 'Error(string)') {
801
+ return ErrorFragment.from('error Error(string)');
802
+ }
803
+ if (key === 'Panic(uint256)') {
804
+ return ErrorFragment.from('error Panic(uint256)');
805
+ }
806
+
807
+ const result = this.#errors.get(key);
808
+ if (result) {
809
+ return result;
810
+ }
811
+
812
+ return null;
813
+ }
814
+
815
+ /**
816
+ * Iterate over all errors, calling %%callback%%, sorted by their name.
817
+ */
818
+ forEachError(callback: (func: ErrorFragment, index: number) => void): void {
819
+ const names = Array.from(this.#errors.keys());
820
+ names.sort((a, b) => a.localeCompare(b));
821
+ for (let i = 0; i < names.length; i++) {
822
+ const name = names[i];
823
+ callback(<ErrorFragment>this.#errors.get(name), i);
824
+ }
825
+ }
826
+
827
+ // Get the 4-byte selector used by Solidity to identify a function
828
+ /*
829
+ getSelector(fragment: ErrorFragment | FunctionFragment): string {
830
+ if (typeof(fragment) === "string") {
831
+ const matches: Array<Fragment> = [ ];
832
+
833
+ try { matches.push(this.getFunction(fragment)); } catch (error) { }
834
+ try { matches.push(this.getError(<string>fragment)); } catch (_) { }
835
+
836
+ if (matches.length === 0) {
837
+ logger.throwArgumentError("unknown fragment", "key", fragment);
838
+ } else if (matches.length > 1) {
839
+ logger.throwArgumentError("ambiguous fragment matches function and error", "key", fragment);
840
+ }
841
+
842
+ fragment = matches[0];
843
+ }
844
+
845
+ return dataSlice(id(fragment.format()), 0, 4);
846
+ }
847
+ */
848
+
849
+ // Get the 32-byte topic hash used by Solidity to identify an event
850
+ /*
851
+ getEventTopic(fragment: EventFragment): string {
852
+ //if (typeof(fragment) === "string") { fragment = this.getEvent(eventFragment); }
853
+ return id(fragment.format());
854
+ }
855
+ */
856
+
857
+ _decodeParams(params: ReadonlyArray<ParamType | string>, data: BytesLike): Result {
858
+ return this.#abiCoder.decode(params as any, data);
859
+ }
860
+
861
+ _encodeParams(params: ReadonlyArray<ParamType>, values: ReadonlyArray<any>): string {
862
+ return this.#abiCoder.encode(params as any, values);
863
+ }
864
+
865
+ /**
866
+ * Encodes a ``tx.data`` object for deploying the Contract with
867
+ * the %%values%% as the constructor arguments.
868
+ */
869
+ encodeDeploy(values?: ReadonlyArray<any>): string {
870
+ return this._encodeParams(this.deploy.inputs, values || []);
871
+ }
872
+
873
+ /**
874
+ * Decodes the result %%data%% (e.g. from an ``eth_call``) for the
875
+ * specified error (see [[getError]] for valid values for
876
+ * %%key%%).
877
+ *
878
+ * Most developers should prefer the [[parseCallResult]] method instead,
879
+ * which will automatically detect a ``CALL_EXCEPTION`` and throw the
880
+ * corresponding error.
881
+ */
882
+ decodeErrorResult(fragment: ErrorFragment | string, data: BytesLike): Result {
883
+ if (typeof fragment === 'string') {
884
+ const f = this.getError(fragment);
885
+ assertArgument(f, 'unknown error', 'fragment', fragment);
886
+ fragment = f;
887
+ }
888
+
889
+ assertArgument(
890
+ dataSlice(data, 0, 4) === fragment.selector,
891
+ `data signature does not match error ${fragment.name}.`,
892
+ 'data',
893
+ data
894
+ );
895
+
896
+ return this._decodeParams(fragment.inputs, dataSlice(data, 4));
897
+ }
898
+
899
+ /**
900
+ * Encodes the transaction revert data for a call result that
901
+ * reverted from the the Contract with the sepcified %%error%%
902
+ * (see [[getError]] for valid values for %%fragment%%) with the %%values%%.
903
+ *
904
+ * This is generally not used by most developers, unless trying to mock
905
+ * a result from a Contract.
906
+ */
907
+ encodeErrorResult(fragment: ErrorFragment | string, values?: ReadonlyArray<any>): string {
908
+ if (typeof fragment === 'string') {
909
+ const f = this.getError(fragment);
910
+ assertArgument(f, 'unknown error', 'fragment', fragment);
911
+ fragment = f;
912
+ }
913
+
914
+ return concat([fragment.selector, this._encodeParams(fragment.inputs, values || [])]);
915
+ }
916
+
917
+ /**
918
+ * Decodes the %%data%% from a transaction ``tx.data`` for
919
+ * the function specified (see [[getFunction]] for valid values
920
+ * for %%fragment%%).
921
+ *
922
+ * Most developers should prefer the [[parseTransaction]] method
923
+ * instead, which will automatically detect the fragment.
924
+ */
925
+ decodeFunctionData(fragment: FunctionFragment | string, data: BytesLike): Result {
926
+ if (typeof fragment === 'string') {
927
+ const f = this.getFunction(fragment);
928
+ assertArgument(f, 'unknown function', 'fragment', fragment);
929
+ fragment = f;
930
+ }
931
+
932
+ assertArgument(
933
+ dataSlice(data, 0, 4) === fragment.selector,
934
+ `data signature does not match function ${fragment.name}.`,
935
+ 'data',
936
+ data
937
+ );
938
+
939
+ return this._decodeParams(fragment.inputs, dataSlice(data, 4));
940
+ }
941
+
942
+ /**
943
+ * Encodes the ``tx.data`` for a transaction that calls the function
944
+ * specified (see [[getFunction]] for valid values for %%fragment%%) with
945
+ * the %%values%%.
946
+ */
947
+ encodeFunctionData(fragment: FunctionFragment | string, values?: ReadonlyArray<any>): string {
948
+ if (typeof fragment === 'string') {
949
+ const f = this.getFunction(fragment);
950
+ assertArgument(f, 'unknown function', 'fragment', fragment);
951
+ fragment = f;
952
+ }
953
+
954
+ return concat([fragment.selector, this._encodeParams(fragment.inputs, values || [])]);
955
+ }
956
+
957
+ /**
958
+ * Decodes the result %%data%% (e.g. from an ``eth_call``) for the
959
+ * specified function (see [[getFunction]] for valid values for
960
+ * %%key%%).
961
+ *
962
+ * Most developers should prefer the [[parseCallResult]] method instead,
963
+ * which will automatically detect a ``CALL_EXCEPTION`` and throw the
964
+ * corresponding error.
965
+ */
966
+ decodeFunctionResult(fragment: FunctionFragment | string, data: BytesLike): Result {
967
+ if (typeof fragment === 'string') {
968
+ const f = this.getFunction(fragment);
969
+ assertArgument(f, 'unknown function', 'fragment', fragment);
970
+ fragment = f;
971
+ }
972
+
973
+ let message = 'invalid length for result data';
974
+
975
+ const bytes = getBytesCopy(data);
976
+ if (bytes.length % 32 === 0) {
977
+ try {
978
+ return this.#abiCoder.decode(fragment.outputs as any, bytes);
979
+ } catch (error) {
980
+ message = 'could not decode result data';
981
+ }
982
+ }
983
+
984
+ // Call returned data with no error, but the data is junk
985
+ assert(false, message, 'BAD_DATA', {
986
+ value: hexlify(bytes),
987
+ info: { method: fragment.name, signature: fragment.format() },
988
+ });
989
+ }
990
+
991
+ makeError(_data: BytesLike, tx: CallExceptionTransaction): CallExceptionError {
992
+ const data = getBytes(_data, 'data');
993
+
994
+ const error = AbiCoder.getBuiltinCallException('call', tx, data);
995
+
996
+ // Not a built-in error; try finding a custom error
997
+ const customPrefix = 'execution reverted (unknown custom error)';
998
+ if (error.message.startsWith(customPrefix)) {
999
+ const selector = hexlify(data.slice(0, 4));
1000
+
1001
+ const ef = this.getError(selector);
1002
+ if (ef) {
1003
+ try {
1004
+ const args = this.#abiCoder.decode(ef.inputs as any, data.slice(4));
1005
+ error.revert = {
1006
+ name: ef.name,
1007
+ signature: ef.format(),
1008
+ args,
1009
+ };
1010
+ error.reason = error.revert.signature;
1011
+ error.message = `execution reverted: ${error.reason}`;
1012
+ } catch (e) {
1013
+ error.message = `execution reverted (coult not decode custom error)`;
1014
+ }
1015
+ }
1016
+ }
1017
+
1018
+ // Add the invocation, if available
1019
+ const parsed = this.parseTransaction(tx);
1020
+ if (parsed) {
1021
+ error.invocation = {
1022
+ method: parsed.name,
1023
+ signature: parsed.signature,
1024
+ args: parsed.args,
1025
+ };
1026
+ }
1027
+
1028
+ return error;
1029
+ }
1030
+
1031
+ /**
1032
+ * Encodes the result data (e.g. from an ``eth_call``) for the
1033
+ * specified function (see [[getFunction]] for valid values
1034
+ * for %%fragment%%) with %%values%%.
1035
+ *
1036
+ * This is generally not used by most developers, unless trying to mock
1037
+ * a result from a Contract.
1038
+ */
1039
+ encodeFunctionResult(fragment: FunctionFragment | string, values?: ReadonlyArray<any>): string {
1040
+ if (typeof fragment === 'string') {
1041
+ const f = this.getFunction(fragment);
1042
+ assertArgument(f, 'unknown function', 'fragment', fragment);
1043
+ fragment = f;
1044
+ }
1045
+ return hexlify(this.#abiCoder.encode(fragment.outputs as any, values || []));
1046
+ }
1047
+ /*
1048
+ spelunk(inputs: Array<ParamType>, values: ReadonlyArray<any>, processfunc: (type: string, value: any) => Promise<any>): Promise<Array<any>> {
1049
+ const promises: Array<Promise<>> = [ ];
1050
+ const process = function(type: ParamType, value: any): any {
1051
+ if (type.baseType === "array") {
1052
+ return descend(type.child
1053
+ }
1054
+ if (type. === "address") {
1055
+ }
1056
+ };
1057
+
1058
+ const descend = function (inputs: Array<ParamType>, values: ReadonlyArray<any>) {
1059
+ if (inputs.length !== values.length) { throw new Error("length mismatch"); }
1060
+
1061
+ };
1062
+
1063
+ const result: Array<any> = [ ];
1064
+ values.forEach((value, index) => {
1065
+ if (value == null) {
1066
+ topics.push(null);
1067
+ } else if (param.baseType === "array" || param.baseType === "tuple") {
1068
+ logger.throwArgumentError("filtering with tuples or arrays not supported", ("contract." + param.name), value);
1069
+ } else if (Array.isArray(value)) {
1070
+ topics.push(value.map((value) => encodeTopic(param, value)));
1071
+ } else {
1072
+ topics.push(encodeTopic(param, value));
1073
+ }
1074
+ });
1075
+ }
1076
+ */
1077
+ // Create the filter for the event with search criteria (e.g. for eth_filterLog)
1078
+ encodeFilterTopics(fragment: EventFragment | string, values: ReadonlyArray<any>): Array<null | string | Array<string>> {
1079
+ if (typeof fragment === 'string') {
1080
+ const f = this.getEvent(fragment);
1081
+ assertArgument(f, 'unknown event', 'eventFragment', fragment);
1082
+ fragment = f;
1083
+ }
1084
+
1085
+ assert(values.length <= fragment.inputs.length, `too many arguments for ${fragment.format()}`, 'UNEXPECTED_ARGUMENT', {
1086
+ count: values.length,
1087
+ expectedCount: fragment.inputs.length,
1088
+ });
1089
+
1090
+ const topics: Array<null | string | Array<string>> = [];
1091
+ if (!fragment.anonymous) {
1092
+ topics.push(fragment.topicHash);
1093
+ }
1094
+
1095
+ // @TODO: Use the coders for this; to properly support tuples, etc.
1096
+ const encodeTopic = (param: ParamType, value: any): string => {
1097
+ if (param.type === 'string') {
1098
+ return id(value);
1099
+ } else if (param.type === 'bytes') {
1100
+ return keccak256(hexlify(value));
1101
+ }
1102
+
1103
+ if (param.type === 'bool' && typeof value === 'boolean') {
1104
+ value = value ? '0x01' : '0x00';
1105
+ }
1106
+
1107
+ if (param.type.match(/^u?int/)) {
1108
+ value = toBeHex(value);
1109
+ }
1110
+
1111
+ // Check addresses are valid
1112
+ if (param.type === 'address') {
1113
+ this.#abiCoder.encode(['address'], [value]);
1114
+ }
1115
+ return zeroPadValue(hexlify(value), 32);
1116
+ //@TOOD should probably be return toHex(value, 32)
1117
+ };
1118
+
1119
+ values.forEach((value, index) => {
1120
+ const param = (<EventFragment>fragment).inputs[index];
1121
+
1122
+ if (!param.indexed) {
1123
+ assertArgument(
1124
+ value == null,
1125
+ 'cannot filter non-indexed parameters; must be null',
1126
+ 'contract.' + param.name,
1127
+ value
1128
+ );
1129
+ return;
1130
+ }
1131
+
1132
+ if (value == null) {
1133
+ topics.push(null);
1134
+ } else if (param.baseType === 'array' || param.baseType === 'tuple') {
1135
+ assertArgument(false, 'filtering with tuples or arrays not supported', 'contract.' + param.name, value);
1136
+ } else if (Array.isArray(value)) {
1137
+ topics.push(value.map((value) => encodeTopic(param, value)));
1138
+ } else {
1139
+ topics.push(encodeTopic(param, value));
1140
+ }
1141
+ });
1142
+
1143
+ // Trim off trailing nulls
1144
+ while (topics.length && topics[topics.length - 1] === null) {
1145
+ topics.pop();
1146
+ }
1147
+
1148
+ return topics;
1149
+ }
1150
+
1151
+ encodeEventLog(fragment: EventFragment | string, values: ReadonlyArray<any>): { data: string; topics: Array<string> } {
1152
+ if (typeof fragment === 'string') {
1153
+ const f = this.getEvent(fragment);
1154
+ assertArgument(f, 'unknown event', 'eventFragment', fragment);
1155
+ fragment = f;
1156
+ }
1157
+
1158
+ const topics: Array<string> = [];
1159
+
1160
+ const dataTypes: Array<ParamType> = [];
1161
+ const dataValues: Array<string> = [];
1162
+
1163
+ if (!fragment.anonymous) {
1164
+ topics.push(fragment.topicHash);
1165
+ }
1166
+
1167
+ assertArgument(values.length === fragment.inputs.length, 'event arguments/values mismatch', 'values', values);
1168
+
1169
+ fragment.inputs.forEach((param, index) => {
1170
+ const value = values[index];
1171
+ if (param.indexed) {
1172
+ if (param.type === 'string') {
1173
+ topics.push(id(value));
1174
+ } else if (param.type === 'bytes') {
1175
+ topics.push(keccak256(value));
1176
+ } else if (param.baseType === 'tuple' || param.baseType === 'array') {
1177
+ // @TODO
1178
+ throw new Error('not implemented');
1179
+ } else {
1180
+ topics.push(this.#abiCoder.encode([param.type], [value]));
1181
+ }
1182
+ } else {
1183
+ dataTypes.push(param);
1184
+ dataValues.push(value);
1185
+ }
1186
+ });
1187
+
1188
+ return {
1189
+ data: this.#abiCoder.encode(dataTypes as any, dataValues),
1190
+ topics: topics,
1191
+ };
1192
+ }
1193
+
1194
+ // Decode a filter for the event and the search criteria
1195
+ decodeEventLog(fragment: EventFragment | string, data: BytesLike, topics?: ReadonlyArray<string>): Result {
1196
+ if (typeof fragment === 'string') {
1197
+ const f = this.getEvent(fragment);
1198
+ assertArgument(f, 'unknown event', 'eventFragment', fragment);
1199
+ fragment = f;
1200
+ }
1201
+
1202
+ if (topics != null && !fragment.anonymous) {
1203
+ const eventTopic = fragment.topicHash;
1204
+ assertArgument(
1205
+ isHexString(topics[0], 32) && topics[0].toLowerCase() === eventTopic,
1206
+ 'fragment/topic mismatch',
1207
+ 'topics[0]',
1208
+ topics[0]
1209
+ );
1210
+ topics = topics.slice(1);
1211
+ }
1212
+
1213
+ const indexed: Array<ParamType> = [];
1214
+ const nonIndexed: Array<ParamType> = [];
1215
+ const dynamic: Array<boolean> = [];
1216
+
1217
+ fragment.inputs.forEach((param, index) => {
1218
+ if (param.indexed) {
1219
+ if (
1220
+ param.type === 'string' ||
1221
+ param.type === 'bytes' ||
1222
+ param.baseType === 'tuple' ||
1223
+ param.baseType === 'array'
1224
+ ) {
1225
+ indexed.push(ParamType.from({ type: 'bytes32', name: param.name }));
1226
+ dynamic.push(true);
1227
+ } else {
1228
+ indexed.push(param);
1229
+ dynamic.push(false);
1230
+ }
1231
+ } else {
1232
+ nonIndexed.push(param);
1233
+ dynamic.push(false);
1234
+ }
1235
+ });
1236
+
1237
+ const resultIndexed = topics != null ? this.#abiCoder.decode(indexed as any, concat(topics)) : null;
1238
+ const resultNonIndexed = this.#abiCoder.decode(nonIndexed as any, data, true);
1239
+
1240
+ //const result: (Array<any> & { [ key: string ]: any }) = [ ];
1241
+ const values: Array<any> = [];
1242
+ const keys: Array<null | string> = [];
1243
+ let nonIndexedIndex = 0,
1244
+ indexedIndex = 0;
1245
+ fragment.inputs.forEach((param, index) => {
1246
+ let value: Indexed | null | unknown = null;
1247
+ if (param.indexed) {
1248
+ if (resultIndexed == null) {
1249
+ value = new Indexed(null);
1250
+ } else if (dynamic[index]) {
1251
+ value = new Indexed(resultIndexed[indexedIndex++]);
1252
+ } else {
1253
+ try {
1254
+ value = resultIndexed[indexedIndex++];
1255
+ } catch (error) {
1256
+ value = error;
1257
+ }
1258
+ }
1259
+ } else {
1260
+ try {
1261
+ value = resultNonIndexed[nonIndexedIndex++];
1262
+ } catch (error) {
1263
+ value = error;
1264
+ }
1265
+ }
1266
+
1267
+ values.push(value);
1268
+ keys.push(param.name || null);
1269
+ });
1270
+
1271
+ return Result.fromItems(values, keys);
1272
+ }
1273
+
1274
+ /**
1275
+ * Parses a transaction, finding the matching function and extracts
1276
+ * the parameter values along with other useful function details.
1277
+ *
1278
+ * If the matching function cannot be found, return null.
1279
+ */
1280
+ parseTransaction(tx: { data: string; value?: BigNumberish }): null | TransactionDescription {
1281
+ const data = getBytes(tx.data, 'tx.data');
1282
+ const value = getBigInt(tx.value != null ? tx.value : 0, 'tx.value');
1283
+
1284
+ const fragment = this.getFunction(hexlify(data.slice(0, 4)));
1285
+
1286
+ if (!fragment) {
1287
+ return null;
1288
+ }
1289
+
1290
+ const args = this.#abiCoder.decode(fragment.inputs as any, data.slice(4));
1291
+ return new TransactionDescription(fragment, fragment.selector, args, value);
1292
+ }
1293
+
1294
+ parseCallResult(data: BytesLike): Result {
1295
+ throw new Error('@TODO');
1296
+ }
1297
+
1298
+ /**
1299
+ * Parses a receipt log, finding the matching event and extracts
1300
+ * the parameter values along with other useful event details.
1301
+ *
1302
+ * If the matching event cannot be found, returns null.
1303
+ */
1304
+ parseLog(log: { topics: Array<string>; data: string }): null | LogDescription {
1305
+ const fragment = this.getEvent(log.topics[0]);
1306
+
1307
+ if (!fragment || fragment.anonymous) {
1308
+ return null;
1309
+ }
1310
+
1311
+ // @TODO: If anonymous, and the only method, and the input count matches, should we parse?
1312
+ // Probably not, because just because it is the only event in the ABI does
1313
+ // not mean we have the full ABI; maybe just a fragment?
1314
+
1315
+ return new LogDescription(fragment, fragment.topicHash, this.decodeEventLog(fragment, log.data, log.topics));
1316
+ }
1317
+
1318
+ /**
1319
+ * Parses a revert data, finding the matching error and extracts
1320
+ * the parameter values along with other useful error details.
1321
+ *
1322
+ * If the matching event cannot be found, returns null.
1323
+ */
1324
+ parseError(data: BytesLike): null | ErrorDescription {
1325
+ const hexData = hexlify(data);
1326
+
1327
+ const fragment = this.getError(dataSlice(hexData, 0, 4));
1328
+
1329
+ if (!fragment) {
1330
+ return null;
1331
+ }
1332
+
1333
+ const args = this.#abiCoder.decode(fragment.inputs as any, dataSlice(hexData, 4));
1334
+ return new ErrorDescription(fragment, fragment.selector, args);
1335
+ }
1336
+
1337
+ /**
1338
+ * Creates a new [[Interface]] from the ABI %%value%%.
1339
+ *
1340
+ * The %%value%% may be provided as an existing [[Interface]] object,
1341
+ * a JSON-encoded ABI or any Human-Readable ABI format.
1342
+ */
1343
+ static from(value: InterfaceAbi | Interface): Interface {
1344
+ // Already an Interface, which is immutable
1345
+ if (value instanceof Interface) {
1346
+ return value;
1347
+ }
1348
+
1349
+ // JSON
1350
+ if (typeof value === 'string') {
1351
+ return new Interface(JSON.parse(value));
1352
+ }
1353
+
1354
+ // Maybe an interface from an older version, or from a symlinked copy
1355
+ if (typeof (<any>value).format === 'function') {
1356
+ return new Interface((<any>value).format('json'));
1357
+ }
1358
+
1359
+ // Array of fragments
1360
+ return new Interface(value);
1361
+ }
1362
+ }