@caict/bop-typescript-sdk 1.0.2 → 1.0.3

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 (256) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/base.tsconfig.json +14 -0
  3. package/dist/bop/bop-base/base.d.ts +24 -0
  4. package/dist/bop/bop-base/base.js +253 -0
  5. package/dist/bop/bop-base/base.js.map +1 -0
  6. package/dist/bop/bop-base/index.d.ts +18 -0
  7. package/dist/bop/bop-base/index.js +69 -0
  8. package/dist/bop/bop-base/index.js.map +1 -0
  9. package/dist/bop/bop-base/permit.d.ts +11 -0
  10. package/dist/bop/bop-base/permit.js +104 -0
  11. package/dist/bop/bop-base/permit.js.map +1 -0
  12. package/dist/bop/bop-base/test/base.test.d.ts +1 -0
  13. package/dist/bop/bop-base/test/base.test.js +772 -0
  14. package/dist/bop/bop-base/test/base.test.js.map +1 -0
  15. package/dist/bop/bop-base/test/index.test.d.ts +1 -0
  16. package/dist/bop/bop-base/test/index.test.js +89 -0
  17. package/dist/bop/bop-base/test/index.test.js.map +1 -0
  18. package/dist/bop/bop-base/test/permit.test.d.ts +1 -0
  19. package/dist/bop/bop-base/test/permit.test.js +140 -0
  20. package/dist/bop/bop-base/test/permit.test.js.map +1 -0
  21. package/dist/bop/bop-proto/bop-ws.d.ts +325 -0
  22. package/dist/bop/bop-proto/bop-ws.js +3599 -0
  23. package/dist/bop/bop-proto/bop-ws.js.map +1 -0
  24. package/dist/bop/bop-proto/bop.d.ts +903 -0
  25. package/dist/bop/bop-proto/bop.js +10421 -0
  26. package/dist/bop/bop-proto/bop.js.map +1 -0
  27. package/dist/bop/bop-ws/index.d.ts +43 -0
  28. package/dist/bop/bop-ws/index.js +265 -0
  29. package/dist/bop/bop-ws/index.js.map +1 -0
  30. package/dist/bop/bop-ws/sample/sample.d.ts +1 -0
  31. package/dist/bop/bop-ws/sample/sample.js +96 -0
  32. package/dist/bop/bop-ws/sample/sample.js.map +1 -0
  33. package/dist/bop/index.d.ts +5 -0
  34. package/dist/bop/index.js +37 -0
  35. package/dist/bop/index.js.map +1 -0
  36. package/dist/bop-sdk/index.d.ts +13 -0
  37. package/dist/bop-sdk/index.js +45 -0
  38. package/dist/bop-sdk/index.js.map +1 -0
  39. package/dist/bop-sdk/interface/abstract-service/abstract-account.d.ts +8 -0
  40. package/dist/bop-sdk/interface/abstract-service/abstract-account.js +7 -0
  41. package/dist/bop-sdk/interface/abstract-service/abstract-account.js.map +1 -0
  42. package/dist/bop-sdk/interface/abstract-service/abstract-chain.d.ts +5 -0
  43. package/dist/bop-sdk/interface/abstract-service/abstract-chain.js +7 -0
  44. package/dist/bop-sdk/interface/abstract-service/abstract-chain.js.map +1 -0
  45. package/dist/bop-sdk/interface/abstract-service/abstract-contract.d.ts +6 -0
  46. package/dist/bop-sdk/interface/abstract-service/abstract-contract.js +7 -0
  47. package/dist/bop-sdk/interface/abstract-service/abstract-contract.js.map +1 -0
  48. package/dist/bop-sdk/interface/abstract-service/abstract-ledger.d.ts +8 -0
  49. package/dist/bop-sdk/interface/abstract-service/abstract-ledger.js +7 -0
  50. package/dist/bop-sdk/interface/abstract-service/abstract-ledger.js.map +1 -0
  51. package/dist/bop-sdk/interface/abstract-service/abstract-provider.d.ts +12 -0
  52. package/dist/bop-sdk/interface/abstract-service/abstract-provider.js +7 -0
  53. package/dist/bop-sdk/interface/abstract-service/abstract-provider.js.map +1 -0
  54. package/dist/bop-sdk/interface/abstract-service/abstract-signer.d.ts +17 -0
  55. package/dist/bop-sdk/interface/abstract-service/abstract-signer.js +109 -0
  56. package/dist/bop-sdk/interface/abstract-service/abstract-signer.js.map +1 -0
  57. package/dist/bop-sdk/interface/abstract-service/abstract-transaction.d.ts +17 -0
  58. package/dist/bop-sdk/interface/abstract-service/abstract-transaction.js +7 -0
  59. package/dist/bop-sdk/interface/abstract-service/abstract-transaction.js.map +1 -0
  60. package/dist/bop-sdk/interface/provider-ws.d.ts +5 -0
  61. package/dist/bop-sdk/interface/provider-ws.js +12 -0
  62. package/dist/bop-sdk/interface/provider-ws.js.map +1 -0
  63. package/dist/bop-sdk/interface/provider.d.ts +7 -0
  64. package/dist/bop-sdk/interface/provider.js +23 -0
  65. package/dist/bop-sdk/interface/provider.js.map +1 -0
  66. package/dist/bop-sdk/interface/service/3rd.d.ts +12 -0
  67. package/dist/bop-sdk/interface/service/3rd.js +49 -0
  68. package/dist/bop-sdk/interface/service/3rd.js.map +1 -0
  69. package/dist/bop-sdk/interface/service/account.d.ts +12 -0
  70. package/dist/bop-sdk/interface/service/account.js +98 -0
  71. package/dist/bop-sdk/interface/service/account.js.map +1 -0
  72. package/dist/bop-sdk/interface/service/chain.d.ts +9 -0
  73. package/dist/bop-sdk/interface/service/chain.js +55 -0
  74. package/dist/bop-sdk/interface/service/chain.js.map +1 -0
  75. package/dist/bop-sdk/interface/service/contract.d.ts +10 -0
  76. package/dist/bop-sdk/interface/service/contract.js +67 -0
  77. package/dist/bop-sdk/interface/service/contract.js.map +1 -0
  78. package/dist/bop-sdk/interface/service/helper.d.ts +20 -0
  79. package/dist/bop-sdk/interface/service/helper.js +383 -0
  80. package/dist/bop-sdk/interface/service/helper.js.map +1 -0
  81. package/dist/bop-sdk/interface/service/ledger.d.ts +12 -0
  82. package/dist/bop-sdk/interface/service/ledger.js +89 -0
  83. package/dist/bop-sdk/interface/service/ledger.js.map +1 -0
  84. package/dist/bop-sdk/interface/service/offline/check/index.js +138 -0
  85. package/dist/bop-sdk/interface/service/offline/common/constant.js +6 -0
  86. package/dist/bop-sdk/interface/service/offline/common/snowFlakeUtils.js +192 -0
  87. package/dist/bop-sdk/interface/service/offline/common/util.js +511 -0
  88. package/dist/bop-sdk/interface/service/offline/exception/customErrors.js +29 -0
  89. package/dist/bop-sdk/interface/service/offline/exception/errors.js +90 -0
  90. package/dist/bop-sdk/interface/service/offline/exception/index.js +5 -0
  91. package/dist/bop-sdk/interface/service/offline/operation/accountCreateOperation.js +28 -0
  92. package/dist/bop-sdk/interface/service/offline/operation/accountSetMetadataOperation.js +44 -0
  93. package/dist/bop-sdk/interface/service/offline/operation/accountSetPrivilegeOperation.js +49 -0
  94. package/dist/bop-sdk/interface/service/offline/operation/contractCreateOperation.js +43 -0
  95. package/dist/bop-sdk/interface/service/offline/operation/contractInvokeOperation.js +42 -0
  96. package/dist/bop-sdk/interface/service/offline/operation/contractInvokeRequestOperation.js +69 -0
  97. package/dist/bop-sdk/interface/service/offline/operation/gasSendOperation.js +29 -0
  98. package/dist/bop-sdk/interface/service/offline/operation/gasSendRequestOperation.js +61 -0
  99. package/dist/bop-sdk/interface/service/offline/operation/index.js +20 -0
  100. package/dist/bop-sdk/interface/service/offline/proto/chain_pb.js +12079 -0
  101. package/dist/bop-sdk/interface/service/offline/proto/common_pb.js +2867 -0
  102. package/dist/bop-sdk/interface/service/offline/transaction/index.js +988 -0
  103. package/dist/bop-sdk/interface/service/offline/transaction/operations.js +188 -0
  104. package/dist/bop-sdk/interface/service/offline/validate/account.js +152 -0
  105. package/dist/bop-sdk/interface/service/offline/validate/contract.js +101 -0
  106. package/dist/bop-sdk/interface/service/offline/validate/index.js +10 -0
  107. package/dist/bop-sdk/interface/service/offline/validate/transaction.js +51 -0
  108. package/dist/bop-sdk/interface/service/transaction.d.ts +21 -0
  109. package/dist/bop-sdk/interface/service/transaction.js +591 -0
  110. package/dist/bop-sdk/interface/service/transaction.js.map +1 -0
  111. package/dist/bop-sdk/interface/signer.d.ts +12 -0
  112. package/dist/bop-sdk/interface/signer.js +53 -0
  113. package/dist/bop-sdk/interface/signer.js.map +1 -0
  114. package/dist/bop-sdk/interface/test/3rd.test.d.ts +1 -0
  115. package/dist/bop-sdk/interface/test/3rd.test.js +1524 -0
  116. package/dist/bop-sdk/interface/test/3rd.test.js.map +1 -0
  117. package/dist/bop-sdk/interface/test/account.test.d.ts +1 -0
  118. package/dist/bop-sdk/interface/test/account.test.js +225 -0
  119. package/dist/bop-sdk/interface/test/account.test.js.map +1 -0
  120. package/dist/bop-sdk/interface/test/chain.test.d.ts +1 -0
  121. package/dist/bop-sdk/interface/test/chain.test.js +72 -0
  122. package/dist/bop-sdk/interface/test/chain.test.js.map +1 -0
  123. package/dist/bop-sdk/interface/test/contract.test.d.ts +1 -0
  124. package/dist/bop-sdk/interface/test/contract.test.js +266 -0
  125. package/dist/bop-sdk/interface/test/contract.test.js.map +1 -0
  126. package/dist/bop-sdk/interface/test/ledger.test.d.ts +1 -0
  127. package/dist/bop-sdk/interface/test/ledger.test.js +167 -0
  128. package/dist/bop-sdk/interface/test/ledger.test.js.map +1 -0
  129. package/dist/bop-sdk/interface/test/provider.test.d.ts +1 -0
  130. package/dist/bop-sdk/interface/test/provider.test.js +295 -0
  131. package/dist/bop-sdk/interface/test/provider.test.js.map +1 -0
  132. package/dist/bop-sdk/interface/test/signer.test.d.ts +1 -0
  133. package/dist/bop-sdk/interface/test/signer.test.js +87 -0
  134. package/dist/bop-sdk/interface/test/signer.test.js.map +1 -0
  135. package/dist/bop-sdk/interface/test/transaction.test.d.ts +1 -0
  136. package/dist/bop-sdk/interface/test/transaction.test.js +663 -0
  137. package/dist/bop-sdk/interface/test/transaction.test.js.map +1 -0
  138. package/dist/bop-sdk/proto/bop-sdk-common.d.ts +225 -0
  139. package/dist/bop-sdk/proto/bop-sdk-common.js +831 -0
  140. package/dist/bop-sdk/proto/bop-sdk-common.js.map +1 -0
  141. package/dist/bop-sdk/proto/bop-sdk-interface.d.ts +623 -0
  142. package/dist/bop-sdk/proto/bop-sdk-interface.js +8623 -0
  143. package/dist/bop-sdk/proto/bop-sdk-interface.js.map +1 -0
  144. package/dist/bop-sdk/proto/bop-sdk-utils.d.ts +107 -0
  145. package/dist/bop-sdk/proto/bop-sdk-utils.js +1160 -0
  146. package/dist/bop-sdk/proto/bop-sdk-utils.js.map +1 -0
  147. package/dist/bop-sdk/utils/abi/abi-coder.d.ts +16 -0
  148. package/dist/bop-sdk/utils/abi/abi-coder.js +101 -0
  149. package/dist/bop-sdk/utils/abi/abi-coder.js.map +1 -0
  150. package/dist/bop-sdk/utils/abi/address.d.ts +8 -0
  151. package/dist/bop-sdk/utils/abi/address.js +116 -0
  152. package/dist/bop-sdk/utils/abi/address.js.map +1 -0
  153. package/dist/bop-sdk/utils/abi/bignumber.d.ts +39 -0
  154. package/dist/bop-sdk/utils/abi/bignumber.js +316 -0
  155. package/dist/bop-sdk/utils/abi/bignumber.js.map +1 -0
  156. package/dist/bop-sdk/utils/abi/bytes.d.ts +41 -0
  157. package/dist/bop-sdk/utils/abi/bytes.js +423 -0
  158. package/dist/bop-sdk/utils/abi/bytes.js.map +1 -0
  159. package/dist/bop-sdk/utils/abi/coders/abstract-coder.d.ts +52 -0
  160. package/dist/bop-sdk/utils/abi/coders/abstract-coder.js +164 -0
  161. package/dist/bop-sdk/utils/abi/coders/abstract-coder.js.map +1 -0
  162. package/dist/bop-sdk/utils/abi/coders/address.d.ts +7 -0
  163. package/dist/bop-sdk/utils/abi/coders/address.js +52 -0
  164. package/dist/bop-sdk/utils/abi/coders/address.js.map +1 -0
  165. package/dist/bop-sdk/utils/abi/coders/anonymous.d.ts +8 -0
  166. package/dist/bop-sdk/utils/abi/coders/anonymous.js +22 -0
  167. package/dist/bop-sdk/utils/abi/coders/anonymous.js.map +1 -0
  168. package/dist/bop-sdk/utils/abi/coders/array.d.ts +13 -0
  169. package/dist/bop-sdk/utils/abi/coders/array.js +220 -0
  170. package/dist/bop-sdk/utils/abi/coders/array.js.map +1 -0
  171. package/dist/bop-sdk/utils/abi/coders/boolean.d.ts +7 -0
  172. package/dist/bop-sdk/utils/abi/coders/boolean.js +20 -0
  173. package/dist/bop-sdk/utils/abi/coders/boolean.js.map +1 -0
  174. package/dist/bop-sdk/utils/abi/coders/bytes.d.ts +11 -0
  175. package/dist/bop-sdk/utils/abi/coders/bytes.js +33 -0
  176. package/dist/bop-sdk/utils/abi/coders/bytes.js.map +1 -0
  177. package/dist/bop-sdk/utils/abi/coders/fixed-bytes.d.ts +9 -0
  178. package/dist/bop-sdk/utils/abi/coders/fixed-bytes.js +28 -0
  179. package/dist/bop-sdk/utils/abi/coders/fixed-bytes.js.map +1 -0
  180. package/dist/bop-sdk/utils/abi/coders/null.d.ts +7 -0
  181. package/dist/bop-sdk/utils/abi/coders/null.js +24 -0
  182. package/dist/bop-sdk/utils/abi/coders/null.js.map +1 -0
  183. package/dist/bop-sdk/utils/abi/coders/number.d.ts +10 -0
  184. package/dist/bop-sdk/utils/abi/coders/number.js +45 -0
  185. package/dist/bop-sdk/utils/abi/coders/number.js.map +1 -0
  186. package/dist/bop-sdk/utils/abi/coders/string.d.ts +8 -0
  187. package/dist/bop-sdk/utils/abi/coders/string.js +21 -0
  188. package/dist/bop-sdk/utils/abi/coders/string.js.map +1 -0
  189. package/dist/bop-sdk/utils/abi/coders/tuple.d.ts +10 -0
  190. package/dist/bop-sdk/utils/abi/coders/tuple.js +60 -0
  191. package/dist/bop-sdk/utils/abi/coders/tuple.js.map +1 -0
  192. package/dist/bop-sdk/utils/abi/constants/addresses.d.ts +1 -0
  193. package/dist/bop-sdk/utils/abi/constants/addresses.js +5 -0
  194. package/dist/bop-sdk/utils/abi/constants/addresses.js.map +1 -0
  195. package/dist/bop-sdk/utils/abi/constants/bignumbers.d.ts +10 -0
  196. package/dist/bop-sdk/utils/abi/constants/bignumbers.js +21 -0
  197. package/dist/bop-sdk/utils/abi/constants/bignumbers.js.map +1 -0
  198. package/dist/bop-sdk/utils/abi/constants/hashes.d.ts +1 -0
  199. package/dist/bop-sdk/utils/abi/constants/hashes.js +5 -0
  200. package/dist/bop-sdk/utils/abi/constants/hashes.js.map +1 -0
  201. package/dist/bop-sdk/utils/abi/constants/index.d.ts +4 -0
  202. package/dist/bop-sdk/utils/abi/constants/index.js +19 -0
  203. package/dist/bop-sdk/utils/abi/constants/index.js.map +1 -0
  204. package/dist/bop-sdk/utils/abi/constants/strings.d.ts +1 -0
  205. package/dist/bop-sdk/utils/abi/constants/strings.js +6 -0
  206. package/dist/bop-sdk/utils/abi/constants/strings.js.map +1 -0
  207. package/dist/bop-sdk/utils/abi/fragments.d.ts +84 -0
  208. package/dist/bop-sdk/utils/abi/fragments.js +919 -0
  209. package/dist/bop-sdk/utils/abi/fragments.js.map +1 -0
  210. package/dist/bop-sdk/utils/abi/id.d.ts +1 -0
  211. package/dist/bop-sdk/utils/abi/id.js +10 -0
  212. package/dist/bop-sdk/utils/abi/id.js.map +1 -0
  213. package/dist/bop-sdk/utils/abi/index.d.ts +4 -0
  214. package/dist/bop-sdk/utils/abi/index.js +21 -0
  215. package/dist/bop-sdk/utils/abi/index.js.map +1 -0
  216. package/dist/bop-sdk/utils/abi/interface.d.ts +83 -0
  217. package/dist/bop-sdk/utils/abi/interface.js +663 -0
  218. package/dist/bop-sdk/utils/abi/interface.js.map +1 -0
  219. package/dist/bop-sdk/utils/abi/keccak256.d.ts +2 -0
  220. package/dist/bop-sdk/utils/abi/keccak256.js +13 -0
  221. package/dist/bop-sdk/utils/abi/keccak256.js.map +1 -0
  222. package/dist/bop-sdk/utils/abi/properties.d.ts +16 -0
  223. package/dist/bop-sdk/utils/abi/properties.js +141 -0
  224. package/dist/bop-sdk/utils/abi/properties.js.map +1 -0
  225. package/dist/bop-sdk/utils/abi/strings/bytes32.d.ts +3 -0
  226. package/dist/bop-sdk/utils/abi/strings/bytes32.js +36 -0
  227. package/dist/bop-sdk/utils/abi/strings/bytes32.js.map +1 -0
  228. package/dist/bop-sdk/utils/abi/strings/idna.d.ts +4 -0
  229. package/dist/bop-sdk/utils/abi/strings/idna.js +200 -0
  230. package/dist/bop-sdk/utils/abi/strings/idna.js.map +1 -0
  231. package/dist/bop-sdk/utils/abi/strings/index.d.ts +4 -0
  232. package/dist/bop-sdk/utils/abi/strings/index.js +17 -0
  233. package/dist/bop-sdk/utils/abi/strings/index.js.map +1 -0
  234. package/dist/bop-sdk/utils/abi/strings/utf8.d.ts +26 -0
  235. package/dist/bop-sdk/utils/abi/strings/utf8.js +265 -0
  236. package/dist/bop-sdk/utils/abi/strings/utf8.js.map +1 -0
  237. package/dist/bop-sdk/utils/encryption-address.d.ts +25 -0
  238. package/dist/bop-sdk/utils/encryption-address.js +426 -0
  239. package/dist/bop-sdk/utils/encryption-address.js.map +1 -0
  240. package/dist/bop-sdk/utils/encryption-crypto.d.ts +16 -0
  241. package/dist/bop-sdk/utils/encryption-crypto.js +406 -0
  242. package/dist/bop-sdk/utils/encryption-crypto.js.map +1 -0
  243. package/dist/bop-sdk/utils/encryption-mnemonics.d.ts +7 -0
  244. package/dist/bop-sdk/utils/encryption-mnemonics.js +129 -0
  245. package/dist/bop-sdk/utils/encryption-mnemonics.js.map +1 -0
  246. package/dist/bop-sdk/utils/index.d.ts +13 -0
  247. package/dist/bop-sdk/utils/index.js +22 -0
  248. package/dist/bop-sdk/utils/index.js.map +1 -0
  249. package/dist/bop-sdk/utils/logger.d.ts +52 -0
  250. package/dist/bop-sdk/utils/logger.js +377 -0
  251. package/dist/bop-sdk/utils/logger.js.map +1 -0
  252. package/dist/index.d.ts +4 -0
  253. package/dist/index.js +18 -0
  254. package/dist/index.js.map +1 -0
  255. package/package.json +92 -88
  256. package/tsconfig.json +24 -0
