@aeternity/aepp-sdk 8.2.0 → 10.0.0-beta.1

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 (145) hide show
  1. package/README.md +16 -9
  2. package/dist/aepp-sdk.browser-script.js +1 -1
  3. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -9
  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 +33 -119
  10. package/es/account/base.js.map +1 -1
  11. package/es/account/memory.js +17 -19
  12. package/es/account/memory.js.map +1 -1
  13. package/es/account/multiple.js +75 -154
  14. package/es/account/multiple.js.map +1 -1
  15. package/es/ae/aens.js +164 -599
  16. package/es/ae/aens.js.map +1 -1
  17. package/es/ae/contract.js +108 -916
  18. package/es/ae/contract.js.map +1 -1
  19. package/es/ae/index.js +89 -250
  20. package/es/ae/index.js.map +1 -1
  21. package/es/ae/oracle.js +132 -500
  22. package/es/ae/oracle.js.map +1 -1
  23. package/es/chain/index.js +4 -23
  24. package/es/chain/index.js.map +1 -1
  25. package/es/chain/node.js +292 -1018
  26. package/es/chain/node.js.map +1 -1
  27. package/es/channel/handlers.js +597 -1086
  28. package/es/channel/handlers.js.map +1 -1
  29. package/es/channel/index.js +203 -451
  30. package/es/channel/index.js.map +1 -1
  31. package/es/channel/internal.js +129 -301
  32. package/es/channel/internal.js.map +1 -1
  33. package/es/contract/aci/index.js +319 -491
  34. package/es/contract/aci/index.js.map +1 -1
  35. package/es/contract/aci/transformation.js +35 -711
  36. package/es/contract/aci/transformation.js.map +1 -1
  37. package/es/contract/compiler.js +129 -203
  38. package/es/contract/compiler.js.map +1 -1
  39. package/es/contract/ga/helpers.js +17 -122
  40. package/es/contract/ga/helpers.js.map +1 -1
  41. package/es/contract/ga/index.js +102 -247
  42. package/es/contract/ga/index.js.map +1 -1
  43. package/es/contract/index.js +1 -1
  44. package/es/contract/index.js.map +1 -1
  45. package/es/index.js +2 -3
  46. package/es/index.js.map +1 -1
  47. package/es/node-pool/index.js +54 -73
  48. package/es/node-pool/index.js.map +1 -1
  49. package/es/node.js +56 -157
  50. package/es/node.js.map +1 -1
  51. package/es/other.d.ts +1 -1
  52. package/es/tx/builder/helpers.js +49 -89
  53. package/es/tx/builder/helpers.js.map +1 -1
  54. package/es/tx/builder/index.js +205 -303
  55. package/es/tx/builder/index.js.map +1 -1
  56. package/es/tx/builder/schema.js +585 -573
  57. package/es/tx/builder/schema.js.map +1 -1
  58. package/es/tx/index.js +1 -1
  59. package/es/tx/index.js.map +1 -1
  60. package/es/tx/tx-object.js +105 -135
  61. package/es/tx/tx-object.js.map +1 -1
  62. package/es/tx/tx.js +810 -1586
  63. package/es/tx/tx.js.map +1 -1
  64. package/es/tx/validator.js +191 -426
  65. package/es/tx/validator.js.map +1 -1
  66. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +17 -21
  67. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
  68. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +38 -74
  69. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
  70. package/es/utils/aepp-wallet-communication/content-script-bridge.js +14 -15
  71. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +1 -1
  72. package/es/utils/aepp-wallet-communication/helpers.js +60 -105
  73. package/es/utils/aepp-wallet-communication/helpers.js.map +1 -1
  74. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +179 -510
  75. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
  76. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +70 -89
  77. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
  78. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +354 -603
  79. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +1 -1
  80. package/es/utils/aepp-wallet-communication/schema.js +43 -39
  81. package/es/utils/aepp-wallet-communication/schema.js.map +1 -1
  82. package/es/utils/aepp-wallet-communication/wallet-detector.js +32 -58
  83. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +1 -1
  84. package/es/utils/amount-formatter.js +41 -61
  85. package/es/utils/amount-formatter.js.map +1 -1
  86. package/es/utils/async-init.js +28 -64
  87. package/es/utils/async-init.js.map +1 -1
  88. package/es/utils/bignumber.js +3 -11
  89. package/es/utils/bignumber.js.map +1 -1
  90. package/es/utils/bytes.js +5 -9
  91. package/es/utils/bytes.js.map +1 -1
  92. package/es/utils/crypto.js +49 -75
  93. package/es/utils/crypto.js.map +1 -1
  94. package/es/utils/hd-wallet.js +45 -81
  95. package/es/utils/hd-wallet.js.map +1 -1
  96. package/es/utils/json-big.js +16 -49
  97. package/es/utils/json-big.js.map +1 -1
  98. package/es/utils/keystore.js +81 -246
  99. package/es/utils/keystore.js.map +1 -1
  100. package/es/utils/mptree.js +88 -134
  101. package/es/utils/mptree.js.map +1 -1
  102. package/es/utils/other.js +10 -60
  103. package/es/utils/other.js.map +1 -1
  104. package/es/utils/semver-satisfies.js +9 -28
  105. package/es/utils/semver-satisfies.js.map +1 -1
  106. package/es/utils/string.js +4 -13
  107. package/es/utils/string.js.map +1 -1
  108. package/es/utils/swagger.js +85 -218
  109. package/es/utils/swagger.js.map +1 -1
  110. package/package.json +52 -43
  111. package/src/account/base.js +8 -9
  112. package/src/account/multiple.js +20 -16
  113. package/src/ae/aens.js +25 -21
  114. package/src/ae/contract.js +65 -246
  115. package/src/ae/index.js +31 -7
  116. package/src/ae/oracle.js +21 -17
  117. package/src/chain/index.js +2 -12
  118. package/src/chain/node.js +26 -29
  119. package/src/channel/handlers.js +0 -1
  120. package/src/channel/index.js +4 -5
  121. package/src/contract/aci/index.js +221 -106
  122. package/src/contract/aci/transformation.js +30 -422
  123. package/src/contract/compiler.js +45 -4
  124. package/src/contract/ga/helpers.js +2 -12
  125. package/src/contract/ga/index.js +22 -26
  126. package/src/index.js +2 -4
  127. package/src/node-pool/index.js +21 -12
  128. package/src/node.js +22 -26
  129. package/src/tx/builder/helpers.js +12 -24
  130. package/src/tx/builder/index.js +18 -15
  131. package/src/tx/builder/schema.js +43 -108
  132. package/src/tx/tx-object.js +0 -2
  133. package/src/tx/tx.js +157 -144
  134. package/src/tx/validator.js +134 -202
  135. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +1 -3
  136. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +9 -10
  137. package/src/utils/aepp-wallet-communication/schema.js +1 -3
  138. package/src/utils/amount-formatter.ts +1 -1
  139. package/src/utils/bignumber.ts +2 -1
  140. package/src/utils/crypto.js +4 -17
  141. package/src/utils/other.ts +1 -1
  142. package/src/utils/semver-satisfies.ts +1 -1
  143. package/src/utils/swagger.js +24 -7
  144. package/CHANGELOG.md +0 -1716
  145. package/src/contract/aci/helpers.js +0 -140
