@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.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"chain.mjs","names":["AE_AMOUNT_FORMATS","formatAmount","verifyTransaction","pause","isNameValid","produceNameId","decode","DRY_RUN_ACCOUNT","AensPointerContextError","DryRunError","InvalidAensNameError","InvalidTxError","RequestTimedOutError","TxTimedOutError","TxNotInChainError","InternalError","_getPollInterval","type","_expectedMineRate","_microBlockCycle","_maxPollInterval","base","block","microblock","Math","min","sendTransaction","tx","onNode","onAccount","verify","waitMined","confirm","options","validation","length","message","map","v","join","txHash","postTransaction","requestOptions","customHeaders","__queue","address","catch","pollResult","poll","txData","hash","rawTx","c","undefined","confirmationHeight","waitForTxConfirm","error","Object","assign","verifyTx","blockHeight","getTransactionByHash","height","awaitHeight","newBlockHeight","getAccount","getAccountByPubkeyAndHeight","getAccountByPubkeyAndHash","getAccountByPubkey","getBalance","format","AETTOS","balance","targetDenomination","getCurrentKeyBlockHeight","interval","attempts","currentHeight","i","th","blocks","max","getCurrentGeneration","getGeneration","hashOrHeight","getGenerationByHeight","getGenerationByHash","getMicroBlockTransactions","getMicroBlockTransactionsByHash","transactions","getKeyBlock","getKeyBlockByHeight","getKeyBlockByHash","getMicroBlockHeader","getMicroBlockHeaderByHash","txDryRunRequests","Map","txDryRunHandler","key","rs","get","delete","dryRunRes","protectedDryRunTxs","top","txEvents","txs","req","accounts","Array","from","Set","accountAddress","pubKey","amount","forEach","reject","results","idx","result","reason","resultPayload","resolve","txDryRun","combine","requests","set","Promise","push","timeout","setTimeout","getContractByteCode","contractId","getContractCode","getContract","getName","name","getNameEntryByName","resolveName","nameOrId","resolveByNode","id","pointer","pointers","find"],"sources":["../src/chain.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2022 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\nimport { AE_AMOUNT_FORMATS, formatAmount } from './utils/amount-formatter'\nimport verifyTransaction from './tx/validator'\nimport { pause } from './utils/other'\nimport { isNameValid, produceNameId, decode } from './tx/builder/helpers'\nimport { DRY_RUN_ACCOUNT, AensName } from './tx/builder/schema'\nimport {\n AensPointerContextError, DryRunError, InvalidAensNameError, InvalidTxError,\n RequestTimedOutError, TxTimedOutError, TxNotInChainError, InternalError\n} from './utils/errors'\nimport Node, { TransformNodeType } from './Node'\nimport {\n Account as AccountNode, ByteCode, ContractObject, DryRunResult, DryRunResults,\n Generation, KeyBlock, MicroBlockHeader, NameEntry, SignedTx\n} from './apis/node'\nimport { EncodedData } from './utils/encoder'\nimport AccountBase from './account/Base'\n\nexport function _getPollInterval (\n type: 'block' | 'microblock',\n { _expectedMineRate = 180000, _microBlockCycle = 3000, _maxPollInterval = 5000 }:\n { _expectedMineRate?: number, _microBlockCycle?: number, _maxPollInterval?: number }\n): number {\n const base = {\n block: _expectedMineRate,\n microblock: _microBlockCycle\n }[type]\n return Math.min(base / 3, _maxPollInterval)\n}\n\n/**\n * Submit a signed transaction for mining\n * @param tx - Transaction to submit\n * @param options - Options\n * @param options.onNode - Node to use\n * @param options.onAccount - Account to use\n * @param options.verify - Verify transaction before sending\n * @param options.waitMined - Ensure that transaction get into block\n * @param options.confirm - Number of micro blocks that should be mined after tx get included\n * @returns Transaction details\n */\nexport async function sendTransaction (\n tx: EncodedData<'tx'>,\n { onNode, onAccount, verify = true, waitMined = true, confirm, ...options }:\n SendTransactionOptions\n): Promise<SendTransactionReturnType> {\n if (verify) {\n const validation = await verifyTransaction(tx, onNode)\n if (validation.length > 0) {\n const message = 'Transaction verification errors: ' +\n validation.map((v: { message: string }) => v.message).join(', ')\n throw new InvalidTxError(message, validation, tx)\n }\n }\n\n try {\n const { txHash } = await onNode.postTransaction({ tx }, {\n requestOptions: {\n customHeaders: {\n __queue: `tx-${await onAccount?.address(options).catch(() => '') ?? ''}`\n }\n }\n })\n\n if (waitMined) {\n const pollResult = await poll(txHash, { onNode, ...options })\n const txData = {\n ...pollResult,\n hash: pollResult.hash as EncodedData<'th'>,\n rawTx: tx\n }\n // wait for transaction confirmation\n if (confirm != null && (confirm === true || confirm > 0)) {\n const c = typeof confirm === 'boolean' ? undefined : confirm\n return {\n ...txData,\n confirmationHeight: await waitForTxConfirm(txHash, { onNode, confirm: c, ...options })\n }\n }\n return txData\n }\n return { hash: txHash, rawTx: tx }\n } catch (error) {\n throw Object.assign(error, {\n rawTx: tx,\n verifyTx: async () => await verifyTransaction(tx, onNode)\n })\n }\n}\n\ntype SendTransactionOptionsType = {\n onNode: Node\n onAccount?: AccountBase\n verify?: boolean\n waitMined?: boolean\n confirm?: boolean | number\n} & Parameters<typeof poll>[1] & Omit<Parameters<typeof waitForTxConfirm>[1], 'confirm'>\ninterface SendTransactionOptions extends SendTransactionOptionsType {}\ninterface SendTransactionReturnType extends Partial<TransformNodeType<SignedTx>> {\n hash: EncodedData<'th'>\n rawTx: EncodedData<'tx'>\n confirmationHeight?: number\n}\n\n/**\n * Wait for transaction confirmation\n * @param txHash - Transaction hash\n * @param options - Options\n * @param options.confirm - Number of micro blocks to wait for transaction confirmation\n * @param options.onNode - Node to use\n * @returns Current Height\n */\nexport async function waitForTxConfirm (\n txHash: EncodedData<'th'>,\n { confirm = 3, onNode, ...options }:\n { confirm?: number, onNode: Node } & Parameters<typeof awaitHeight>[1]\n): Promise<number> {\n const { blockHeight } = await onNode.getTransactionByHash(txHash)\n const height = await awaitHeight(blockHeight + confirm, { onNode, ...options })\n const { blockHeight: newBlockHeight } = await onNode.getTransactionByHash(txHash)\n switch (newBlockHeight) {\n case -1:\n throw new TxNotInChainError(txHash)\n case blockHeight:\n return height\n default:\n return await waitForTxConfirm(txHash, { onNode, confirm, ...options })\n }\n}\n\n/**\n * Get account by account public key\n * @param address - Account address (public key)\n * @param options - Options\n * @param options.height - Get account on specific block by block height\n * @param options.hash - Get account on specific block by micro block hash or key block hash\n * @param options.onNode - Node to use\n */\nexport async function getAccount (\n address: EncodedData<'ak' | 'ct'>,\n { height, hash, onNode }:\n { height?: number, hash?: EncodedData<'kh' | 'mh'>, onNode: Node }\n): Promise<TransformNodeType<AccountNode>> {\n if (height != null) return await onNode.getAccountByPubkeyAndHeight(address, height)\n if (hash != null) return await onNode.getAccountByPubkeyAndHash(address, hash)\n return await onNode.getAccountByPubkey(address)\n}\n\n/**\n * Request the balance of specified account\n * @param address - The public account address to obtain the balance for\n * @param options - Options\n * @param options.format\n * @param options.height - The chain height at which to obtain the balance for\n * (default: top of chain)\n * @param options.hash - The block hash on which to obtain the balance for (default: top of chain)\n */\nexport async function getBalance (\n address: EncodedData<'ak' | 'ct'>,\n { format = AE_AMOUNT_FORMATS.AETTOS, ...options }:\n { format?: AE_AMOUNT_FORMATS } & Parameters<typeof getAccount>[1]\n): Promise<string> {\n const { balance } = await getAccount(address, options).catch(() => ({ balance: 0n }))\n\n return formatAmount(balance, { targetDenomination: format })\n}\n\n/**\n * Obtain current height of the chain\n * @returns Current chain height\n */\nexport async function height ({ onNode }: { onNode: Node }): Promise<number> {\n return (await onNode.getCurrentKeyBlockHeight()).height\n}\n\n/**\n * Wait for the chain to reach a specific height\n * @param height - Height to wait for\n * @param options - Options\n * @param options.interval - Interval (in ms) at which to poll the chain\n * @param options.attempts - Number of polling attempts after which to fail\n * @param options.onNode - Node to use\n * @returns Current chain height\n */\nexport async function awaitHeight (\n height: number,\n { interval, attempts = 20, onNode, ...options }:\n { interval?: number, attempts?: number, onNode: Node }\n & Parameters<typeof _getPollInterval>[1]\n): Promise<number> {\n interval ??= _getPollInterval('block', options)\n let currentHeight\n for (let i = 0; i < attempts; i++) {\n if (i !== 0) await pause(interval)\n currentHeight = (await onNode.getCurrentKeyBlockHeight()).height\n if (currentHeight >= height) return currentHeight\n }\n throw new RequestTimedOutError((attempts - 1) * interval, currentHeight, height)\n}\n\n/**\n * Wait for a transaction to be mined\n * @param th - The hash of transaction to poll\n * @param options - Options\n * @param options.interval - Interval (in ms) at which to poll the chain\n * @param options.blocks - Number of blocks mined after which to fail\n * @param options.onNode - Node to use\n * @returns The transaction as it was mined\n */\nexport async function poll (\n th: EncodedData<'th'>,\n { blocks = 10, interval, onNode, ...options }:\n { blocks?: number, interval?: number, onNode: Node } & Parameters<typeof _getPollInterval>[1]\n): Promise<TransformNodeType<SignedTx>> {\n interval ??= _getPollInterval('microblock', options)\n const max = await height({ onNode }) + blocks\n do {\n const tx = await onNode.getTransactionByHash(th)\n if (tx.blockHeight !== -1) return tx\n await pause(interval)\n } while (await height({ onNode }) < max)\n throw new TxTimedOutError(blocks, th)\n}\n\n/**\n * Obtain current generation\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Current Generation\n */\nexport async function getCurrentGeneration (\n { onNode }: { onNode: Node }\n): Promise<TransformNodeType<Generation>> {\n return await onNode.getCurrentGeneration()\n}\n\n/**\n * Get generation by hash or height\n * @param hashOrHeight - Generation hash or height\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Generation\n */\nexport async function getGeneration (\n hashOrHeight: EncodedData<'kh'> | number, { onNode }: { onNode: Node }\n): Promise<TransformNodeType<Generation>> {\n if (typeof hashOrHeight === 'number') return await onNode.getGenerationByHeight(hashOrHeight)\n return await onNode.getGenerationByHash(hashOrHeight)\n}\n\n/**\n * Get micro block transactions\n * @param hash - Micro block hash\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Transactions\n */\nexport async function getMicroBlockTransactions (\n hash: EncodedData<'mh'>, { onNode }: { onNode: Node }\n): Promise<TransformNodeType<SignedTx[]>> {\n return (await onNode.getMicroBlockTransactionsByHash(hash)).transactions\n}\n\n/**\n * Get key block\n * @param hashOrHeight - Key block hash or height\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Key Block\n */\nexport async function getKeyBlock (\n hashOrHeight: EncodedData<'kh'> | number, { onNode }: { onNode: Node }\n): Promise<TransformNodeType<KeyBlock>> {\n if (typeof hashOrHeight === 'number') return await onNode.getKeyBlockByHeight(hashOrHeight)\n return await onNode.getKeyBlockByHash(hashOrHeight)\n}\n\n/**\n * Get micro block header\n * @param hash - Micro block hash\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Micro block header\n */\nexport async function getMicroBlockHeader (\n hash: EncodedData<'mh'>, { onNode }: { onNode: Node }\n): Promise<TransformNodeType<MicroBlockHeader>> {\n return await onNode.getMicroBlockHeaderByHash(hash)\n}\n\ninterface TxDryRunArguments {\n tx: EncodedData<'tx'>\n accountAddress: EncodedData<'ak'>\n top?: number\n txEvents?: any\n resolve: Function\n reject: Function\n}\nconst txDryRunRequests: Map<string, TxDryRunArguments[] & { timeout?: NodeJS.Timeout }> = new Map()\n\nasync function txDryRunHandler (key: string, onNode: Node): Promise<void> {\n const rs = txDryRunRequests.get(key)\n txDryRunRequests.delete(key)\n if (rs == null) throw new InternalError('Can\\'t get dry-run request')\n\n let dryRunRes\n try {\n dryRunRes = await onNode.protectedDryRunTxs({\n top: rs[0].top,\n txEvents: rs[0].txEvents,\n txs: rs.map(req => ({ tx: req.tx })),\n accounts: Array.from(new Set(rs.map(req => req.accountAddress)))\n .map(pubKey => ({ pubKey, amount: DRY_RUN_ACCOUNT.amount }))\n })\n } catch (error) {\n rs.forEach(({ reject }) => reject(error))\n return\n }\n\n const { results, txEvents } = dryRunRes\n results.forEach(({ result, reason, ...resultPayload }, idx) => {\n const { resolve, reject, tx, accountAddress } = rs[idx]\n if (result === 'ok') return resolve({ ...resultPayload, txEvents })\n reject(Object.assign(\n new DryRunError(reason as string), { tx, accountAddress }\n ))\n })\n}\n\n/**\n * Transaction dry-run\n * @param tx - transaction to execute\n * @param accountAddress - address that will be used to execute transaction\n * @param options - Options\n * @param options.top - hash of block on which to make dry-run\n * @param options.txEvents - collect and return on-chain tx events that would result from the call\n * @param options.combine - Enables combining of similar requests to a single dry-run call\n * @param options.onNode - Node to use\n */\nexport async function txDryRun (\n tx: EncodedData<'tx'>,\n accountAddress: EncodedData<'ak'>,\n { top, txEvents, combine, onNode }:\n { top?: number, txEvents?: boolean, combine?: boolean, onNode: Node }\n): Promise<{\n txEvents?: TransformNodeType<DryRunResults['txEvents']>\n } & TransformNodeType<DryRunResult>> {\n const key = combine === true ? [top, txEvents].join() : 'immediate'\n const requests = txDryRunRequests.get(key) ?? []\n txDryRunRequests.set(key, requests)\n return await new Promise((resolve, reject) => {\n requests.push({ tx, accountAddress, top, txEvents, resolve, reject })\n if (combine !== true) {\n void txDryRunHandler(key, onNode)\n return\n }\n requests.timeout ??= setTimeout(() => { void txDryRunHandler(key, onNode) })\n })\n}\n\n/**\n * Get contract byte code\n * @param contractId - Contract address\n * @param options - Options\n * @param options.onNode - Node to use\n */\nexport async function getContractByteCode (\n contractId: EncodedData<'ct'>, { onNode }: { onNode: Node }\n): Promise<TransformNodeType<ByteCode>> {\n return await onNode.getContractCode(contractId)\n}\n\n/**\n * Get contract entry\n * @param contractId - Contract address\n * @param options - Options\n * @param options.onNode - Node to use\n */\nexport async function getContract (\n contractId: EncodedData<'ct'>, { onNode }: { onNode: Node }\n): Promise<TransformNodeType<ContractObject>> {\n return await onNode.getContract(contractId)\n}\n\n/**\n * Get name entry\n * @param name - AENS name\n * @param options - Options\n * @param options.onNode - Node to use\n */\nexport async function getName (\n name: AensName, { onNode }: { onNode: Node }\n): Promise<TransformNodeType<NameEntry>> {\n return await onNode.getNameEntryByName(name)\n}\n\n/**\n * Resolve AENS name and return name hash\n * @param nameOrId - AENS name or address\n * @param key - in AENS pointers record\n * @param options - Options\n * @param options.verify - To ensure that name exist and have a corresponding pointer\n * // TODO: avoid that to don't trust to current api gateway\n * @param options.resolveByNode - Enables pointer resolving using node\n * @param options.onNode - Node to use\n * @returns Address or AENS name hash\n */\nexport async function resolveName <Type extends 'ak' | 'ct'> (\n nameOrId: AensName | EncodedData<Type>,\n key: string,\n { verify = true, resolveByNode = false, onNode }:\n { verify?: boolean, resolveByNode?: boolean, onNode: Node }\n): Promise<EncodedData<Type | 'nm'>> {\n try {\n const id = nameOrId as EncodedData<Type>\n decode(id)\n return id\n } catch (error) {}\n if (isNameValid(nameOrId)) {\n if (verify || resolveByNode) {\n const name = await onNode.getNameEntryByName(nameOrId)\n const pointer = name.pointers.find(pointer => pointer.key === key)\n if (pointer == null) throw new AensPointerContextError(nameOrId, key)\n if (resolveByNode) return pointer.id as EncodedData<Type>\n }\n return produceNameId(nameOrId)\n }\n throw new InvalidAensNameError(`Invalid name or address: ${nameOrId}`)\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;A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A;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,eAAeE,WAAf,CACLC,QADK,EAELzC,GAFK,UAK8B;EAAA,IAFnC;IAAEpE,MAAM,GAAG,IAAX;IAAiB8G,aAAa,GAAG,KAAjC;IAAwChH;EAAxC,CAEmC;;EACnC,IAAI;IACF,MAAMiH,EAAE,GAAGF,QAAX;IACArI,MAAM,CAACuI,EAAD,CAAN;IACA,OAAOA,EAAP;EACD,CAJD,CAIE,OAAOrF,KAAP,EAAc,CAAE;;EAClB,IAAIpD,WAAW,CAACuI,QAAD,CAAf,EAA2B;IACzB,IAAI7G,MAAM,IAAI8G,aAAd,EAA6B;MAC3B,MAAMJ,IAAI,GAAG,MAAM5G,MAAM,CAAC6G,kBAAP,CAA0BE,QAA1B,CAAnB;MACA,MAAMG,OAAO,GAAGN,IAAI,CAACO,QAAL,CAAcC,IAAd,CAAmBF,OAAO,IAAIA,OAAO,CAAC5C,GAAR,KAAgBA,GAA9C,CAAhB;MACA,IAAI4C,OAAO,IAAI,IAAf,EAAqB,MAAM,IAAItI,uBAAJ,CAA4BmI,QAA5B,EAAsCzC,GAAtC,CAAN;MACrB,IAAI0C,aAAJ,EAAmB,OAAOE,OAAO,CAACD,EAAf;IACpB;;IACD,OAAOxI,aAAa,CAACsI,QAAD,CAApB;EACD;;EACD,MAAM,IAAIjI,oBAAJ,CAA0B,4BAA2BiI,QAAS,EAA9D,CAAN;AACD"}
1
+ {"version":3,"file":"chain.mjs","names":["AE_AMOUNT_FORMATS","formatAmount","verifyTransaction","pause","isNameValid","produceNameId","DRY_RUN_ACCOUNT","AensPointerContextError","DryRunError","InvalidAensNameError","TransactionError","TxTimedOutError","TxNotInChainError","InternalError","decode","_getPollInterval","type","_expectedMineRate","_microBlockCycle","_maxPollInterval","base","block","microblock","Math","min","InvalidTxError","constructor","message","validation","transaction","name","getHeight","onNode","getCurrentKeyBlockHeight","height","poll","th","blocks","interval","options","max","tx","getTransactionByHash","blockHeight","awaitHeight","currentHeight","waitForTxConfirm","txHash","confirm","newBlockHeight","sendTransaction","onAccount","verify","waitMined","length","map","v","join","__queue","address","error","postTransaction","requestOptions","customHeaders","pollResult","txData","hash","rawTx","c","undefined","confirmationHeight","Object","assign","verifyTx","getAccount","getAccountByPubkeyAndHeight","getAccountByPubkeyAndHash","getAccountByPubkey","getBalance","format","AETTOS","balance","catch","targetDenomination","getCurrentGeneration","getGeneration","hashOrHeight","getGenerationByHeight","getGenerationByHash","getMicroBlockTransactions","getMicroBlockTransactionsByHash","transactions","getKeyBlock","getKeyBlockByHeight","getKeyBlockByHash","getMicroBlockHeader","getMicroBlockHeaderByHash","txDryRunRequests","Map","txDryRunHandler","key","rs","get","delete","dryRunRes","protectedDryRunTxs","top","txEvents","txs","req","accounts","Array","from","Set","accountAddress","pubKey","amount","forEach","reject","results","idx","result","reason","resultPayload","resolve","txDryRun","combine","requests","set","Promise","push","timeout","setTimeout","getContractByteCode","contractId","getContractCode","getContract","getName","getNameEntryByName","resolveName","nameOrId","resolveByNode","pointer","pointers","find","p","id"],"sources":["../src/chain.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2022 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\nimport { AE_AMOUNT_FORMATS, formatAmount } from './utils/amount-formatter';\nimport verifyTransaction, { ValidatorResult } from './tx/validator';\nimport { pause } from './utils/other';\nimport { isNameValid, produceNameId } from './tx/builder/helpers';\nimport { DRY_RUN_ACCOUNT } from './tx/builder/schema';\nimport { AensName } from './tx/builder/constants';\nimport {\n AensPointerContextError, DryRunError, InvalidAensNameError, TransactionError,\n TxTimedOutError, TxNotInChainError, InternalError,\n} from './utils/errors';\nimport Node, { TransformNodeType } from './Node';\nimport {\n Account as AccountNode, ByteCode, ContractObject, DryRunResult, DryRunResults,\n Generation, KeyBlock, MicroBlockHeader, NameEntry, SignedTx,\n} from './apis/node';\nimport { decode, Encoded, Encoding } from './utils/encoder';\nimport AccountBase from './account/Base';\n\n/**\n * @category chain\n */\nexport function _getPollInterval(\n type: 'block' | 'microblock',\n { _expectedMineRate = 180000, _microBlockCycle = 3000, _maxPollInterval = 5000 }:\n { _expectedMineRate?: number; _microBlockCycle?: number; _maxPollInterval?: number },\n): number {\n const base = {\n block: _expectedMineRate,\n microblock: _microBlockCycle,\n }[type];\n return Math.min(base / 3, _maxPollInterval);\n}\n\n/**\n * @category exception\n */\nexport class InvalidTxError extends TransactionError {\n validation: ValidatorResult[];\n\n transaction: Encoded.Transaction;\n\n constructor(\n message: string,\n validation: ValidatorResult[],\n transaction: Encoded.Transaction,\n ) {\n super(message);\n this.name = 'InvalidTxError';\n this.validation = validation;\n this.transaction = transaction;\n }\n}\n\n/**\n * Obtain current height of the chain\n * @category chain\n * @returns Current chain height\n */\nexport async function getHeight({ onNode }: { onNode: Node }): Promise<number> {\n return (await onNode.getCurrentKeyBlockHeight()).height;\n}\n\n/**\n * Wait for a transaction to be mined\n * @category chain\n * @param th - The hash of transaction to poll\n * @param options - Options\n * @param options.interval - Interval (in ms) at which to poll the chain\n * @param options.blocks - Number of blocks mined after which to fail\n * @param options.onNode - Node to use\n * @returns The transaction as it was mined\n */\nexport async function poll(\n th: Encoded.TxHash,\n {\n blocks = 10, interval, onNode, ...options\n }:\n { blocks?: number; interval?: number; onNode: Node } & Parameters<typeof _getPollInterval>[1],\n): Promise<TransformNodeType<SignedTx>> {\n interval ??= _getPollInterval('microblock', options);\n const max = await getHeight({ onNode }) + blocks;\n do {\n const tx = await onNode.getTransactionByHash(th);\n if (tx.blockHeight !== -1) return tx;\n await pause(interval);\n } while (await getHeight({ onNode }) < max);\n throw new TxTimedOutError(blocks, th);\n}\n\n/**\n * Wait for the chain to reach a specific height\n * @category chain\n * @param height - Height to wait for\n * @param options - Options\n * @param options.interval - Interval (in ms) at which to poll the chain\n * @param options.onNode - Node to use\n * @returns Current chain height\n */\nexport async function awaitHeight(\n height: number,\n { interval, onNode, ...options }:\n { interval?: number; onNode: Node } & Parameters<typeof _getPollInterval>[1],\n): Promise<number> {\n interval ??= _getPollInterval('block', options);\n let currentHeight;\n do {\n if (currentHeight != null) await pause(interval);\n currentHeight = (await onNode.getCurrentKeyBlockHeight()).height;\n } while (currentHeight < height);\n return currentHeight;\n}\n\n/**\n * Wait for transaction confirmation\n * @category chain\n * @param txHash - Transaction hash\n * @param options - Options\n * @param options.confirm - Number of micro blocks to wait for transaction confirmation\n * @param options.onNode - Node to use\n * @returns Current Height\n */\nexport async function waitForTxConfirm(\n txHash: Encoded.TxHash,\n { confirm = 3, onNode, ...options }:\n { confirm?: number; onNode: Node } & Parameters<typeof awaitHeight>[1],\n): Promise<number> {\n const { blockHeight } = await onNode.getTransactionByHash(txHash);\n const height = await awaitHeight(blockHeight + confirm, { onNode, ...options });\n const { blockHeight: newBlockHeight } = await onNode.getTransactionByHash(txHash);\n switch (newBlockHeight) {\n case -1:\n throw new TxNotInChainError(txHash);\n case blockHeight:\n return height;\n default:\n return waitForTxConfirm(txHash, { onNode, confirm, ...options });\n }\n}\n\n/**\n * Submit a signed transaction for mining\n * @category chain\n * @param tx - Transaction to submit\n * @param options - Options\n * @param options.onNode - Node to use\n * @param options.onAccount - Account to use\n * @param options.verify - Verify transaction before sending\n * @param options.waitMined - Ensure that transaction get into block\n * @param options.confirm - Number of micro blocks that should be mined after tx get included\n * @returns Transaction details\n */\nexport async function sendTransaction(\n tx: Encoded.Transaction,\n {\n onNode, onAccount, verify = true, waitMined = true, confirm, ...options\n }:\n SendTransactionOptions,\n): Promise<SendTransactionReturnType> {\n if (verify) {\n const validation = await verifyTransaction(tx, onNode);\n if (validation.length > 0) {\n const message = `Transaction verification errors: ${\n validation.map((v: { message: string }) => v.message).join(', ')}`;\n throw new InvalidTxError(message, validation, tx);\n }\n }\n\n try {\n let __queue;\n try {\n __queue = onAccount != null ? `tx-${await onAccount.address(options)}` : null;\n } catch (error) {\n __queue = null;\n }\n const { txHash } = await onNode.postTransaction(\n { tx },\n __queue != null ? { requestOptions: { customHeaders: { __queue } } } : {},\n );\n\n if (waitMined) {\n const pollResult = await poll(txHash, { onNode, ...options });\n const txData = {\n ...pollResult,\n hash: pollResult.hash as Encoded.TxHash,\n rawTx: tx,\n };\n // wait for transaction confirmation\n if (confirm != null && (confirm === true || confirm > 0)) {\n const c = typeof confirm === 'boolean' ? undefined : confirm;\n return {\n ...txData,\n confirmationHeight: await waitForTxConfirm(txHash, { onNode, confirm: c, ...options }),\n };\n }\n return txData;\n }\n return { hash: txHash, rawTx: tx };\n } catch (error) {\n throw Object.assign(error, {\n rawTx: tx,\n verifyTx: async () => verifyTransaction(tx, onNode),\n });\n }\n}\n\ntype SendTransactionOptionsType = {\n onNode: Node;\n onAccount?: AccountBase;\n verify?: boolean;\n waitMined?: boolean;\n confirm?: boolean | number;\n} & Parameters<typeof poll>[1] & Omit<Parameters<typeof waitForTxConfirm>[1], 'confirm'>;\ninterface SendTransactionOptions extends SendTransactionOptionsType {}\ninterface SendTransactionReturnType extends Partial<TransformNodeType<SignedTx>> {\n hash: Encoded.TxHash;\n rawTx: Encoded.Transaction;\n confirmationHeight?: number;\n}\n\n/**\n * Get account by account public key\n * @category chain\n * @param address - Account address (public key)\n * @param options - Options\n * @param options.height - Get account on specific block by block height\n * @param options.hash - Get account on specific block by micro block hash or key block hash\n * @param options.onNode - Node to use\n */\nexport async function getAccount(\n address: Encoded.AccountAddress | Encoded.ContractAddress,\n { height, hash, onNode }:\n { height?: number; hash?: Encoded.KeyBlockHash | Encoded.MicroBlockHash; onNode: Node },\n): Promise<TransformNodeType<AccountNode>> {\n if (height != null) return onNode.getAccountByPubkeyAndHeight(address, height);\n if (hash != null) return onNode.getAccountByPubkeyAndHash(address, hash);\n return onNode.getAccountByPubkey(address);\n}\n\n/**\n * Request the balance of specified account\n * @category chain\n * @param address - The public account address to obtain the balance for\n * @param options - Options\n * @param options.format\n * @param options.height - The chain height at which to obtain the balance for\n * (default: top of chain)\n * @param options.hash - The block hash on which to obtain the balance for (default: top of chain)\n */\nexport async function getBalance(\n address: Encoded.AccountAddress | Encoded.ContractAddress,\n { format = AE_AMOUNT_FORMATS.AETTOS, ...options }:\n { format?: AE_AMOUNT_FORMATS } & Parameters<typeof getAccount>[1],\n): Promise<string> {\n const { balance } = await getAccount(address, options).catch(() => ({ balance: 0n }));\n\n return formatAmount(balance, { targetDenomination: format });\n}\n\n/**\n * Obtain current generation\n * @category chain\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Current Generation\n */\nexport async function getCurrentGeneration(\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<Generation>> {\n return onNode.getCurrentGeneration();\n}\n\n/**\n * Get generation by hash or height\n * @category chain\n * @param hashOrHeight - Generation hash or height\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Generation\n */\nexport async function getGeneration(\n hashOrHeight: Encoded.KeyBlockHash | number,\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<Generation>> {\n if (typeof hashOrHeight === 'number') return onNode.getGenerationByHeight(hashOrHeight);\n return onNode.getGenerationByHash(hashOrHeight);\n}\n\n/**\n * Get micro block transactions\n * @category chain\n * @param hash - Micro block hash\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Transactions\n */\nexport async function getMicroBlockTransactions(\n hash: Encoded.MicroBlockHash,\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<SignedTx[]>> {\n return (await onNode.getMicroBlockTransactionsByHash(hash)).transactions;\n}\n\n/**\n * Get key block\n * @category chain\n * @param hashOrHeight - Key block hash or height\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Key Block\n */\nexport async function getKeyBlock(\n hashOrHeight: Encoded.KeyBlockHash | number,\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<KeyBlock>> {\n if (typeof hashOrHeight === 'number') return onNode.getKeyBlockByHeight(hashOrHeight);\n return onNode.getKeyBlockByHash(hashOrHeight);\n}\n\n/**\n * Get micro block header\n * @category chain\n * @param hash - Micro block hash\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Micro block header\n */\nexport async function getMicroBlockHeader(\n hash: Encoded.MicroBlockHash,\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<MicroBlockHeader>> {\n return onNode.getMicroBlockHeaderByHash(hash);\n}\n\ninterface TxDryRunArguments {\n tx: Encoded.Transaction;\n accountAddress: Encoded.AccountAddress;\n top?: number;\n txEvents?: any;\n resolve: Function;\n reject: Function;\n}\nconst txDryRunRequests: Map<string, TxDryRunArguments[] & { timeout?: NodeJS.Timeout }> = new Map();\n\nasync function txDryRunHandler(key: string, onNode: Node): Promise<void> {\n const rs = txDryRunRequests.get(key);\n txDryRunRequests.delete(key);\n if (rs == null) throw new InternalError('Can\\'t get dry-run request');\n\n let dryRunRes;\n try {\n dryRunRes = await onNode.protectedDryRunTxs({\n top: rs[0].top,\n txEvents: rs[0].txEvents,\n txs: rs.map((req) => ({ tx: req.tx })),\n accounts: Array.from(new Set(rs.map((req) => req.accountAddress)))\n .map((pubKey) => ({ pubKey, amount: DRY_RUN_ACCOUNT.amount })),\n });\n } catch (error) {\n rs.forEach(({ reject }) => reject(error));\n return;\n }\n\n const { results, txEvents } = dryRunRes;\n results.forEach(({ result, reason, ...resultPayload }, idx) => {\n const {\n resolve, reject, tx, accountAddress,\n } = rs[idx];\n if (result === 'ok') resolve({ ...resultPayload, txEvents });\n else reject(Object.assign(new DryRunError(reason as string), { tx, accountAddress }));\n });\n}\n\n/**\n * Transaction dry-run\n * @category chain\n * @param tx - transaction to execute\n * @param accountAddress - address that will be used to execute transaction\n * @param options - Options\n * @param options.top - hash of block on which to make dry-run\n * @param options.txEvents - collect and return on-chain tx events that would result from the call\n * @param options.combine - Enables combining of similar requests to a single dry-run call\n * @param options.onNode - Node to use\n */\nexport async function txDryRun(\n tx: Encoded.Transaction,\n accountAddress: Encoded.AccountAddress,\n {\n top, txEvents, combine, onNode,\n }:\n { top?: number; txEvents?: boolean; combine?: boolean; onNode: Node },\n): Promise<{\n txEvents?: TransformNodeType<DryRunResults['txEvents']>;\n } & TransformNodeType<DryRunResult>> {\n const key = combine === true ? [top, txEvents].join() : 'immediate';\n const requests = txDryRunRequests.get(key) ?? [];\n txDryRunRequests.set(key, requests);\n return new Promise((resolve, reject) => {\n requests.push({\n tx, accountAddress, top, txEvents, resolve, reject,\n });\n if (combine !== true) {\n void txDryRunHandler(key, onNode);\n return;\n }\n requests.timeout ??= setTimeout(() => { void txDryRunHandler(key, onNode); });\n });\n}\n\n/**\n * Get contract byte code\n * @category contract\n * @param contractId - Contract address\n * @param options - Options\n * @param options.onNode - Node to use\n */\nexport async function getContractByteCode(\n contractId: Encoded.ContractAddress,\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<ByteCode>> {\n return onNode.getContractCode(contractId);\n}\n\n/**\n * Get contract entry\n * @category contract\n * @param contractId - Contract address\n * @param options - Options\n * @param options.onNode - Node to use\n */\nexport async function getContract(\n contractId: Encoded.ContractAddress,\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<ContractObject>> {\n return onNode.getContract(contractId);\n}\n\n/**\n * Get name entry\n * @category AENS\n * @param name - AENS name\n * @param options - Options\n * @param options.onNode - Node to use\n */\nexport async function getName(\n name: AensName,\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<NameEntry>> {\n return onNode.getNameEntryByName(name);\n}\n\n/**\n * Resolve AENS name and return name hash\n * @category AENS\n * @param nameOrId - AENS name or address\n * @param key - in AENS pointers record\n * @param options - Options\n * @param options.verify - To ensure that name exist and have a corresponding pointer\n * // TODO: avoid that to don't trust to current api gateway\n * @param options.resolveByNode - Enables pointer resolving using node\n * @param options.onNode - Node to use\n * @returns Address or AENS name hash\n */\nexport async function resolveName <\n Type extends Encoding.AccountAddress | Encoding.ContractAddress,\n>(\n nameOrId: AensName | Encoded.Generic<Type>,\n key: string,\n { verify = true, resolveByNode = false, onNode }:\n { verify?: boolean; resolveByNode?: boolean; onNode: Node },\n): Promise<Encoded.Generic<Type | Encoding.Name>> {\n if (isNameValid(nameOrId)) {\n if (verify || resolveByNode) {\n const name = await onNode.getNameEntryByName(nameOrId);\n const pointer = name.pointers.find((p) => p.key === key);\n if (pointer == null) throw new AensPointerContextError(nameOrId, key);\n if (resolveByNode) return pointer.id as Encoded.Generic<Type>;\n }\n return produceNameId(nameOrId);\n }\n try {\n decode(nameOrId);\n return nameOrId;\n } catch (error) {\n throw new InvalidAensNameError(`Invalid name or address: ${nameOrId}`);\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;SACSA,iB,EAAmBC,Y;OACrBC,iB;SACEC,K;SACAC,W,EAAaC,a;SACbC,e;SAGPC,uB,EAAyBC,W,EAAaC,oB,EAAsBC,gB,EAC5DC,e,EAAiBC,iB,EAAmBC,a;SAO7BC,M;;AAGT;AACA;AACA;AACA,OAAO,SAASC,gBAAT,CACLC,IADK,QAIG;EAAA,IAFR;IAAEC,iBAAiB,GAAG,MAAtB;IAA8BC,gBAAgB,GAAG,IAAjD;IAAuDC,gBAAgB,GAAG;EAA1E,CAEQ;EACR,MAAMC,IAAI,GAAG;IACXC,KAAK,EAAEJ,iBADI;IAEXK,UAAU,EAAEJ;EAFD,EAGXF,IAHW,CAAb;EAIA,OA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D,IAAOA,CAAC,CAAC7C,GAAF,KAAUA,GAApC,CAAhB;MACA,IAAI0C,OAAO,IAAI,IAAf,EAAqB,MAAM,IAAIvI,uBAAJ,CAA4BqI,QAA5B,EAAsCxC,GAAtC,CAAN;MACrB,IAAIyC,aAAJ,EAAmB,OAAOC,OAAO,CAACI,EAAf;IACpB;;IACD,OAAO7I,aAAa,CAACuI,QAAD,CAApB;EACD;;EACD,IAAI;IACF9H,MAAM,CAAC8H,QAAD,CAAN;IACA,OAAOA,QAAP;EACD,CAHD,CAGE,OAAOhF,KAAP,EAAc;IACd,MAAM,IAAInD,oBAAJ,CAA0B,4BAA2BmI,QAAS,EAA9D,CAAN;EACD;AACF"}
@@ -1,7 +1,7 @@
1
1
  import { ChannelState, ChannelMessage, ChannelFsm, SignTx } from './internal';
2
- import { EncodedData } from '../utils/encoder';
3
- import Channel from '.';
4
- export declare function appendSignature(tx: EncodedData<'tx'>, signFn: SignTx): Promise<EncodedData<'tx'> | number | null>;
2
+ import { Encoded } from '../utils/encoder';
3
+ import type Channel from '.';
4
+ export declare function appendSignature(tx: Encoded.Transaction, signFn: SignTx): Promise<Encoded.Transaction | number | null>;
5
5
  export declare function awaitingConnection(channel: Channel, message: ChannelMessage): ChannelFsm | undefined;
6
6
  export declare function awaitingReconnection(channel: Channel, message: ChannelMessage, state: ChannelState): Promise<ChannelFsm>;
7
7
  export declare function awaitingChannelCreateTx(channel: Channel, message: ChannelMessage): Promise<ChannelFsm | undefined>;
@@ -16,39 +16,44 @@ import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/ins
16
16
  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
17
  * PERFORMANCE OF THIS SOFTWARE.
18
18
  */
19
+
20
+ /* eslint-disable consistent-return */
21
+
22
+ /* eslint-disable default-case */
23
+
24
+ /* eslint-disable @typescript-eslint/no-use-before-define */
19
25
  import { generateKeyPair, encodeContractAddress } from "../utils/crypto.mjs";
20
26
  import { options, changeStatus, changeState, call, send, emit, channelId, disconnect, fsmId } from "./internal.mjs";
21
27
  import { unpackTx, buildTx } from "../tx/builder/index.mjs";
22
- import { encode } from "../tx/builder/helpers.mjs";
28
+ import { encode, Encoding } from "../utils/encoder.mjs";
23
29
  import { IllegalArgumentError, InsufficientBalanceError, ChannelConnectionError, UnexpectedChannelMessageError } from "../utils/errors.mjs";
24
- import { TX_TYPE } from "../tx/builder/schema.mjs";
30
+ import { Tag } from "../tx/builder/constants.mjs";
25
31
  export async function appendSignature(tx, signFn) {
26
32
  const {
27
33
  signatures,
28
34
  encodedTx
29
- } = unpackTx(tx, TX_TYPE.signed).tx;
30
- const result = await signFn(encode(encodedTx.rlpEncoded, 'tx'));
35
+ } = unpackTx(tx, Tag.SignedTx).tx;
36
+ const result = await signFn(encode(encodedTx.rlpEncoded, Encoding.Transaction));
31
37
 
32
38
  if (typeof result === 'string') {
33
39
  const {
34
40
  tx: signedTx
35
- } = unpackTx(result, TX_TYPE.signed);
41
+ } = unpackTx(result, Tag.SignedTx);
36
42
  return buildTx({
37
43
  signatures: signatures.concat(signedTx.signatures),
38
44
  encodedTx: signedTx.encodedTx.rlpEncoded
39
- }, TX_TYPE.signed).tx;
45
+ }, Tag.SignedTx).tx;
40
46
  }