@@ -0,0 +1,919 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErrorFragment = exports.FunctionFragment = exports.ConstructorFragment = exports.EventFragment = exports.Fragment = exports.ParamType = exports.FormatTypes = void 0;
4
+ const bignumber_1 = require("./bignumber");
5
+ const properties_1 = require("./properties");
6
+ const logger_1 = require("../logger");
7
+ const version = "fragments/5.7.0";
8
+ const logger = new logger_1.Logger(version);
9
+ const _constructorGuard = {};
10
+ let ModifiersBytes = {
11
+ calldata: true,
12
+ memory: true,
13
+ storage: true,
14
+ };
15
+ let ModifiersNest = {
16
+ calldata: true,
17
+ memory: true,
18
+ };
19
+ function checkModifier(type, name) {
20
+ if (type === "bytes" || type === "string") {
21
+ if (ModifiersBytes[name]) {
22
+ return true;
23
+ }
24
+ }
25
+ else if (type === "address") {
26
+ if (name === "payable") {
27
+ return true;
28
+ }
29
+ }
30
+ else if (type.indexOf("[") >= 0 || type === "tuple") {
31
+ if (ModifiersNest[name]) {
32
+ return true;
33
+ }
34
+ }
35
+ if (ModifiersBytes[name] || name === "payable") {
36
+ logger.throwArgumentError("invalid modifier", "name", name);
37
+ }
38
+ return false;
39
+ }
40
+ // @TODO: Make sure that children of an indexed tuple are marked with a null indexed
41
+ function parseParamType(param, allowIndexed) {
42
+ let originalParam = param;
43
+ function throwError(i) {
44
+ logger.throwArgumentError(`unexpected character at position ${i}`, "param", param);
45
+ }
46
+ param = param.replace(/\s/g, " ");
47
+ function newNode(parent) {
48
+ let node = {
49
+ type: "",
50
+ name: "",
51
+ parent: parent,
52
+ state: { allowType: true },
53
+ };
54
+ if (allowIndexed) {
55
+ node.indexed = false;
56
+ }
57
+ return node;
58
+ }
59
+ let parent = { type: "", name: "", state: { allowType: true } };
60
+ let node = parent;
61
+ for (let i = 0; i < param.length; i++) {
62
+ let c = param[i];
63
+ switch (c) {
64
+ case "(":
65
+ if (node.state.allowType && node.type === "") {
66
+ node.type = "tuple";
67
+ }
68
+ else if (!node.state.allowParams) {
69
+ throwError(i);
70
+ }
71
+ node.state.allowType = false;
72
+ node.type = verifyType(node.type);
73
+ node.components = [newNode(node)];
74
+ node = node.components[0];
75
+ break;
76
+ case ")":
77
+ delete node.state;
78
+ if (node.name === "indexed") {
79
+ if (!allowIndexed) {
80
+ throwError(i);
81
+ }
82
+ node.indexed = true;
83
+ node.name = "";
84
+ }
85
+ if (checkModifier(node.type, node.name)) {
86
+ node.name = "";
87
+ }
88
+ node.type = verifyType(node.type);
89
+ let child = node;
90
+ node = node.parent;
91
+ if (!node) {
92
+ throwError(i);
93
+ }
94
+ delete child.parent;
95
+ node.state.allowParams = false;
96
+ node.state.allowName = true;
97
+ node.state.allowArray = true;
98
+ break;
99
+ case ",":
100
+ delete node.state;
101
+ if (node.name === "indexed") {
102
+ if (!allowIndexed) {
103
+ throwError(i);
104
+ }
105
+ node.indexed = true;
106
+ node.name = "";
107
+ }
108
+ if (checkModifier(node.type, node.name)) {
109
+ node.name = "";
110
+ }
111
+ node.type = verifyType(node.type);
112
+ let sibling = newNode(node.parent);
113
+ //{ type: "", name: "", parent: node.parent, state: { allowType: true } };
114
+ node.parent.components.push(sibling);
115
+ delete node.parent;
116
+ node = sibling;
117
+ break;
118
+ // Hit a space...
119
+ case " ":
120
+ // If reading type, the type is done and may read a param or name
121
+ if (node.state.allowType) {
122
+ if (node.type !== "") {
123
+ node.type = verifyType(node.type);
124
+ delete node.state.allowType;
125
+ node.state.allowName = true;
126
+ node.state.allowParams = true;
127
+ }
128
+ }
129
+ // If reading name, the name is done
130
+ if (node.state.allowName) {
131
+ if (node.name !== "") {
132
+ if (node.name === "indexed") {
133
+ if (!allowIndexed) {
134
+ throwError(i);
135
+ }
136
+ if (node.indexed) {
137
+ throwError(i);
138
+ }
139
+ node.indexed = true;
140
+ node.name = "";
141
+ }
142
+ else if (checkModifier(node.type, node.name)) {
143
+ node.name = "";
144
+ }
145
+ else {
146
+ node.state.allowName = false;
147
+ }
148
+ }
149
+ }
150
+ break;
151
+ case "[":
152
+ if (!node.state.allowArray) {
153
+ throwError(i);
154
+ }
155
+ node.type += c;
156
+ node.state.allowArray = false;
157
+ node.state.allowName = false;
158
+ node.state.readArray = true;
159
+ break;
160
+ case "]":
161
+ if (!node.state.readArray) {
162
+ throwError(i);
163
+ }
164
+ node.type += c;
165
+ node.state.readArray = false;
166
+ node.state.allowArray = true;
167
+ node.state.allowName = true;
168
+ break;
169
+ default:
170
+ if (node.state.allowType) {
171
+ node.type += c;
172
+ node.state.allowParams = true;
173
+ node.state.allowArray = true;
174
+ }
175
+ else if (node.state.allowName) {
176
+ node.name += c;
177
+ delete node.state.allowArray;
178
+ }
179
+ else if (node.state.readArray) {
180
+ node.type += c;
181
+ }
182
+ else {
183
+ throwError(i);
184
+ }
185
+ }
186
+ }
187
+ if (node.parent) {
188
+ logger.throwArgumentError("unexpected eof", "param", param);
189
+ }
190
+ delete parent.state;
191
+ if (node.name === "indexed") {
192
+ if (!allowIndexed) {
193
+ throwError(originalParam.length - 7);
194
+ }
195
+ if (node.indexed) {
196
+ throwError(originalParam.length - 7);
197
+ }
198
+ node.indexed = true;
199
+ node.name = "";
200
+ }
201
+ else if (checkModifier(node.type, node.name)) {
202
+ node.name = "";
203
+ }
204
+ parent.type = verifyType(parent.type);
205
+ return parent;
206
+ }
207
+ function populate(object, params) {
208
+ for (let key in params) {
209
+ (0, properties_1.defineReadOnly)(object, key, params[key]);
210
+ }
211
+ }
212
+ exports.FormatTypes = Object.freeze({
213
+ // Bare formatting, as is needed for computing a sighash of an event or function
214
+ sighash: "sighash",
215
+ // Human-Readable with Minimal spacing and without names (compact human-readable)
216
+ minimal: "minimal",
217
+ // Human-Readable with nice spacing, including all names
218
+ full: "full",
219
+ // JSON-format a la Solidity
220
+ json: "json",
221
+ });
222
+ const paramTypeArray = new RegExp(/^(.*)\[([0-9]*)\]$/);
223
+ class ParamType {
224
+ constructor(constructorGuard, params) {
225
+ if (constructorGuard !== _constructorGuard) {
226
+ logger.throwError("use fromString", logger_1.Logger.errors.UNSUPPORTED_OPERATION, {
227
+ operation: "new ParamType()",
228
+ });
229
+ }
230
+ populate(this, params);
231
+ let match = this.type.match(paramTypeArray);
232
+ if (match) {
233
+ populate(this, {
234
+ arrayLength: parseInt(match[2] || "-1"),
235
+ arrayChildren: ParamType.fromObject({
236
+ type: match[1],
237
+ components: this.components,
238
+ }),
239
+ baseType: "array",
240
+ });
241
+ }
242
+ else {
243
+ populate(this, {
244
+ arrayLength: null,
245
+ arrayChildren: null,
246
+ baseType: this.components != null ? "tuple" : this.type,
247
+ });
248
+ }
249
+ this._isParamType = true;
250
+ Object.freeze(this);
251
+ }
252
+ // Format the parameter fragment
253
+ // - sighash: "(uint256,address)"
254
+ // - minimal: "tuple(uint256,address) indexed"
255
+ // - full: "tuple(uint256 foo, address bar) indexed baz"
256
+ format(format) {
257
+ if (!format) {
258
+ format = exports.FormatTypes.sighash;
259
+ }
260
+ if (!exports.FormatTypes[format]) {
261
+ logger.throwArgumentError("invalid format type", "format", format);
262
+ }
263
+ if (format === exports.FormatTypes.json) {
264
+ let result = {
265
+ type: this.baseType === "tuple" ? "tuple" : this.type,
266
+ name: this.name || undefined,
267
+ };
268
+ if (typeof this.indexed === "boolean") {
269
+ result.indexed = this.indexed;
270
+ }
271
+ if (this.components) {
272
+ result.components = this.components.map((comp) => JSON.parse(comp.format(format)));
273
+ }
274
+ return JSON.stringify(result);
275
+ }
276
+ let result = "";
277
+ // Array
278
+ if (this.baseType === "array") {
279
+ result += this.arrayChildren.format(format);
280
+ result +=
281
+ "[" + (this.arrayLength < 0 ? "" : String(this.arrayLength)) + "]";
282
+ }
283
+ else {
284
+ if (this.baseType === "tuple") {
285
+ if (format !== exports.FormatTypes.sighash) {
286
+ result += this.type;
287
+ }
288
+ result +=
289
+ "(" +
290
+ this.components
291
+ .map((comp) => comp.format(format))
292
+ .join(format === exports.FormatTypes.full ? ", " : ",") +
293
+ ")";
294
+ }
295
+ else {
296
+ result += this.type;
297
+ }
298
+ }
299
+ if (format !== exports.FormatTypes.sighash) {
300
+ if (this.indexed === true) {
301
+ result += " indexed";
302
+ }
303
+ if (format === exports.FormatTypes.full && this.name) {
304
+ result += " " + this.name;
305
+ }
306
+ }
307
+ return result;
308
+ }
309
+ static from(value, allowIndexed) {
310
+ if (typeof value === "string") {
311
+ return ParamType.fromString(value, allowIndexed);
312
+ }
313
+ return ParamType.fromObject(value);
314
+ }
315
+ static fromObject(value) {
316
+ if (ParamType.isParamType(value)) {
317
+ return value;
318
+ }
319
+ return new ParamType(_constructorGuard, {
320
+ name: value.name || null,
321
+ type: verifyType(value.type),
322
+ indexed: value.indexed == null ? null : !!value.indexed,
323
+ components: value.components
324
+ ? value.components.map(ParamType.fromObject)
325
+ : null,
326
+ });
327
+ }
328
+ static fromString(value, allowIndexed) {
329
+ function ParamTypify(node) {
330
+ return ParamType.fromObject({
331
+ name: node.name,
332
+ type: node.type,
333
+ indexed: node.indexed,
334
+ components: node.components,
335
+ });
336
+ }
337
+ return ParamTypify(parseParamType(value, !!allowIndexed));
338
+ }
339
+ static isParamType(value) {
340
+ return !!(value != null && value._isParamType);
341
+ }
342
+ }
343
+ exports.ParamType = ParamType;
344
+ function parseParams(value, allowIndex) {
345
+ return splitNesting(value).map((param) => ParamType.fromString(param, allowIndex));
346
+ }
347
+ class Fragment {
348
+ constructor(constructorGuard, params) {
349
+ if (constructorGuard !== _constructorGuard) {
350
+ logger.throwError("use a static from method", logger_1.Logger.errors.UNSUPPORTED_OPERATION, {
351
+ operation: "new Fragment()",
352
+ });
353
+ }
354
+ populate(this, params);
355
+ this._isFragment = true;
356
+ Object.freeze(this);
357
+ }
358
+ static from(value) {
359
+ if (Fragment.isFragment(value)) {
360
+ return value;
361
+ }
362
+ if (typeof value === "string") {
363
+ return Fragment.fromString(value);
364
+ }
365
+ return Fragment.fromObject(value);
366
+ }
367
+ static fromObject(value) {
368
+ if (Fragment.isFragment(value)) {
369
+ return value;
370
+ }
371
+ switch (value.type) {
372
+ case "function":
373
+ return FunctionFragment.fromObject(value);
374
+ case "event":
375
+ return EventFragment.fromObject(value);
376
+ case "constructor":
377
+ return ConstructorFragment.fromObject(value);
378
+ case "error":
379
+ return ErrorFragment.fromObject(value);
380
+ case "fallback":
381
+ case "receive":
382
+ // @TODO: Something? Maybe return a FunctionFragment? A custom DefaultFunctionFragment?
383
+ return null;
384
+ }
385
+ return logger.throwArgumentError("invalid fragment object", "value", value);
386
+ }
387
+ static fromString(value) {
388
+ // Make sure the "returns" is surrounded by a space and all whitespace is exactly one space
389
+ value = value.replace(/\s/g, " ");
390
+ value = value
391
+ .replace(/\(/g, " (")
392
+ .replace(/\)/g, ") ")
393
+ .replace(/\s+/g, " ");
394
+ value = value.trim();
395
+ if (value.split(" ")[0] === "event") {
396
+ return EventFragment.fromString(value.substring(5).trim());
397
+ }
398
+ else if (value.split(" ")[0] === "function") {
399
+ return FunctionFragment.fromString(value.substring(8).trim());
400
+ }
401
+ else if (value.split("(")[0].trim() === "constructor") {
402
+ return ConstructorFragment.fromString(value.trim());
403
+ }
404
+ else if (value.split(" ")[0] === "error") {
405
+ return ErrorFragment.fromString(value.substring(5).trim());
406
+ }
407
+ return logger.throwArgumentError("unsupported fragment", "value", value);
408
+ }
409
+ static isFragment(value) {
410
+ return !!(value && value._isFragment);
411
+ }
412
+ }
413
+ exports.Fragment = Fragment;
414
+ class EventFragment extends Fragment {
415
+ format(format) {
416
+ if (!format) {
417
+ format = exports.FormatTypes.sighash;
418
+ }
419
+ if (!exports.FormatTypes[format]) {
420
+ logger.throwArgumentError("invalid format type", "format", format);
421
+ }
422
+ if (format === exports.FormatTypes.json) {
423
+ return JSON.stringify({
424
+ type: "event",
425
+ anonymous: this.anonymous,
426
+ name: this.name,
427
+ inputs: this.inputs.map((input) => JSON.parse(input.format(format))),
428
+ });
429
+ }
430
+ let result = "";
431
+ if (format !== exports.FormatTypes.sighash) {
432
+ result += "event ";
433
+ }
434
+ result +=
435
+ this.name +
436
+ "(" +
437
+ this.inputs
438
+ .map((input) => input.format(format))
439
+ .join(format === exports.FormatTypes.full ? ", " : ",") +
440
+ ") ";
441
+ if (format !== exports.FormatTypes.sighash) {
442
+ if (this.anonymous) {
443
+ result += "anonymous ";
444
+ }
445
+ }
446
+ return result.trim();
447
+ }
448
+ static from(value) {
449
+ if (typeof value === "string") {
450
+ return EventFragment.fromString(value);
451
+ }
452
+ return EventFragment.fromObject(value);
453
+ }
454
+ static fromObject(value) {
455
+ if (EventFragment.isEventFragment(value)) {
456
+ return value;
457
+ }
458
+ if (value.type !== "event") {
459
+ logger.throwArgumentError("invalid event object", "value", value);
460
+ }
461
+ const params = {
462
+ name: verifyIdentifier(value.name),
463
+ anonymous: value.anonymous,
464
+ inputs: value.inputs ? value.inputs.map(ParamType.fromObject) : [],
465
+ type: "event",
466
+ };
467
+ return new EventFragment(_constructorGuard, params);
468
+ }
469
+ static fromString(value) {
470
+ let match = value.match(regexParen);
471
+ if (!match) {
472
+ logger.throwArgumentError("invalid event string", "value", value);
473
+ }
474
+ let anonymous = false;
475
+ match[3].split(" ").forEach((modifier) => {
476
+ switch (modifier.trim()) {
477
+ case "anonymous":
478
+ anonymous = true;
479
+ break;
480
+ case "":
481
+ break;
482
+ default:
483
+ logger.warn("unknown modifier: " + modifier);
484
+ }
485
+ });
486
+ return EventFragment.fromObject({
487
+ name: match[1].trim(),
488
+ anonymous: anonymous,
489
+ inputs: parseParams(match[2], true),
490
+ type: "event",
491
+ });
492
+ }
493
+ static isEventFragment(value) {
494
+ return value && value._isFragment && value.type === "event";
495
+ }
496
+ }
497
+ exports.EventFragment = EventFragment;
498
+ function parseGas(value, params) {
499
+ params.gas = null;
500
+ let comps = value.split("@");
501
+ if (comps.length !== 1) {
502
+ if (comps.length > 2) {
503
+ logger.throwArgumentError("invalid human-readable ABI signature", "value", value);
504
+ }
505
+ if (!comps[1].match(/^[0-9]+$/)) {
506
+ logger.throwArgumentError("invalid human-readable ABI signature gas", "value", value);
507
+ }
508
+ params.gas = bignumber_1.BigNumber.from(comps[1]);
509
+ return comps[0];
510
+ }
511
+ return value;
512
+ }
513
+ function parseModifiers(value, params) {
514
+ params.constant = false;
515
+ params.payable = false;
516
+ params.stateMutability = "nonpayable";
517
+ value.split(" ").forEach((modifier) => {
518
+ switch (modifier.trim()) {
519
+ case "constant":
520
+ params.constant = true;
521
+ break;
522
+ case "payable":
523
+ params.payable = true;
524
+ params.stateMutability = "payable";
525
+ break;
526
+ case "nonpayable":
527
+ params.payable = false;
528
+ params.stateMutability = "nonpayable";
529
+ break;
530
+ case "pure":
531
+ params.constant = true;
532
+ params.stateMutability = "pure";
533
+ break;
534
+ case "view":
535
+ params.constant = true;
536
+ params.stateMutability = "view";
537
+ break;
538
+ case "external":
539
+ case "public":
540
+ case "":
541
+ break;
542
+ default:
543
+ console.log("unknown modifier: " + modifier);
544
+ }
545
+ });
546
+ }
547
+ function verifyState(value) {
548
+ let result = {
549
+ constant: false,
550
+ payable: true,
551
+ stateMutability: "payable",
552
+ };
553
+ if (value.stateMutability != null) {
554
+ result.stateMutability = value.stateMutability;
555
+ // Set (and check things are consistent) the constant property
556
+ result.constant =
557
+ result.stateMutability === "view" || result.stateMutability === "pure";
558
+ if (value.constant != null) {
559
+ if (!!value.constant !== result.constant) {
560
+ logger.throwArgumentError("cannot have constant function with mutability " +
561
+ result.stateMutability, "value", value);
562
+ }
563
+ }
564
+ // Set (and check things are consistent) the payable property
565
+ result.payable = result.stateMutability === "payable";
566
+ if (value.payable != null) {
567
+ if (!!value.payable !== result.payable) {
568
+ logger.throwArgumentError("cannot have payable function with mutability " +
569
+ result.stateMutability, "value", value);
570
+ }
571
+ }
572
+ }
573
+ else if (value.payable != null) {
574
+ result.payable = !!value.payable;
575
+ // If payable we can assume non-constant; otherwise we can't assume
576
+ if (value.constant == null &&
577
+ !result.payable &&
578
+ value.type !== "constructor") {
579
+ logger.throwArgumentError("unable to determine stateMutability", "value", value);
580
+ }
581
+ result.constant = !!value.constant;
582
+ if (result.constant) {
583
+ result.stateMutability = "view";
584
+ }
585
+ else {
586
+ result.stateMutability = result.payable ? "payable" : "nonpayable";
587
+ }
588
+ if (result.payable && result.constant) {
589
+ logger.throwArgumentError("cannot have constant payable function", "value", value);
590
+ }
591
+ }
592
+ else if (value.constant != null) {
593
+ result.constant = !!value.constant;
594
+ result.payable = !result.constant;
595
+ result.stateMutability = result.constant ? "view" : "payable";
596
+ }
597
+ else if (value.type !== "constructor") {
598
+ logger.throwArgumentError("unable to determine stateMutability", "value", value);
599
+ }
600
+ return result;
601
+ }
602
+ class ConstructorFragment extends Fragment {
603
+ format(format) {
604
+ if (!format) {
605
+ format = exports.FormatTypes.sighash;
606
+ }
607
+ if (!exports.FormatTypes[format]) {
608
+ logger.throwArgumentError("invalid format type", "format", format);
609
+ }
610
+ if (format === exports.FormatTypes.json) {
611
+ return JSON.stringify({
612
+ type: "constructor",
613
+ stateMutability: this.stateMutability !== "nonpayable"
614
+ ? this.stateMutability
615
+ : undefined,
616
+ payable: this.payable,
617
+ gas: this.gas ? this.gas.toNumber() : undefined,
618
+ inputs: this.inputs.map((input) => JSON.parse(input.format(format))),
619
+ });
620
+ }
621
+ if (format === exports.FormatTypes.sighash) {
622
+ logger.throwError("cannot format a constructor for sighash", logger_1.Logger.errors.UNSUPPORTED_OPERATION, {
623
+ operation: "format(sighash)",
624
+ });
625
+ }
626
+ let result = "constructor(" +
627
+ this.inputs
628
+ .map((input) => input.format(format))
629
+ .join(format === exports.FormatTypes.full ? ", " : ",") +
630
+ ") ";
631
+ if (this.stateMutability && this.stateMutability !== "nonpayable") {
632
+ result += this.stateMutability + " ";
633
+ }
634
+ return result.trim();
635
+ }
636
+ static from(value) {
637
+ if (typeof value === "string") {
638
+ return ConstructorFragment.fromString(value);
639
+ }
640
+ return ConstructorFragment.fromObject(value);
641
+ }
642
+ static fromObject(value) {
643
+ if (ConstructorFragment.isConstructorFragment(value)) {
644
+ return value;
645
+ }
646
+ if (value.type !== "constructor") {
647
+ logger.throwArgumentError("invalid constructor object", "value", value);
648
+ }
649
+ let state = verifyState(value);
650
+ if (state.constant) {
651
+ logger.throwArgumentError("constructor cannot be constant", "value", value);
652
+ }
653
+ const params = {
654
+ name: null,
655
+ type: value.type,
656
+ inputs: value.inputs ? value.inputs.map(ParamType.fromObject) : [],
657
+ payable: state.payable,
658
+ stateMutability: state.stateMutability,
659
+ gas: value.gas ? bignumber_1.BigNumber.from(value.gas) : null,
660
+ };
661
+ return new ConstructorFragment(_constructorGuard, params);
662
+ }
663
+ static fromString(value) {
664
+ let params = { type: "constructor" };
665
+ value = parseGas(value, params);
666
+ console.log(value);
667
+ let parens = value.match(regexParen);
668
+ if (!parens || parens[1].trim() !== "constructor") {
669
+ logger.throwArgumentError("invalid constructor string", "value", value);
670
+ }
671
+ params.inputs = parseParams(parens[2].trim(), false);
672
+ parseModifiers(parens[3].trim(), params);
673
+ return ConstructorFragment.fromObject(params);
674
+ }
675
+ static isConstructorFragment(value) {
676
+ return value && value._isFragment && value.type === "constructor";
677
+ }
678
+ }
679
+ exports.ConstructorFragment = ConstructorFragment;
680
+ class FunctionFragment extends ConstructorFragment {
681
+ format(format) {
682
+ if (!format) {
683
+ format = exports.FormatTypes.sighash;
684
+ }
685
+ if (!exports.FormatTypes[format]) {
686
+ logger.throwArgumentError("invalid format type", "format", format);
687
+ }
688
+ if (format === exports.FormatTypes.json) {
689
+ return JSON.stringify({
690
+ type: "function",
691
+ name: this.name,
692
+ constant: this.constant,
693
+ stateMutability: this.stateMutability !== "nonpayable"
694
+ ? this.stateMutability
695
+ : undefined,
696
+ payable: this.payable,
697
+ gas: this.gas ? this.gas.toNumber() : undefined,
698
+ inputs: this.inputs.map((input) => JSON.parse(input.format(format))),
699
+ outputs: this.outputs.map((output) => JSON.parse(output.format(format))),
700
+ });
701
+ }
702
+ let result = "";
703
+ if (format !== exports.FormatTypes.sighash) {
704
+ result += "function ";
705
+ }
706
+ result +=
707
+ this.name +
708
+ "(" +
709
+ this.inputs
710
+ .map((input) => input.format(format))
711
+ .join(format === exports.FormatTypes.full ? ", " : ",") +
712
+ ") ";
713
+ if (format !== exports.FormatTypes.sighash) {
714
+ if (this.stateMutability) {
715
+ if (this.stateMutability !== "nonpayable") {
716
+ result += this.stateMutability + " ";
717
+ }
718
+ }
719
+ else if (this.constant) {
720
+ result += "view ";
721
+ }
722
+ if (this.outputs && this.outputs.length) {
723
+ result +=
724
+ "returns (" +
725
+ this.outputs.map((output) => output.format(format)).join(", ") +
726
+ ") ";
727
+ }
728
+ if (this.gas != null) {
729
+ result += "@" + this.gas.toString() + " ";
730
+ }
731
+ }
732
+ return result.trim();
733
+ }
734
+ static from(value) {
735
+ if (typeof value === "string") {
736
+ return FunctionFragment.fromString(value);
737
+ }
738
+ return FunctionFragment.fromObject(value);
739
+ }
740
+ static fromObject(value) {
741
+ if (FunctionFragment.isFunctionFragment(value)) {
742
+ return value;
743
+ }
744
+ if (value.type !== "function") {
745
+ logger.throwArgumentError("invalid function object", "value", value);
746
+ }
747
+ let state = verifyState(value);
748
+ const params = {
749
+ type: value.type,
750
+ name: verifyIdentifier(value.name),
751
+ constant: state.constant,
752
+ inputs: value.inputs ? value.inputs.map(ParamType.fromObject) : [],
753
+ outputs: value.outputs ? value.outputs.map(ParamType.fromObject) : [],
754
+ payable: state.payable,
755
+ stateMutability: state.stateMutability,
756
+ gas: value.gas ? bignumber_1.BigNumber.from(value.gas) : null,
757
+ };
758
+ return new FunctionFragment(_constructorGuard, params);
759
+ }
760
+ static fromString(value) {
761
+ let params = { type: "function" };
762
+ value = parseGas(value, params);
763
+ let comps = value.split(" returns ");
764
+ if (comps.length > 2) {
765
+ logger.throwArgumentError("invalid function string", "value", value);
766
+ }
767
+ let parens = comps[0].match(regexParen);
768
+ if (!parens) {
769
+ logger.throwArgumentError("invalid function signature", "value", value);
770
+ }
771
+ params.name = parens[1].trim();
772
+ if (params.name) {
773
+ verifyIdentifier(params.name);
774
+ }
775
+ params.inputs = parseParams(parens[2], false);
776
+ parseModifiers(parens[3].trim(), params);
777
+ // We have outputs
778
+ if (comps.length > 1) {
779
+ let returns = comps[1].match(regexParen);
780
+ if (returns[1].trim() != "" || returns[3].trim() != "") {
781
+ logger.throwArgumentError("unexpected tokens", "value", value);
782
+ }
783
+ params.outputs = parseParams(returns[2], false);
784
+ }
785
+ else {
786
+ params.outputs = [];
787
+ }
788
+ return FunctionFragment.fromObject(params);
789
+ }
790
+ static isFunctionFragment(value) {
791
+ return value && value._isFragment && value.type === "function";
792
+ }
793
+ }
794
+ exports.FunctionFragment = FunctionFragment;
795
+ //export class StructFragment extends Fragment {
796
+ //}
797
+ function checkForbidden(fragment) {
798
+ const sig = fragment.format();
799
+ if (sig === "Error(string)" || sig === "Panic(uint256)") {
800
+ logger.throwArgumentError(`cannot specify user defined ${sig} error`, "fragment", fragment);
801
+ }
802
+ return fragment;
803
+ }
804
+ class ErrorFragment extends Fragment {
805
+ format(format) {
806
+ if (!format) {
807
+ format = exports.FormatTypes.sighash;
808
+ }
809
+ if (!exports.FormatTypes[format]) {
810
+ logger.throwArgumentError("invalid format type", "format", format);
811
+ }
812
+ if (format === exports.FormatTypes.json) {
813
+ return JSON.stringify({
814
+ type: "error",
815
+ name: this.name,
816
+ inputs: this.inputs.map((input) => JSON.parse(input.format(format))),
817
+ });
818
+ }
819
+ let result = "";
820
+ if (format !== exports.FormatTypes.sighash) {
821
+ result += "error ";
822
+ }
823
+ result +=
824
+ this.name +
825
+ "(" +
826
+ this.inputs
827
+ .map((input) => input.format(format))
828
+ .join(format === exports.FormatTypes.full ? ", " : ",") +
829
+ ") ";
830
+ return result.trim();
831
+ }
832
+ static from(value) {
833
+ if (typeof value === "string") {
834
+ return ErrorFragment.fromString(value);
835
+ }
836
+ return ErrorFragment.fromObject(value);
837
+ }
838
+ static fromObject(value) {
839
+ if (ErrorFragment.isErrorFragment(value)) {
840
+ return value;
841
+ }
842
+ if (value.type !== "error") {
843
+ logger.throwArgumentError("invalid error object", "value", value);
844
+ }
845
+ const params = {
846
+ type: value.type,
847
+ name: verifyIdentifier(value.name),
848
+ inputs: value.inputs ? value.inputs.map(ParamType.fromObject) : [],
849
+ };
850
+ return checkForbidden(new ErrorFragment(_constructorGuard, params));
851
+ }
852
+ static fromString(value) {
853
+ let params = { type: "error" };
854
+ let parens = value.match(regexParen);
855
+ if (!parens) {
856
+ logger.throwArgumentError("invalid error signature", "value", value);
857
+ }
858
+ params.name = parens[1].trim();
859
+ if (params.name) {
860
+ verifyIdentifier(params.name);
861
+ }
862
+ params.inputs = parseParams(parens[2], false);
863
+ return checkForbidden(ErrorFragment.fromObject(params));
864
+ }
865
+ static isErrorFragment(value) {
866
+ return value && value._isFragment && value.type === "error";
867
+ }
868
+ }
869
+ exports.ErrorFragment = ErrorFragment;
870
+ function verifyType(type) {
871
+ // These need to be transformed to their full description
872
+ if (type.match(/^uint($|[^1-9])/)) {
873
+ type = "uint256" + type.substring(4);
874
+ }
875
+ else if (type.match(/^int($|[^1-9])/)) {
876
+ type = "int256" + type.substring(3);
877
+ }
878
+ // @TODO: more verification
879
+ return type;
880
+ }
881
+ // See: https://github.com/ethereum/solidity/blob/1f8f1a3db93a548d0555e3e14cfc55a10e25b60e/docs/grammar/SolidityLexer.g4#L234
882
+ const regexIdentifier = new RegExp("^[a-zA-Z$_][a-zA-Z0-9$_]*$");
883
+ function verifyIdentifier(value) {
884
+ if (!value || !value.match(regexIdentifier)) {
885
+ logger.throwArgumentError(`invalid identifier "${value}"`, "value", value);
886
+ }
887
+ return value;
888
+ }
889
+ const regexParen = new RegExp("^([^)(]*)\\((.*)\\)([^)(]*)$");
890
+ function splitNesting(value) {
891
+ value = value.trim();
892
+ let result = [];
893
+ let accum = "";
894
+ let depth = 0;
895
+ for (let offset = 0; offset < value.length; offset++) {
896
+ let c = value[offset];
897
+ if (c === "," && depth === 0) {
898
+ result.push(accum);
899
+ accum = "";
900
+ }
901
+ else {
902
+ accum += c;
903
+ if (c === "(") {
904
+ depth++;
905
+ }
906
+ else if (c === ")") {
907
+ depth--;
908
+ if (depth === -1) {
909
+ logger.throwArgumentError("unbalanced parenthesis", "value", value);
910
+ }
911
+ }
912
+ }
913
+ }
914
+ if (accum) {
915
+ result.push(accum);
916
+ }
917
+ return result;
918
+ }
919
+ //# sourceMappingURL=fragments.js.map