package/src/ae/aens.js CHANGED
@@ -26,7 +26,6 @@
26
26
  * @example import { Aens } from '@aeternity/aepp-sdk'
27
27
  */
28
28
 
29
- import * as R from 'ramda'
30
29
  import { salt } from '../utils/crypto'
31
30
  import {
32
31
  commitmentHash,
@@ -63,12 +62,13 @@ import { CLIENT_TTL, NAME_FEE, NAME_TTL } from '../tx/builder/schema'
63
62
  */
64
63
  async function revoke (name, options = {}) {
65
64
  ensureNameValid(name)
66
- const opt = R.merge(this.Ae.defaults, options)
65
+ const opt = { ...this.Ae.defaults, ...options }
67
66
 
68
- const nameRevokeTx = await this.nameRevokeTx(R.merge(opt, {
67
+ const nameRevokeTx = await this.nameRevokeTx({
68
+ ...opt,
69
69
  nameId: produceNameId(name),
70
70
  accountId: await this.address(opt)
71
- }))
71
+ })
72
72
 
73
73
  return this.send(nameRevokeTx, opt)
74
74
  }
@@ -103,18 +103,19 @@ async function revoke (name, options = {}) {
103
103
  */
104
104
  async function update (name, pointers = [], options = { extendPointers: false }) {
105
105
  ensureNameValid(name)
106
- const opt = R.merge(this.Ae.defaults, options)
106
+ const opt = { ...this.Ae.defaults, ...options }
107
107
  if (!validatePointers(pointers)) throw new Error('Invalid pointers array')
108
108
 
109
109
  pointers = [
110
110
  ...options.extendPointers ? (await this.getName(name)).pointers : [],
111
- ...pointers.map(p => R.fromPairs([['id', p], ['key', classify(p)]]))
111
+ ...pointers.map(p => Object.fromEntries([['id', p], ['key', classify(p)]]))
112
112
  ].reduce((acc, el) => [...acc.filter(p => p.key !== el.key), el], [])
113
- const nameUpdateTx = await this.nameUpdateTx(R.merge(opt, {
113
+ const nameUpdateTx = await this.nameUpdateTx({
114
+ ...opt,
114
115
  nameId: produceNameId(name),
115
116
  accountId: await this.address(opt),
116
117
  pointers
117
- }))
118
+ })
118
119
 
119
120
  return this.send(nameUpdateTx, opt)
120
121
  }
@@ -145,13 +146,14 @@ async function update (name, pointers = [], options = { extendPointers: false })
145
146
  */
146
147
  async function transfer (name, account, options = {}) {
147
148
  ensureNameValid(name)
148
- const opt = R.merge(this.Ae.defaults, options)
149
+ const opt = { ...this.Ae.defaults, ...options }
149
150
 
150
- const nameTransferTx = await this.nameTransferTx(R.merge(opt, {
151
+ const nameTransferTx = await this.nameTransferTx({
152
+ ...opt,
151
153
  nameId: produceNameId(name),
152
154
  accountId: await this.address(opt),
153
155
  recipientId: account
154
- }))
156
+ })
155
157
 
156
158
  return this.send(nameTransferTx, opt)
157
159
  }
@@ -186,22 +188,22 @@ async function query (name, opt = {}) {
186
188
  pointers: o.pointers || [],
187
189
  update: async (pointers = [], options = {}) => {
188
190
  return {
189
- ...(await this.aensUpdate(name, pointers, R.merge(opt, options))),
191
+ ...(await this.aensUpdate(name, pointers, { ...opt, ...options })),
190
192
  ...(await this.aensQuery(name))
191
193
  }
192
194
  },
193
195
  transfer: async (account, options = {}) => {
194
196
  return {
195
- ...(await this.aensTransfer(name, account, R.merge(opt, options))),
197
+ ...(await this.aensTransfer(name, account, { ...opt, ...options })),
196
198
  ...(await this.aensQuery(name))
197
199
  }
198
200
  },
199
- revoke: async (options = {}) => this.aensRevoke(name, R.merge(opt, options)),
201
+ revoke: async (options = {}) => this.aensRevoke(name, { ...opt, ...options }),
200
202
  extendTtl: async (nameTtl = NAME_TTL, options = {}) => {
201
203
  if (!nameTtl || typeof nameTtl !== 'number' || nameTtl > NAME_TTL) throw new Error('Ttl must be an number and less then 180000 blocks')
202
204
 
203
205
  return {
204
- ...(await this.aensUpdate(name, o.pointers.map(p => p.id), { ...R.merge(opt, options), nameTtl })),
206
+ ...(await this.aensUpdate(name, o.pointers.map(p => p.id), { ...opt, ...options, nameTtl })),
205
207
  ...(await this.aensQuery(name))
206
208
  }
207
209
  }
@@ -233,18 +235,19 @@ async function query (name, opt = {}) {
233
235
  */
234
236
  async function claim (name, salt, options) {
235
237
  ensureNameValid(name)
236
- const opt = R.merge(this.Ae.defaults, options)
238
+ const opt = { ...this.Ae.defaults, ...options }
237
239
 
238
240
  const minNameFee = getMinimumNameFee(name)
239
241
  if (opt.nameFee !== this.Ae.defaults.nameFee && minNameFee.gt(opt.nameFee)) {
240
242
  throw new Error(`the provided fee ${opt.nameFee} is not enough to execute the claim, required: ${minNameFee}`)
241
243
  }
242
244
  opt.nameFee = opt.nameFee !== this.Ae.defaults.nameFee ? opt.nameFee : minNameFee
243
- const claimTx = await this.nameClaimTx(R.merge(opt, {
245
+ const claimTx = await this.nameClaimTx({
246
+ ...opt,
244
247
  accountId: await this.address(opt),
245
248
  nameSalt: salt,
246
249
  name: encode(name, 'nm')
247
- }))
250
+ })
248
251
 
249
252
  const result = await this.send(claimTx, opt)
250
253
  if (!isAuctionName(name)) {
@@ -282,15 +285,16 @@ async function claim (name, salt, options) {
282
285
  */
283
286
  async function preclaim (name, options = {}) {
284
287
  ensureNameValid(name)
285
- const opt = R.merge(this.Ae.defaults, options)
288
+ const opt = { ...this.Ae.defaults, ...options }
286
289
  const _salt = salt()
287
290
  const height = await this.height()
288
291
  const commitmentId = commitmentHash(name, _salt)
289
292
 
290
- const preclaimTx = await this.namePreclaimTx(R.merge(opt, {
293
+ const preclaimTx = await this.namePreclaimTx({
294
+ ...opt,
291
295
  accountId: await this.address(opt),
292
296
  commitmentId
293
- }))
297
+ })
294
298
 
295
299
  const result = await this.send(preclaimTx, opt)
296
300
 
@@ -27,87 +27,23 @@
27
27
  */
28
28
 
29
29
  import Ae from './'
30
- import * as R from 'ramda'
31
30
  import ContractCompilerAPI from '../contract/compiler'
32
31
  import ContractBase from '../contract'
33
32
  import getContractInstance from '../contract/aci'
34
33
  import NodePool from '../node-pool'
35
- import { AMOUNT, DEPOSIT, DRY_RUN_ACCOUNT, GAS, MIN_GAS_PRICE } from '../tx/builder/schema'
34
+ import { AMOUNT, DEPOSIT, GAS, MIN_GAS_PRICE } from '../tx/builder/schema'
36
35
  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
36
 
102
37
  /**
103
38
  * Static contract call(using dry-run)
104
39
  * @function
105
40
  * @alias module:@aeternity/aepp-sdk/es/ae/contract
106
41
  * @category async
42
+ * @deprecated
107
43
  * @param {String} source Contract source code
108
- * @param {String} address Contract address
44
+ * @param {String} contractAddress Contract address
109
45
  * @param {String} name Name of function to call
110
- * @param {Array|String} args Argument's or callData for call/deploy transaction
46
+ * @param {Array} args Arguments array for call/deploy transaction
111
47
  * @param {Object} [options]
112
48
  * @param {Number|String} [options.top] Block height or hash on which you want to call contract
113
49
  * @param {String} [options.bytecode] Block hash on which you want to call contract
@@ -120,39 +56,9 @@ async function contractDecodeData (source, fn, callValue, callResult, options) {
120
56
  * decode: (type) => Decode call result
121
57
  * }
122
58
  */
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
- }
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 })
156
62
  }
157
63
 
158
64
  /**
@@ -160,12 +66,14 @@ async function contractCallStatic (source, address, name, args = [], options = {
160
66
  * @function
161
67
  * @alias module:@aeternity/aepp-sdk/es/ae/contract
162
68
  * @category async
69
+ * @deprecated
163
70
  * @param {String} source Contract source code
164
- * @param {String} address Contract address or AENS name
71
+ * @param {String} contractAddress Contract address or AENS name
165
72
  * @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
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
169
77
  * @example
170
78
  * const callResult = await client.contractCall(source, address, fnName, args = [], options)
171
79
  * {
@@ -174,23 +82,9 @@ async function contractCallStatic (source, address, name, args = [], options = {
174
82
  * decode: (type) => Decode call result
175
83
  * }
176
84
  */
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
- }
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)
194
88
  }
195
89
 
196
90
  /**
@@ -198,10 +92,11 @@ async function contractCall (source, address, name, argsOrCallData = [], options
198
92
  * @function
199
93
  * @alias module:@aeternity/aepp-sdk/es/ae/contract
200
94
  * @category async
95
+ * @deprecated
201
96
  * @param {String} code Compiled contract
202
97
  * @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)
98
+ * @param {Array} params Arguments of contract constructor(init) function. Can be array of arguments or callData string
99
+ * @param {Object} [options] Transaction options (fee, ttl, gas, amount, deposit)
205
100
  * @param {Object} [options.filesystem={}] Contract external namespaces map* @return {Promise<Object>} Result object
206
101
  * @return {Promise<Object>} Result object
207
102
  * @example
@@ -216,31 +111,10 @@ async function contractCall (source, address, name, argsOrCallData = [], options
216
111
  * callStatic: (fnName, args = [], options) => Static all contract function
217
112
  * }
218
113
  */
219
- async function contractDeploy (code, source, initState = [], options = {}) {
220
- const opt = { ...this.Ae.defaults, ...options }
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
- })
114
+ async function contractDeploy (code, source, params, options) {
115
+ const contract = await this.getContractInstance({ ...options, source })
116
+ contract.bytecode = code
117
+ return contract.deploy(params, options)
244
118
  }
