@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
@@ -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,253 +27,10 @@
27
27
  */
28
28
 
29
29
  import Ae from './'
30
- import * as R from 'ramda'
31
- import ContractCompilerAPI from '../contract/compiler'
32
- import ContractBase from '../contract'
30
+ import ContractCompilerHttp from '../contract/compiler'
33
31
  import getContractInstance from '../contract/aci'
34
- import NodePool from '../node-pool'
35
- import { AMOUNT, DEPOSIT, DRY_RUN_ACCOUNT, GAS, MIN_GAS_PRICE } from '../tx/builder/schema'
32
+ import { AMOUNT, MIN_GAS_PRICE } from '../tx/builder/schema'
36
33
  import { decode, produceNameId } from '../tx/builder/helpers'
37
- import TxObject from '../tx/tx-object'
38
-
39
- async function _sendAndProcess (tx, source, name, options) {
40
- const txData = await this.send(tx, options)
41
- const result = { hash: txData.hash, tx: TxObject({ tx: txData.rawTx }), txData, rawTx: txData.rawTx }
42
- if (options.waitMined === false) return result
43
- const txInfo = await this.getTxInfo(txData.hash)
44
- await this._handleCallError(source, name, txInfo)
45
- return { ...result, result: txInfo }
46
- }
47
-
48
- /**
49
- * Handle contract call error
50
- * @function
51
- * @private
52
- * @alias module:@aeternity/aepp-sdk/es/ae/contract
53
- * @category async
54
- * @param {String} source contract source code
55
- * @param {String} name name of called method
56
- * @param {Object} result call result object
57
- * @throws Error Decoded error
58
- * @return {Promise<void>}
59
- */
60
- async function _handleCallError (source, name, result) {
61
- if (result.returnType === 'ok') return
62
- const error = await this.contractDecodeCallResultAPI(source, name, result.returnValue, result.returnType)
63
- const message = error[{ revert: 'abort' }[result.returnType] || result.returnType][0]
64
- throw new Error(`Invocation failed${message ? `: "${message}"` : ''}`)
65
- }
66
-
67
- /**
68
- * Encode call data for contract call
69
- * @function
70
- * @alias module:@aeternity/aepp-sdk/es/ae/contract
71
- * @category async
72
- * @param {String} source Contract source code
73
- * @param {String} name Name of function to call
74
- * @param {Array} args Argument's for call
75
- * @param {Object} [options={}] Options
76
- * @param {Object} [options.filesystem={}] Contract external namespaces map
77
- * @return {Promise<String>}
78
- */
79
- async function contractEncodeCall (source, name, args, options) {
80
- return this.contractEncodeCallDataAPI(source, name, args, options)
81
- }
82
-
83
- /**
84
- * Decode contract call result data
85
- * @function
86
- * @alias module:@aeternity/aepp-sdk/es/ae/contract
87
- * @category async
88
- * @param {String} source - source code
89
- * @param {String } fn - function name
90
- * @param {String} callValue - result call data
91
- * @param {String} callResult - result status
92
- * @param {Object} [options={}] Options
93
- * @param {Object} [options.filesystem={}] Contract external namespaces map
94
- * @return {Promise<String>} Result object
95
- * @example
96
- * const decodedData = await client.contractDecodeData(SourceCode ,'functionName', 'cb_asdasdasd...', 'ok|revert')lt
97
- */
98
- async function contractDecodeData (source, fn, callValue, callResult, options) {
99
- return this.contractDecodeCallResultAPI(source, fn, callValue, callResult, options)
100
- }
101
-
102
- /**
103
- * Static contract call(using dry-run)
104
- * @function
105
- * @alias module:@aeternity/aepp-sdk/es/ae/contract
106
- * @category async
107
- * @param {String} source Contract source code
108
- * @param {String} address Contract address
109
- * @param {String} name Name of function to call
110
- * @param {Array|String} args Argument's or callData for call/deploy transaction
111
- * @param {Object} [options]
112
- * @param {Number|String} [options.top] Block height or hash on which you want to call contract
113
- * @param {String} [options.bytecode] Block hash on which you want to call contract
114
- * @param {Object} [options.filesystem] Contract external namespaces map
115
- * @return {Promise<Object>} Result object
116
- * @example
117
- * const callResult = await client.contractCallStatic(source, address, fnName, args)
118
- * {
119
- * result: TX_DATA,
120
- * decode: (type) => Decode call result
121
- * }
122
- */
123
- async function contractCallStatic (source, address, name, args = [], options = {}) {
124
- const callerId = await this.address(options).catch(() => DRY_RUN_ACCOUNT.pub)
125
- if (typeof options.top === 'number') {
126
- options.top = (await this.getKeyBlock(options.top)).hash
127
- }
128
- const txOpt = {
129
- ...this.Ae.defaults,
130
- ...options,
131
- callData: Array.isArray(args) ? await this.contractEncodeCall(source, name, args, options) : args,
132
- nonce: options.top && (await this.getAccount(callerId, { hash: options.top })).nonce + 1
133
- }
134
- const tx = name === 'init'
135
- ? (await this.contractCreateTx({
136
- ...txOpt,
137
- code: options.bytecode,
138
- ownerId: callerId
139
- })).tx
140
- : await this.contractCallTx({
141
- ...txOpt,
142
- callerId,
143
- contractId: await this.resolveName(address, 'ct', { resolveByNode: true })
144
- })
145
-
146
- const { callObj, ...dryRunOther } = await this.txDryRun(tx, callerId, options)
147
-
148
- await this._handleCallError(source, name, callObj)
149
- const { returnType, returnValue } = callObj
150
- return {
151
- ...dryRunOther,
152
- tx: TxObject({ tx }),
153
- result: callObj,
154
- decode: () => this.contractDecodeData(source, name, returnValue, returnType, options)
155
- }
156
- }
157
-
158
- /**
159
- * Call contract function
160
- * @function
161
- * @alias module:@aeternity/aepp-sdk/es/ae/contract
162
- * @category async
163
- * @param {String} source Contract source code
164
- * @param {String} address Contract address or AENS name
165
- * @param {String} name Name of function to call
166
- * @param {Array|String} argsOrCallData Argument's array or callData for call function
167
- * @param {Object} [options={}] Transaction options (fee, ttl, gas, amount, deposit)
168
- * @param {Object} [options.filesystem={}] Contract external namespaces map* @return {Promise<Object>} Result object
169
- * @example
170
- * const callResult = await client.contractCall(source, address, fnName, args = [], options)
171
- * {
172
- * hash: TX_HASH,
173
- * result: TX_DATA,
174
- * decode: (type) => Decode call result
175
- * }
176
- */
177
- async function contractCall (source, address, name, argsOrCallData = [], options = {}) {
178
- const opt = R.merge(this.Ae.defaults, options)
179
-
180
- const tx = await this.contractCallTx(R.merge(opt, {
181
- callerId: await this.address(opt),
182
- contractId: await this.resolveName(address, 'ct', { resolveByNode: true }),
183
- callData: Array.isArray(argsOrCallData) ? await this.contractEncodeCall(source, name, argsOrCallData, opt) : argsOrCallData
184
- }))
185
-
186
- const { hash, rawTx, result, txData } = await this._sendAndProcess(tx, source, name, opt)
187
- return {
188
- hash,
189
- rawTx,
190
- result,
191
- txData,
192
- decode: () => result ? this.contractDecodeData(source, name, result.returnValue, result.returnType, opt) : {}
193
- }
194
- }
195
-
196
- /**
197
- * Deploy contract to the node
198
- * @function
199
- * @alias module:@aeternity/aepp-sdk/es/ae/contract
200
- * @category async
201
- * @param {String} code Compiled contract
202
- * @param {String} source Contract source code
203
- * @param {Array|String} initState Arguments of contract constructor(init) function. Can be array of arguments or callData string
204
- * @param {Object} [options={}] Transaction options (fee, ttl, gas, amount, deposit)
205
- * @param {Object} [options.filesystem={}] Contract external namespaces map* @return {Promise<Object>} Result object
206
- * @return {Promise<Object>} Result object
207
- * @example
208
- * const deployed = await client.contractDeploy(bytecode, source, init = [], options)
209
- * {
210
- * owner: OWNER_PUB_KEY,
211
- * transaction: TX_HASH,
212
- * address: CONTRACT_ADDRESS,
213
- * createdAt: Date,
214
- * result: DEPLOY_TX_DATA,
215
- * call: (fnName, args = [], options) => Call contract function,
216
- * callStatic: (fnName, args = [], options) => Static all contract function
217
- * }
218
- */
219
- async function contractDeploy (code, source, initState = [], options = {}) {
220
- const opt = { ...this.Ae.defaults, ...options, deposit: DEPOSIT }
221
- const callData = Array.isArray(initState) ? await this.contractEncodeCall(source, 'init', initState, opt) : initState
222
- const ownerId = await this.address(opt)
223
-
224
- const { tx, contractId } = await this.contractCreateTx(R.merge(opt, {
225
- callData,
226
- code,
227
- ownerId
228
- }))
229
-
230
- const { hash, rawTx, result, txData } = await this._sendAndProcess(tx, source, 'init', opt)
231
- return Object.freeze({
232
- result,
233
- owner: ownerId,
234
- transaction: hash,
235
- rawTx,
236
- txData,
237
- address: contractId,
238
- call: (name, args, options) =>
239
- this.contractCall(source, contractId, name, args, { ...opt, ...options }),
240
- callStatic: (name, args, options) =>
241
- this.contractCallStatic(source, contractId, name, args, { ...opt, ...options }),
242
- createdAt: new Date()
243
- })
244
- }
245
-
246
- /**
247
- * Compile contract source code
248
- * @function
249
- * @alias module:@aeternity/aepp-sdk/es/ae/contract
250
- * @category async
251
- * @param {String} source Contract sourece code
252
- * @param {Object} [options={}] Transaction options (fee, ttl, gas, amount, deposit)
253
- * @param {Object} [options.filesystem={}] Contract external namespaces map* @return {Promise<Object>} Result object
254
- * @return {Promise<Object>} Result object
255
- * @example
256
- * const compiled = await client.contractCompile(SOURCE_CODE)
257
- * {
258
- * bytecode: CONTRACT_BYTE_CODE,
259
- * deploy: (init = [], options = {}) => Deploy Contract,
260
- * encodeCall: (fnName, args = []) => Prepare callData
261
- * }
262
- */
263
- async function contractCompile (source, options = {}) {
264
- const opt = { ...this.Ae.defaults, ...options }
265
- const bytecode = await this.compileContractAPI(source, options)
266
- return Object.freeze({
267
- encodeCall: (name, args) => this.contractEncodeCall(source, name, args, opt),
268
- deploy: (init, options) => this.contractDeploy(bytecode, source, init, { ...opt, ...options }),
269
- deployStatic: (init, options) => this.contractCallStatic(source, null, 'init', init, {
270
- ...opt,
271
- ...options,
272
- bytecode
273
- }),
274
- bytecode
275
- })
276
- }
277
34
 
