@aeternity/aepp-sdk 9.0.1 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (284) hide show
  1. package/README.md +15 -14
  2. package/dist/aepp-sdk.browser-script.js +1 -1
  3. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +7 -36
  4. package/dist/aepp-sdk.browser-script.js.map +1 -1
  5. package/dist/aepp-sdk.browser.js +1 -1
  6. package/dist/aepp-sdk.browser.js.map +1 -1
  7. package/dist/aepp-sdk.js +1 -1
  8. package/dist/aepp-sdk.js.map +1 -1
  9. package/es/account/base.mjs +179 -0
  10. package/es/account/base.mjs.map +1 -0
  11. package/es/account/memory.mjs +99 -0
  12. package/es/account/memory.mjs.map +1 -0
  13. package/es/account/multiple.mjs +179 -0
  14. package/es/account/multiple.mjs.map +1 -0
  15. package/es/ae/aens.mjs +404 -0
  16. package/es/ae/aens.mjs.map +1 -0
  17. package/es/ae/{aepp.js → aepp.mjs} +9 -9
  18. package/es/ae/aepp.mjs.map +1 -0
  19. package/es/ae/contract.mjs +159 -0
  20. package/es/ae/contract.mjs.map +1 -0
  21. package/es/ae/index.mjs +207 -0
  22. package/es/ae/index.mjs.map +1 -0
  23. package/es/ae/oracle.mjs +339 -0
  24. package/es/ae/oracle.mjs.map +1 -0
  25. package/es/ae/{universal.js → universal.mjs} +10 -10
  26. package/es/ae/universal.mjs.map +1 -0
  27. package/es/ae/{wallet.js → wallet.mjs} +10 -10
  28. package/es/ae/wallet.mjs.map +1 -0
  29. package/es/aepp-wallet-communication/schema.d.ts +74 -0
  30. package/es/bignumber.d.ts +1 -7
  31. package/es/chain/{index.js → index.mjs} +29 -9
  32. package/es/chain/index.mjs.map +1 -0
  33. package/es/chain/node.mjs +442 -0
  34. package/es/chain/node.mjs.map +1 -0
  35. package/es/channel/handlers.mjs +1110 -0
  36. package/es/channel/handlers.mjs.map +1 -0
  37. package/es/channel/{index.js → index.mjs} +245 -472
  38. package/es/channel/index.mjs.map +1 -0
  39. package/es/channel/internal.mjs +283 -0
  40. package/es/channel/internal.mjs.map +1 -0
  41. package/es/contract/aci.mjs +477 -0
  42. package/es/contract/aci.mjs.map +1 -0
  43. package/es/contract/compiler.mjs +115 -0
  44. package/es/contract/compiler.mjs.map +1 -0
  45. package/es/contract/ga/helpers.mjs +30 -0
  46. package/es/contract/ga/helpers.mjs.map +1 -0
  47. package/es/contract/ga/index.mjs +178 -0
  48. package/es/contract/ga/index.mjs.map +1 -0
  49. package/es/errors.d.ts +284 -0
  50. package/es/index.mjs +57 -0
  51. package/es/index.mjs.map +1 -0
  52. package/es/node-pool/index.mjs +188 -0
  53. package/es/node-pool/index.mjs.map +1 -0
  54. package/es/node.mjs +133 -0
  55. package/es/node.mjs.map +1 -0
  56. package/es/other.d.ts +1 -1
  57. package/es/tx/builder/field-types.mjs +74 -0
  58. package/es/tx/builder/field-types.mjs.map +1 -0
  59. package/es/tx/builder/helpers.mjs +363 -0
  60. package/es/tx/builder/helpers.mjs.map +1 -0
  61. package/es/tx/builder/index.mjs +606 -0
  62. package/es/tx/builder/index.mjs.map +1 -0
  63. package/es/tx/builder/schema.mjs +760 -0
  64. package/es/tx/builder/schema.mjs.map +1 -0
  65. package/es/tx/{index.js → index.mjs} +107 -15
  66. package/es/tx/index.mjs.map +1 -0
  67. package/es/tx/tx-object.mjs +283 -0
  68. package/es/tx/tx-object.mjs.map +1 -0
  69. package/es/tx/tx.mjs +938 -0
  70. package/es/tx/tx.mjs.map +1 -0
  71. package/es/tx/validator.mjs +247 -0
  72. package/es/tx/validator.mjs.map +1 -0
  73. package/es/typings/blakejs/index.d.mjs +2 -0
  74. package/es/typings/blakejs/{index.d.js.map → index.d.mjs.map} +1 -1
  75. package/es/utils/aepp-wallet-communication/connection/{browser-runtime.js → browser-runtime.mjs} +27 -29
  76. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
  77. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +183 -0
  78. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +1 -0
  79. package/es/utils/aepp-wallet-communication/connection/{index.js → index.mjs} +7 -3
  80. package/es/utils/aepp-wallet-communication/connection/index.mjs.map +1 -0
  81. package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs} +29 -23
  82. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
  83. package/es/utils/aepp-wallet-communication/helpers.mjs +92 -0
  84. package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
  85. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +375 -0
  86. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
  87. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +275 -0
  88. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
  89. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +541 -0
  90. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +1 -0
  91. package/es/utils/aepp-wallet-communication/schema.mjs +102 -0
  92. package/es/utils/aepp-wallet-communication/schema.mjs.map +1 -0
  93. package/es/utils/aepp-wallet-communication/wallet-detector.mjs +110 -0
  94. package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  95. package/es/utils/amount-formatter.mjs +139 -0
  96. package/es/utils/amount-formatter.mjs.map +1 -0
  97. package/es/utils/async-init.mjs +64 -0
  98. package/es/utils/async-init.mjs.map +1 -0
  99. package/es/utils/bignumber.mjs +21 -0
  100. package/es/utils/bignumber.mjs.map +1 -0
  101. package/es/utils/{bytes.js → bytes.mjs} +16 -12
  102. package/es/utils/bytes.mjs.map +1 -0
  103. package/es/utils/{crypto-ts.js → crypto-ts.mjs} +11 -3
  104. package/es/utils/crypto-ts.mjs.map +1 -0
  105. package/es/utils/crypto.mjs +239 -0
  106. package/es/utils/crypto.mjs.map +1 -0
  107. package/es/utils/errors.mjs +689 -0
  108. package/es/utils/errors.mjs.map +1 -0
  109. package/es/utils/hd-wallet.mjs +111 -0
  110. package/es/utils/hd-wallet.mjs.map +1 -0
  111. package/es/utils/json-big.mjs +45 -0
  112. package/es/utils/json-big.mjs.map +1 -0
  113. package/es/utils/keystore.mjs +240 -0
  114. package/es/utils/keystore.mjs.map +1 -0
  115. package/es/utils/mptree.mjs +161 -0
  116. package/es/utils/mptree.mjs.map +1 -0
  117. package/es/utils/other.mjs +43 -0
  118. package/es/utils/other.mjs.map +1 -0
  119. package/es/utils/semver-satisfies.mjs +16 -0
  120. package/es/utils/semver-satisfies.mjs.map +1 -0
  121. package/es/utils/{string.js → string.mjs} +5 -14
  122. package/es/utils/string.mjs.map +1 -0
  123. package/es/utils/swagger.mjs +164 -0
  124. package/es/utils/swagger.mjs.map +1 -0
  125. package/package.json +55 -62
  126. package/src/account/base.js +3 -1
  127. package/src/account/memory.js +13 -8
  128. package/src/account/multiple.js +31 -22
  129. package/src/ae/aens.js +75 -77
  130. package/src/ae/aepp.js +2 -2
  131. package/src/ae/contract.js +27 -291
  132. package/src/ae/index.js +9 -7
  133. package/src/ae/oracle.js +51 -28
  134. package/src/ae/universal.js +4 -2
  135. package/src/ae/wallet.js +2 -2
  136. package/src/chain/index.js +29 -6
  137. package/src/chain/node.js +95 -67
  138. package/src/channel/handlers.js +30 -21
  139. package/src/channel/index.js +44 -20
  140. package/src/channel/internal.js +30 -24
  141. package/src/contract/aci.js +376 -0
  142. package/src/contract/compiler.js +41 -91
  143. package/src/contract/ga/helpers.js +10 -13
  144. package/src/contract/ga/index.js +42 -33
  145. package/src/index.js +9 -10
  146. package/src/node-pool/index.js +29 -17
  147. package/src/node.js +33 -36
  148. package/src/tx/builder/field-types.js +61 -0
  149. package/src/tx/builder/helpers.js +126 -84
  150. package/src/tx/builder/index.js +83 -41
  151. package/src/tx/builder/schema.js +50 -40
  152. package/src/tx/index.js +101 -12
  153. package/src/tx/tx-object.js +35 -15
  154. package/src/tx/tx.js +232 -153
  155. package/src/tx/validator.js +34 -12
  156. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +11 -5
  157. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +35 -13
  158. package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
  159. package/src/utils/aepp-wallet-communication/content-script-bridge.js +14 -7
  160. package/src/utils/aepp-wallet-communication/helpers.js +6 -14
  161. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +107 -60
  162. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +24 -11
  163. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +98 -56
  164. package/src/utils/aepp-wallet-communication/schema.ts +80 -0
  165. package/src/utils/aepp-wallet-communication/wallet-detector.js +6 -2
  166. package/src/utils/amount-formatter.ts +4 -3
  167. package/src/utils/async-init.js +10 -6
  168. package/src/utils/bignumber.ts +3 -10
  169. package/src/utils/bytes.ts +3 -2
  170. package/src/utils/crypto-ts.ts +2 -2
  171. package/src/utils/crypto.js +10 -144
  172. package/src/utils/errors.ts +683 -0
  173. package/src/utils/hd-wallet.js +11 -26
  174. package/src/utils/keystore.js +57 -53
  175. package/src/utils/mptree.ts +12 -6
  176. package/src/utils/other.ts +1 -1
  177. package/src/utils/semver-satisfies.ts +1 -1
  178. package/src/utils/swagger.js +75 -45
  179. package/es/account/base.js +0 -259
  180. package/es/account/base.js.map +0 -1
  181. package/es/account/memory.js +0 -86
  182. package/es/account/memory.js.map +0 -1
  183. package/es/account/multiple.js +0 -267
  184. package/es/account/multiple.js.map +0 -1
  185. package/es/ae/aens.js +0 -829
  186. package/es/ae/aens.js.map +0 -1
  187. package/es/ae/aepp.js.map +0 -1
  188. package/es/ae/contract.js +0 -985
  189. package/es/ae/contract.js.map +0 -1
  190. package/es/ae/index.js +0 -442
  191. package/es/ae/index.js.map +0 -1
  192. package/es/ae/oracle.js +0 -690
  193. package/es/ae/oracle.js.map +0 -1
  194. package/es/ae/universal.js.map +0 -1
  195. package/es/ae/wallet.js.map +0 -1
  196. package/es/chain/index.js.map +0 -1
  197. package/es/chain/node.js +0 -1119
  198. package/es/chain/node.js.map +0 -1
  199. package/es/channel/handlers.js +0 -1601
  200. package/es/channel/handlers.js.map +0 -1
  201. package/es/channel/index.js.map +0 -1
  202. package/es/channel/internal.js +0 -438
  203. package/es/channel/internal.js.map +0 -1
  204. package/es/contract/aci/helpers.js +0 -298
  205. package/es/contract/aci/helpers.js.map +0 -1
  206. package/es/contract/aci/index.js +0 -517
  207. package/es/contract/aci/index.js.map +0 -1
  208. package/es/contract/aci/transformation.js +0 -742
  209. package/es/contract/aci/transformation.js.map +0 -1
  210. package/es/contract/compiler.js +0 -316
  211. package/es/contract/compiler.js.map +0 -1
  212. package/es/contract/ga/helpers.js +0 -120
  213. package/es/contract/ga/helpers.js.map +0 -1
  214. package/es/contract/ga/index.js +0 -307
  215. package/es/contract/ga/index.js.map +0 -1
  216. package/es/contract/index.js +0 -158
  217. package/es/contract/index.js.map +0 -1
  218. package/es/index.js +0 -57
  219. package/es/index.js.map +0 -1
  220. package/es/node-pool/index.js +0 -204
  221. package/es/node-pool/index.js.map +0 -1
  222. package/es/node.js +0 -228
  223. package/es/node.js.map +0 -1
  224. package/es/tx/builder/helpers.js +0 -355
  225. package/es/tx/builder/helpers.js.map +0 -1
  226. package/es/tx/builder/index.js +0 -686
  227. package/es/tx/builder/index.js.map +0 -1
  228. package/es/tx/builder/schema.js +0 -695
  229. package/es/tx/builder/schema.js.map +0 -1
  230. package/es/tx/index.js.map +0 -1
  231. package/es/tx/tx-object.js +0 -297
  232. package/es/tx/tx-object.js.map +0 -1
  233. package/es/tx/tx.js +0 -1757
  234. package/es/tx/tx.js.map +0 -1
  235. package/es/tx/validator.js +0 -344
  236. package/es/tx/validator.js.map +0 -1
  237. package/es/typings/blakejs/index.d.js +0 -2
  238. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
  239. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -211
  240. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
  241. package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
  242. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
  243. package/es/utils/aepp-wallet-communication/helpers.js +0 -148
  244. package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
  245. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -652
  246. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
  247. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -285
  248. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
  249. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -763
  250. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
  251. package/es/utils/aepp-wallet-communication/schema.js +0 -103
  252. package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
  253. package/es/utils/aepp-wallet-communication/wallet-detector.js +0 -135
  254. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
  255. package/es/utils/amount-formatter.js +0 -152
  256. package/es/utils/amount-formatter.js.map +0 -1
  257. package/es/utils/async-init.js +0 -103
  258. package/es/utils/async-init.js.map +0 -1
  259. package/es/utils/bignumber.js +0 -36
  260. package/es/utils/bignumber.js.map +0 -1
  261. package/es/utils/bytes.js.map +0 -1
  262. package/es/utils/crypto-ts.js.map +0 -1
  263. package/es/utils/crypto.js +0 -358
  264. package/es/utils/crypto.js.map +0 -1
  265. package/es/utils/hd-wallet.js +0 -148
  266. package/es/utils/hd-wallet.js.map +0 -1
  267. package/es/utils/json-big.js +0 -78
  268. package/es/utils/json-big.js.map +0 -1
  269. package/es/utils/keystore.js +0 -393
  270. package/es/utils/keystore.js.map +0 -1
  271. package/es/utils/mptree.js +0 -198
  272. package/es/utils/mptree.js.map +0 -1
  273. package/es/utils/other.js +0 -93
  274. package/es/utils/other.js.map +0 -1
  275. package/es/utils/semver-satisfies.js +0 -35
  276. package/es/utils/semver-satisfies.js.map +0 -1
  277. package/es/utils/string.js.map +0 -1
  278. package/es/utils/swagger.js +0 -269
  279. package/es/utils/swagger.js.map +0 -1
  280. package/src/contract/aci/helpers.js +0 -140
  281. package/src/contract/aci/index.js +0 -191
  282. package/src/contract/aci/transformation.js +0 -464
  283. package/src/contract/index.js +0 -159
  284. package/src/utils/aepp-wallet-communication/schema.js +0 -110
