@aeternity/aepp-sdk 10.0.0 → 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 (238) 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 -27
  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.js → base.mjs} +20 -10
  10. package/es/account/base.mjs.map +1 -0
  11. package/es/account/{memory.js → memory.mjs} +29 -14
  12. package/es/account/memory.mjs.map +1 -0
  13. package/es/account/{multiple.js → multiple.mjs} +10 -9
  14. package/es/account/multiple.mjs.map +1 -0
  15. package/es/ae/{aens.js → aens.mjs} +18 -22
  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.js → index.mjs} +8 -7
  22. package/es/ae/index.mjs.map +1 -0
  23. package/es/ae/{oracle.js → oracle.mjs} +33 -16
  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} +20 -4
  32. package/es/chain/index.mjs.map +1 -0
  33. package/es/chain/{node.js → node.mjs} +121 -73
  34. package/es/chain/node.mjs.map +1 -0
  35. package/es/channel/{handlers.js → handlers.mjs} +18 -20
  36. package/es/channel/handlers.mjs.map +1 -0
  37. package/es/channel/{index.js → index.mjs} +7 -7
  38. package/es/channel/index.mjs.map +1 -0
  39. package/es/channel/{internal.js → internal.mjs} +49 -32
  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.js → index.mjs} +36 -28
  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.js → index.mjs} +11 -10
  53. package/es/node-pool/index.mjs.map +1 -0
  54. package/es/{node.js → node.mjs} +9 -8
  55. package/es/node.mjs.map +1 -0
  56. package/es/tx/builder/field-types.mjs +74 -0
  57. package/es/tx/builder/field-types.mjs.map +1 -0
  58. package/es/tx/builder/{helpers.js → helpers.mjs} +114 -56
  59. package/es/tx/builder/helpers.mjs.map +1 -0
  60. package/es/tx/builder/{index.js → index.mjs} +79 -68
  61. package/es/tx/builder/index.mjs.map +1 -0
  62. package/es/tx/builder/{schema.js → schema.mjs} +11 -65
  63. package/es/tx/builder/schema.mjs.map +1 -0
  64. package/es/tx/{index.js → index.mjs} +5 -2
  65. package/es/tx/index.mjs.map +1 -0
  66. package/es/tx/{tx-object.js → tx-object.mjs} +22 -15
  67. package/es/tx/tx-object.mjs.map +1 -0
  68. package/es/tx/{tx.js → tx.mjs} +15 -14
  69. package/es/tx/tx.mjs.map +1 -0
  70. package/es/tx/{validator.js → validator.mjs} +72 -33
  71. package/es/tx/validator.mjs.map +1 -0
  72. package/es/typings/blakejs/index.d.mjs +2 -0
  73. package/es/typings/blakejs/{index.d.js.map → index.d.mjs.map} +1 -1
  74. package/es/utils/aepp-wallet-communication/connection/{browser-runtime.js → browser-runtime.mjs} +7 -6
  75. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
  76. package/es/utils/aepp-wallet-communication/connection/{browser-window-message.js → browser-window-message.mjs} +10 -11
  77. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +1 -0
  78. package/es/utils/aepp-wallet-communication/connection/{index.js → index.mjs} +5 -2
  79. package/es/utils/aepp-wallet-communication/connection/index.mjs.map +1 -0
  80. package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs} +6 -5
  81. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
  82. package/es/utils/aepp-wallet-communication/{helpers.js → helpers.mjs} +3 -14
  83. package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
  84. package/es/utils/aepp-wallet-communication/rpc/{aepp-rpc.js → aepp-rpc.mjs} +113 -67
  85. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
  86. package/es/utils/aepp-wallet-communication/rpc/{rpc-client.js → rpc-client.mjs} +14 -9
  87. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
  88. package/es/utils/aepp-wallet-communication/rpc/{wallet-rpc.js → wallet-rpc.mjs} +71 -63
  89. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +1 -0
  90. package/es/utils/aepp-wallet-communication/schema.mjs +102 -0
  91. package/es/utils/aepp-wallet-communication/schema.mjs.map +1 -0
  92. package/es/utils/aepp-wallet-communication/{wallet-detector.js → wallet-detector.mjs} +6 -5
  93. package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  94. package/es/utils/{amount-formatter.js → amount-formatter.mjs} +14 -7
  95. package/es/utils/amount-formatter.mjs.map +1 -0
  96. package/es/utils/{async-init.js → async-init.mjs} +8 -11
  97. package/es/utils/async-init.mjs.map +1 -0
  98. package/es/utils/{bignumber.js → bignumber.mjs} +2 -9
  99. package/es/utils/bignumber.mjs.map +1 -0
  100. package/es/utils/{bytes.js → bytes.mjs} +16 -8
  101. package/es/utils/bytes.mjs.map +1 -0
  102. package/es/utils/{crypto-ts.js → crypto-ts.mjs} +11 -3
  103. package/es/utils/crypto-ts.mjs.map +1 -0
  104. package/es/utils/{crypto.js → crypto.mjs} +40 -105
  105. package/es/utils/crypto.mjs.map +1 -0
  106. package/es/utils/errors.mjs +689 -0
  107. package/es/utils/errors.mjs.map +1 -0
  108. package/es/utils/{hd-wallet.js → hd-wallet.mjs} +33 -34
  109. package/es/utils/hd-wallet.mjs.map +1 -0
  110. package/es/utils/{json-big.js → json-big.mjs} +1 -1
  111. package/es/utils/{json-big.js.map → json-big.mjs.map} +1 -1
  112. package/es/utils/{keystore.js → keystore.mjs} +63 -51
  113. package/es/utils/keystore.mjs.map +1 -0
  114. package/es/utils/{mptree.js → mptree.mjs} +21 -12
  115. package/es/utils/mptree.mjs.map +1 -0
  116. package/es/utils/{other.js → other.mjs} +2 -2
  117. package/es/utils/other.mjs.map +1 -0
  118. package/es/utils/{semver-satisfies.js → semver-satisfies.mjs} +1 -1
  119. package/es/utils/{semver-satisfies.js.map → semver-satisfies.mjs.map} +1 -1
  120. package/es/utils/{string.js → string.mjs} +1 -1
  121. package/es/utils/{string.js.map → string.mjs.map} +1 -1
  122. package/es/utils/{swagger.js → swagger.mjs} +46 -14
  123. package/es/utils/swagger.mjs.map +1 -0
  124. package/package.json +46 -55
  125. package/src/account/memory.js +13 -8
  126. package/src/account/multiple.js +12 -4
  127. package/src/ae/aens.js +12 -17
  128. package/src/ae/aepp.js +2 -2
  129. package/src/ae/contract.js +15 -152
  130. package/src/ae/index.js +2 -1
  131. package/src/ae/oracle.js +25 -10
  132. package/src/ae/universal.js +2 -2
  133. package/src/ae/wallet.js +2 -2
  134. package/src/chain/index.js +21 -2
  135. package/src/chain/node.js +80 -53
  136. package/src/channel/handlers.js +20 -17
  137. package/src/channel/internal.js +30 -24
  138. package/src/contract/{aci/index.js → aci.js} +152 -93
  139. package/src/contract/compiler.js +22 -117
  140. package/src/contract/ga/helpers.js +7 -5
  141. package/src/contract/ga/index.js +27 -24
  142. package/src/index.js +7 -8
  143. package/src/node-pool/index.js +9 -8
  144. package/src/node.js +5 -7
  145. package/src/tx/builder/field-types.js +61 -0
  146. package/src/tx/builder/helpers.js +113 -58
  147. package/src/tx/builder/index.js +39 -34
  148. package/src/tx/builder/schema.js +11 -25
  149. package/src/tx/tx-object.js +10 -9
  150. package/src/tx/tx.js +17 -8
  151. package/src/tx/validator.js +25 -5
  152. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +8 -3
  153. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +10 -6
  154. package/src/utils/aepp-wallet-communication/content-script-bridge.js +5 -4
  155. package/src/utils/aepp-wallet-communication/helpers.js +2 -12
  156. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +81 -55
  157. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +15 -6
  158. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +60 -49
  159. package/src/utils/aepp-wallet-communication/schema.ts +80 -0
  160. package/src/utils/aepp-wallet-communication/wallet-detector.js +3 -2
  161. package/src/utils/amount-formatter.ts +4 -3
  162. package/src/utils/async-init.js +10 -6
  163. package/src/utils/bignumber.ts +1 -9
  164. package/src/utils/bytes.ts +3 -2
  165. package/src/utils/crypto-ts.ts +2 -2
  166. package/src/utils/crypto.js +9 -92
  167. package/src/utils/errors.ts +683 -0
  168. package/src/utils/hd-wallet.js +11 -26
  169. package/src/utils/keystore.js +47 -51
  170. package/src/utils/mptree.ts +12 -6
  171. package/src/utils/swagger.js +67 -44
  172. package/CHANGELOG.md +0 -1603
  173. package/es/account/base.js.map +0 -1
  174. package/es/account/memory.js.map +0 -1
  175. package/es/account/multiple.js.map +0 -1
  176. package/es/ae/aens.js.map +0 -1
  177. package/es/ae/aepp.js.map +0 -1
  178. package/es/ae/contract.js +0 -312
  179. package/es/ae/contract.js.map +0 -1
  180. package/es/ae/index.js.map +0 -1
  181. package/es/ae/oracle.js.map +0 -1
  182. package/es/ae/universal.js.map +0 -1
  183. package/es/ae/wallet.js.map +0 -1
  184. package/es/chain/index.js.map +0 -1
  185. package/es/chain/node.js.map +0 -1
  186. package/es/channel/handlers.js.map +0 -1
  187. package/es/channel/index.js.map +0 -1
  188. package/es/channel/internal.js.map +0 -1
  189. package/es/contract/aci/helpers.js +0 -298
  190. package/es/contract/aci/helpers.js.map +0 -1
  191. package/es/contract/aci/index.js +0 -361
  192. package/es/contract/aci/index.js.map +0 -1
  193. package/es/contract/aci/transformation.js +0 -66
  194. package/es/contract/aci/transformation.js.map +0 -1
  195. package/es/contract/compiler.js +0 -244
  196. package/es/contract/compiler.js.map +0 -1
  197. package/es/contract/ga/helpers.js +0 -22
  198. package/es/contract/ga/helpers.js.map +0 -1
  199. package/es/contract/ga/index.js.map +0 -1
  200. package/es/contract/index.js +0 -162
  201. package/es/contract/index.js.map +0 -1
  202. package/es/index.js +0 -57
  203. package/es/index.js.map +0 -1
  204. package/es/node-pool/index.js.map +0 -1
  205. package/es/node.js.map +0 -1
  206. package/es/tx/builder/helpers.js.map +0 -1
  207. package/es/tx/builder/index.js.map +0 -1
  208. package/es/tx/builder/schema.js.map +0 -1
  209. package/es/tx/index.js.map +0 -1
  210. package/es/tx/tx-object.js.map +0 -1
  211. package/es/tx/tx.js.map +0 -1
  212. package/es/tx/validator.js.map +0 -1
  213. package/es/typings/blakejs/index.d.js +0 -2
  214. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
  215. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
  216. package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
  217. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
  218. package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
  219. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
  220. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
  221. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
  222. package/es/utils/aepp-wallet-communication/schema.js +0 -107
  223. package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
  224. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
  225. package/es/utils/amount-formatter.js.map +0 -1
  226. package/es/utils/async-init.js.map +0 -1
  227. package/es/utils/bignumber.js.map +0 -1
  228. package/es/utils/bytes.js.map +0 -1
  229. package/es/utils/crypto-ts.js.map +0 -1
  230. package/es/utils/crypto.js.map +0 -1
  231. package/es/utils/hd-wallet.js.map +0 -1
  232. package/es/utils/keystore.js.map +0 -1
  233. package/es/utils/mptree.js.map +0 -1
  234. package/es/utils/other.js.map +0 -1
  235. package/es/utils/swagger.js.map +0 -1
  236. package/src/contract/aci/transformation.js +0 -72
  237. package/src/contract/index.js +0 -163
  238. package/src/utils/aepp-wallet-communication/schema.js +0 -108
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * ISC License (ISC)
3
- * Copyright (c) 2018 aeternity developers
3
+ * Copyright (c) 2021 aeternity developers
4
4
  *