278
35
  /**
279
36
  * Utility method to create a delegate signature for a contract
@@ -286,20 +43,19 @@ async function contractCompile (source, options = {}) {
286
43
  * @return {Promise<String>} Signature in hex representation
287
44
  */
288
45
  async function delegateSignatureCommon (ids = [], opt = {}) {
289
- return this.sign(
290
- Buffer.concat(
291
- [
292
- Buffer.from(this.getNetworkId(opt)),
293
- ...(Object.prototype.hasOwnProperty.call(opt, 'onAccount') ? [decode(await this.address(opt))] : []),
294
- ...ids.map(e => decode(e))
295
- ]
296
- ),
46
+ const signature = await this.sign(
47
+ Buffer.concat([
48
+ Buffer.from(this.getNetworkId(opt)),
49
+ ...ids.map(e => decode(e))
50
+ ]),
297
51
  opt
298
- ).then(s => Buffer.from(s).toString('hex'))
52
+ )
53
+ return Buffer.from(signature).toString('hex')
299
54
  }
300
55
 
301
56
  /**
302
- * Helper to generate a signature to delegate pre-claim/claim/transfer/revoke of a name to a contract.
57
+ * Helper to generate a signature to delegate pre-claim/claim/transfer/revoke of a name to
58
+ * a contract.
303
59
  * @function
304
60
  * @alias module:@aeternity/aepp-sdk/es/ae/contract
305
61
  * @category async
@@ -308,19 +64,24 @@ async function delegateSignatureCommon (ids = [], opt = {}) {
308
64
  * @param {{ onAccount: String | Object }} [opt={}] opt Options
309
65
  * @return {Promise<String>} Signature for delegation
310
66
  * @example
311
- * const client = await Universal({ ... })
67
+ * const aeSdk = await Universal({ ... })
312
68
  * const contractId = 'ct_asd2ks...' // contract address
313
69
  * const name = 'example.chain' // AENS name
314
- * const onAccount = await client.address() // Sign with a specific account
70
+ * const onAccount = await aeSdk.address() // Sign with a specific account
315
71
  * // Preclaim signature
316
72
  * const params = { contractId }
317
- * const preclaimSig = await client.createAensDelegationSignature(params, { onAccount: current })
73
+ * const preclaimSig = await aeSdk.createAensDelegationSignature(params, { onAccount: current })
318
74
  * // Claim, transfer and revoke signature
319
75
  * const params = { contractId, name }
320
- * const aensDelegationSig = await contract.createAensDelegationSignature(params, name, { onAccount: current })
76
+ * const aensDelegationSig = await contract.createAensDelegationSignature(
77
+ * params, name, { onAccount: current }
78
+ * )
321
79
  */
