@aeternity/aepp-sdk 12.0.0 → 12.1.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 (283) hide show
  1. package/dist/aepp-sdk.browser-script.js +1 -1
  2. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -15
  3. package/dist/aepp-sdk.browser-script.js.map +1 -1
  4. package/dist/aepp-sdk.browser.js +2 -1
  5. package/dist/aepp-sdk.browser.js.LICENSE.txt +1 -0
  6. package/dist/aepp-sdk.browser.js.map +1 -1
  7. package/dist/aepp-sdk.js +20764 -1
  8. package/dist/aepp-sdk.js.map +1 -1
  9. package/es/AeSdk.d.ts +7 -7
  10. package/es/AeSdk.mjs.map +1 -1
  11. package/es/AeSdkAepp.d.ts +4 -3
  12. package/es/AeSdkAepp.mjs +2 -1
  13. package/es/AeSdkAepp.mjs.map +1 -1
  14. package/es/AeSdkBase.d.ts +22 -21
  15. package/es/AeSdkBase.mjs +25 -21
  16. package/es/AeSdkBase.mjs.map +1 -1
  17. package/es/AeSdkWallet.d.ts +4 -3
  18. package/es/AeSdkWallet.mjs +5 -1
  19. package/es/AeSdkWallet.mjs.map +1 -1
  20. package/es/Node.d.ts +7 -10
  21. package/es/Node.mjs +63 -57
  22. package/es/Node.mjs.map +1 -1
  23. package/es/account/Base.d.ts +7 -4
  24. package/es/account/Base.mjs +3 -3
  25. package/es/account/Base.mjs.map +1 -1
  26. package/es/account/Memory.d.ts +5 -4
  27. package/es/account/Memory.mjs +24 -2
  28. package/es/account/Memory.mjs.map +1 -1
  29. package/es/account/Rpc.d.ts +6 -6
  30. package/es/account/Rpc.mjs +3 -2
  31. package/es/account/Rpc.mjs.map +1 -1
  32. package/es/aens.d.ts +27 -14
  33. package/es/aens.mjs +27 -21
  34. package/es/aens.mjs.map +1 -1
  35. package/es/aepp-wallet-communication/connection/Browser.d.ts +2 -1
  36. package/es/aepp-wallet-communication/connection/Browser.mjs +5 -2
  37. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
  38. package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
  39. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +1 -0
  40. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
  41. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +1 -0
  42. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +5 -1
  43. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
  44. package/es/aepp-wallet-communication/connection-proxy.d.ts +1 -0
  45. package/es/aepp-wallet-communication/connection-proxy.mjs +1 -0
  46. package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
  47. package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +1 -0
  48. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +5 -5
  49. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
  50. package/es/aepp-wallet-communication/rpc/types.d.ts +8 -8
  51. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
  52. package/es/aepp-wallet-communication/schema.d.ts +17 -2
  53. package/es/aepp-wallet-communication/schema.mjs +54 -17
  54. package/es/aepp-wallet-communication/schema.mjs.map +1 -1
  55. package/es/aepp-wallet-communication/wallet-detector.d.ts +2 -1
  56. package/es/aepp-wallet-communication/wallet-detector.mjs +2 -3
  57. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
  58. package/es/apis/node/models/index.d.ts +6 -2
  59. package/es/apis/node/models/index.mjs.map +1 -1
  60. package/es/apis/node/models/mappers.mjs +4 -2
  61. package/es/apis/node/models/mappers.mjs.map +1 -1
  62. package/es/chain.d.ts +92 -64
  63. package/es/chain.mjs +190 -154
  64. package/es/chain.mjs.map +1 -1
  65. package/es/channel/handlers.d.ts +3 -3
  66. package/es/channel/handlers.mjs +42 -44
  67. package/es/channel/handlers.mjs.map +1 -1
  68. package/es/channel/index.d.ts +43 -52
  69. package/es/channel/index.mjs +46 -49
  70. package/es/channel/index.mjs.map +1 -1
  71. package/es/channel/internal.d.ts +16 -15
  72. package/es/channel/internal.mjs +67 -62
  73. package/es/channel/internal.mjs.map +1 -1
  74. package/es/contract/Compiler.d.ts +1 -0
  75. package/es/contract/Compiler.mjs +5 -4
  76. package/es/contract/Compiler.mjs.map +1 -1
  77. package/es/contract/aci.d.ts +17 -15
  78. package/es/contract/aci.mjs +58 -45
  79. package/es/contract/aci.mjs.map +1 -1
  80. package/es/contract/ga.d.ts +16 -15
  81. package/es/contract/ga.mjs +12 -7
  82. package/es/contract/ga.mjs.map +1 -1
  83. package/es/contract/methods.d.ts +9 -6
  84. package/es/contract/methods.mjs +9 -6
  85. package/es/contract/methods.mjs.map +1 -1
  86. package/es/deprecated/index.d.ts +143 -0
  87. package/es/deprecated/index.mjs +162 -0
  88. package/es/deprecated/index.mjs.map +1 -0
  89. package/es/deprecated/methods.d.ts +18 -0
  90. package/es/deprecated/methods.mjs +26 -0
  91. package/es/deprecated/methods.mjs.map +1 -0
  92. package/es/index.d.ts +4 -1
  93. package/es/index.mjs +4 -1
  94. package/es/index.mjs.map +1 -1
  95. package/es/oracle.d.ts +69 -62
  96. package/es/oracle.mjs +121 -103
  97. package/es/oracle.mjs.map +1 -1
  98. package/es/spend.d.ts +16 -15
  99. package/es/spend.mjs +19 -30
  100. package/es/spend.mjs.map +1 -1
  101. package/es/tx/builder/address.d.ts +25 -0
  102. package/es/tx/builder/address.mjs +45 -0
  103. package/es/tx/builder/address.mjs.map +1 -0
  104. package/es/tx/builder/constants.d.ts +55 -26
  105. package/es/tx/builder/constants.mjs +60 -38
  106. package/es/tx/builder/constants.mjs.map +1 -1
  107. package/es/tx/builder/field-types/coin-amount.d.ts +13 -0
  108. package/es/tx/builder/field-types/coin-amount.mjs +26 -0
  109. package/es/tx/builder/field-types/coin-amount.mjs.map +1 -0
  110. package/es/tx/builder/field-types/deposit.d.ts +15 -0
  111. package/es/tx/builder/field-types/deposit.mjs +19 -0
  112. package/es/tx/builder/field-types/deposit.mjs.map +1 -0
  113. package/es/tx/builder/field-types/fee.d.ts +25 -0
  114. package/es/tx/{min-fee.mjs → builder/field-types/fee.mjs} +62 -60
  115. package/es/tx/builder/field-types/fee.mjs.map +1 -0
  116. package/es/tx/builder/field-types/field.d.ts +6 -0
  117. package/es/tx/builder/field-types/field.mjs +15 -0
  118. package/es/tx/builder/field-types/field.mjs.map +1 -0
  119. package/es/tx/builder/field-types/gas-limit.d.ts +12 -0
  120. package/es/tx/builder/field-types/gas-limit.mjs +33 -0
  121. package/es/tx/builder/field-types/gas-limit.mjs.map +1 -0
  122. package/es/tx/builder/field-types/gas-price.d.ts +8 -0
  123. package/es/tx/builder/field-types/gas-price.mjs +18 -0
  124. package/es/tx/builder/field-types/gas-price.mjs.map +1 -0
  125. package/es/tx/builder/field-types/index.d.ts +70 -0
  126. package/es/tx/builder/field-types/index.mjs +25 -0
  127. package/es/tx/builder/field-types/index.mjs.map +1 -0
  128. package/es/tx/builder/field-types/name-fee.d.ts +20 -0
  129. package/es/tx/builder/field-types/name-fee.mjs +24 -0
  130. package/es/tx/builder/field-types/name-fee.mjs.map +1 -0
  131. package/es/tx/builder/field-types/name-id.d.ts +14 -0
  132. package/es/tx/builder/field-types/name-id.mjs +19 -0
  133. package/es/tx/builder/field-types/name-id.mjs.map +1 -0
  134. package/es/tx/builder/field-types/name.d.ts +13 -0
  135. package/es/tx/builder/field-types/name.mjs +18 -0
  136. package/es/tx/builder/field-types/name.mjs.map +1 -0
  137. package/es/tx/builder/field-types/short-u-int.d.ts +6 -0
  138. package/es/tx/builder/field-types/short-u-int.mjs +12 -0
  139. package/es/tx/builder/field-types/short-u-int.mjs.map +1 -0
  140. package/es/tx/builder/field-types/u-int.d.ts +8 -0
  141. package/es/tx/builder/field-types/u-int.mjs +14 -0
  142. package/es/tx/builder/field-types/u-int.mjs.map +1 -0
  143. package/es/tx/builder/helpers.d.ts +27 -33
  144. package/es/tx/builder/helpers.mjs +41 -47
  145. package/es/tx/builder/helpers.mjs.map +1 -1
  146. package/es/tx/builder/index.d.ts +25 -12
  147. package/es/tx/builder/index.mjs +74 -83
  148. package/es/tx/builder/index.mjs.map +1 -1
  149. package/es/tx/builder/schema.d.ts +995 -144
  150. package/es/tx/builder/schema.mjs +121 -170
  151. package/es/tx/builder/schema.mjs.map +1 -1
  152. package/es/tx/index.d.ts +28 -27
  153. package/es/tx/index.mjs +97 -117
  154. package/es/tx/index.mjs.map +1 -1
  155. package/es/tx/validator.d.ts +4 -3
  156. package/es/tx/validator.mjs +79 -92
  157. package/es/tx/validator.mjs.map +1 -1
  158. package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -1
  159. package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -1
  160. package/es/typings/bip32-path/index.d.mjs.map +1 -1
  161. package/es/typings/blakejs/index.d.mjs.map +1 -1
  162. package/es/typings/sha-js/index.d.mjs +2 -0
  163. package/es/typings/sha-js/index.d.mjs.map +1 -0
  164. package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -1
  165. package/es/utils/amount-formatter.d.ts +9 -9
  166. package/es/utils/amount-formatter.mjs +17 -17
  167. package/es/utils/amount-formatter.mjs.map +1 -1
  168. package/es/utils/autorest.mjs +7 -7
  169. package/es/utils/autorest.mjs.map +1 -1
  170. package/es/utils/bignumber.mjs +2 -1
  171. package/es/utils/bignumber.mjs.map +1 -1
  172. package/es/utils/bytes.mjs +1 -1
  173. package/es/utils/bytes.mjs.map +1 -1
  174. package/es/utils/crypto.d.ts +8 -23
  175. package/es/utils/crypto.mjs +15 -41
  176. package/es/utils/crypto.mjs.map +1 -1
  177. package/es/utils/encoder-types.d.ts +61 -0
  178. package/es/utils/encoder-types.mjs +36 -0
  179. package/es/utils/encoder-types.mjs.map +1 -0
  180. package/es/utils/encoder.d.ts +6 -7
  181. package/es/utils/encoder.mjs +42 -26
  182. package/es/utils/encoder.mjs.map +1 -1
  183. package/es/utils/errors.d.ts +1 -11
  184. package/es/utils/errors.mjs +4 -20
  185. package/es/utils/errors.mjs.map +1 -1
  186. package/es/utils/hd-wallet.d.ts +18 -2
  187. package/es/utils/hd-wallet.mjs +64 -34
  188. package/es/utils/hd-wallet.mjs.map +1 -1
  189. package/es/utils/json-big.mjs +2 -2
  190. package/es/utils/json-big.mjs.map +1 -1
  191. package/es/utils/keystore.mjs +4 -2
  192. package/es/utils/keystore.mjs.map +1 -1
  193. package/es/utils/mptree.d.ts +2 -2
  194. package/es/utils/mptree.mjs +11 -6
  195. package/es/utils/mptree.mjs.map +1 -1
  196. package/es/utils/other.d.ts +8 -2
  197. package/es/utils/other.mjs +15 -3
  198. package/es/utils/other.mjs.map +1 -1
  199. package/es/utils/semver-satisfies.d.ts +1 -1
  200. package/es/utils/semver-satisfies.mjs +2 -2
  201. package/es/utils/semver-satisfies.mjs.map +1 -1
  202. package/es/utils/string.mjs.map +1 -1
  203. package/package.json +35 -33
  204. package/src/AeSdk.ts +30 -27
  205. package/src/AeSdkAepp.ts +93 -84
  206. package/src/AeSdkBase.ts +148 -130
  207. package/src/AeSdkWallet.ts +172 -156
  208. package/src/Node.ts +108 -102
  209. package/src/account/Base.ts +42 -32
  210. package/src/account/Memory.ts +45 -30
  211. package/src/account/Rpc.ts +32 -30
  212. package/src/aens.ts +124 -108
  213. package/src/aepp-wallet-communication/connection/Browser.ts +18 -15
  214. package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +22 -21
  215. package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +63 -52
  216. package/src/aepp-wallet-communication/connection-proxy.ts +8 -7
  217. package/src/aepp-wallet-communication/rpc/RpcClient.ts +67 -61
  218. package/src/aepp-wallet-communication/rpc/types.ts +32 -32
  219. package/src/aepp-wallet-communication/schema.ts +117 -74
  220. package/src/aepp-wallet-communication/wallet-detector.ts +29 -28
  221. package/src/apis/node/code-model-v4.yaml +54 -20
  222. package/src/apis/node/models/index.ts +6 -2
  223. package/src/apis/node/models/mappers.ts +4 -2
  224. package/src/chain.ts +286 -228
  225. package/src/channel/handlers.ts +424 -372
  226. package/src/channel/index.ts +285 -251
  227. package/src/channel/internal.ts +248 -232
  228. package/src/contract/Compiler.ts +22 -21
  229. package/src/contract/aci.ts +267 -258
  230. package/src/contract/ga.ts +93 -72
  231. package/src/contract/methods.ts +32 -27
  232. package/src/deprecated/index.ts +170 -0
  233. package/src/deprecated/methods.ts +25 -0
  234. package/src/index.ts +37 -32
  235. package/src/oracle.ts +211 -189
  236. package/src/spend.ts +82 -70
  237. package/src/tx/builder/address.ts +50 -0
  238. package/src/tx/builder/constants.ts +82 -52
  239. package/src/tx/builder/field-types/coin-amount.ts +27 -0
  240. package/src/tx/builder/field-types/deposit.ts +21 -0
  241. package/src/tx/builder/field-types/fee.ts +143 -0
  242. package/src/tx/builder/field-types/field.ts +9 -0
  243. package/src/tx/builder/field-types/gas-limit.ts +41 -0
  244. package/src/tx/builder/field-types/gas-price.ts +16 -0
  245. package/src/tx/builder/field-types/index.ts +45 -0
  246. package/src/tx/builder/field-types/name-fee.ts +32 -0
  247. package/src/tx/builder/field-types/name-id.ts +20 -0
  248. package/src/tx/builder/field-types/name.ts +18 -0
  249. package/src/tx/builder/field-types/short-u-int.ts +11 -0
  250. package/src/tx/builder/field-types/u-int.ts +16 -0
  251. package/src/tx/builder/helpers.ts +112 -117
  252. package/src/tx/builder/index.ts +203 -197
  253. package/src/tx/builder/schema.ts +421 -465
  254. package/src/tx/index.ts +128 -135
  255. package/src/tx/validator.ts +165 -161
  256. package/src/typings/@aeternity__argon2-browser/index.d.ts +1 -1
  257. package/src/typings/@aeternity__uuid/index.d.ts +3 -1
  258. package/src/typings/bip32-path/index.d.ts +6 -6
  259. package/src/typings/blakejs/index.d.ts +4 -32
  260. package/src/typings/sha-js/index.d.ts +5 -0
  261. package/src/typings/tweetnacl-auth/index.d.ts +2 -2
  262. package/src/utils/amount-formatter.ts +41 -41
  263. package/src/utils/autorest.ts +57 -54
  264. package/src/utils/bignumber.ts +7 -6
  265. package/src/utils/bytes.ts +19 -19
  266. package/src/utils/crypto.ts +82 -94
  267. package/src/utils/encoder-types.ts +63 -0
  268. package/src/utils/encoder.ts +104 -56
  269. package/src/utils/errors.ts +246 -264
  270. package/src/utils/hd-wallet.ts +114 -82
  271. package/src/utils/json-big.ts +16 -15
  272. package/src/utils/keystore.ts +65 -62
  273. package/src/utils/mptree.ts +59 -56
  274. package/src/utils/other.ts +26 -18
  275. package/src/utils/semver-satisfies.ts +15 -11
  276. package/src/utils/string.ts +10 -10
  277. package/es/tx/builder/field-types.d.ts +0 -62
  278. package/es/tx/builder/field-types.mjs +0 -126
  279. package/es/tx/builder/field-types.mjs.map +0 -1
  280. package/es/tx/min-fee.d.ts +0 -20
  281. package/es/tx/min-fee.mjs.map +0 -1
  282. package/src/tx/builder/field-types.ts +0 -111
  283. package/src/tx/min-fee.ts +0 -136