245
119
 
246
120
  /**
@@ -264,7 +138,7 @@ async function contractCompile (source, options = {}) {
264
138
  const opt = { ...this.Ae.defaults, ...options }
265
139
  const bytecode = await this.compileContractAPI(source, options)
266
140
  return Object.freeze({
267
- encodeCall: (name, args) => this.contractEncodeCall(source, name, args, opt),
141
+ encodeCall: (name, args) => this.contractEncodeCallDataAPI(source, name, args, opt),
268
142
  deploy: (init, options) => this.contractDeploy(bytecode, source, init, { ...opt, ...options }),
269
143
  deployStatic: (init, options) => this.contractCallStatic(source, null, 'init', init, {
270
144
  ...opt,
@@ -286,111 +160,65 @@ async function contractCompile (source, options = {}) {
286
160
  * @return {Promise<String>} Signature in hex representation
287
161
  */
288
162
  async function delegateSignatureCommon (ids = [], opt = {}) {
289
- return this.sign(
290
- Buffer.concat(
291
- [
292
- Buffer.from(this.getNetworkId(opt)),
293
- decode(await this.address(opt)),
294
- ...ids.map(e => decode(e))
295
- ]
296
- ),
163
+ const signature = await this.sign(
164
+ Buffer.concat([
165
+ Buffer.from(this.getNetworkId(opt)),
166
+ ...(Object.prototype.hasOwnProperty.call(opt, 'onAccount') ? [decode(await this.address(opt))] : []),
167
+ ...ids.map(e => decode(e))
168
+ ]),
297
169
  opt
298
- ).then(s => Buffer.from(s).toString('hex'))
299
- }
300
-
301
- /**
302
- * Helper to generate a signature to delegate a name pre-claim to a contract.
303
- * @function
304
- * @alias module:@aeternity/aepp-sdk/es/ae/contract
305
- * @category async
306
- * @param {String} contractId Contract Id
307
- * @param {{ onAccount: String | Object }} [opt={}] opt Options
308
- * @return {Promise<String>} Signature for delegation
309
- */
310
- async function delegateNamePreclaimSignature (contractId, opt = {}) {
311
- return this.delegateSignatureCommon([contractId], opt)
312
- }
313
-
314
- /**
315
- * Helper to generate a signature to delegate a name claim to a contract.
316
- * @function
317
- * @alias module:@aeternity/aepp-sdk/es/ae/contract
318
- * @category async
319
- * @param {String} name The name being claimed
320
- * @param {String} contractId Contract Id
321
- * @param {{ onAccount: String | Object }} [opt={}] opt Options
322
- * @return {Promise<String>} Signature for delegation
323
- */
324
- async function delegateNameClaimSignature (contractId, name, opt = {}) {
325
- return this.delegateSignatureCommon([produceNameId(name), contractId], opt)
326
- }
327
-
328
- /**
329
- * Helper to generate a signature to delegate a name transfer to a contract.
330
- * @function
331
- * @alias module:@aeternity/aepp-sdk/es/ae/contract
332
- * @category async
333
- * @param {String} contractId Contract Id
334
- * @param {String} name The name being transferred
335
- * @param {{ onAccount: String | Object }} [opt={}] opt Options
336
- * @return {Promise<String>} Signature for delegation
337
- */
338
- async function delegateNameTransferSignature (contractId, name, opt = {}) {
339
- return this.delegateSignatureCommon([produceNameId(name), contractId], opt)
170
+ )
171
+ return Buffer.from(signature).toString('hex')
340
172
  }