322
80
  async function createAensDelegationSignature ({ contractId, name }, opt = {}) {
323
- return this.delegateSignatureCommon([...name ? [produceNameId(name)] : [], contractId], opt)
81
+ return this.delegateSignatureCommon(
82
+ [await this.address(opt), ...name ? [produceNameId(name)] : [], contractId],
83
+ opt
84
+ )
324
85
  }
325
86
 
326
87
  /**
@@ -333,10 +94,10 @@ async function createAensDelegationSignature ({ contractId, name }, opt = {}) {
333
94
  * @param {{ onAccount: String | Object }} [opt={}] opt Options
334
95
  * @return {Promise<String>} Signature for delegation
335
96
  * @example
336
- * const client = await Universal({ ... })
97
+ * const aeSdk = await Universal({ ... })
337
98
  * const contractId = 'ct_asd2ks...' // contract address
338
99
  * const queryId = 'oq_...' // Oracle Query Id
339
- * const onAccount = await client.address() // Sign with a specific account
100
+ * const onAccount = await aeSdk.address() // Sign with a specific account
340
101
  * // Oracle register and extend signature
341
102
  * const params = { contractId }
342
103
  * const oracleDelegationSig = await contract.createOracleDelegationSignature(params, { onAccount })
@@ -359,35 +120,16 @@ async function createOracleDelegationSignature ({ contractId, queryId }, opt = {
359
120
  * @param {Object} [options={}] - Initializer object
360
121
  * @return {Object} Contract instance
361
122
  * @example
362
- * import Transaction from '@aeternity/aepp-sdk/es/tx/tx
363
- * import MemoryAccount from '@aeternity/aepp-sdk/es/account/memory
364
- * import ChainNode from '@aeternity/aepp-sdk/es/chain/node
365
- * import ContractCompilerAPI from '@aeternity/aepp-sdk/es/contract/compiler
366
- * // or using bundle
367
- * import {
368
- * Transaction,
369
- * MemoryAccount,
370
- * ChainNode,
371
- * ContractCompilerAPI
372
- * } from '@aeternity/aepp-sdk
123
+ * import { Transaction, MemoryAccount, ChainNode } from '@aeternity/aepp-sdk
373
124
  *
374
125
  * const ContractWithAE = await Contract
375
126
  * .compose(Transaction, MemoryAccount, ChainNode) // AE implementation
376
- * .compose(ContractCompilerAPI) // ContractBase implementation
377
127
  * const client = await ContractWithAe({ url, internalUrl, compilerUrl, keypair, ... })
378
128
  *
379
129
  */