5
5
  * Permission to use, copy, modify, and/or distribute this software for any
6
6
  * purpose with or without fee is hereby granted, provided that the above
@@ -27,129 +27,11 @@
27
27
  */
28
28
 
29
29
  import Ae from './'
30
- import ContractCompilerAPI from '../contract/compiler'
31
- import ContractBase from '../contract'
30
+ import ContractCompilerHttp from '../contract/compiler'
32
31
  import getContractInstance from '../contract/aci'
33
- import NodePool from '../node-pool'
34
- import { AMOUNT, DEPOSIT, GAS, MIN_GAS_PRICE } from '../tx/builder/schema'
32
+ import { AMOUNT, MIN_GAS_PRICE } from '../tx/builder/schema'
35
33
  import { decode, produceNameId } from '../tx/builder/helpers'
36
34
 
37
- /**
38
- * Static contract call(using dry-run)
39
- * @function
40
- * @alias module:@aeternity/aepp-sdk/es/ae/contract
41
- * @category async
42
- * @deprecated
43
- * @param {String} source Contract source code
44
- * @param {String} contractAddress Contract address
45
- * @param {String} name Name of function to call
46
- * @param {Array} args Arguments array for call/deploy transaction
47
- * @param {Object} [options]
48
- * @param {Number|String} [options.top] Block height or hash on which you want to call contract
49
- * @param {String} [options.bytecode] Block hash on which you want to call contract
50
- * @param {Object} [options.filesystem] Contract external namespaces map
51
- * @return {Promise<Object>} Result object
52
- * @example
53
- * const callResult = await client.contractCallStatic(source, address, fnName, args)
54
- * {
55
- * result: TX_DATA,
56
- * decode: (type) => Decode call result
57
- * }
58
- */
59
- async function contractCallStatic (source, contractAddress, name, args = [], options) {
60
- const contract = await this.getContractInstance({ ...options, source, contractAddress })
61
- return contract.call(name, args, { ...options, callStatic: true })
62
- }
63
-
64
- /**
65
- * Call contract function
66
- * @function
67
- * @alias module:@aeternity/aepp-sdk/es/ae/contract
68
- * @category async
69
- * @deprecated
70
- * @param {String} source Contract source code
71
- * @param {String} contractAddress Contract address or AENS name
72
- * @param {String} name Name of function to call
73
- * @param {Array} args Arguments array for call/deploy transaction
74
- * @param {Object} [options] Transaction options (fee, ttl, gas, amount, deposit)
75
- * @param {Object} [options.filesystem] Contract external namespaces map
76
- * @return {Promise<Object>} Result object
77
- * @example
78
- * const callResult = await client.contractCall(source, address, fnName, args = [], options)
79
- * {
80
- * hash: TX_HASH,
81
- * result: TX_DATA,
82
- * decode: (type) => Decode call result
83
- * }
84
- */
85
- async function contractCall (source, contractAddress, name, args, options) {
86
- const contract = await this.getContractInstance({ ...options, source, contractAddress })
87
- return contract.call(name, args, options)
88
- }
89
-
90
- /**
91
- * Deploy contract to the node
92
- * @function
93
- * @alias module:@aeternity/aepp-sdk/es/ae/contract
94
- * @category async
95
- * @deprecated
96
- * @param {String} code Compiled contract
97
- * @param {String} source Contract source code
98
- * @param {Array} params Arguments of contract constructor(init) function. Can be array of
99
- * arguments or callData string
100
- * @param {Object} [options] Transaction options (fee, ttl, gas, amount, deposit)
101
- * @param {Object} [options.filesystem={}] Contract external namespaces map*
102
- * @return {Promise<Object>} Result object
103
- * @example
104
- * const deployed = await client.contractDeploy(bytecode, source, init = [], options)
105
- * {
106
- * owner: OWNER_PUB_KEY,
107
- * transaction: TX_HASH,
108
- * address: CONTRACT_ADDRESS,
109
- * createdAt: Date,
110
- * result: DEPLOY_TX_DATA,
111
- * call: (fnName, args = [], options) => Call contract function,
112
- * callStatic: (fnName, args = [], options) => Static all contract function
113
- * }
114
- */
115
- async function contractDeploy (code, source, params, options) {
116
- const contract = await this.getContractInstance({ ...options, source })
117
- contract.bytecode = code
118
- return contract.deploy(params, options)
119
- }
120
-
121
- /**
122
- * Compile contract source code
123
- * @function
124
- * @alias module:@aeternity/aepp-sdk/es/ae/contract
125
- * @category async
126
- * @param {String} source Contract sourece code
127
- * @param {Object} [options={}] Transaction options (fee, ttl, gas, amount, deposit)
128
- * @param {Object} [options.filesystem={}] Contract external namespaces map*
129
- * @return {Promise<Object>} Result object
130
- * @example
131
- * const compiled = await client.contractCompile(SOURCE_CODE)
132
- * {
133
- * bytecode: CONTRACT_BYTE_CODE,
134
- * deploy: (init = [], options = {}) => Deploy Contract,
135
- * encodeCall: (fnName, args = []) => Prepare callData
136
- * }
137
- */
138
- async function contractCompile (source, options = {}) {
139
- const opt = { ...this.Ae.defaults, ...options }
140
- const bytecode = await this.compileContractAPI(source, options)
141
- return Object.freeze({
142
- encodeCall: (name, args) => this.contractEncodeCallDataAPI(source, name, args, opt),
143
- deploy: (init, options) => this.contractDeploy(bytecode, source, init, { ...opt, ...options }),
144
- deployStatic: (init, options) => this.contractCallStatic(source, null, 'init', init, {
145
- ...opt,
146
- ...options,
147
- bytecode
148
- }),
149
- bytecode
150
- })
151
- }
152
-
153
35
  /**
154
36
  * Utility method to create a delegate signature for a contract
155
37
  * @function
@@ -164,7 +46,6 @@ async function delegateSignatureCommon (ids = [], opt = {}) {
164
46
  const signature = await this.sign(
165
47
  Buffer.concat([
166
48
  Buffer.from(this.getNetworkId(opt)),
167
- ...(Object.prototype.hasOwnProperty.call(opt, 'onAccount') ? [decode(await this.address(opt))] : []),
168
49
  ...ids.map(e => decode(e))
169
50
  ]),
170
51
  opt
@@ -183,13 +64,13 @@ async function delegateSignatureCommon (ids = [], opt = {}) {
183
64
  * @param {{ onAccount: String | Object }} [opt={}] opt Options
184
65
  * @return {Promise<String>} Signature for delegation
185
66
  * @example
186
- * const client = await Universal({ ... })
67
+ * const aeSdk = await Universal({ ... })
187
68
  * const contractId = 'ct_asd2ks...' // contract address
188
69
  * const name = 'example.chain' // AENS name
189
- * const onAccount = await client.address() // Sign with a specific account
70
+ * const onAccount = await aeSdk.address() // Sign with a specific account
190
71
  * // Preclaim signature
191
72
  * const params = { contractId }
192
- * const preclaimSig = await client.createAensDelegationSignature(params, { onAccount: current })
73
+ * const preclaimSig = await aeSdk.createAensDelegationSignature(params, { onAccount: current })
193
74
  * // Claim, transfer and revoke signature
194
75
  * const params = { contractId, name }
195
76
  * const aensDelegationSig = await contract.createAensDelegationSignature(
@@ -197,7 +78,10 @@ async function delegateSignatureCommon (ids = [], opt = {}) {
197
78
  * )
198
79
  */