341
173
 
342
174
  /**
343
- * Helper to generate a signature to delegate a name revoke to a contract.
344
- * @function
345
- * @alias module:@aeternity/aepp-sdk/es/ae/contract
346
- * @category async
347
- * @param {String} contractId Contract Id
348
- * @param {String} name The name being revoked
349
- * @param {{ onAccount: String | Object }} [opt={}] opt Options
350
- * @return {Promise<String>} Signature for delegation
351
- */
352
- async function delegateNameRevokeSignature (contractId, name, opt = {}) {
353
- return this.delegateSignatureCommon([produceNameId(name), contractId], opt)
354
- }
355
-
356
- /**
357
- * Helper to generate a signature to delegate a Oracle register to a contract.
358
- * @function
359
- * @alias module:@aeternity/aepp-sdk/es/ae/contract
360
- * @category async
361
- * @param {String} contractId Contract Id
362
- * @param {{ onAccount: String | Object }} [opt={}] opt Options
363
- * @return {Promise<String>} Signature for delegation
364
- */
365
- async function delegateOracleRegisterSignature (contractId, opt = {}) {
366
- return this.delegateSignatureCommon([contractId], opt)
367
- }
368
-
369
- /**
370
- * Helper to generate a signature to delegate a Oracle extend to a contract.
175
+ * Helper to generate a signature to delegate pre-claim/claim/transfer/revoke of a name to a contract.
371
176
  * @function
372
177
  * @alias module:@aeternity/aepp-sdk/es/ae/contract
373
178
  * @category async
374
179
  * @param {String} contractId Contract Id
180
+ * @param {String} [name] The name
375
181
  * @param {{ onAccount: String | Object }} [opt={}] opt Options
376
182
  * @return {Promise<String>} Signature for delegation
183
+ * @example
184
+ * const client = await Universal({ ... })
185
+ * const contractId = 'ct_asd2ks...' // contract address
186
+ * const name = 'example.chain' // AENS name
187
+ * const onAccount = await client.address() // Sign with a specific account
188
+ * // Preclaim signature
189
+ * const params = { contractId }
190
+ * const preclaimSig = await client.createAensDelegationSignature(params, { onAccount: current })
191
+ * // Claim, transfer and revoke signature
192
+ * const params = { contractId, name }
193
+ * const aensDelegationSig = await contract.createAensDelegationSignature(params, name, { onAccount: current })
377
194
  */