41
47
 
42
48
  return result;
43
49
  }
44
50
 
45
51
  function handleUnexpectedMessage(_channel, message, state) {
46
- if ((state === null || state === void 0 ? void 0 : state.reject) != null) {
47
- state.reject(Object.assign(new UnexpectedChannelMessageError(`Unexpected message received:\n\n${JSON.stringify(message)}`), {
48
- wsMessage: message
49
- }));
50
- }
52
+ var _state$reject;
51
53
 
54
+ state === null || state === void 0 ? void 0 : (_state$reject = state.reject) === null || _state$reject === void 0 ? void 0 : _state$reject.call(state, Object.assign(new UnexpectedChannelMessageError(`Unexpected message received:\n\n${JSON.stringify(message)}`), {
55
+ wsMessage: message
56
+ }));
52
57
  return {
53
58
  handler: channelOpen
54
59
  };
@@ -134,7 +139,7 @@ export async function awaitingChannelCreateTx(channel, message) {
134
139
  };
135
140
  }
136
141
 
137
- const signedTx = await appendSignature(message.params.data.signed_tx, async tx => await channelOptions.sign(tag, tx));
142
+ const signedTx = await appendSignature(message.params.data.signed_tx, async tx => channelOptions.sign(tag, tx));
138
143
  send(channel, {
139
144
  jsonrpc: '2.0',
140
145
  method: `channels.${tag}`,
@@ -304,7 +309,7 @@ export async function channelOpen(channel, message, state) {
304
309
  };
305
310
 
306
311
  case 'channels.sign.shutdown_sign_ack':
307
- return await awaitingTxSignRequest(channel, message, state);
312
+ return awaitingTxSignRequest(channel, message, state);
308
313
  }
309
314
  }
