@aeternity/aepp-sdk 8.2.1 → 10.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.
- package/CHANGELOG.md +216 -337
- package/README.md +16 -9
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -9
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +1 -1
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +1 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/account/base.js +36 -120
- package/es/account/base.js.map +1 -1
- package/es/account/memory.js +17 -19
- package/es/account/memory.js.map +1 -1
- package/es/account/multiple.js +79 -156
- package/es/account/multiple.js.map +1 -1
- package/es/ae/aens.js +205 -626
- package/es/ae/aens.js.map +1 -1
- package/es/ae/contract.js +114 -918
- package/es/ae/contract.js.map +1 -1
- package/es/ae/index.js +90 -250
- package/es/ae/index.js.map +1 -1
- package/es/ae/oracle.js +136 -504
- package/es/ae/oracle.js.map +1 -1
- package/es/ae/universal.js.map +1 -1
- package/es/chain/index.js +12 -27
- package/es/chain/index.js.map +1 -1
- package/es/chain/node.js +289 -1020
- package/es/chain/node.js.map +1 -1
- package/es/channel/handlers.js +597 -1086
- package/es/channel/handlers.js.map +1 -1
- package/es/channel/index.js +238 -465
- package/es/channel/index.js.map +1 -1
- package/es/channel/internal.js +129 -301
- package/es/channel/internal.js.map +1 -1
- package/es/contract/aci/index.js +328 -495
- package/es/contract/aci/index.js.map +1 -1
- package/es/contract/aci/transformation.js +35 -711
- package/es/contract/aci/transformation.js.map +1 -1
- package/es/contract/compiler.js +131 -203
- package/es/contract/compiler.js.map +1 -1
- package/es/contract/ga/helpers.js +17 -122
- package/es/contract/ga/helpers.js.map +1 -1
- package/es/contract/ga/index.js +108 -249
- package/es/contract/ga/index.js.map +1 -1
- package/es/contract/index.js +7 -3
- package/es/contract/index.js.map +1 -1
- package/es/index.js +3 -3
- package/es/index.js.map +1 -1
- package/es/node-pool/index.js +57 -74
- package/es/node-pool/index.js.map +1 -1
- package/es/node.js +65 -161
- package/es/node.js.map +1 -1
- package/es/other.d.ts +1 -1
- package/es/tx/builder/helpers.js +62 -115
- package/es/tx/builder/helpers.js.map +1 -1
- package/es/tx/builder/index.js +218 -309
- package/es/tx/builder/index.js.map +1 -1
- package/es/tx/builder/schema.js +586 -573
- package/es/tx/builder/schema.js.map +1 -1
- package/es/tx/index.js +102 -13
- package/es/tx/index.js.map +1 -1
- package/es/tx/tx-object.js +114 -138
- package/es/tx/tx-object.js.map +1 -1
- package/es/tx/tx.js +810 -1586
- package/es/tx/tx.js.map +1 -1
- package/es/tx/validator.js +191 -426
- package/es/tx/validator.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +20 -23
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +53 -80
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/es/utils/aepp-wallet-communication/connection/index.js.map +1 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js +24 -19
- package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +1 -1
- package/es/utils/aepp-wallet-communication/helpers.js +60 -105
- package/es/utils/aepp-wallet-communication/helpers.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +191 -514
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +78 -93
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +381 -613
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/schema.js +43 -39
- package/es/utils/aepp-wallet-communication/schema.js.map +1 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js +32 -58
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +1 -1
- package/es/utils/amount-formatter.js +41 -61
- package/es/utils/amount-formatter.js.map +1 -1
- package/es/utils/async-init.js +28 -64
- package/es/utils/async-init.js.map +1 -1
- package/es/utils/bignumber.js +3 -11
- package/es/utils/bignumber.js.map +1 -1
- package/es/utils/bytes.js +5 -9
- package/es/utils/bytes.js.map +1 -1
- package/es/utils/crypto.js +41 -106
- package/es/utils/crypto.js.map +1 -1
- package/es/utils/hd-wallet.js +45 -81
- package/es/utils/hd-wallet.js.map +1 -1
- package/es/utils/json-big.js +16 -49
- package/es/utils/json-big.js.map +1 -1
- package/es/utils/keystore.js +81 -246
- package/es/utils/keystore.js.map +1 -1
- package/es/utils/mptree.js +88 -134
- package/es/utils/mptree.js.map +1 -1
- package/es/utils/other.js +10 -60
- package/es/utils/other.js.map +1 -1
- package/es/utils/semver-satisfies.js +9 -28
- package/es/utils/semver-satisfies.js.map +1 -1
- package/es/utils/string.js +4 -13
- package/es/utils/string.js.map +1 -1
- package/es/utils/swagger.js +87 -224
- package/es/utils/swagger.js.map +1 -1
- package/package.json +51 -44
- package/src/account/base.js +11 -10
- package/src/account/multiple.js +24 -18
- package/src/ae/aens.js +64 -61
- package/src/ae/contract.js +71 -248
- package/src/ae/index.js +34 -9
- package/src/ae/oracle.js +30 -22
- package/src/ae/universal.js +3 -1
- package/src/chain/index.js +10 -16
- package/src/chain/node.js +38 -38
- package/src/channel/handlers.js +10 -4
- package/src/channel/index.js +44 -20
- package/src/contract/aci/index.js +234 -112
- package/src/contract/aci/transformation.js +30 -422
- package/src/contract/compiler.js +50 -5
- package/src/contract/ga/helpers.js +6 -14
- package/src/contract/ga/index.js +28 -28
- package/src/contract/index.js +6 -2
- package/src/index.js +4 -4
- package/src/node-pool/index.js +24 -13
- package/src/node.js +29 -30
- package/src/tx/builder/helpers.js +31 -56
- package/src/tx/builder/index.js +67 -28
- package/src/tx/builder/schema.js +79 -121
- package/src/tx/index.js +101 -12
- package/src/tx/tx-object.js +25 -8
- package/src/tx/tx.js +229 -150
- package/src/tx/validator.js +134 -202
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +3 -2
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +25 -7
- package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +10 -4
- package/src/utils/aepp-wallet-communication/helpers.js +4 -2
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +33 -12
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +9 -5
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +59 -29
- package/src/utils/aepp-wallet-communication/schema.js +1 -3
- package/src/utils/aepp-wallet-communication/wallet-detector.js +4 -1
- package/src/utils/amount-formatter.ts +1 -1
- package/src/utils/bignumber.ts +2 -1
- package/src/utils/crypto.js +4 -68
- package/src/utils/keystore.js +10 -2
- package/src/utils/other.ts +1 -1
- package/src/utils/semver-satisfies.ts +1 -1
- package/src/utils/swagger.js +22 -10
- package/src/contract/aci/helpers.js +0 -140
package/src/ae/contract.js
CHANGED
|
@@ -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,
|
|
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}
|
|
44
|
+
* @param {String} contractAddress Contract address
|
|
109
45
|
* @param {String} name Name of function to call
|
|
110
|
-
* @param {Array
|
|
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,
|
|
124
|
-
const
|
|
125
|
-
|
|
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}
|
|
71
|
+
* @param {String} contractAddress Contract address or AENS name
|
|
165
72
|
* @param {String} name Name of function to call
|
|
166
|
-
* @param {Array
|
|
167
|
-
* @param {Object} [options
|
|
168
|
-
* @param {Object} [options.filesystem
|
|
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,
|
|
178
|
-
const
|
|
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,11 +92,13 @@ 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
|
|
204
|
-
*
|
|
205
|
-
* @param {Object} [options
|
|
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*
|
|
206
102
|
* @return {Promise<Object>} Result object
|
|
207
103
|
* @example
|
|
208
104
|
* const deployed = await client.contractDeploy(bytecode, source, init = [], options)
|
|
@@ -216,31 +112,10 @@ async function contractCall (source, address, name, argsOrCallData = [], options
|
|
|
216
112
|
* callStatic: (fnName, args = [], options) => Static all contract function
|
|
217
113
|
* }
|
|
218
114
|
*/
|
|
219
|
-
async function contractDeploy (code, source,
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
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
|
-
})
|
|
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)
|
|
244
119
|
}
|
|
245
120
|
|
|
246
121
|
/**
|
|
@@ -250,7 +125,7 @@ async function contractDeploy (code, source, initState = [], options = {}) {
|
|
|
250
125
|
* @category async
|
|
251
126
|
* @param {String} source Contract sourece code
|
|
252
127
|
* @param {Object} [options={}] Transaction options (fee, ttl, gas, amount, deposit)
|
|
253
|
-
* @param {Object} [options.filesystem={}] Contract external namespaces map*
|
|
128
|
+
* @param {Object} [options.filesystem={}] Contract external namespaces map*
|
|
254
129
|
* @return {Promise<Object>} Result object
|
|
255
130
|
* @example
|
|
256
131
|
* const compiled = await client.contractCompile(SOURCE_CODE)
|
|
@@ -264,7 +139,7 @@ async function contractCompile (source, options = {}) {
|
|
|
264
139
|
const opt = { ...this.Ae.defaults, ...options }
|
|
265
140
|
const bytecode = await this.compileContractAPI(source, options)
|
|
266
141
|
return Object.freeze({
|
|
267
|
-
encodeCall: (name, args) => this.
|
|
142
|
+
encodeCall: (name, args) => this.contractEncodeCallDataAPI(source, name, args, opt),
|
|
268
143
|
deploy: (init, options) => this.contractDeploy(bytecode, source, init, { ...opt, ...options }),
|
|
269
144
|
deployStatic: (init, options) => this.contractCallStatic(source, null, 'init', init, {
|
|
270
145
|
...opt,
|
|
@@ -286,111 +161,68 @@ async function contractCompile (source, options = {}) {
|
|
|
286
161
|
* @return {Promise<String>} Signature in hex representation
|
|
287
162
|
*/
|
|
288
163
|
async function delegateSignatureCommon (ids = [], opt = {}) {
|
|
289
|
-
|
|
290
|
-
Buffer.concat(
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
]
|
|
296
|
-
),
|
|
164
|
+
const signature = await this.sign(
|
|
165
|
+
Buffer.concat([
|
|
166
|
+
Buffer.from(this.getNetworkId(opt)),
|
|
167
|
+
...(Object.prototype.hasOwnProperty.call(opt, 'onAccount') ? [decode(await this.address(opt))] : []),
|
|
168
|
+
...ids.map(e => decode(e))
|
|
169
|
+
]),
|
|
297
170
|
opt
|
|
298
|
-
)
|
|
171
|
+
)
|
|
172
|
+
return Buffer.from(signature).toString('hex')
|
|
299
173
|
}
|
|
300
174
|
|
|
301
175
|
/**
|
|
302
|
-
* Helper to generate a signature to delegate
|
|
303
|
-
*
|
|
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)
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
/**
|
|
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.
|
|
176
|
+
* Helper to generate a signature to delegate pre-claim/claim/transfer/revoke of a name to
|
|
177
|
+
* a contract.
|
|
371
178
|
* @function
|
|
372
179
|
* @alias module:@aeternity/aepp-sdk/es/ae/contract
|
|
373
180
|
* @category async
|
|
374
181
|
* @param {String} contractId Contract Id
|
|
182
|
+
* @param {String} [name] The name
|
|
375
183
|
* @param {{ onAccount: String | Object }} [opt={}] opt Options
|
|
376
184
|
* @return {Promise<String>} Signature for delegation
|
|
185
|
+
* @example
|
|
186
|
+
* const client = await Universal({ ... })
|
|
187
|
+
* const contractId = 'ct_asd2ks...' // contract address
|
|
188
|
+
* const name = 'example.chain' // AENS name
|
|
189
|
+
* const onAccount = await client.address() // Sign with a specific account
|
|
190
|
+
* // Preclaim signature
|
|
191
|
+
* const params = { contractId }
|
|
192
|
+
* const preclaimSig = await client.createAensDelegationSignature(params, { onAccount: current })
|
|
193
|
+
* // Claim, transfer and revoke signature
|
|
194
|
+
* const params = { contractId, name }
|
|
195
|
+
* const aensDelegationSig = await contract.createAensDelegationSignature(
|
|
196
|
+
* params, name, { onAccount: current }
|
|
197
|
+
* )
|
|
377
198
|
*/
|
|
378
|
-
async function
|
|
379
|
-
return this.delegateSignatureCommon([contractId], opt)
|
|
199
|
+
async function createAensDelegationSignature ({ contractId, name }, opt = {}) {
|
|
200
|
+
return this.delegateSignatureCommon([...name ? [produceNameId(name)] : [], contractId], opt)
|
|
380
201
|
}
|
|
381
202
|
|
|
382
203
|
/**
|
|
383
|
-
* Helper to generate a signature to delegate a Oracle
|
|
204
|
+
* Helper to generate a signature to delegate register/extend/respond of a Oracle to a contract.
|
|
384
205
|
* @function
|
|
385
206
|
* @alias module:@aeternity/aepp-sdk/es/ae/contract
|
|
386
207
|
* @category async
|
|
387
|
-
* @param {String} queryId Oracle Query Id
|
|
388
208
|
* @param {String} contractId Contract Id
|
|
209
|
+
* @param {String} [queryId] Oracle Query Id
|
|
389
210
|
* @param {{ onAccount: String | Object }} [opt={}] opt Options
|
|
390
211
|
* @return {Promise<String>} Signature for delegation
|
|
212
|
+
* @example
|
|
213
|
+
* const client = await Universal({ ... })
|
|
214
|
+
* const contractId = 'ct_asd2ks...' // contract address
|
|
215
|
+
* const queryId = 'oq_...' // Oracle Query Id
|
|
216
|
+
* const onAccount = await client.address() // Sign with a specific account
|
|
217
|
+
* // Oracle register and extend signature
|
|
218
|
+
* const params = { contractId }
|
|
219
|
+
* const oracleDelegationSig = await contract.createOracleDelegationSignature(params, { onAccount })
|
|
220
|
+
* // Oracle respond signature
|
|
221
|
+
* const params = { contractId, queryId }
|
|
222
|
+
* const respondSig = await contract.createOracleDelegationSignature(params, queryId)
|
|
391
223
|
*/
|
|
392
|
-
async function
|
|
393
|
-
return this.delegateSignatureCommon([queryId, contractId], opt)
|
|
224
|
+
async function createOracleDelegationSignature ({ contractId, queryId }, opt = {}) {
|
|
225
|
+
return this.delegateSignatureCommon([...queryId ? [queryId] : [], contractId], opt)
|
|
394
226
|
}
|
|
395
227
|
|
|
396
228
|
/**
|
|
@@ -429,21 +261,12 @@ export const ContractAPI = Ae.compose(ContractBase, {
|
|
|
429
261
|
contractCallStatic,
|
|
430
262
|
contractDeploy,
|
|
431
263
|
contractCall,
|
|
432
|
-
contractEncodeCall,
|
|
433
|
-
contractDecodeData,
|
|
434
|
-
_handleCallError,
|
|
435
|
-
_sendAndProcess,
|
|
436
264
|
// Delegation for contract
|
|
437
|
-
// AENS
|
|
438
265
|
delegateSignatureCommon,
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
delegateNameTransferSignature,
|
|
442
|
-
delegateNameRevokeSignature,
|
|
266
|
+
// AENS
|
|
267
|
+
createAensDelegationSignature,
|
|
443
268
|
// Oracle
|
|
444
|
-
|
|
445
|
-
delegateOracleExtendSignature,
|
|
446
|
-
delegateOracleRespondSignature
|
|
269
|
+
createOracleDelegationSignature
|
|
447
270
|
},
|
|
448
271
|
deepProps: {
|
|
449
272
|
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,21 @@ 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]
|
|
40
|
+
* @param {Object} [options.verify=true] - Verify transaction before broadcast, throw error if not
|
|
41
|
+
* valid
|
|
42
42
|
* @return {Object} Transaction
|
|
43
43
|
*/
|
|
44
44
|
async function send (tx, options = {}) {
|
|
45
|
-
const opt =
|
|
46
|
-
const { contractId
|
|
47
|
-
|
|
45
|
+
const opt = { ...this.Ae.defaults, ...options }
|
|
46
|
+
const { contractId, authFun } = options.innerTx
|
|
47
|
+
? { contractId: false }
|
|
48
|
+
: await this.getAccount(await this.address(opt))
|
|
49
|
+
const signed = contractId
|
|
48
50
|
? await this.signUsingGA(tx, { ...opt, authFun })
|
|
49
51
|
: await this.signTransaction(tx, opt)
|
|
50
|
-
return
|
|
52
|
+
return opt.innerTx
|
|
53
|
+
? { hash: TxBuilder.buildTxHash(signed), rawTx: signed }
|
|
54
|
+
: this.sendTransaction(signed, opt)
|
|
51
55
|
}
|
|
52
56
|
|
|
53
57
|
async function signUsingGA (tx, { authData, authFun, ...options } = {}) {
|
|
@@ -70,7 +74,7 @@ async function spend (amount, recipientIdOrName, options) {
|
|
|
70
74
|
await this.spendTx({
|
|
71
75
|
...opt,
|
|
72
76
|
senderId: await this.address(opt),
|
|
73
|
-
recipientId: await this.resolveName(recipientIdOrName, '
|
|
77
|
+
recipientId: await this.resolveName(recipientIdOrName, 'account_pubkey', opt),
|
|
74
78
|
amount
|
|
75
79
|
}),
|
|
76
80
|
opt
|
|
@@ -93,7 +97,7 @@ async function transferFunds (fraction, recipientIdOrName, options) {
|
|
|
93
97
|
throw new Error(`Fraction should be a number between 0 and 1, got ${fraction}`)
|
|
94
98
|
}
|
|
95
99
|
const opt = { ...this.Ae.defaults, ...options }
|
|
96
|
-
const recipientId = await this.resolveName(recipientIdOrName, '
|
|
100
|
+
const recipientId = await this.resolveName(recipientIdOrName, 'account_pubkey', opt)
|
|
97
101
|
const senderId = await this.address(opt)
|
|
98
102
|
const balance = new BigNumber(await this.balance(senderId))
|
|
99
103
|
const desiredAmount = balance.times(fraction).integerValue(BigNumber.ROUND_HALF_UP)
|
|
@@ -105,6 +109,27 @@ async function transferFunds (fraction, recipientIdOrName, options) {
|
|
|
105
109
|
return this.send(await this.spendTx({ ...opt, senderId, recipientId, amount }), opt)
|
|
106
110
|
}
|
|
107
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Submit transaction of another account paying for it (fee and gas)
|
|
114
|
+
* @instance
|
|
115
|
+
* @category async
|
|
116
|
+
* @rtype (transaction: String, options?: Object) => Promise[String]
|
|
117
|
+
* @param {String} transaction - tx_<base64>-encoded transaction
|
|
118
|
+
* @param {Object} [options]
|
|
119
|
+
* @return {Object} Transaction
|
|
120
|
+
*/
|
|
121
|
+
async function payForTransaction (transaction, options) {
|
|
122
|
+
const opt = { ...this.Ae.defaults, ...options }
|
|
123
|
+
return this.send(
|
|
124
|
+
await this.payingForTx({
|
|
125
|
+
...opt,
|
|
126
|
+
payerId: await this.address(opt),
|
|
127
|
+
tx: transaction
|
|
128
|
+
}),
|
|
129
|
+
opt
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
|
|
108
133
|
/**
|
|
109
134
|
* Remove all listeners for RPC
|
|
110
135
|
* @instance
|
|
@@ -135,7 +160,7 @@ function destroyInstance () {
|
|
|
135
160
|
* @return {Object} Ae instance
|
|
136
161
|
*/
|
|
137
162
|
const Ae = stampit(Tx, AccountBase, Chain, {
|
|
138
|
-
methods: { send, spend, transferFunds, destroyInstance, signUsingGA },
|
|
163
|
+
methods: { send, spend, transferFunds, payForTransaction, destroyInstance, signUsingGA },
|
|
139
164
|
deepProps: { Ae: { defaults: { denomination: AE_AMOUNT_FORMATS.AETTOS } } }
|
|
140
165
|
})
|
|
141
166
|
|
package/src/ae/oracle.js
CHANGED
|
@@ -27,10 +27,9 @@
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
import Ae from './'
|
|
30
|
-
import
|
|
31
|
-
import { decodeBase64Check, assertedType } from '../utils/crypto'
|
|
30
|
+
import { decodeBase64Check } from '../utils/crypto'
|
|
32
31
|
import { pause } from '../utils/other'
|
|
33
|
-
import { oracleQueryId } from '../tx/builder/helpers'
|
|
32
|
+
import { oracleQueryId, decode } from '../tx/builder/helpers'
|
|
34
33
|
import { unpackTx } from '../tx/builder'
|
|
35
34
|
import { ORACLE_TTL, QUERY_FEE, QUERY_TTL, RESPONSE_TTL } from '../tx/builder/schema'
|
|
36
35
|
|
|
@@ -117,13 +116,17 @@ async function getQueryObject (oracleId, queryId) {
|
|
|
117
116
|
* @param {Object} [options.interval] Poll interval(default: 5000)
|
|
118
117
|
* @return {Promise<Object>} OracleQuery object
|
|
119
118
|
*/
|
|
120
|
-
export async function pollForQueryResponse (
|
|
119
|
+
export async function pollForQueryResponse (
|
|
120
|
+
oracleId,
|
|
121
|
+
queryId,
|
|
122
|
+
{ attempts = 20, interval = 5000 } = {}
|
|
123
|
+
) {
|
|
121
124
|
for (let i = 0; i < attempts; i++) {
|
|
122
125
|
if (i) await pause(interval)
|
|
123
126
|
const { response } = await this.api.getOracleQueryByPubkeyAndQueryId(oracleId, queryId)
|
|
124
|
-
const responseBuffer =
|
|
127
|
+
const responseBuffer = decode(response, 'or')
|
|
125
128
|
if (responseBuffer.length) {
|
|
126
|
-
return
|
|
129
|
+
return String(responseBuffer)
|
|
127
130
|
}
|
|
128
131
|
}
|
|
129
132
|
throw new Error(`Giving up after ${(attempts - 1) * interval}ms`)
|
|
@@ -138,22 +141,23 @@ export async function pollForQueryResponse (oracleId, queryId, { attempts = 20,
|
|
|
138
141
|
* @param {String} queryFormat Format of query
|
|
139
142
|
* @param {String} responseFormat Format of query response
|
|
140
143
|
* @param {Object} [options={}] Options
|
|
141
|
-
* @param {String|Number} [options.queryFee]
|
|
142
|
-
* @param {Object} [options.oracleTtl]
|
|
143
|
-
* @param {Number} [options.abiVersion]
|
|
144
|
-
* @param {Number|String} [options.fee]
|
|
144
|
+
* @param {String|Number} [options.queryFee] Oracle query Fee
|
|
145
|
+
* @param {Object} [options.oracleTtl] OracleTtl object {type: 'delta|block', value: 'number'}
|
|
146
|
+
* @param {Number} [options.abiVersion] Always 0 (do not use virtual machine)
|
|
147
|
+
* @param {Number|String} [options.fee] Transaction fee
|
|
145
148
|
* @param {Number|String} [options.ttl] Transaction time to leave
|
|
146
149
|
* @return {Promise<Object>} Oracle object
|
|
147
150
|
*/
|
|
148
151
|
async function registerOracle (queryFormat, responseFormat, options = {}) {
|
|
149
|
-
const opt =
|
|
152
|
+
const opt = { ...this.Ae.defaults, ...options } // Preset VmVersion for oracle
|
|
150
153
|
const accountId = await this.address(opt)
|
|
151
154
|
|
|
152
|
-
const oracleRegisterTx = await this.oracleRegisterTx(
|
|
155
|
+
const oracleRegisterTx = await this.oracleRegisterTx({
|
|
156
|
+
...opt,
|
|
153
157
|
accountId,
|
|
154
158
|
queryFormat,
|
|
155
159
|
responseFormat
|
|
156
|
-
})
|
|
160
|
+
})
|
|
157
161
|
return {
|
|
158
162
|
...await this.send(oracleRegisterTx, opt),
|
|
159
163
|
...await this.getOracleObject(`ok_${accountId.slice(3)}`)
|
|
@@ -177,14 +181,16 @@ async function registerOracle (queryFormat, responseFormat, options = {}) {
|
|
|
177
181
|
* @return {Promise<Object>} Query object
|
|
178
182
|
*/
|
|
179
183
|
async function postQueryToOracle (oracleId, query, options = {}) {
|
|
180
|
-
const
|
|
184
|
+
const queryFee = options.queryFee || (await this.api.getOracleByPubkey(oracleId)).queryFee
|
|
185
|
+
const opt = { ...this.Ae.defaults, queryFee, ...options }
|
|
181
186
|
const senderId = await this.address(opt)
|
|
182
187
|
|
|
183
|
-
const oracleRegisterTx = await this.oraclePostQueryTx(
|
|
188
|
+
const oracleRegisterTx = await this.oraclePostQueryTx({
|
|
189
|
+
...opt,
|
|
184
190
|
oracleId,
|
|
185
191
|
senderId,
|
|
186
192
|
query
|
|
187
|
-
})
|
|
193
|
+
})
|
|
188
194
|
const queryId = oracleQueryId(senderId, unpackTx(oracleRegisterTx).tx.nonce, oracleId)
|
|
189
195
|
return {
|
|
190
196
|
...await this.send(oracleRegisterTx, opt),
|
|
@@ -206,14 +212,15 @@ async function postQueryToOracle (oracleId, query, options = {}) {
|
|
|
206
212
|
* @return {Promise<Object>} Oracle object
|
|
207
213
|
*/
|
|
208
214
|
async function extendOracleTtl (oracleId, oracleTtl, options = {}) {
|
|
209
|
-
const opt =
|
|
215
|
+
const opt = { ...this.Ae.defaults, ...options }
|
|
210
216
|
const callerId = await this.address(opt)
|
|
211
217
|
|
|
212
|
-
const oracleExtendTx = await this.oracleExtendTx(
|
|
218
|
+
const oracleExtendTx = await this.oracleExtendTx({
|
|
219
|
+
...opt,
|
|
213
220
|
oracleId,
|
|
214
221
|
callerId,
|
|
215
222
|
oracleTtl
|
|
216
|
-
})
|
|
223
|
+
})
|
|
217
224
|
return {
|
|
218
225
|
...await this.send(oracleExtendTx, opt),
|
|
219
226
|
...await this.getOracleObject(oracleId)
|
|
@@ -236,15 +243,16 @@ async function extendOracleTtl (oracleId, oracleTtl, options = {}) {
|
|
|
236
243
|
* @return {Promise<Object>} Oracle object
|
|
237
244
|
*/
|
|
238
245
|
async function respondToQuery (oracleId, queryId, response, options = {}) {
|
|
239
|
-
const opt =
|
|
246
|
+
const opt = { ...this.Ae.defaults, ...options }
|
|
240
247
|
const callerId = await this.address(opt)
|
|
241
248
|
|
|
242
|
-
const oracleRespondTx = await this.oracleRespondTx(
|
|
249
|
+
const oracleRespondTx = await this.oracleRespondTx({
|
|
250
|
+
...opt,
|
|
243
251
|
oracleId,
|
|
244
252
|
queryId,
|
|
245
253
|
callerId,
|
|
246
254
|
response
|
|
247
|
-
})
|
|
255
|
+
})
|
|
248
256
|
return {
|
|
249
257
|
...await this.send(oracleRespondTx, opt),
|
|
250
258
|
...await this.getOracleObject(oracleId)
|
package/src/ae/universal.js
CHANGED
|
@@ -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(
|
|
45
|
+
export default Ae.compose(
|
|
46
|
+
AccountMultiple, Chain, Transaction, Aens, Contract, Oracle, GeneralizeAccount
|
|
47
|
+
)
|