378
- async function delegateOracleExtendSignature (contractId, opt = {}) {
379
- return this.delegateSignatureCommon([contractId], opt)
195
+ async function createAensDelegationSignature ({ contractId, name }, opt = {}) {
196
+ return this.delegateSignatureCommon([...name ? [produceNameId(name)] : [], contractId], opt)
380
197
  }
381
198
 
382
199
  /**
383
- * Helper to generate a signature to delegate a Oracle respond to a contract.
200
+ * Helper to generate a signature to delegate register/extend/respond of a Oracle to a contract.
384
201
  * @function
385
202
  * @alias module:@aeternity/aepp-sdk/es/ae/contract
386
203
  * @category async
387
- * @param {String} queryId Oracle Query Id
388
204
  * @param {String} contractId Contract Id
205
+ * @param {String} [queryId] Oracle Query Id
389
206
  * @param {{ onAccount: String | Object }} [opt={}] opt Options
390
207
  * @return {Promise<String>} Signature for delegation
208
+ * @example
209
+ * const client = await Universal({ ... })
210
+ * const contractId = 'ct_asd2ks...' // contract address
211
+ * const queryId = 'oq_...' // Oracle Query Id
212
+ * const onAccount = await client.address() // Sign with a specific account
213
+ * // Oracle register and extend signature
214
+ * const params = { contractId }
215
+ * const oracleDelegationSig = await contract.createOracleDelegationSignature(params, { onAccount })
216
+ * // Oracle respond signature
217
+ * const params = { contractId, queryId }
218
+ * const respondSig = await contract.createOracleDelegationSignature(params, queryId)
391
219
  */
392
- async function delegateOracleRespondSignature (queryId, contractId, opt = {}) {
393
- return this.delegateSignatureCommon([queryId, contractId], opt)
220
+ async function createOracleDelegationSignature ({ contractId, queryId }, opt = {}) {
221
+ return this.delegateSignatureCommon([...queryId ? [queryId] : [], contractId], opt)
394
222
  }
395
223
 
396
224
  /**
@@ -429,21 +257,12 @@ export const ContractAPI = Ae.compose(ContractBase, {
429
257
  contractCallStatic,
430
258
  contractDeploy,
431
259
  contractCall,
432
- contractEncodeCall,
433
- contractDecodeData,
434
- _handleCallError,
435
- _sendAndProcess,
436
260
  // Delegation for contract
437
- // AENS
438
261
  delegateSignatureCommon,
439
- delegateNamePreclaimSignature,
440
- delegateNameClaimSignature,
441
- delegateNameTransferSignature,
442
- delegateNameRevokeSignature,
262
+ // AENS
263
+ createAensDelegationSignature,
443
264
  // Oracle
444
- delegateOracleRegisterSignature,
445
- delegateOracleExtendSignature,
446
- delegateOracleRespondSignature
265
+ createOracleDelegationSignature
447
266
  },
448
267
  deepProps: {
449
268
  Ae: {
package/src/ae/index.js CHANGED
@@ -27,7 +27,6 @@ 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'
33
32
 
@@ -38,16 +37,20 @@ import { AE_AMOUNT_FORMATS } from '../utils/amount-formatter'
38
37
  * @rtype (tx: String, options: Object) => Promise[String]
39
38
  * @param {String} tx - Transaction
40
39
  * @param {Object} [options={}] options - Options
41
- * @param {Object} [options.verify] verify - Verify transaction before broadcast, throw error if not valid
40
+ * @param {Object} [options.verify=true] verify - Verify transaction before broadcast, throw error if not valid
42
41
  * @return {Object} Transaction
43
42
  */
44
43
  async function send (tx, options = {}) {
45
- const opt = R.merge(this.Ae.defaults, options)
46
- const { contractId: gaId, authFun } = await this.getAccount(await this.address(opt))
47
- const signed = gaId
44
+ const opt = { ...this.Ae.defaults, ...options }
45
+ const { contractId, authFun } = options.innerTx
46
+ ? { contractId: false }
47
+ : await this.getAccount(await this.address(opt))
48
+ const signed = contractId
48
49
  ? await this.signUsingGA(tx, { ...opt, authFun })
49
50
  : await this.signTransaction(tx, opt)
50
- return this.sendTransaction(signed, opt)
51
+ return opt.innerTx
52
+ ? { hash: TxBuilder.buildTxHash(signed), rawTx: signed }
53
+ : this.sendTransaction(signed, opt)
51
54
  }
52
55
 
53
56
  async function signUsingGA (tx, { authData, authFun, ...options } = {}) {
@@ -105,6 +108,27 @@ async function transferFunds (fraction, recipientIdOrName, options) {
105
108
  return this.send(await this.spendTx({ ...opt, senderId, recipientId, amount }), opt)
106
109
  }
107
110
 
111
+ /**
112
+ * Submit transaction of another account paying for it (fee and gas)
113
+ * @instance
114
+ * @category async
115
+ * @rtype (transaction: String, options?: Object) => Promise[String]
116
+ * @param {String} transaction - tx_<base64>-encoded transaction
117
+ * @param {Object} [options]
118
+ * @return {Object} Transaction
119
+ */
120
+ async function payForTransaction (transaction, options) {
121
+ const opt = { ...this.Ae.defaults, ...options }
122
+ return this.send(
123
+ await this.payingForTx({
124
+ ...opt,
125
+ payerId: await this.address(opt),
126
+ tx: transaction
127
+ }),
128
+ opt
129
+ )
130
+ }
131
+
108
132
  /**
109
133
  * Remove all listeners for RPC
110
134
  * @instance
@@ -135,7 +159,7 @@ function destroyInstance () {
135
159
  * @return {Object} Ae instance
136
160
  */
137
161
  const Ae = stampit(Tx, AccountBase, Chain, {
138
- methods: { send, spend, transferFunds, destroyInstance, signUsingGA },
162
+ methods: { send, spend, transferFunds, payForTransaction, destroyInstance, signUsingGA },
139
163
  deepProps: { Ae: { defaults: { denomination: AE_AMOUNT_FORMATS.AETTOS } } }
140
164
  })
141
165