310
315
 
@@ -335,7 +340,7 @@ export async function awaitingOffChainTx(channel, message, state) {
335
340
  };
336
341
  }
337
342
 
338
- const signedTx = await appendSignature(message.params.data.signed_tx, async tx => await sign(tx, {
343
+ const signedTx = await appendSignature(message.params.data.signed_tx, async tx => sign(tx, {
339
344
  updates: message.params.data.updates
340
345
  }));
341
346
 
@@ -489,7 +494,7 @@ export async function awaitingTxSignRequest(channel, message, state) {
489
494
  };
490
495
  }
491
496
  } else {
492
- const signedTx = await appendSignature(message.params.data.signed_tx, async tx => await channelOptions.sign(tag, tx, {
497
+ const signedTx = await appendSignature(message.params.data.signed_tx, async tx => channelOptions.sign(tag, tx, {
493
498
  updates: message.params.data.updates
494
499
  }));
495
500
 
@@ -572,7 +577,7 @@ export async function awaitingShutdownTx(channel, message, state) {
572
577
  };
573
578
  }
574
579
 
575
- const signedTx = await appendSignature(message.params.data.signed_tx, async tx => await state.sign(tx));
580
+ const signedTx = await appendSignature(message.params.data.signed_tx, async tx => state.sign(tx));
576
581
  send(channel, {
577
582
  jsonrpc: '2.0',
578
583
  method: 'channels.shutdown_sign',
@@ -643,7 +648,7 @@ export async function awaitingWithdrawTx(channel, message, state) {
643
648
  };
644
649
  }
645
650
 
646
- const signedTx = await appendSignature(message.params.data.signed_tx, async tx => await sign(tx, {
651
+ const signedTx = await appendSignature(message.params.data.signed_tx, async tx => sign(tx, {
647
652
  updates: message.params.data.updates
648
653
  }));
649
654
 
@@ -680,10 +685,9 @@ export async function awaitingWithdrawTx(channel, message, state) {
680
685
  }
681
686
  export function awaitingWithdrawCompletion(channel, message, state) {
682
687
  if (message.method === 'channels.on_chain_tx') {
683
- if (state.onOnChainTx != null) {
684
- state.onOnChainTx(message.params.data.tx);
685
- }
688
+ var _state$onOnChainTx;
686
689
 
690
+ (_state$onOnChainTx = state.onOnChainTx) === null || _state$onOnChainTx === void 0 ? void 0 : _state$onOnChainTx.call(state, message.params.data.tx);
687
691
  return {
688
692
  handler: awaitingWithdrawCompletion,
689
693
  state
@@ -694,16 +698,13 @@ export function awaitingWithdrawCompletion(channel, message, state) {
694
698
  var _context2;
695
699
 
696
700
  if (_includesInstanceProperty(_context2 = ['own_withdraw_locked', 'withdraw_locked']).call(_context2, message.params.data.event)) {
701
+ var _callbacks$message$pa;
702
+
697
703
  const callbacks = {
698
704
  own_withdraw_locked: state.onOwnWithdrawLocked,
699
705
  withdraw_locked: state.onWithdrawLocked
700
706
  };
701
- const callback = callbacks[message.params.data.event];
702
-
703
- if (callback != null) {
704
- callback();
705
- }
706
-
707
+ (_callbacks$message$pa = callbacks[message.params.data.event]) === null || _callbacks$message$pa === void 0 ? void 0 : _callbacks$message$pa.call(callbacks);
707
708
  return {
708
709
  handler: awaitingWithdrawCompletion,
709
710
  state
@@ -769,7 +770,7 @@ export async function awaitingDepositTx(channel, message, state) {
769
770
  };
770
771
  }
771
772
 
772
- const signedTx = await appendSignature(message.params.data.signed_tx, async tx => await sign(tx, {
773
+ const signedTx = await appendSignature(message.params.data.signed_tx, async tx => sign(tx, {
773
774
  updates: message.params.data.updates
774
775
  }));
775
776
 
@@ -806,10 +807,9 @@ export async function awaitingDepositTx(channel, message, state) {
806
807
  }
807
808
  export function awaitingDepositCompletion(channel, message, state) {
808
809
  if (message.method === 'channels.on_chain_tx') {
809
- if (state.onOnChainTx != null) {
810
- state.onOnChainTx(message.params.data.tx);
811
- }
810
+ var _state$onOnChainTx2;
812
811
 
812
+ (_state$onOnChainTx2 = state.onOnChainTx) === null || _state$onOnChainTx2 === void 0 ? void 0 : _state$onOnChainTx2.call(state, message.params.data.tx);
813
813
  return {
814
814
  handler: awaitingDepositCompletion,
815
815
  state
@@ -820,16 +820,13 @@ export function awaitingDepositCompletion(channel, message, state) {
820
820
  var _context3;
821
821
 
822
822
  if (_includesInstanceProperty(_context3 = ['own_deposit_locked', 'deposit_locked']).call(_context3, message.params.data.event)) {
823
+ var _callbacks$message$pa2;
824
+
823
825
  const callbacks = {
824
826
  own_deposit_locked: state.onOwnDepositLocked,
825
827
  deposit_locked: state.onDepositLocked
826
828
  };
827
- const callback = callbacks[message.params.data.event];
828
-
829
- if (callback != null) {
830
- callback();
831
- }
832
-
829
+ (_callbacks$message$pa2 = callbacks[message.params.data.event]) === null || _callbacks$message$pa2 === void 0 ? void 0 : _callbacks$message$pa2.call(callbacks);
833
830
  return {
834
831
  handler: awaitingDepositCompletion,
835
832
  state
@@ -889,7 +886,7 @@ export async function awaitingNewContractTx(channel, message, state) {
889
886
  };
890
887
  }
891
888
 
892
- const signedTx = await appendSignature(message.params.data.signed_tx, async tx => await state.sign(tx));
889
+ const signedTx = await appendSignature(message.params.data.signed_tx, async tx => state.sign(tx));
893
890
 
894
891
  if (typeof signedTx === 'string') {
895
892
  send(channel, {
@@ -928,10 +925,12 @@ export function awaitingNewContractCompletion(channel, message, state) {
928
925
  if (message.method === 'channels.update') {
929
926
  const {
930
927
  round
931
- } = unpackTx(message.params.data.state, TX_TYPE.signed).tx.encodedTx.tx;
928
+ } = unpackTx(message.params.data.state, Tag.SignedTx).tx.encodedTx.tx;
932
929
 
933
930
  if ((channelOptions === null || channelOptions === void 0 ? void 0 : channelOptions.role) != null) {
934
- const role = channelOptions.role === 'initiator' ? 'initiatorId' : channelOptions.role === 'responder' ? 'responderId' : null;
931
+ let role = null;
932
+ if (channelOptions.role === 'initiator') role = 'initiatorId';
933
+ if (channelOptions.role === 'responder') role = 'responderId';
935
934
 
936
935
  if (role != null) {
937
936
  const owner = channelOptions === null || channelOptions === void 0 ? void 0 : channelOptions[role];
@@ -991,7 +990,7 @@ export async function awaitingCallContractUpdateTx(channel, message, state) {
991
990
  };
992
991
  }
993
992
 
994
- const signedTx = await appendSignature(message.params.data.signed_tx, async tx => await state.sign(tx, {
993
+ const signedTx = await appendSignature(message.params.data.signed_tx, async tx => state.sign(tx, {
995
994
  updates: message.params.data.updates
996
995
  }));
997
996
 
@@ -1028,7 +1027,7 @@ export async function awaitingCallContractUpdateTx(channel, message, state) {
1028
1027
  }
1029
1028
  export async function awaitingCallContractForceProgressUpdate(channel, message, state) {
1030
1029
  if (message.method === 'channels.sign.force_progress_tx') {
1031
- const signedTx = await appendSignature(message.params.data.signed_tx, async tx => await state.sign(tx, {
1030
+ const signedTx = await appendSignature(message.params.data.signed_tx, async tx => state.sign(tx, {
1032
1031
  updates: message.params.data.updates
1033
1032
  }));
1034
1033
  send(channel, {
@@ -1048,10 +1047,9 @@ export async function awaitingCallContractForceProgressUpdate(channel, message,
1048
1047
  }
1049
1048
  export function awaitingForceProgressCompletion(channel, message, state) {
1050
1049
  if (message.method === 'channels.on_chain_tx') {
1051
- if (state.onOnChainTx != null) {
1052
- state.onOnChainTx(message.params.data);
1053
- }
1050
+ var _state$onOnChainTx3;
1054
1051
 
1052
+ (_state$onOnChainTx3 = state.onOnChainTx) === null || _state$onOnChainTx3 === void 0 ? void 0 : _state$onOnChainTx3.call(state, message.params.data.tx);
1055
1053
  emit(channel, 'onChainTx', message.params.data.tx, {
1056
1054
  info: message.params.data.info,
1057
1055
  type: message.params.data.type