199
80
  async function createAensDelegationSignature ({ contractId, name }, opt = {}) {
200
- return this.delegateSignatureCommon([...name ? [produceNameId(name)] : [], contractId], opt)
81
+ return this.delegateSignatureCommon(
82
+ [await this.address(opt), ...name ? [produceNameId(name)] : [], contractId],
83
+ opt
84
+ )
201
85
  }
202
86
 
203
87
  /**
@@ -210,10 +94,10 @@ async function createAensDelegationSignature ({ contractId, name }, opt = {}) {
210
94
  * @param {{ onAccount: String | Object }} [opt={}] opt Options
211
95
  * @return {Promise<String>} Signature for delegation
212
96
  * @example
213
- * const client = await Universal({ ... })
97
+ * const aeSdk = await Universal({ ... })
214
98
  * const contractId = 'ct_asd2ks...' // contract address
215
99
  * const queryId = 'oq_...' // Oracle Query Id
216
- * const onAccount = await client.address() // Sign with a specific account
100
+ * const onAccount = await aeSdk.address() // Sign with a specific account
217
101
  * // Oracle register and extend signature
218
102
  * const params = { contractId }
219
103
  * const oracleDelegationSig = await contract.createOracleDelegationSignature(params, { onAccount })
@@ -236,31 +120,16 @@ async function createOracleDelegationSignature ({ contractId, queryId }, opt = {
236
120
  * @param {Object} [options={}] - Initializer object
237
121
  * @return {Object} Contract instance
238
122
  * @example
239
- * import Transaction from '@aeternity/aepp-sdk/es/tx/tx
240
- * import MemoryAccount from '@aeternity/aepp-sdk/es/account/memory
241
- * import ChainNode from '@aeternity/aepp-sdk/es/chain/node
242
- * import ContractCompilerAPI from '@aeternity/aepp-sdk/es/contract/compiler
243
- * // or using bundle
244
- * import {
245
- * Transaction,
246
- * MemoryAccount,
247
- * ChainNode,
248
- * ContractCompilerAPI
249
- * } from '@aeternity/aepp-sdk
123
+ * import { Transaction, MemoryAccount, ChainNode } from '@aeternity/aepp-sdk
250
124
  *
251
125
  * const ContractWithAE = await Contract
252
126
  * .compose(Transaction, MemoryAccount, ChainNode) // AE implementation
253
- * .compose(ContractCompilerAPI) // ContractBase implementation
254
127
  * const client = await ContractWithAe({ url, internalUrl, compilerUrl, keypair, ... })
255
128
  *
256
129
  */