package/es/chain.mjs CHANGED
@@ -17,9 +17,14 @@
17
17
  import { AE_AMOUNT_FORMATS, formatAmount } from "./utils/amount-formatter.mjs";
18
18
  import verifyTransaction from "./tx/validator.mjs";
19
19
  import { pause } from "./utils/other.mjs";
20
- import { isNameValid, produceNameId, decode } from "./tx/builder/helpers.mjs";
20
+ import { isNameValid, produceNameId } from "./tx/builder/helpers.mjs";
21
21
  import { DRY_RUN_ACCOUNT } from "./tx/builder/schema.mjs";
22
- import { AensPointerContextError, DryRunError, InvalidAensNameError, InvalidTxError, RequestTimedOutError, TxTimedOutError, TxNotInChainError, InternalError } from "./utils/errors.mjs";
22
+ import { AensPointerContextError, DryRunError, InvalidAensNameError, TransactionError, TxTimedOutError, TxNotInChainError, InternalError } from "./utils/errors.mjs";
23
+ import { decode } from "./utils/encoder.mjs";
24
+
25
+ /**
26
+ * @category chain
27
+ */
23
28
  export function _getPollInterval(type, _ref) {
24
29
  let {
25
30
  _expectedMineRate = 180000,
@@ -32,8 +37,139 @@ export function _getPollInterval(type, _ref) {
32
37
  }[type];
33
38
  return Math.min(base / 3, _maxPollInterval);
34
39
  }
40
+ /**
41
+ * @category exception
42
+ */
43
+
44
+ export class InvalidTxError extends TransactionError {
45
+ constructor(message, validation, transaction) {
46
+ super(message);
47
+ this.name = 'InvalidTxError';
48
+ this.validation = validation;
49
+ this.transaction = transaction;
50
+ }
51
+
52
+ }
53
+ /**
54
+ * Obtain current height of the chain
55
+ * @category chain
56
+ * @returns Current chain height
57
+ */
58
+
59
+ export async function getHeight(_ref2) {
60
+ let {
61
+ onNode
62
+ } = _ref2;
63
+ return (await onNode.getCurrentKeyBlockHeight()).height;
64
+ }
65
+ /**
66
+ * Wait for a transaction to be mined
67
+ * @category chain
68
+ * @param th - The hash of transaction to poll
69
+ * @param options - Options
70
+ * @param options.interval - Interval (in ms) at which to poll the chain
71
+ * @param options.blocks - Number of blocks mined after which to fail
72
+ * @param options.onNode - Node to use
73
+ * @returns The transaction as it was mined
74
+ */
75
+
76
+ export async function poll(th, _ref3) {
77
+ var _interval;
78
+
79
+ let {
80
+ blocks = 10,
81
+ interval,
82
+ onNode,
83
+ ...options
84
+ } = _ref3;
85
+ (_interval = interval) !== null && _interval !== void 0 ? _interval : interval = _getPollInterval('microblock', options);
86
+ const max = (await getHeight({
87
+ onNode
88
+ })) + blocks;
89
+
90
+ do {
91
+ const tx = await onNode.getTransactionByHash(th);
92
+ if (tx.blockHeight !== -1) return tx;
93
+ await pause(interval);
94
+ } while ((await getHeight({
95
+ onNode
96
+ })) < max);
97
+
98
+ throw new TxTimedOutError(blocks, th);
99
+ }
100
+ /**
101
+ * Wait for the chain to reach a specific height
102
+ * @category chain
103
+ * @param height - Height to wait for
104
+ * @param options - Options
105
+ * @param options.interval - Interval (in ms) at which to poll the chain
106
+ * @param options.onNode - Node to use
107
+ * @returns Current chain height
108
+ */
109
+
110
+ export async function awaitHeight(height, _ref4) {
111
+ var _interval2;
112
+
113
+ let {
114
+ interval,
115
+ onNode,
116
+ ...options
117
+ } = _ref4;
118
+ (_interval2 = interval) !== null && _interval2 !== void 0 ? _interval2 : interval = _getPollInterval('block', options);
119
+ let currentHeight;
120
+
121
+ do {
122
+ if (currentHeight != null) await pause(interval);
123
+ currentHeight = (await onNode.getCurrentKeyBlockHeight()).height;
124
+ } while (currentHeight < height);
125
+
126
+ return currentHeight;
127
+ }
128
+ /**
129
+ * Wait for transaction confirmation
130
+ * @category chain
131
+ * @param txHash - Transaction hash
132
+ * @param options - Options
133
+ * @param options.confirm - Number of micro blocks to wait for transaction confirmation
134
+ * @param options.onNode - Node to use
135
+ * @returns Current Height
136
+ */
137
+
138
+ export async function waitForTxConfirm(txHash, _ref5) {
139
+ let {
140
+ confirm = 3,
141
+ onNode,
142
+ ...options
143
+ } = _ref5;
144
+ const {
145
+ blockHeight
146
+ } = await onNode.getTransactionByHash(txHash);
147
+ const height = await awaitHeight(blockHeight + confirm, {
148
+ onNode,
149
+ ...options
150
+ });
151
+ const {
152
+ blockHeight: newBlockHeight
153
+ } = await onNode.getTransactionByHash(txHash);
154
+
155
+ switch (newBlockHeight) {
156
+ case -1:
157
+ throw new TxNotInChainError(txHash);
158
+
159
+ case blockHeight:
160
+ return height;
161
+
162
+ default:
163
+ return waitForTxConfirm(txHash, {
164
+ onNode,
165
+ confirm,
166
+ ...options
167
+ });
168
+ }
169
+ }
35
170
  /**
36
171
  * Submit a signed transaction for mining
172
+ * @category chain
37
173
  * @param tx - Transaction to submit
38
174
  * @param options - Options
39
175
  * @param options.onNode - Node to use
@@ -44,7 +180,7 @@ export function _getPollInterval(type, _ref) {
44
180
  * @returns Transaction details
45
181
  */
46
182
 
47
- export async function sendTransaction(tx, _ref2) {
183
+ export async function sendTransaction(tx, _ref6) {
48
184
  let {
49
185
  onNode,
50
186
  onAccount,
@@ -52,31 +188,37 @@ export async function sendTransaction(tx, _ref2) {
52
188
  waitMined = true,
53
189
  confirm,
54
190
  ...options
55
- } = _ref2;
191
+ } = _ref6;
56
192
 
57
193
  if (verify) {
58
194
  const validation = await verifyTransaction(tx, onNode);
59
195
 
60
196
  if (validation.length > 0) {
61
- const message = 'Transaction verification errors: ' + validation.map(v => v.message).join(', ');
197
+ const message = `Transaction verification errors: ${validation.map(v => v.message).join(', ')}`;
62
198
  throw new InvalidTxError(message, validation, tx);
63
199
  }
64
200
  }
65
201
 
66
202
  try {
67
- var _await$onAccount$addr;
203
+ let __queue;
204
+
205
+ try {
206
+ __queue = onAccount != null ? `tx-${await onAccount.address(options)}` : null;
207
+ } catch (error) {
208
+ __queue = null;
209
+ }
68
210
 
69
211
  const {
70
212
  txHash
71
213
  } = await onNode.postTransaction({
72
214
  tx
73
- }, {
215
+ }, __queue != null ? {
74
216
  requestOptions: {
75
217
  customHeaders: {
76
- __queue: `tx-${(_await$onAccount$addr = await (onAccount === null || onAccount === void 0 ? void 0 : onAccount.address(options).catch(() => ''))) !== null && _await$onAccount$addr !== void 0 ? _await$onAccount$addr : ''}`
218
+ __queue
77
219
  }
78
220
  }
79
- });
221
+ } : {});
80
222
 
81
223
  if (waitMined) {
82
224
  const pollResult = await poll(txHash, {
@@ -109,72 +251,33 @@ export async function sendTransaction(tx, _ref2) {
109
251
  } catch (error) {
110
252
  throw Object.assign(error, {
111
253
  rawTx: tx,
112
- verifyTx: async () => await verifyTransaction(tx, onNode)
254
+ verifyTx: async () => verifyTransaction(tx, onNode)
113
255
  });
114
256
  }
115
257
  }
116
258
 
117
- /**
118
- * Wait for transaction confirmation
119
- * @param txHash - Transaction hash
120
- * @param options - Options
121
- * @param options.confirm - Number of micro blocks to wait for transaction confirmation
122
- * @param options.onNode - Node to use
123
- * @returns Current Height
124
- */
125
- export async function waitForTxConfirm(txHash, _ref3) {
126
- let {
127
- confirm = 3,
128
- onNode,
129
- ...options
130
- } = _ref3;
131
- const {
132
- blockHeight
133
- } = await onNode.getTransactionByHash(txHash);
134
- const height = await awaitHeight(blockHeight + confirm, {
135
- onNode,
136
- ...options
137
- });
138
- const {
139
- blockHeight: newBlockHeight
140
- } = await onNode.getTransactionByHash(txHash);
141
-
142
- switch (newBlockHeight) {
143
- case -1:
144
- throw new TxNotInChainError(txHash);
145
-
146
- case blockHeight:
147
- return height;
148
-
149
- default:
150
- return await waitForTxConfirm(txHash, {
151
- onNode,
152
- confirm,
153
- ...options
154
- });
155
- }
156
- }
157
259
  /**
158
260
  * Get account by account public key
261
+ * @category chain
159
262
  * @param address - Account address (public key)
160
263
  * @param options - Options
161
264
  * @param options.height - Get account on specific block by block height
162
265
  * @param options.hash - Get account on specific block by micro block hash or key block hash
163
266
  * @param options.onNode - Node to use
164
267
  */
165
-
166
- export async function getAccount(address, _ref4) {
268
+ export async function getAccount(address, _ref7) {
167
269
  let {
168
270
  height,
169
271
  hash,
170
272
  onNode
171
- } = _ref4;
172
- if (height != null) return await onNode.getAccountByPubkeyAndHeight(address, height);
173
- if (hash != null) return await onNode.getAccountByPubkeyAndHash(address, hash);
174
- return await onNode.getAccountByPubkey(address);
273
+ } = _ref7;
274
+ if (height != null) return onNode.getAccountByPubkeyAndHeight(address, height);
275
+ if (hash != null) return onNode.getAccountByPubkeyAndHash(address, hash);
276
+ return onNode.getAccountByPubkey(address);
175
277
  }
176
278
  /**
177
279
  * Request the balance of specified account
280
+ * @category chain
178
281
  * @param address - The public account address to obtain the balance for
179
282
  * @param options - Options
180
283
  * @param options.format
@@ -183,11 +286,11 @@ export async function getAccount(address, _ref4) {
183
286
  * @param options.hash - The block hash on which to obtain the balance for (default: top of chain)
184
287
  */
185
288
 
186
- export async function getBalance(address, _ref5) {
289
+ export async function getBalance(address, _ref8) {
187
290
  let {
188
291
  format = AE_AMOUNT_FORMATS.AETTOS,
189
292
  ...options
190
- } = _ref5;
293
+ } = _ref8;
191
294
  const {
192
295
  balance
193
296
  } = await getAccount(address, options).catch(() => ({
@@ -197,83 +300,9 @@ export async function getBalance(address, _ref5) {
197
300
  targetDenomination: format
198
301
  });
199
302
  }
200
- /**
201
- * Obtain current height of the chain
202
- * @returns Current chain height
203
- */
204
-
205
- export async function height(_ref6) {
206
- let {
207
- onNode
208
- } = _ref6;
209
- return (await onNode.getCurrentKeyBlockHeight()).height;
210
- }
211
- /**
212
- * Wait for the chain to reach a specific height
213
- * @param height - Height to wait for
214
- * @param options - Options
215
- * @param options.interval - Interval (in ms) at which to poll the chain
216
- * @param options.attempts - Number of polling attempts after which to fail
217
- * @param options.onNode - Node to use
218
- * @returns Current chain height
219
- */
220
-
221
- export async function awaitHeight(height, _ref7) {
222
- var _interval;
223
-
224
- let {
225
- interval,
226
- attempts = 20,
227
- onNode,
228
- ...options
229
- } = _ref7;
230
- (_interval = interval) !== null && _interval !== void 0 ? _interval : interval = _getPollInterval('block', options);
231
- let currentHeight;
232
-
233
- for (let i = 0; i < attempts; i++) {
234
- if (i !== 0) await pause(interval);
235
- currentHeight = (await onNode.getCurrentKeyBlockHeight()).height;
236
- if (currentHeight >= height) return currentHeight;
237
- }
238
-
239
- throw new RequestTimedOutError((attempts - 1) * interval, currentHeight, height);
240
- }
241
- /**
242
- * Wait for a transaction to be mined
243
- * @param th - The hash of transaction to poll
244
- * @param options - Options
245
- * @param options.interval - Interval (in ms) at which to poll the chain
246
- * @param options.blocks - Number of blocks mined after which to fail
247
- * @param options.onNode - Node to use
248
- * @returns The transaction as it was mined
249
- */
250
-
251
- export async function poll(th, _ref8) {
252
- var _interval2;
253
-
254
- let {
255
- blocks = 10,
256
- interval,
257
- onNode,
258
- ...options
259
- } = _ref8;
260
- (_interval2 = interval) !== null && _interval2 !== void 0 ? _interval2 : interval = _getPollInterval('microblock', options);
261
- const max = (await height({
262
- onNode
263
- })) + blocks;
264
-
265
- do {
266
- const tx = await onNode.getTransactionByHash(th);
267
- if (tx.blockHeight !== -1) return tx;
268
- await pause(interval);
269
- } while ((await height({
270
- onNode
271
- })) < max);
272
-
273
- throw new TxTimedOutError(blocks, th);
274
- }
275
303
  /**
276
304
  * Obtain current generation
305
+ * @category chain
277
306
  * @param options - Options
278
307
  * @param options.onNode - Node to use
279
308
  * @returns Current Generation
@@ -283,10 +312,11 @@ export async function getCurrentGeneration(_ref9) {
283
312
  let {
284
313
  onNode
285
314
  } = _ref9;
286
- return await onNode.getCurrentGeneration();
315
+ return onNode.getCurrentGeneration();
287
316
  }
288
317
  /**
289
318
  * Get generation by hash or height
319
+ * @category chain
290
320
  * @param hashOrHeight - Generation hash or height
291
321
  * @param options - Options
292
322
  * @param options.onNode - Node to use
@@ -297,11 +327,12 @@ export async function getGeneration(hashOrHeight, _ref10) {
297
327
  let {
298
328
  onNode
299
329
  } = _ref10;
300
- if (typeof hashOrHeight === 'number') return await onNode.getGenerationByHeight(hashOrHeight);
301
- return await onNode.getGenerationByHash(hashOrHeight);
330
+ if (typeof hashOrHeight === 'number') return onNode.getGenerationByHeight(hashOrHeight);
331
+ return onNode.getGenerationByHash(hashOrHeight);
302
332
  }
303
333
  /**
304
334
  * Get micro block transactions
335
+ * @category chain
305
336
  * @param hash - Micro block hash
306
337
  * @param options - Options
307
338
  * @param options.onNode - Node to use
@@ -316,6 +347,7 @@ export async function getMicroBlockTransactions(hash, _ref11) {
316
347
  }
317
348
  /**
318
349
  * Get key block
350
+ * @category chain
319
351
  * @param hashOrHeight - Key block hash or height
320
352
  * @param options - Options
321
353
  * @param options.onNode - Node to use
@@ -326,11 +358,12 @@ export async function getKeyBlock(hashOrHeight, _ref12) {
326
358
  let {
327
359
  onNode
328
360
  } = _ref12;
329
- if (typeof hashOrHeight === 'number') return await onNode.getKeyBlockByHeight(hashOrHeight);
330
- return await onNode.getKeyBlockByHash(hashOrHeight);
361
+ if (typeof hashOrHeight === 'number') return onNode.getKeyBlockByHeight(hashOrHeight);
362
+ return onNode.getKeyBlockByHash(hashOrHeight);
331
363
  }
332
364
  /**
333
365
  * Get micro block header
366
+ * @category chain
334
367
  * @param hash - Micro block hash
335
368
  * @param options - Options
336
369
  * @param options.onNode - Node to use
@@ -341,7 +374,7 @@ export async function getMicroBlockHeader(hash, _ref13) {
341
374
  let {
342
375
  onNode
343
376
  } = _ref13;
344
- return await onNode.getMicroBlockHeaderByHash(hash);
377
+ return onNode.getMicroBlockHeaderByHash(hash);
345
378
  }
346
379
  const txDryRunRequests = new Map();
347
380
 
@@ -389,10 +422,9 @@ async function txDryRunHandler(key, onNode) {
389
422
  tx,
390
423
  accountAddress
391
424
  } = rs[idx];
392
- if (result === 'ok') return resolve({ ...resultPayload,
425
+ if (result === 'ok') resolve({ ...resultPayload,
393
426
  txEvents
394
- });
395
- reject(Object.assign(new DryRunError(reason), {
427
+ });else reject(Object.assign(new DryRunError(reason), {
396
428
  tx,
397
429
  accountAddress
398
430
  }));
@@ -400,6 +432,7 @@ async function txDryRunHandler(key, onNode) {
400
432
  }
401
433
  /**
402
434
  * Transaction dry-run
435
+ * @category chain
403
436
  * @param tx - transaction to execute
404
437
  * @param accountAddress - address that will be used to execute transaction
405
438
  * @param options - Options
@@ -422,7 +455,7 @@ export async function txDryRun(tx, accountAddress, _ref16) {
422
455
  const key = combine === true ? [top, txEvents].join() : 'immediate';
423
456
  const requests = (_txDryRunRequests$get = txDryRunRequests.get(key)) !== null && _txDryRunRequests$get !== void 0 ? _txDryRunRequests$get : [];
424
457
  txDryRunRequests.set(key, requests);
425
- return await new Promise((resolve, reject) => {
458
+ return new Promise((resolve, reject) => {
426
459
  var _requests$timeout;
427
460
 
428
461
  requests.push({
@@ -446,6 +479,7 @@ export async function txDryRun(tx, accountAddress, _ref16) {
446
479
  }
447
480
  /**
448
481
  * Get contract byte code
482
+ * @category contract
449
483
  * @param contractId - Contract address
450
484
  * @param options - Options
451
485
  * @param options.onNode - Node to use
@@ -455,10 +489,11 @@ export async function getContractByteCode(contractId, _ref17) {
455
489
  let {
456
490
  onNode
457
491
  } = _ref17;
458
- return await onNode.getContractCode(contractId);
492
+ return onNode.getContractCode(contractId);
459
493
  }
460
494
  /**
461
495
  * Get contract entry
496
+ * @category contract
462
497
  * @param contractId - Contract address
463
498
  * @param options - Options
464
499
  * @param options.onNode - Node to use
@@ -468,10 +503,11 @@ export async function getContract(contractId, _ref18) {
468
503
  let {
469
504
  onNode
470
505
  } = _ref18;
471
- return await onNode.getContract(contractId);
506
+ return onNode.getContract(contractId);
472
507
  }
473
508
  /**
474
509
  * Get name entry
510
+ * @category AENS
475
511
  * @param name - AENS name
476
512
  * @param options - Options
477
513
  * @param options.onNode - Node to use
@@ -481,10 +517,11 @@ export async function getName(name, _ref19) {
481
517
  let {
482
518
  onNode
483
519
  } = _ref19;
484
- return await onNode.getNameEntryByName(name);
520
+ return onNode.getNameEntryByName(name);
485
521
  }
486
522
  /**
487
523
  * Resolve AENS name and return name hash
524
+ * @category AENS
488
525
  * @param nameOrId - AENS name or address
489
526
  * @param key - in AENS pointers record
490
527
  * @param options - Options
@@ -502,16 +539,10 @@ export async function resolveName(nameOrId, key, _ref20) {
502
539
  onNode
503
540
  } = _ref20;
504
541
 
505
- try {
506
- const id = nameOrId;
507
- decode(id);
508
- return id;
509
- } catch (error) {}
510
-
511
542
  if (isNameValid(nameOrId)) {
512
543
  if (verify || resolveByNode) {
513
544
  const name = await onNode.getNameEntryByName(nameOrId);
514
- const pointer = name.pointers.find(pointer => pointer.key === key);
545
+ const pointer = name.pointers.find(p => p.key === key);
515
546
  if (pointer == null) throw new AensPointerContextError(nameOrId, key);
516
547
  if (resolveByNode) return pointer.id;
517
548
  }
@@ -519,6 +550,11 @@ export async function resolveName(nameOrId, key, _ref20) {
519
550
  return produceNameId(nameOrId);
520
551
  }
521
552
 
522
- throw new InvalidAensNameError(`Invalid name or address: ${nameOrId}`);
553
+ try {
554
+ decode(nameOrId);
555
+ return nameOrId;
556
+ } catch (error) {
557
+ throw new InvalidAensNameError(`Invalid name or address: ${nameOrId}`);
558
+ }
523
559
  }
524
560
  //# sourceMappingURL=chain.mjs.map