@@ -21,14 +21,14 @@
21
21
  * @export Wallet
22
22
  * @example import { RpcWallet } from '@aeternity/aepp-sdk'
23
23
  */
24
- import Ae from './';
25
- import Chain from '../chain/node';
26
- import Tx from '../tx/tx';
27
- import Contract from './contract';
28
- import GeneralizeAccount from '../contract/ga';
29
- import WalletRpc from '../utils/aepp-wallet-communication/rpc/wallet-rpc';
30
- import Oracle from './oracle';
31
- import Aens from './aens';
24
+ import Ae from "./index.mjs";
25
+ import Chain from "../chain/node.mjs";
26
+ import Tx from "../tx/tx.mjs";
27
+ import Contract from "./contract.mjs";
28
+ import GeneralizedAccount from "../contract/ga/index.mjs";
29
+ import WalletRpc from "../utils/aepp-wallet-communication/rpc/wallet-rpc.mjs";
30
+ import Oracle from "./oracle.mjs";
31
+ import Aens from "./aens.mjs";
32
32
  /**
33
33
  * Wallet Stamp
34
34
  * @function
@@ -46,5 +46,5 @@ import Aens from './aens';
46
46
  })
47
47
  */
48
48
 
49
- export default Ae.compose(WalletRpc, Tx, Contract, Oracle, Aens, GeneralizeAccount, Chain);
50
- //# sourceMappingURL=wallet.js.map
49
+ export default Ae.compose(WalletRpc, Tx, Contract, Oracle, Aens, GeneralizedAccount, Chain);
50
+ //# sourceMappingURL=wallet.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ae/wallet.js"],"names":["Ae","Chain","Tx","Contract","GeneralizedAccount","WalletRpc","Oracle","Aens","compose"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;OAEOA,E;OACAC,K;OACAC,E;OACAC,Q;OACAC,kB;OACAC,S;OACAC,M;OACAC,I;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAeP,EAAE,CAACQ,OAAH,CAAWH,SAAX,EAAsBH,EAAtB,EAA0BC,QAA1B,EAAoCG,MAApC,EAA4CC,IAA5C,EAAkDH,kBAAlD,EAAsEH,KAAtE,CAAf","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2018 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 */\n\n/**\n * Wallet module\n * @module @aeternity/aepp-sdk/es/ae/wallet\n * @export Wallet\n * @example import { RpcWallet } from '@aeternity/aepp-sdk'\n */\n\nimport Ae from './'\nimport Chain from '../chain/node'\nimport Tx from '../tx/tx'\nimport Contract from './contract'\nimport GeneralizedAccount from '../contract/ga'\nimport WalletRpc from '../utils/aepp-wallet-communication/rpc/wallet-rpc'\nimport Oracle from './oracle'\nimport Aens from './aens'\n\n/**\n * Wallet Stamp\n * @function\n * @alias module:@aeternity/aepp-sdk/es/ae/wallet\n * @rtype Stamp\n * @param {Object} [options={}] - Initializer object\n * @param {String} options.url - Node instance to connect to\n * @param {Account[]} [options.accounts] - Accounts to initialize with\n * @param {String} [options.account] - Public key of account to preselect\n * @return {Object} Wallet instance\n * @example Wallet({\n url: 'https://testnet.aeternity.io/',\n accounts: [MemoryAccount({keypair})],\n address: keypair.publicKey,\n})\n */\nexport default Ae.compose(WalletRpc, Tx, Contract, Oracle, Aens, GeneralizedAccount, Chain)\n"],"file":"wallet.mjs"}
@@ -0,0 +1,74 @@
1
+ export declare const VERSION = 1;
2
+ export declare const enum MESSAGE_DIRECTION {
3
+ to_waellet = "to_waellet",
4
+ to_aepp = "to_aepp"
5
+ }
6
+ export declare const enum WALLET_TYPE {
7
+ window = "window",
8
+ extension = "extension"
9
+ }
10
+ export declare const enum SUBSCRIPTION_TYPES {
11
+ subscribe = "subscribe",
12
+ unsubscribe = "unsubscribe"
13
+ }
14
+ export declare const enum METHODS {
15
+ readyToConnect = "connection.announcePresence",
16
+ updateAddress = "address.update",
17
+ address = "address.get",
18
+ connect = "connection.open",
19
+ sign = "transaction.sign",
20
+ signMessage = "message.sign",
21
+ subscribeAddress = "address.subscribe",
22
+ updateNetwork = "networkId.update",
23
+ closeConnection = "connection.close"
24
+ }
25
+ export declare const enum RPC_STATUS {
26
+ CONNECTED = "CONNECTED",
27
+ NODE_BINDED = "NODE_BINDED",
28
+ DISCONNECTED = "DISCONNECTED",
29
+ CONNECTION_REJECTED = "CONNECTION_REJECTED",
30
+ WAITING_FOR_CONNECTION_APPROVE = "WAITING_FOR_CONNECTION_APPROVE",
31
+ WAITING_FOR_CONNECTION_REQUEST = "WAITING_FOR_CONNECTION_REQUEST"
32
+ }
33
+ export declare const ERRORS: {
34
+ broadcastFailed: (error?: {}) => {
35
+ code: number;
36
+ data: {};
37
+ message: string;
38
+ };
39
+ invalidTransaction: (error?: {}) => {
40
+ code: number;
41
+ data: {};
42
+ message: string;
43
+ };
44
+ rejectedByUser: (error?: {}) => {
45
+ code: number;
46
+ data: {};
47
+ message: string;
48
+ };
49
+ connectionDeny: (error?: {}) => {
50
+ code: number;
51
+ data: {};
52
+ message: string;
53
+ };
54
+ permissionDeny: (address: string) => {
55
+ code: number;
56
+ message: string;
57
+ };
58
+ internalError: (message: string) => {
59
+ code: number;
60
+ message: string;
61
+ };
62
+ notAuthorize: () => {
63
+ code: number;
64
+ message: string;
65
+ };
66
+ unsupportedProtocol: () => {
67
+ code: number;
68
+ message: string;
69
+ };
70
+ unsupportedNetwork: () => {
71
+ code: number;
72
+ message: string;
73
+ };
74
+ };
package/es/bignumber.d.ts CHANGED
@@ -1,15 +1,9 @@
1
1
  /**
2
2
  * Big Number Helpers
3
3
  * @module @aeternity/aepp-sdk/es/utils/bignumber
4
- * @example import { parseBigNumber, isBigNumber, ceil } from '@aeternity/aepp-sdk/es/utils/bignumber'
4
+ * @example import { isBigNumber, ceil } from '@aeternity/aepp-sdk/es/utils/bignumber'
5
5
  */