380
- export const ContractAPI = Ae.compose(ContractBase, {
130
+ export default Ae.compose(ContractCompilerHttp, {
381
131
  methods: {
382
132
  getContractInstance,
383
- contractCompile,
384
- contractCallStatic,
385
- contractDeploy,
386
- contractCall,
387
- contractEncodeCall,
388
- contractDecodeData,
389
- _handleCallError,
390
- _sendAndProcess,
391
133
  // Delegation for contract
392
134
  delegateSignatureCommon,
393
135
  // AENS
@@ -398,15 +140,9 @@ export const ContractAPI = Ae.compose(ContractBase, {
398
140
  deepProps: {
399
141
  Ae: {
400
142
  defaults: {
401
- deposit: DEPOSIT,
402
143
  gasPrice: MIN_GAS_PRICE,
403
- amount: AMOUNT,
404
- gas: GAS
144
+ amount: AMOUNT
405
145
  }
406
146
  }
407
147
  }
408
148
  })
409
-
410
- export const Contract = ContractAPI.compose(NodePool)
411
- export const ContractWithCompiler = Contract.compose(ContractCompilerAPI)
412
- export default ContractWithCompiler
package/src/ae/index.js CHANGED
@@ -27,9 +27,9 @@ import Tx from '../tx'
27
27
  import Chain from '../chain'
28
28
  import AccountBase from '../account/base'
29
29
  import TxBuilder from '../tx/builder'
30
- import * as R from 'ramda'
31
30
  import BigNumber from 'bignumber.js'
32
31
  import { AE_AMOUNT_FORMATS } from '../utils/amount-formatter'
32
+ import { ArgumentError } from '../utils/errors'
33
33
 
34
34
  /**
35
35
  * Sign and post a transaction to the chain
@@ -38,13 +38,15 @@ import { AE_AMOUNT_FORMATS } from '../utils/amount-formatter'
38
38
  * @rtype (tx: String, options: Object) => Promise[String]
39
39
  * @param {String} tx - Transaction
40
40
  * @param {Object} [options={}] options - Options
41
- * @param {Object} [options.verify=true] verify - Verify transaction before broadcast, throw error if not valid
41
+ * @param {Object} [options.verify=true] - Verify transaction before broadcast, throw error if not
42
+ * valid
42
43
  * @return {Object} Transaction
43
44
  */
44
45
  async function send (tx, options = {}) {
45
- const opt = R.merge(this.Ae.defaults, options)
46
+ const opt = { ...this.Ae.defaults, ...options }
46
47
  const { contractId, authFun } = options.innerTx
47
- ? { contractId: false } : await this.getAccount(await this.address(opt))
48
+ ? { contractId: false }
49
+ : await this.getAccount(await this.address(opt))
48
50
  const signed = contractId
49
51
  ? await this.signUsingGA(tx, { ...opt, authFun })
50
52
  : await this.signTransaction(tx, opt)
@@ -73,7 +75,7 @@ async function spend (amount, recipientIdOrName, options) {
73
75
  await this.spendTx({
74
76
  ...opt,
75
77
  senderId: await this.address(opt),
76
- recipientId: await this.resolveName(recipientIdOrName, 'ak', opt),
78
+ recipientId: await this.resolveName(recipientIdOrName, 'account_pubkey', opt),
77
79
  amount
78
80
  }),
79
81
  opt
@@ -93,10 +95,10 @@ async function spend (amount, recipientIdOrName, options) {
93
95
  */
94
96
  async function transferFunds (fraction, recipientIdOrName, options) {
95
97
  if (fraction < 0 || fraction > 1) {
96
- 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)
97
99
  }
98
100
  const opt = { ...this.Ae.defaults, ...options }
99
- const recipientId = await this.resolveName(recipientIdOrName, 'ak', opt)
101
+ const recipientId = await this.resolveName(recipientIdOrName, 'account_pubkey', opt)
100
102
  const senderId = await this.address(opt)
101
103
  const balance = new BigNumber(await this.balance(senderId))
102
104
  const desiredAmount = balance.times(fraction).integerValue(BigNumber.ROUND_HALF_UP)
package/src/ae/oracle.js CHANGED
@@ -27,12 +27,11 @@
27
27
  */
28
28
 
29
29
  import Ae from './'
30
- import * as R from 'ramda'
31
- import { decodeBase64Check } from '../utils/crypto'
32
30
  import { pause } from '../utils/other'
33
31
  import { oracleQueryId, decode } from '../tx/builder/helpers'
34
32
  import { unpackTx } from '../tx/builder'
35
33
  import { ORACLE_TTL, QUERY_FEE, QUERY_TTL, RESPONSE_TTL } from '../tx/builder/schema'
34
+ import { RequestTimedOutError } from '../utils/errors'
36
35
 
37
36
  /**
38
37
  * Constructor for Oracle Object (helper object for using Oracle)
@@ -68,7 +67,11 @@ async function getOracleObject (oracleId) {
68
67
  * @param {Number} [options.interval] Poll interval(default: 5000)
69
68
  * @return {Function} stopPolling - Stop polling function
70
69
  */
71
- function pollForQueries (oracleId, onQuery, { interval = 5000 } = {}) {
70
+ function pollForQueries (
71
+ oracleId,
72
+ onQuery,
73
+ { interval = this._getPollInterval('microblock') } = {}
74
+ ) {
72
75
  const knownQueryIds = new Set()
73
76
  const checkNewQueries = async () => {
74
77
  const queries = ((await this.api.getOracleQueriesByPubkey(oracleId)).oracleQueries || [])
@@ -77,9 +80,15 @@ function pollForQueries (oracleId, onQuery, { interval = 5000 } = {}) {
77
80
  if (queries.length) onQuery(queries)
78
81
  }
79
82
 
80
- checkNewQueries()
81
- const intervalId = setInterval(checkNewQueries, interval)
82
- 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 }
83
92
  }
84
93
 
85
94
  /**
@@ -96,11 +105,16 @@ async function getQueryObject (oracleId, queryId) {
96
105
  const q = await this.api.getOracleQueryByPubkeyAndQueryId(oracleId, queryId)
97
106
  return {
98
107
  ...q,
99
- decodedQuery: decodeBase64Check(q.query.slice(3)).toString(),
100
- decodedResponse: decodeBase64Check(q.response.slice(3)).toString(),
108
+ decodedQuery: decode(q.query).toString(),
109
+ decodedResponse: decode(q.response).toString(),
101
110
  respond: this.respondToQuery.bind(this, oracleId, queryId),
102
111
  pollForResponse: this.pollForQueryResponse.bind(this, oracleId, queryId),
103
- 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)
104
118
  }
105
119
  }
106
120
 
@@ -117,16 +131,20 @@ async function getQueryObject (oracleId, queryId) {
117
131
  * @param {Object} [options.interval] Poll interval(default: 5000)
118
132
  * @return {Promise<Object>} OracleQuery object
119
133
  */
120
- export async function pollForQueryResponse (oracleId, queryId, { attempts = 20, interval = 5000 } = {}) {
134
+ export async function pollForQueryResponse (
135
+ oracleId,
136
+ queryId,
137
+ { attempts = 20, interval = this._getPollInterval('microblock') } = {}
138
+ ) {
121
139
  for (let i = 0; i < attempts; i++) {
122
140
  if (i) await pause(interval)
123
141
  const { response } = await this.api.getOracleQueryByPubkeyAndQueryId(oracleId, queryId)
124
142
  const responseBuffer = decode(response, 'or')
125
143
  if (responseBuffer.length) {
126
- return { response, decode: () => responseBuffer } // TODO: Return just responseBuffer
144
+ return String(responseBuffer)
127
145
  }
128
146
  }
129
- throw new Error(`Giving up after ${(attempts - 1) * interval}ms`)
147
+ throw new RequestTimedOutError((attempts - 1) * interval)
130
148
  }
131
149
 
132
150
  /**
@@ -138,22 +156,23 @@ export async function pollForQueryResponse (oracleId, queryId, { attempts = 20,
138
156
  * @param {String} queryFormat Format of query
139
157
  * @param {String} responseFormat Format of query response
140
158
  * @param {Object} [options={}] Options
141
- * @param {String|Number} [options.queryFee] queryFee Oracle query Fee
142
- * @param {Object} [options.oracleTtl] oracleTtl OracleTtl object {type: 'delta|block', value: 'number'}
143
- * @param {Number} [options.abiVersion] abiVersion Always 0 (do not use virtual machine)
144
- * @param {Number|String} [options.fee] fee Transaction fee
159
+ * @param {String|Number} [options.queryFee] Oracle query Fee
160
+ * @param {Object} [options.oracleTtl] OracleTtl object {type: 'delta|block', value: 'number'}
161
+ * @param {Number} [options.abiVersion] Always 0 (do not use virtual machine)
162
+ * @param {Number|String} [options.fee] Transaction fee
145
163
  * @param {Number|String} [options.ttl] Transaction time to leave
146
164
  * @return {Promise<Object>} Oracle object
147
165
  */
148
166
  async function registerOracle (queryFormat, responseFormat, options = {}) {
149
- const opt = R.merge(this.Ae.defaults, options) // Preset VmVersion for oracle
167
+ const opt = { ...this.Ae.defaults, ...options } // Preset VmVersion for oracle
150
168
  const accountId = await this.address(opt)
151
169
 
152
- const oracleRegisterTx = await this.oracleRegisterTx(R.merge(opt, {
170
+ const oracleRegisterTx = await this.oracleRegisterTx({
171
+ ...opt,
153
172
  accountId,
154
173
  queryFormat,
155
174
  responseFormat
156
- }))
175
+ })
157
176
  return {
158
177
  ...await this.send(oracleRegisterTx, opt),
159
178
  ...await this.getOracleObject(`ok_${accountId.slice(3)}`)
@@ -177,14 +196,16 @@ async function registerOracle (queryFormat, responseFormat, options = {}) {
177
196
  * @return {Promise<Object>} Query object
178
197
  */
179
198
  async function postQueryToOracle (oracleId, query, options = {}) {
180
- const opt = R.merge(this.Ae.defaults, options)
199
+ const queryFee = options.queryFee || (await this.api.getOracleByPubkey(oracleId)).queryFee
200
+ const opt = { ...this.Ae.defaults, queryFee, ...options }
181
201
  const senderId = await this.address(opt)
182
202
 
183
- const oracleRegisterTx = await this.oraclePostQueryTx(R.merge(opt, {
203
+ const oracleRegisterTx = await this.oraclePostQueryTx({
204
+ ...opt,
184
205
  oracleId,
185
206
  senderId,
186
207
  query
187
- }))
208
+ })
188
209
  const queryId = oracleQueryId(senderId, unpackTx(oracleRegisterTx).tx.nonce, oracleId)
189
210
  return {
190
211
  ...await this.send(oracleRegisterTx, opt),
@@ -206,14 +227,15 @@ async function postQueryToOracle (oracleId, query, options = {}) {
206
227
  * @return {Promise<Object>} Oracle object
207
228
  */
208
229
  async function extendOracleTtl (oracleId, oracleTtl, options = {}) {
209
- const opt = R.merge(this.Ae.defaults, options)
230
+ const opt = { ...this.Ae.defaults, ...options }
210
231
  const callerId = await this.address(opt)
211
232
 
212
- const oracleExtendTx = await this.oracleExtendTx(R.merge(opt, {
233
+ const oracleExtendTx = await this.oracleExtendTx({
234
+ ...opt,
213
235
  oracleId,
214
236
  callerId,
215
237
  oracleTtl
216
- }))
238
+ })
217
239
  return {
218
240
  ...await this.send(oracleExtendTx, opt),
219
241
  ...await this.getOracleObject(oracleId)
@@ -236,15 +258,16 @@ async function extendOracleTtl (oracleId, oracleTtl, options = {}) {
236
258
  * @return {Promise<Object>} Oracle object
237
259
  */
238
260
  async function respondToQuery (oracleId, queryId, response, options = {}) {
239
- const opt = R.merge(this.Ae.defaults, options)
261
+ const opt = { ...this.Ae.defaults, ...options }
240
262
  const callerId = await this.address(opt)
241
263
 
242
- const oracleRespondTx = await this.oracleRespondTx(R.merge(opt, {
264
+ const oracleRespondTx = await this.oracleRespondTx({
265
+ ...opt,
243
266
  oracleId,
244
267
  queryId,
245
268
  callerId,
246
269
  response
247
- }))
270
+ })
248
271
  return {
249
272
  ...await this.send(oracleRespondTx, opt),
250
273
  ...await this.getOracleObject(oracleId)
@@ -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
 
@@ -42,4 +42,6 @@ import Contract from './contract'
42
42
  * @param {Object} [options={}] - Initializer object
43
43
  * @return {Object} Universal instance
44
44
  */
45
- export default Ae.compose(AccountMultiple, Chain, Transaction, Aens, Contract, Oracle, GeneralizeAccount)
45
+ export default Ae.compose(
46
+ AccountMultiple, Chain, Transaction, Aens, Contract, Oracle, GeneralizedAccount
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)