257
- export const ContractAPI = Ae.compose(ContractBase, {
130
+ export default Ae.compose(ContractCompilerHttp, {
258
131
  methods: {
259
132
  getContractInstance,
260
- contractCompile,
261
- contractCallStatic,
262
- contractDeploy,
263
- contractCall,
264
133
  // Delegation for contract
265
134
  delegateSignatureCommon,
266
135
  // AENS
@@ -271,15 +140,9 @@ export const ContractAPI = Ae.compose(ContractBase, {
271
140
  deepProps: {
272
141
  Ae: {
273
142
  defaults: {
274
- deposit: DEPOSIT,
275
143
  gasPrice: MIN_GAS_PRICE,
276
- amount: AMOUNT,
277
- gas: GAS
144
+ amount: AMOUNT
278
145
  }
279
146
  }
280
147
  }
281
148
  })
282
-
283
- export const Contract = ContractAPI.compose(NodePool)
284
- export const ContractWithCompiler = Contract.compose(ContractCompilerAPI)
285
- export default ContractWithCompiler
package/src/ae/index.js CHANGED
@@ -29,6 +29,7 @@ import AccountBase from '../account/base'
29
29
  import TxBuilder from '../tx/builder'
30
30
  import BigNumber from 'bignumber.js'
31
31
  import { AE_AMOUNT_FORMATS } from '../utils/amount-formatter'
32
+ import { ArgumentError } from '../utils/errors'
32
33
 
33
34
  /**
34
35
  * Sign and post a transaction to the chain
@@ -94,7 +95,7 @@ async function spend (amount, recipientIdOrName, options) {
94
95
  */
95
96
  async function transferFunds (fraction, recipientIdOrName, options) {
96
97
  if (fraction < 0 || fraction > 1) {
97
- throw new Error(`Fraction should be a number between 0 and 1, got ${fraction}`)
98
+ throw new ArgumentError('fraction', 'a number between 0 and 1', fraction)
98
99
  }
99
100
  const opt = { ...this.Ae.defaults, ...options }
100
101
  const recipientId = await this.resolveName(recipientIdOrName, 'account_pubkey', opt)
package/src/ae/oracle.js CHANGED
@@ -27,11 +27,11 @@
27
27
  */
28
28
 
29
29
  import Ae from './'
30
- import { decodeBase64Check } from '../utils/crypto'
31
30
  import { pause } from '../utils/other'
32
31
  import { oracleQueryId, decode } from '../tx/builder/helpers'
33
32
  import { unpackTx } from '../tx/builder'
34
33
  import { ORACLE_TTL, QUERY_FEE, QUERY_TTL, RESPONSE_TTL } from '../tx/builder/schema'
34
+ import { RequestTimedOutError } from '../utils/errors'
35
35
 
36
36
  /**
37
37
  * Constructor for Oracle Object (helper object for using Oracle)
@@ -67,7 +67,11 @@ async function getOracleObject (oracleId) {
67
67
  * @param {Number} [options.interval] Poll interval(default: 5000)
68
68
  * @return {Function} stopPolling - Stop polling function
69
69
  */
70
- function pollForQueries (oracleId, onQuery, { interval = 5000 } = {}) {
70
+ function pollForQueries (
71
+ oracleId,
72
+ onQuery,
73
+ { interval = this._getPollInterval('microblock') } = {}
74
+ ) {
71
75
  const knownQueryIds = new Set()
72
76
  const checkNewQueries = async () => {
73
77
  const queries = ((await this.api.getOracleQueriesByPubkey(oracleId)).oracleQueries || [])
@@ -76,9 +80,15 @@ function pollForQueries (oracleId, onQuery, { interval = 5000 } = {}) {
76
80
  if (queries.length) onQuery(queries)
77
81
  }
78
82
 
79
- checkNewQueries()
80
- const intervalId = setInterval(checkNewQueries, interval)
81
- return () => clearInterval(intervalId)
83
+ let stopped
84
+ (async () => {
85
+ while (!stopped) { // eslint-disable-line no-unmodified-loop-condition
86
+ // TODO: allow to handle this error somehow
87
+ await checkNewQueries().catch(console.error)
88
+ await pause(interval)
89
+ }
90
+ })()
91
+ return () => { stopped = true }
82
92
  }
83
93
 
84
94
  /**
@@ -95,11 +105,16 @@ async function getQueryObject (oracleId, queryId) {
95
105
  const q = await this.api.getOracleQueryByPubkeyAndQueryId(oracleId, queryId)
96
106
  return {
97
107
  ...q,
98
- decodedQuery: decodeBase64Check(q.query.slice(3)).toString(),
99
- decodedResponse: decodeBase64Check(q.response.slice(3)).toString(),
108
+ decodedQuery: decode(q.query).toString(),
109
+ decodedResponse: decode(q.response).toString(),
100
110
  respond: this.respondToQuery.bind(this, oracleId, queryId),
101
111
  pollForResponse: this.pollForQueryResponse.bind(this, oracleId, queryId),
102
- decode: (data) => decodeBase64Check(data.slice(3))
112
+ /**
113
+ * @deprecated use TxBuilderHelper.decode instead
114
+ * @param data
115
+ * @returns {Buffer}
116
+ */
117
+ decode: (data) => decode(data)
103
118
  }
104
119
  }
105
120
 
@@ -119,7 +134,7 @@ async function getQueryObject (oracleId, queryId) {
119
134
  export async function pollForQueryResponse (
120
135
  oracleId,
121
136
  queryId,
122
- { attempts = 20, interval = 5000 } = {}
137
+ { attempts = 20, interval = this._getPollInterval('microblock') } = {}
123
138
  ) {
124
139
  for (let i = 0; i < attempts; i++) {
125
140
  if (i) await pause(interval)
@@ -129,7 +144,7 @@ export async function pollForQueryResponse (
129
144
  return String(responseBuffer)
130
145
  }
131
146
  }
132
- throw new Error(`Giving up after ${(attempts - 1) * interval}ms`)
147
+ throw new RequestTimedOutError((attempts - 1) * interval)
133
148
  }
134
149
 
135
150
  /**
@@ -27,7 +27,7 @@ import Chain from '../chain/node'
27
27
  import Aens from './aens'
28
28
  import Transaction from '../tx/tx'
29
29
  import Oracle from './oracle'
30
- import GeneralizeAccount from '../contract/ga'
30
+ import GeneralizedAccount from '../contract/ga'
31
31
  import AccountMultiple from '../account/multiple'
32
32
  import Contract from './contract'
33
33
 
@@ -43,5 +43,5 @@ import Contract from './contract'
43
43
  * @return {Object} Universal instance
44
44
  */
45
45
  export default Ae.compose(
46
- AccountMultiple, Chain, Transaction, Aens, Contract, Oracle, GeneralizeAccount
46
+ AccountMultiple, Chain, Transaction, Aens, Contract, Oracle, GeneralizedAccount
47
47
  )
package/src/ae/wallet.js CHANGED
@@ -26,7 +26,7 @@ import Ae from './'
26
26
  import Chain from '../chain/node'
27
27
  import Tx from '../tx/tx'
28
28
  import Contract from './contract'
29
- import GeneralizeAccount from '../contract/ga'
29
+ import GeneralizedAccount from '../contract/ga'
30
30
  import WalletRpc from '../utils/aepp-wallet-communication/rpc/wallet-rpc'
31
31
  import Oracle from './oracle'
32
32
  import Aens from './aens'
@@ -47,4 +47,4 @@ import Aens from './aens'
47
47
  address: keypair.publicKey,
48
48
  })
49
49
  */
50
- export default Ae.compose(WalletRpc, Tx, Contract, Oracle, Aens, GeneralizeAccount, Chain)
50
+ export default Ae.compose(WalletRpc, Tx, Contract, Oracle, Aens, GeneralizedAccount, Chain)
@@ -37,13 +37,32 @@ import { required } from '@stamp/required'
37
37
  * @return {Object} Chain instance
38
38
  */
39
39
  const Chain = stampit({
40
- deepProps: { Ae: { defaults: { waitMined: true, verify: true } } }
40
+ deepProps: {
41
+ Ae: {
42
+ defaults: {
43
+ waitMined: true,
44
+ verify: true,
45
+ _expectedMineRate: 180000,
46
+ _microBlockCycle: 3000,
47
+ _maxPollInterval: 5000
48
+ }
49
+ }
50
+ },
51
+ methods: {
52
+ _getPollInterval (type) {
53
+ const base = {
54
+ block: this.Ae.defaults._expectedMineRate,
55
+ microblock: this.Ae.defaults._microBlockCycle
56
+ }[type]
57
+ if (!base) throw new Error(`Unknown poll type: ${type}`)
58
+ return Math.min(base / 3, this.Ae.defaults._maxPollInterval)
59
+ }
60
+ }
41
61
  }, required({
42
62
  methods: {
43
63
  sendTransaction: required,
44
64
  height: required,
45
65
  awaitHeight: required,
46
- topBlock: required,
47
66
  poll: required,
48
67
  balance: required,
49
68
  getBalance: required,
package/src/chain/node.js CHANGED
@@ -21,6 +21,16 @@ import NodePool from '../node-pool'
21
21
  import { pause } from '../utils/other'
22
22
  import { isNameValid, produceNameId, decode } from '../tx/builder/helpers'
23
23
  import { DRY_RUN_ACCOUNT } from '../tx/builder/schema'
24
+ import {
25
+ AensPointerContextError,
26
+ DryRunError,
27
+ InvalidAensNameError,
28
+ InvalidTxError,
29
+ RequestTimedOutError,
30
+ TxTimedOutError,
31
+ TxNotInChainError,
32
+ ArgumentError
33
+ } from '../utils/errors'
24
34
 
25
35
  /**
26
36
  * ChainNode module
@@ -32,13 +42,13 @@ import { DRY_RUN_ACCOUNT } from '../tx/builder/schema'
32
42
  */
33
43
 
34
44
  async function sendTransaction (tx, options = {}) {
35
- const { waitMined, verify } = { ...this.Ae.defaults, ...options }
36
- if (verify) {
45
+ const opt = { ...this.Ae.defaults, ...options }
46
+ if (opt.verify) {
37
47
  const validation = await verifyTransaction(tx, this.selectedNode.instance)
38
48
  if (validation.length) {
39
49
  const message = 'Transaction verification errors: ' +
40
50
  validation.map(v => v.message).join(', ')
41
- throw Object.assign(new Error(message), {
51
+ throw Object.assign(new InvalidTxError(message), {
42
52
  code: 'TX_VERIFICATION_ERROR',
43
53
  validation,
44
54
  transaction: tx
@@ -47,9 +57,11 @@ async function sendTransaction (tx, options = {}) {
47
57
  }
48
58
 
49
59
  try {
50
- const { txHash } = await this.api.postTransaction({ tx })
60
+ const { txHash } = await this.api.postTransaction({ tx }, {
61
+ __queue: `tx-${await this.address?.(options).catch(() => '')}`
62
+ })
51
63
 
52
- if (waitMined) {
64
+ if (opt.waitMined) {
53
65
  const txData = { ...await this.poll(txHash, options), rawTx: tx }
54
66
  // wait for transaction confirmation
55
67
  if (options.confirm) {
@@ -68,12 +80,12 @@ async function sendTransaction (tx, options = {}) {
68
80
 
69
81
  async function waitForTxConfirm (txHash, options = { confirm: 3 }) {
70
82
  options.confirm = options.confirm === true ? 3 : options.confirm
71
- const { blockHeight } = await this.tx(txHash)
83
+ const { blockHeight } = await this.api.getTransactionByHash(txHash)
72
84
  const height = await this.awaitHeight(blockHeight + options.confirm, options)
73
- const { blockHeight: newBlockHeight } = await this.tx(txHash)
85
+ const { blockHeight: newBlockHeight } = await this.api.getTransactionByHash(txHash)
74
86
  switch (newBlockHeight) {
75
87
  case -1:
76
- throw new Error(`Transaction ${txHash} is removed from chain`)
88
+ throw new TxNotInChainError(txHash)
77
89
  case blockHeight:
78
90
  return height
79
91
  default:
@@ -103,6 +115,9 @@ async function getBalance (address, { height, hash, format = AE_AMOUNT_FORMATS.A
103
115
  return formatAmount(balance, { targetDenomination: format }).toString()
104
116
  }
105
117
 
118
+ /**
119
+ * @deprecated use `sdk.api.getTransactionByHash/getTransactionInfoByHash` instead
120
+ */
106
121
  async function tx (hash, info = true) {
107
122
  const tx = await this.api.getTransactionByHash(hash)
108
123
  if (['ContractCreateTx', 'ContractCallTx', 'ChannelForceProgressTx'].includes(tx.tx.type) && info && tx.blockHeight !== -1) {
@@ -114,45 +129,36 @@ async function tx (hash, info = true) {
114
129
  }
115
130
 
116
131
  async function height () {
117
- try {
118
- if (!this._heightPromise) {
119
- this._heightPromise = this.api.getCurrentKeyBlockHeight()
120
- }
121
- return (await this._heightPromise).height
122
- } finally {
123
- delete this._heightPromise
124
- }
132
+ return (await this.api.getCurrentKeyBlockHeight()).height
125
133
  }
126
134
 
127
- async function awaitHeight (height, { interval = 5000, attempts = 20 } = {}) {
135
+ async function awaitHeight (
136
+ height,
137
+ { interval = this._getPollInterval('block'), attempts = 20 } = {}
138
+ ) {
128
139
  let currentHeight
129
140
  for (let i = 0; i < attempts; i++) {
130
141
  if (i) await pause(interval)
131
142
  currentHeight = await this.height()
132
143
  if (currentHeight >= height) return currentHeight
133
144
  }
134
- throw new Error(`Giving up after ${(attempts - 1) * interval}ms, current height: ${currentHeight}, desired height: ${height}`)
135
- }
136
-
137
- /**
138
- * @deprecated
139
- */
140
- async function topBlock () {
141
- return this.api.getTopHeader()
145
+ throw new RequestTimedOutError((attempts - 1) * interval, currentHeight, height)
142
146
  }
143
147
 
144
- async function poll (th, { blocks = 10, interval = 500, allowUnsynced = false } = {}) {
148
+ async function poll (th, { blocks = 10, interval = this._getPollInterval('microblock') } = {}) {
145
149
  const max = await this.height() + blocks
146
150
  do {
147
- const tx = await this.tx(th).catch(_ => null)
148
- if (tx && (tx.blockHeight !== -1 || (allowUnsynced && tx.height))) {
149
- return tx
150
- }
151
+ const tx = await this.api.getTransactionByHash(th)
152
+ if (tx.blockHeight !== -1) return tx
151
153
  await pause(interval)
152
154
  } while (await this.height() < max)
153
- throw new Error(`Giving up after ${blocks} blocks mined, transaction hash: ${th}`)
155
+ const status = this.api.getCheckTxInPool && (await this.api.getCheckTxInPool(th)).status
156
+ throw new TxTimedOutError(blocks, th, status)
154
157
  }
155
158
 
159
+ /**
160
+ * @deprecated use `sdk.api.getTransactionInfoByHash` instead
161
+ */
156
162
  async function getTxInfo (hash) {
157
163
  const result = await this.api.getTransactionInfoByHash(hash)
158
164
  return result.callInfo || result
@@ -169,7 +175,7 @@ async function getCurrentGeneration () {
169
175
  async function getGeneration (hashOrHeight) {
170
176
  if (typeof hashOrHeight === 'string') return this.api.getGenerationByHash(hashOrHeight)
171
177
  if (typeof hashOrHeight === 'number') return this.api.getGenerationByHeight(hashOrHeight)
172
- throw new Error('Invalid param, param must be hash or height')
178
+ throw new ArgumentError('hashOrHeight', 'a string or number', hashOrHeight)
173
179
  }
174
180
 
175
181
  async function getMicroBlockTransactions (hash) {
@@ -179,30 +185,53 @@ async function getMicroBlockTransactions (hash) {
179
185
  async function getKeyBlock (hashOrHeight) {
180
186
  if (typeof hashOrHeight === 'string') return this.api.getKeyBlockByHash(hashOrHeight)
181
187
  if (typeof hashOrHeight === 'number') return this.api.getKeyBlockByHeight(hashOrHeight)
182
- throw new Error('Invalid param, param must be hash or height')
188
+ throw new ArgumentError('hashOrHeight', 'a string or number', hashOrHeight)
183
189
  }
184
190
 
185
191
  async function getMicroBlockHeader (hash) {
186
192
  return this.api.getMicroBlockHeaderByHash(hash)
187
193
  }
188
194
 
189
- async function txDryRun (tx, accountAddress, options) {
190
- const { results: [{ result, reason, ...resultPayload }], ...other } =
191
- await this.api.protectedDryRunTxs({
192
- ...options,
193
- txs: [{ tx }],
194
- accounts: [{
195
- pubKey: accountAddress,
196
- amount: DRY_RUN_ACCOUNT.amount
197
- }]
195
+ async function txDryRunHandler (key) {
196
+ const rs = this._txDryRun[key]
197
+ delete this._txDryRun[key]
198
+
199
+ let dryRunRes
200
+ try {
201
+ dryRunRes = await this.api.protectedDryRunTxs({
202
+ top: rs[0].top,
203
+ txEvents: rs[0].txEvents,
204
+ txs: rs.map(req => ({ tx: req.tx })),
205
+ accounts: Array.from(new Set(rs.map(req => req.accountAddress)))
206
+ .map(pubKey => ({ pubKey, amount: DRY_RUN_ACCOUNT.amount }))
198
207
  })
208
+ } catch (error) {
209
+ rs.forEach(({ reject }) => reject(error))
210
+ return
211
+ }
199
212
 
200
- if (result === 'ok') return { ...resultPayload, ...other }
213
+ const { results, txEvents } = dryRunRes
214
+ results.forEach(({ result, reason, ...resultPayload }, idx) => {
215
+ const { resolve, reject, tx, options, accountAddress } = rs[idx]
216
+ if (result === 'ok') return resolve({ ...resultPayload, txEvents })
217
+ reject(Object.assign(
218
+ new DryRunError(reason), { tx, accountAddress, options }
219
+ ))
220
+ })
221
+ }
201
222
 
202
- throw Object.assign(
203
- new Error('Dry run error, ' + reason),
204
- { tx, accountAddress, options }
205
- )
223
+ async function txDryRun (tx, accountAddress, { top, txEvents, combine }) {
224
+ const key = combine ? [top, txEvents].join() : 'immediate'
225
+ this._txDryRun ??= {}
226
+ this._txDryRun[key] ??= []
227
+ return new Promise((resolve, reject) => {
228
+ this._txDryRun[key].push({ tx, accountAddress, top, txEvents, resolve, reject })
229
+ if (!combine) {
230
+ txDryRunHandler.call(this, key)
231
+ return
232
+ }
233
+ this._txDryRun[key].timeout ??= setTimeout(txDryRunHandler.bind(this, key))
234
+ })
206
235
  }
207
236
 
208
237
  async function getContractByteCode (contractId) {
@@ -229,7 +258,7 @@ async function getName (name) {
229
258
  */
230
259
  async function resolveName (nameOrId, key, { verify, resolveByNode } = {}) {
231
260
  if (!nameOrId || typeof nameOrId !== 'string') {
232
- throw new Error(`Name or address should be a string: ${nameOrId}`)
261
+ throw new InvalidAensNameError(`Name or address should be a string: ${nameOrId}`)
233
262
  }
234
263
  try {
235
264
  decode(nameOrId)
@@ -237,17 +266,16 @@ async function resolveName (nameOrId, key, { verify, resolveByNode } = {}) {
237
266
  } catch (error) {}
238
267
  if (isNameValid(nameOrId)) {
239
268
  if (verify || resolveByNode) {
240
- const name = await this.api.getNameEntryByName(nameOrId).catch(_ => null)
241
- if (!name) throw new Error(`Name not found: ${nameOrId}`)
269
+ const name = await this.api.getNameEntryByName(nameOrId)
242
270
  const pointer = name.pointers.find(pointer => pointer.key === key)
243
271
  if (!pointer) {
244
- throw new Error(`Name ${nameOrId} don't have pointers for ${key}`)
272
+ throw new AensPointerContextError(`Name ${nameOrId} don't have pointers for ${key}`)
245
273
  }
246
274
  if (resolveByNode) return pointer.id
247
275
  }
248
276
  return produceNameId(nameOrId)
249
277
  }
250
- throw new Error(`Invalid name or address: ${nameOrId}`)
278
+ throw new InvalidAensNameError(`Invalid name or address: ${nameOrId}`)
251
279
  }
252
280
 
253
281
  /**
@@ -269,7 +297,6 @@ const ChainNode = Chain.compose(NodePool, {
269
297
  balance,
270
298
  getBalance,
271
299
  getAccount,
272
- topBlock,
273
300
  tx,
274
301
  height,
275
302
  awaitHeight,