6
6
  import BigNumber from 'bignumber.js';
7
- /**
8
- * Convert number to string
9
- * @param {String|Number|BigNumber} number number to convert
10
- * @return {String}
11
- */
12
- export declare const parseBigNumber: (number: string | number | BigNumber) => string;
13
7
  /**
14
8
  * Check if value is BigNumber, Number or number string representation
15
9
  * @param {String|Number|BigNumber} number number to convert
@@ -22,7 +22,7 @@
22
22
  * @example import { Chain } from '@aeternity/aepp-sdk'
23
23
  */
24
24
  import stampit from '@stamp/it';
25
- import { required } from '@stamp/required';
25
+ import _stampRequired from '@stamp/required';
26
26
  /**
27
27
  * Basic Chain Stamp
28
28
  *
@@ -35,21 +35,37 @@ import { required } from '@stamp/required';
35
35
  * @return {Object} Chain instance
36
36
  */
37
37
 
38
- var Chain = stampit({
38
+ const {
39
+ required
40
+ } = _stampRequired;
41
+ const Chain = stampit({
39
42
  deepProps: {
40
43
  Ae: {
41
44
  defaults: {
42
45
  waitMined: true,
43
- verify: true
46
+ verify: true,
47
+ _expectedMineRate: 180000,
48
+ _microBlockCycle: 3000,
49
+ _maxPollInterval: 5000
44
50
  }
45
51
  }
52
+ },
53
+ methods: {
54
+ _getPollInterval(type) {
55
+ const base = {
56
+ block: this.Ae.defaults._expectedMineRate,
57
+ microblock: this.Ae.defaults._microBlockCycle
58
+ }[type];
59
+ if (!base) throw new Error(`Unknown poll type: ${type}`);
60
+ return Math.min(base / 3, this.Ae.defaults._maxPollInterval);
61
+ }
62
+
46
63
  }
47
64
  }, required({
48
65
  methods: {
49
66
  sendTransaction: required,
50
67
  height: required,
51
68
  awaitHeight: required,
52
- topBlock: required,
53
69
  poll: required,
54
70
  balance: required,
55
71
  getBalance: required,
@@ -118,8 +134,10 @@ var Chain = stampit({
118
134
  * @rtype (address: String, options?: Object) => balance: Number
119
135
  * @param {String} address - The public account address to obtain the balance for
120
136
  * @param {Object} [options={}] - Options
121
- * @param {Number} options.height - The chain height at which to obtain the balance for (default: top of chain)
122
- * @param {String} options.hash - The block hash on which to obtain the balance for (default: top of chain)
137
+ * @param {Number} options.height - The chain height at which to obtain the balance for (default:
138
+ * top of chain)
139
+ * @param {String} options.hash - The block hash on which to obtain the balance for (default: top
140
+ * of chain)
123
141
  * @return {Object} The transaction as it was mined
124
142
  */
125
143
 
@@ -131,7 +149,8 @@ var Chain = stampit({
131
149
  * @category async
132
150
  * @rtype (hash: String, info = false) => tx: Object
133
151
  * @param {String} hash - Transaction hash
134
- * @param {Boolean} info - Retrieve additional transaction date. Works only for (ContractCreate and ContractCall transaction's)
152
+ * @param {Boolean} info - Retrieve additional transaction date. Works only for (ContractCreate and
153
+ * ContractCall transaction's)
135
154
  * @return {Object} Transaction
136
155
  */
137
156
 
@@ -244,9 +263,10 @@ var Chain = stampit({
244
263
  * @param {String} tx - transaction to execute
245
264
  * @param {String} accountAddress - address that will be used to execute transaction
246
265
  * @param {String|Number} [options.top] - hash of block on which to make dry-run
247
- * @param {Boolean} [options.txEvents] - collect and return on-chain tx events that would result from the call
266
+ * @param {Boolean} [options.txEvents] - collect and return on-chain tx events that would result
267
+ * from the call
248
268
  * @return {Object} Result
249
269
  */
250
270
 
251
271
  export default Chain;
252
- //# sourceMappingURL=index.js.map
272
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/chain/index.js"],"names":["stampit","Chain","deepProps","Ae","defaults","waitMined","verify","_expectedMineRate","_microBlockCycle","_maxPollInterval","methods","_getPollInterval","type","base","block","microblock","Error","Math","min","required","sendTransaction","height","awaitHeight","poll","balance","getBalance","tx","getTxInfo","mempool","txDryRun","getAccount"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAOA,OAAP,MAAoB,WAApB;AACA,2BAAyB,iBAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACA,MAAMC,KAAK,GAAGD,OAAO,CAAC;AACpBE,EAAAA,SAAS,EAAE;AACTC,IAAAA,EAAE,EAAE;AACFC,MAAAA,QAAQ,EAAE;AACRC,QAAAA,SAAS,EAAE,IADH;AAERC,QAAAA,MAAM,EAAE,IAFA;AAGRC,QAAAA,iBAAiB,EAAE,MAHX;AAIRC,QAAAA,gBAAgB,EAAE,IAJV;AAKRC,QAAAA,gBAAgB,EAAE;AALV;AADR;AADK,GADS;AAYpBC,EAAAA,OAAO,EAAE;AACPC,IAAAA,gBAAgB,CAAEC,IAAF,EAAQ;AACtB,YAAMC,IAAI,GAAG;AACXC,QAAAA,KAAK,EAAE,KAAKX,EAAL,CAAQC,QAAR,CAAiBG,iBADb;AAEXQ,QAAAA,UAAU,EAAE,KAAKZ,EAAL,CAAQC,QAAR,CAAiBI;AAFlB,QAGXI,IAHW,CAAb;AAIA,UAAI,CAACC,IAAL,EAAW,MAAM,IAAIG,KAAJ,CAAW,sBAAqBJ,IAAK,EAArC,CAAN;AACX,aAAOK,IAAI,CAACC,GAAL,CAASL,IAAI,GAAG,CAAhB,EAAmB,KAAKV,EAAL,CAAQC,QAAR,CAAiBK,gBAApC,CAAP;AACD;;AARM;AAZW,CAAD,EAsBlBU,QAAQ,CAAC;AACVT,EAAAA,OAAO,EAAE;AACPU,IAAAA,eAAe,EAAED,QADV;AAEPE,IAAAA,MAAM,EAAEF,QAFD;AAGPG,IAAAA,WAAW,EAAEH,QAHN;AAIPI,IAAAA,IAAI,EAAEJ,QAJC;AAKPK,IAAAA,OAAO,EAAEL,QALF;AAMPM,IAAAA,UAAU,EAAEN,QANL;AAOPO,IAAAA,EAAE,EAAEP,QAPG;AAQPQ,IAAAA,SAAS,EAAER,QARJ;AASPS,IAAAA,OAAO,EAAET,QATF;AAUPU,IAAAA,QAAQ,EAAEV,QAVH;AAWPW,IAAAA,UAAU,EAAEX;AAXL;AADC,CAAD,CAtBU,CAArB;AAsCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,eAAelB,KAAf","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2018 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 */\n\n/**\n * Chain module\n * @module @aeternity/aepp-sdk/es/chain\n * @export Chain\n * @example import { Chain } from '@aeternity/aepp-sdk'\n */\n\nimport stampit from '@stamp/it'\nimport { required } from '@stamp/required'\n\n/**\n * Basic Chain Stamp\n *\n * Attempting to create instances from the Stamp without overwriting all\n * abstract methods using composition will result in an exception.\n * @function\n * @alias module:@aeternity/aepp-sdk/es/chain\n * @rtype Stamp\n * @param {Object} [options={}] - Initializer object\n * @return {Object} Chain instance\n */\nconst Chain = stampit({\n deepProps: {\n Ae: {\n defaults: {\n waitMined: true,\n verify: true,\n _expectedMineRate: 180000,\n _microBlockCycle: 3000,\n _maxPollInterval: 5000\n }\n }\n },\n methods: {\n _getPollInterval (type) {\n const base = {\n block: this.Ae.defaults._expectedMineRate,\n microblock: this.Ae.defaults._microBlockCycle\n }[type]\n if (!base) throw new Error(`Unknown poll type: ${type}`)\n return Math.min(base / 3, this.Ae.defaults._maxPollInterval)\n }\n }\n}, required({\n methods: {\n sendTransaction: required,\n height: required,\n awaitHeight: required,\n poll: required,\n balance: required,\n getBalance: required,\n tx: required,\n getTxInfo: required,\n mempool: required,\n txDryRun: required,\n getAccount: required\n }\n}))\n\n/**\n * Submit a signed transaction for mining\n * @function sendTransaction\n * @instance\n * @abstract\n * @category async\n * @rtype (tx: String, options?: Object) => tx: Promise[Object]|txHash: Promise[String]\n * @param {String} tx - Transaction to submit\n * @param {String} [options={}] - Options to pass to the implementation\n * @param {String} [options.verify=true] - Verify transaction before broadcast.\n * @return {Object} Transaction\n */\n\n/**\n * Obtain current height of the chain\n * @function height\n * @instance\n * @abstract\n * @category async\n * @rtype () => height: Number\n * @return {Number} Current chain height\n */\n\n/**\n * Wait for the chain to reach a specific height\n * @function awaitHeight\n * @instance\n * @abstract\n * @category async\n * @rtype (height: Number, options?: Object) => height: Number\n * @param {Object} [options={}] - Options\n * @param {Number} options.interval - Interval (in ms) at which to poll the chain\n * @param {Number} options.attempts - Number of polling attempts after which to fail\n * @return {Number} Current chain height\n */\n\n/**\n * Wait for a transaction to be mined\n * @function poll\n * @instance\n * @abstract\n * @category async\n * @rtype (th: String, options?: Object) => tx: Object\n * @param {Object} [options={}] - Options\n * @param {Number} options.interval - Interval (in ms) at which to poll the chain\n * @param {Number} options.blocks - Number of blocks mined after which to fail\n * @return {Object} The transaction as it was mined\n */\n\n/**\n * Request the balance of specified account\n * @function balance\n * @instance\n * @abstract\n * @category async\n * @rtype (address: String, options?: Object) => balance: Number\n * @param {String} address - The public account address to obtain the balance for\n * @param {Object} [options={}] - Options\n * @param {Number} options.height - The chain height at which to obtain the balance for (default:\n * top of chain)\n * @param {String} options.hash - The block hash on which to obtain the balance for (default: top\n * of chain)\n * @return {Object} The transaction as it was mined\n */\n\n/**\n * Obtain a transaction based on its hash\n * @function tx\n * @instance\n * @abstract\n * @category async\n * @rtype (hash: String, info = false) => tx: Object\n * @param {String} hash - Transaction hash\n * @param {Boolean} info - Retrieve additional transaction date. Works only for (ContractCreate and\n * ContractCall transaction's)\n * @return {Object} Transaction\n */\n\n/**\n * Obtain a transaction info based on its hash\n * @function getTxInfo\n * @instance\n * @abstract\n * @category async\n * @rtype (hash: String) => tx: Object\n * @param {String} hash - Transaction hash\n * @return {Object} Transaction\n */\n\n/**\n * Obtain transaction's from mempool\n * @function mempool\n * @instance\n * @abstract\n * @category async\n * @rtype () => txs: [...Object]\n * @return {Object[]} Transactions\n */\n\n/**\n * Obtain current generation\n * @function getCurrentGeneration\n * @instance\n * @abstract\n * @category async\n * @rtype () => generation: Object\n * @return {Object} Current Generation\n */\n\n/**\n * Get generation by hash or height\n * @function getGeneration\n * @instance\n * @abstract\n * @category async\n * @rtype (hashOrHeight) => generation: Object\n * @param {String|Number} hashOrHeight - Generation hash or height\n * @return {Object} Generation\n */\n\n/**\n * Wait for transaction confirmation\n * @function waitForTxConfirm\n * @instance\n * @abstract\n * @category async\n * @rtype (txHash: String, { confirm: Number | Boolean } = { confirm: 3 }) => Promise<Number>\n * @param {String} txHash - Transaction hash\n * @param {Object} [options] - options\n * @param {Number} [options.confirm=3] - Number of blocks to wait for transaction confirmation\n * @return {Promise<Number>} Current Height\n */\n\n/**\n * Get micro block transactions\n * @function getMicroBlockTransactions\n * @instance\n * @abstract\n * @category async\n * @rtype (hash) => txs: [...Object]\n * @return {Object[]} Transactions\n */\n\n/**\n * Get key block\n * @function getKeyBlock\n * @instance\n * @abstract\n * @category async\n * @rtype (hashOrHeight) => keyBlock: Object\n * @return {Object} Key Block\n */\n\n/**\n * Get micro block header\n * @function getMicroBlockHeader\n * @instance\n * @abstract\n * @category async\n * @rtype (hash) => header: Object\n * @return {Object} Micro block header\n */\n\n/**\n * Get account by account public key\n * @function getAccount\n * @instance\n * @abstract\n * @category async\n * @rtype (address, { hash, height }) => account: Object\n * @param {String} address - Account public key\n * @param {Object} [options={}] - Options\n * @param {Number} [options.height] - Get account on specific block by block height\n * @param {String} [options.hash] - Get account on specific block by block hash\n * @return {Object} Account\n */\n\n/**\n * Transaction dry-run\n * @function txDryRun\n * @instance\n * @abstract\n * @category async\n * @rtype (tx, accountAddress, options) => result: Object\n * @param {String} tx - transaction to execute\n * @param {String} accountAddress - address that will be used to execute transaction\n * @param {String|Number} [options.top] - hash of block on which to make dry-run\n * @param {Boolean} [options.txEvents] - collect and return on-chain tx events that would result\n * from the call\n * @return {Object} Result\n */\n\nexport default Chain\n"],"file":"index.mjs"}
@@ -0,0 +1,442 @@
1
+ /*
2
+ * ISC License (ISC)
3
+ * Copyright (c) 2018 aeternity developers
4
+ *
5
+ * Permission to use, copy, modify, and/or distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ * PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+ import Chain from "./index.mjs";
18
+ import { AE_AMOUNT_FORMATS, formatAmount } from "../utils/amount-formatter.mjs";
19
+ import verifyTransaction from "../tx/validator.mjs";
20
+ import NodePool from "../node-pool/index.mjs";
21
+ import { pause } from "../utils/other.mjs";
22
+ import { isNameValid, produceNameId, decode } from "../tx/builder/helpers.mjs";
23
+ import { DRY_RUN_ACCOUNT } from "../tx/builder/schema.mjs";
24
+ import { AensPointerContextError, DryRunError, InvalidAensNameError, InvalidTxError, RequestTimedOutError, TxTimedOutError, TxNotInChainError, ArgumentError } from "../utils/errors.mjs";
25
+ /**
26
+ * ChainNode module
27
+ *
28
+ * This is the complement to {@link module:@aeternity/aepp-sdk/es/chain}.
29
+ * @module @aeternity/aepp-sdk/es/chain/node
30
+ * @export ChainNode
31
+ * @example import { ChainNode } from '@aeternity/aepp-sdk'
32
+ */
33
+
34
+ async function sendTransaction(tx) {
35
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
36
+ const opt = { ...this.Ae.defaults,
37
+ ...options
38
+ };
39
+
40
+ if (opt.verify) {
41
+ const validation = await verifyTransaction(tx, this.selectedNode.instance);
42
+
43
+ if (validation.length) {
44
+ const message = 'Transaction verification errors: ' + validation.map(v => v.message).join(', ');
45
+ throw Object.assign(new InvalidTxError(message), {
46
+ code: 'TX_VERIFICATION_ERROR',
47
+ validation,
48
+ transaction: tx
49
+ });
50
+ }
51
+ }
52
+
53
+ try {
54
+ var _this$address;
55
+
56
+ const {
57
+ txHash
58
+ } = await this.api.postTransaction({
59
+ tx
60
+ }, {
61
+ __queue: `tx-${await ((_this$address = this.address) === null || _this$address === void 0 ? void 0 : _this$address.call(this, options).catch(() => ''))}`
62
+ });
63
+
64
+ if (opt.waitMined) {
65
+ const txData = { ...(await this.poll(txHash, options)),
66
+ rawTx: tx
67
+ }; // wait for transaction confirmation
68
+
69
+ if (options.confirm) {
70
+ return { ...txData,
71
+ confirmationHeight: await this.waitForTxConfirm(txHash, options)
72
+ };
73
+ }
74
+
75
+ return txData;
76
+ }
77
+
78
+ return {
79
+ hash: txHash,
80
+ rawTx: tx
81
+ };
82
+ } catch (error) {
83
+ throw Object.assign(error, {
84
+ rawTx: tx,
85
+ verifyTx: () => verifyTransaction(tx, this.selectedNode.instance)
86
+ });
87
+ }
88
+ }
89
+
90
+ async function waitForTxConfirm(txHash) {
91
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
92
+ confirm: 3
93
+ };
94
+ options.confirm = options.confirm === true ? 3 : options.confirm;
95
+ const {
96
+ blockHeight
97
+ } = await this.api.getTransactionByHash(txHash);
98
+ const height = await this.awaitHeight(blockHeight + options.confirm, options);
99
+ const {
100
+ blockHeight: newBlockHeight
101
+ } = await this.api.getTransactionByHash(txHash);
102
+
103
+ switch (newBlockHeight) {
104
+ case -1:
105
+ throw new TxNotInChainError(txHash);
106
+
107
+ case blockHeight:
108
+ return height;
109
+
110
+ default:
111
+ return waitForTxConfirm(txHash, options);
112
+ }
113
+ }
114
+
115
+ async function getAccount(address) {
116
+ let {
117
+ height,
118
+ hash
119
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
120
+ if (height) return this.api.getAccountByPubkeyAndHeight(address, height);
121
+ if (hash) return this.api.getAccountByPubkeyAndHash(address, hash);
122
+ return this.api.getAccountByPubkey(address);
123
+ }
124
+ /**
125
+ * @function
126
+ * @deprecated
127
+ */
128
+
129
+
130
+ async function balance(address) {
131
+ let {
132
+ height,
133
+ hash,
134
+ format = AE_AMOUNT_FORMATS.AETTOS
135
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
136
+ const {
137
+ balance
138
+ } = await this.getAccount(address, {
139
+ hash,
140
+ height
141
+ });
142
+ return formatAmount(balance, {
143
+ targetDenomination: format
144
+ }).toString();
145
+ }
146
+
147
+ async function getBalance(address) {
148
+ let {
149
+ height,
150
+ hash,
151
+ format = AE_AMOUNT_FORMATS.AETTOS
152
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
153
+ const {
154
+ balance
155
+ } = await this.getAccount(address, {
156
+ hash,
157
+ height
158
+ }).catch(_ => ({
159
+ balance: 0
160
+ }));
161
+ return formatAmount(balance, {
162
+ targetDenomination: format
163
+ }).toString();
164
+ }
165
+ /**
166
+ * @deprecated use `sdk.api.getTransactionByHash/getTransactionInfoByHash` instead
167
+ */
168
+
169
+
170
+ async function tx(hash) {
171
+ let info = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
172
+ const tx = await this.api.getTransactionByHash(hash);
173
+
174
+ if (['ContractCreateTx', 'ContractCallTx', 'ChannelForceProgressTx'].includes(tx.tx.type) && info && tx.blockHeight !== -1) {
175
+ try {
176
+ return { ...tx,
177
+ ...(await this.getTxInfo(hash))
178
+ };
179
+ } catch (e) {}
180
+ }
181
+
182
+ return tx;
183
+ }
184
+
185
+ async function height() {
186
+ return (await this.api.getCurrentKeyBlockHeight()).height;
187
+ }
188
+
189
+ async function awaitHeight(height) {
190
+ let {
191
+ interval = this._getPollInterval('block'),
192
+ attempts = 20
193
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
194
+ let currentHeight;
195
+
196
+ for (let i = 0; i < attempts; i++) {
197
+ if (i) await pause(interval);
198
+ currentHeight = await this.height();
199
+ if (currentHeight >= height) return currentHeight;
200
+ }
201
+
202
+ throw new RequestTimedOutError((attempts - 1) * interval, currentHeight, height);
203
+ }
204
+
205
+ async function poll(th) {
206
+ let {
207
+ blocks = 10,
208
+ interval = this._getPollInterval('microblock')
209
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
210
+ const max = (await this.height()) + blocks;
211
+
212
+ do {
213
+ const tx = await this.api.getTransactionByHash(th);
214
+ if (tx.blockHeight !== -1) return tx;
215
+ await pause(interval);
216
+ } while ((await this.height()) < max);
217
+
218
+ const status = this.api.getCheckTxInPool && (await this.api.getCheckTxInPool(th)).status;
219
+ throw new TxTimedOutError(blocks, th, status);
220
+ }
221
+ /**
222
+ * @deprecated use `sdk.api.getTransactionInfoByHash` instead
223
+ */
224
+
225
+
226
+ async function getTxInfo(hash) {
227
+ const result = await this.api.getTransactionInfoByHash(hash);
228
+ return result.callInfo || result;
229
+ }
230
+
231
+ async function mempool() {
232
+ return this.api.getPendingTransactions();
233
+ }
234
+
235
+ async function getCurrentGeneration() {
236
+ return this.api.getCurrentGeneration();
237
+ }
238
+
239
+ async function getGeneration(hashOrHeight) {
240
+ if (typeof hashOrHeight === 'string') return this.api.getGenerationByHash(hashOrHeight);
241
+ if (typeof hashOrHeight === 'number') return this.api.getGenerationByHeight(hashOrHeight);
242
+ throw new ArgumentError('hashOrHeight', 'a string or number', hashOrHeight);
243
+ }
244
+
245
+ async function getMicroBlockTransactions(hash) {
246
+ return (await this.api.getMicroBlockTransactionsByHash(hash)).transactions;
247
+ }
248
+
249
+ async function getKeyBlock(hashOrHeight) {
250
+ if (typeof hashOrHeight === 'string') return this.api.getKeyBlockByHash(hashOrHeight);
251
+ if (typeof hashOrHeight === 'number') return this.api.getKeyBlockByHeight(hashOrHeight);
252
+ throw new ArgumentError('hashOrHeight', 'a string or number', hashOrHeight);
253
+ }
254
+
255
+ async function getMicroBlockHeader(hash) {
256
+ return this.api.getMicroBlockHeaderByHash(hash);
257
+ }
258
+
259
+ async function txDryRunHandler(key) {
260
+ const rs = this._txDryRun[key];
261
+ delete this._txDryRun[key];
262
+ let dryRunRes;
263
+
264
+ try {
265
+ dryRunRes = await this.api.protectedDryRunTxs({
266
+ top: rs[0].top,
267
+ txEvents: rs[0].txEvents,
268
+ txs: rs.map(req => ({
269
+ tx: req.tx
270
+ })),
271
+ accounts: Array.from(new Set(rs.map(req => req.accountAddress))).map(pubKey => ({
272
+ pubKey,
273
+ amount: DRY_RUN_ACCOUNT.amount
274
+ }))
275
+ });
276
+ } catch (error) {
277
+ rs.forEach(_ref => {
278
+ let {
279
+ reject
280
+ } = _ref;
281
+ return reject(error);
282
+ });
283
+ return;
284
+ }
285
+
286
+ const {
287
+ results,
288
+ txEvents
289
+ } = dryRunRes;
290
+ results.forEach((_ref2, idx) => {
291
+ let {
292
+ result,
293
+ reason,
294
+ ...resultPayload
295
+ } = _ref2;
296
+ const {
297
+ resolve,
298
+ reject,
299
+ tx,
300
+ options,
301
+ accountAddress
302
+ } = rs[idx];
303
+ if (result === 'ok') return resolve({ ...resultPayload,
304
+ txEvents
305
+ });
306
+ reject(Object.assign(new DryRunError(reason), {
307
+ tx,
308
+ accountAddress,
309
+ options
310
+ }));
311
+ });
312
+ }
313
+
314
+ async function txDryRun(tx, accountAddress, _ref3) {
315
+ var _this$_txDryRun, _this$_txDryRun2, _this$_txDryRun2$key;
316
+
317
+ let {
318
+ top,
319
+ txEvents,
320
+ combine
321
+ } = _ref3;
322
+ const key = combine ? [top, txEvents].join() : 'immediate';
323
+ (_this$_txDryRun = this._txDryRun) !== null && _this$_txDryRun !== void 0 ? _this$_txDryRun : this._txDryRun = {};
324
+ (_this$_txDryRun2$key = (_this$_txDryRun2 = this._txDryRun)[key]) !== null && _this$_txDryRun2$key !== void 0 ? _this$_txDryRun2$key : _this$_txDryRun2[key] = [];
325
+ return new Promise((resolve, reject) => {
326
+ var _this$_txDryRun$key, _this$_txDryRun$key$t;
327
+
328
+ this._txDryRun[key].push({
329
+ tx,
330
+ accountAddress,
331
+ top,
332
+ txEvents,
333
+ resolve,
334
+ reject
335
+ });
336
+
337
+ if (!combine) {
338
+ txDryRunHandler.call(this, key);
339
+ return;
340
+ }
341
+
342
+ (_this$_txDryRun$key$t = (_this$_txDryRun$key = this._txDryRun[key]).timeout) !== null && _this$_txDryRun$key$t !== void 0 ? _this$_txDryRun$key$t : _this$_txDryRun$key.timeout = setTimeout(txDryRunHandler.bind(this, key));
343
+ });
344
+ }
345
+
346
+ async function getContractByteCode(contractId) {
347
+ return this.api.getContractCode(contractId);
348
+ }
349
+
350
+ async function getContract(contractId) {
351
+ return this.api.getContract(contractId);
352
+ }
353
+
354
+ async function getName(name) {
355
+ return this.api.getNameEntryByName(name);
356
+ }
357
+ /**
358
+ * Resolve AENS name and return name hash
359
+ * @param {String} nameOrId
360
+ * @param {String} key in AENS pointers record
361
+ * @param {Object} [options]
362
+ * @param {Boolean} [options.verify] To ensure that name exist and have a corresponding pointer
363
+ * // TODO: avoid that to don't trust to current api gateway
364
+ * @param {Boolean} [options.resolveByNode] Enables pointer resolving using node
365
+ * @return {String} Address or AENS name hash
366
+ */
367
+
368
+
369
+ async function resolveName(nameOrId, key) {
370
+ let {
371
+ verify,
372
+ resolveByNode
373
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
374
+
375
+ if (!nameOrId || typeof nameOrId !== 'string') {
376
+ throw new InvalidAensNameError(`Name or address should be a string: ${nameOrId}`);
377
+ }
378
+
379
+ try {
380
+ decode(nameOrId);
381
+ return nameOrId;
382
+ } catch (error) {}
383
+
384
+ if (isNameValid(nameOrId)) {
385
+ if (verify || resolveByNode) {
386
+ const name = await this.api.getNameEntryByName(nameOrId);
387
+ const pointer = name.pointers.find(pointer => pointer.key === key);
388
+
389
+ if (!pointer) {
390
+ throw new AensPointerContextError(`Name ${nameOrId} don't have pointers for ${key}`);
391
+ }
392
+
393
+ if (resolveByNode) return pointer.id;
394
+ }
395
+
396
+ return produceNameId(nameOrId);
397
+ }
398
+
399
+ throw new InvalidAensNameError(`Invalid name or address: ${nameOrId}`);
400
+ }
401
+ /**
402
+ * ChainNode Stamp
403
+ *
404
+ * This is implementation of {@link module:@aeternity/aepp-sdk/es/chain--Chain}
405
+ * composed with {@link module:@aeternity/aepp-sdk/es/contract/node--ContractNodeAPI} and
406
+ * {@link module:@aeternity/aepp-sdk/es/oracle/node--OracleNodeAPI}
407
+ * @function
408
+ * @alias module:@aeternity/aepp-sdk/es/chain/node
409
+ * @rtype Stamp
410
+ * @param {Object} [options={}] - Initializer object
411
+ * @return {Object} ChainNode instance
412
+ * @example ChainNode({url: 'https://testnet.aeternity.io/'})
413
+ */
414
+
415
+
416
+ const ChainNode = Chain.compose(NodePool, {
417
+ methods: {
418
+ sendTransaction,
419
+ balance,
420
+ getBalance,
421
+ getAccount,
422
+ tx,
423
+ height,
424
+ awaitHeight,
425
+ poll,
426
+ getTxInfo,
427
+ mempool,
428
+ getCurrentGeneration,
429
+ getGeneration,
430
+ getMicroBlockHeader,
431
+ getMicroBlockTransactions,
432
+ getKeyBlock,
433
+ txDryRun,
434
+ getContractByteCode,
435
+ getContract,
436
+ getName,
437
+ waitForTxConfirm,
438
+ resolveName
439
+ }
440
+ });
441
+ export default ChainNode;
442
+ //# sourceMappingURL=node.mjs.map