@aeternity/aepp-sdk 9.0.1 → 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.
- 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 +30 -122
- 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 +73 -164
- package/es/account/multiple.js.map +1 -1
- package/es/ae/aens.js +164 -599
- package/es/ae/aens.js.map +1 -1
- package/es/ae/contract.js +82 -759
- package/es/ae/contract.js.map +1 -1
- package/es/ae/index.js +78 -315
- package/es/ae/index.js.map +1 -1
- package/es/ae/oracle.js +130 -498
- package/es/ae/oracle.js.map +1 -1
- package/es/chain/index.js +1 -1
- package/es/chain/index.js.map +1 -1
- package/es/chain/node.js +288 -1008
- 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 +203 -451
- 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 +319 -480
- 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 +129 -203
- package/es/contract/compiler.js.map +1 -1
- package/es/contract/ga/helpers.js +16 -114
- package/es/contract/ga/helpers.js.map +1 -1
- package/es/contract/ga/index.js +101 -242
- package/es/contract/ga/index.js.map +1 -1
- package/es/contract/index.js +1 -1
- package/es/contract/index.js.map +1 -1
- package/es/index.js +1 -2
- package/es/index.js.map +1 -1
- package/es/node-pool/index.js +54 -73
- package/es/node-pool/index.js.map +1 -1
- package/es/node.js +56 -157
- package/es/node.js.map +1 -1
- package/es/other.d.ts +1 -1
- package/es/tx/builder/helpers.js +38 -75
- package/es/tx/builder/helpers.js.map +1 -1
- package/es/tx/builder/index.js +196 -294
- package/es/tx/builder/index.js.map +1 -1
- package/es/tx/builder/schema.js +577 -459
- package/es/tx/builder/schema.js.map +1 -1
- package/es/tx/index.js +1 -1
- package/es/tx/index.js.map +1 -1
- package/es/tx/tx-object.js +105 -132
- package/es/tx/tx-object.js.map +1 -1
- package/es/tx/tx.js +808 -1628
- package/es/tx/tx.js.map +1 -1
- package/es/tx/validator.js +132 -268
- package/es/tx/validator.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +17 -21
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +38 -74
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js +14 -15
- 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 +179 -510
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +70 -89
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +353 -600
- 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 +47 -62
- 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 +85 -224
- package/es/utils/swagger.js.map +1 -1
- package/package.json +44 -40
- package/src/account/multiple.js +18 -19
- package/src/ae/aens.js +25 -21
- package/src/ae/contract.js +32 -163
- package/src/ae/index.js +3 -3
- package/src/ae/oracle.js +18 -14
- package/src/chain/node.js +2 -4
- package/src/channel/handlers.js +0 -1
- package/src/channel/index.js +4 -5
- package/src/contract/aci/index.js +221 -102
- package/src/contract/aci/transformation.js +30 -422
- package/src/contract/compiler.js +45 -4
- package/src/contract/ga/helpers.js +1 -8
- package/src/contract/ga/index.js +13 -11
- package/src/index.js +0 -2
- package/src/node-pool/index.js +21 -12
- package/src/node.js +22 -26
- package/src/tx/builder/index.js +2 -1
- package/src/tx/builder/schema.js +2 -1
- package/src/tx/tx.js +147 -143
- package/src/tx/validator.js +9 -7
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +1 -3
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +3 -3
- package/src/utils/aepp-wallet-communication/schema.js +1 -3
- package/src/utils/bignumber.ts +2 -1
- package/src/utils/other.ts +1 -1
- package/src/utils/semver-satisfies.ts +1 -1
- package/src/utils/swagger.js +14 -7
- 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 =
|
|
65
|
+
const opt = { ...this.Ae.defaults, ...options }
|
|
67
66
|
|
|
68
|
-
const nameRevokeTx = await this.nameRevokeTx(
|
|
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 =
|
|
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 =>
|
|
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(
|
|
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 =
|
|
149
|
+
const opt = { ...this.Ae.defaults, ...options }
|
|
149
150
|
|
|
150
|
-
const nameTransferTx = await this.nameTransferTx(
|
|
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,
|
|
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,
|
|
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,
|
|
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), { ...
|
|
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 =
|
|
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(
|
|
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 =
|
|
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(
|
|
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
|
|
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,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
|
|
204
|
-
* @param {Object} [options
|
|
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,
|
|
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
|
-
})
|
|
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.
|
|
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,16 +160,15 @@ async function contractCompile (source, options = {}) {
|
|
|
286
160
|
* @return {Promise<String>} Signature in hex representation
|
|
287
161
|
*/
|
|
288
162
|
async function delegateSignatureCommon (ids = [], opt = {}) {
|
|
289
|
-
|
|
290
|
-
Buffer.concat(
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
-
)
|
|
170
|
+
)
|
|
171
|
+
return Buffer.from(signature).toString('hex')
|
|
299
172
|
}
|
|
300
173
|
|
|
301
174
|
/**
|
|
@@ -384,10 +257,6 @@ export const ContractAPI = Ae.compose(ContractBase, {
|
|
|
384
257
|
contractCallStatic,
|
|
385
258
|
contractDeploy,
|
|
386
259
|
contractCall,
|
|
387
|
-
contractEncodeCall,
|
|
388
|
-
contractDecodeData,
|
|
389
|
-
_handleCallError,
|
|
390
|
-
_sendAndProcess,
|
|
391
260
|
// Delegation for contract
|
|
392
261
|
delegateSignatureCommon,
|
|
393
262
|
// AENS
|
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
|
|
|
@@ -42,9 +41,10 @@ import { AE_AMOUNT_FORMATS } from '../utils/amount-formatter'
|
|
|
42
41
|
* @return {Object} Transaction
|
|
43
42
|
*/
|
|
44
43
|
async function send (tx, options = {}) {
|
|
45
|
-
const opt =
|
|
44
|
+
const opt = { ...this.Ae.defaults, ...options }
|
|
46
45
|
const { contractId, authFun } = options.innerTx
|
|
47
|
-
? { contractId: false }
|
|
46
|
+
? { contractId: false }
|
|
47
|
+
: await this.getAccount(await this.address(opt))
|
|
48
48
|
const signed = contractId
|
|
49
49
|
? await this.signUsingGA(tx, { ...opt, authFun })
|
|
50
50
|
: await this.signTransaction(tx, opt)
|
package/src/ae/oracle.js
CHANGED
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
import Ae from './'
|
|
30
|
-
import * as R from 'ramda'
|
|
31
30
|
import { decodeBase64Check } from '../utils/crypto'
|
|
32
31
|
import { pause } from '../utils/other'
|
|
33
32
|
import { oracleQueryId, decode } from '../tx/builder/helpers'
|
|
@@ -123,7 +122,7 @@ export async function pollForQueryResponse (oracleId, queryId, { attempts = 20,
|
|
|
123
122
|
const { response } = await this.api.getOracleQueryByPubkeyAndQueryId(oracleId, queryId)
|
|
124
123
|
const responseBuffer = decode(response, 'or')
|
|
125
124
|
if (responseBuffer.length) {
|
|
126
|
-
return
|
|
125
|
+
return String(responseBuffer)
|
|
127
126
|
}
|
|
128
127
|
}
|
|
129
128
|
throw new Error(`Giving up after ${(attempts - 1) * interval}ms`)
|
|
@@ -146,14 +145,15 @@ export async function pollForQueryResponse (oracleId, queryId, { attempts = 20,
|
|
|
146
145
|
* @return {Promise<Object>} Oracle object
|
|
147
146
|
*/
|
|
148
147
|
async function registerOracle (queryFormat, responseFormat, options = {}) {
|
|
149
|
-
const opt =
|
|
148
|
+
const opt = { ...this.Ae.defaults, ...options } // Preset VmVersion for oracle
|
|
150
149
|
const accountId = await this.address(opt)
|
|
151
150
|
|
|
152
|
-
const oracleRegisterTx = await this.oracleRegisterTx(
|
|
151
|
+
const oracleRegisterTx = await this.oracleRegisterTx({
|
|
152
|
+
...opt,
|
|
153
153
|
accountId,
|
|
154
154
|
queryFormat,
|
|
155
155
|
responseFormat
|
|
156
|
-
})
|
|
156
|
+
})
|
|
157
157
|
return {
|
|
158
158
|
...await this.send(oracleRegisterTx, opt),
|
|
159
159
|
...await this.getOracleObject(`ok_${accountId.slice(3)}`)
|
|
@@ -177,14 +177,16 @@ async function registerOracle (queryFormat, responseFormat, options = {}) {
|
|
|
177
177
|
* @return {Promise<Object>} Query object
|
|
178
178
|
*/
|
|
179
179
|
async function postQueryToOracle (oracleId, query, options = {}) {
|
|
180
|
-
const
|
|
180
|
+
const queryFee = options.queryFee || (await this.api.getOracleByPubkey(oracleId)).queryFee
|
|
181
|
+
const opt = { ...this.Ae.defaults, queryFee, ...options }
|
|
181
182
|
const senderId = await this.address(opt)
|
|
182
183
|
|
|
183
|
-
const oracleRegisterTx = await this.oraclePostQueryTx(
|
|
184
|
+
const oracleRegisterTx = await this.oraclePostQueryTx({
|
|
185
|
+
...opt,
|
|
184
186
|
oracleId,
|
|
185
187
|
senderId,
|
|
186
188
|
query
|
|
187
|
-
})
|
|
189
|
+
})
|
|
188
190
|
const queryId = oracleQueryId(senderId, unpackTx(oracleRegisterTx).tx.nonce, oracleId)
|
|
189
191
|
return {
|
|
190
192
|
...await this.send(oracleRegisterTx, opt),
|
|
@@ -206,14 +208,15 @@ async function postQueryToOracle (oracleId, query, options = {}) {
|
|
|
206
208
|
* @return {Promise<Object>} Oracle object
|
|
207
209
|
*/
|
|
208
210
|
async function extendOracleTtl (oracleId, oracleTtl, options = {}) {
|
|
209
|
-
const opt =
|
|
211
|
+
const opt = { ...this.Ae.defaults, ...options }
|
|
210
212
|
const callerId = await this.address(opt)
|
|
211
213
|
|
|
212
|
-
const oracleExtendTx = await this.oracleExtendTx(
|
|
214
|
+
const oracleExtendTx = await this.oracleExtendTx({
|
|
215
|
+
...opt,
|
|
213
216
|
oracleId,
|
|
214
217
|
callerId,
|
|
215
218
|
oracleTtl
|
|
216
|
-
})
|
|
219
|
+
})
|
|
217
220
|
return {
|
|
218
221
|
...await this.send(oracleExtendTx, opt),
|
|
219
222
|
...await this.getOracleObject(oracleId)
|
|
@@ -236,15 +239,16 @@ async function extendOracleTtl (oracleId, oracleTtl, options = {}) {
|
|
|
236
239
|
* @return {Promise<Object>} Oracle object
|
|
237
240
|
*/
|
|
238
241
|
async function respondToQuery (oracleId, queryId, response, options = {}) {
|
|
239
|
-
const opt =
|
|
242
|
+
const opt = { ...this.Ae.defaults, ...options }
|
|
240
243
|
const callerId = await this.address(opt)
|
|
241
244
|
|
|
242
|
-
const oracleRespondTx = await this.oracleRespondTx(
|
|
245
|
+
const oracleRespondTx = await this.oracleRespondTx({
|
|
246
|
+
...opt,
|
|
243
247
|
oracleId,
|
|
244
248
|
queryId,
|
|
245
249
|
callerId,
|
|
246
250
|
response
|
|
247
|
-
})
|
|
251
|
+
})
|
|
248
252
|
return {
|
|
249
253
|
...await this.send(oracleRespondTx, opt),
|
|
250
254
|
...await this.getOracleObject(oracleId)
|
package/src/chain/node.js
CHANGED
|
@@ -14,8 +14,6 @@
|
|
|
14
14
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
15
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
*/
|
|
17
|
-
import * as R from 'ramda'
|
|
18
|
-
|
|
19
17
|
import Chain from './'
|
|
20
18
|
import { AE_AMOUNT_FORMATS, formatAmount } from '../utils/amount-formatter'
|
|
21
19
|
import verifyTransaction from '../tx/validator'
|
|
@@ -34,7 +32,7 @@ import { DRY_RUN_ACCOUNT, NAME_ID_KEY } from '../tx/builder/schema'
|
|
|
34
32
|
*/
|
|
35
33
|
|
|
36
34
|
async function sendTransaction (tx, options = {}) {
|
|
37
|
-
const { waitMined, verify } =
|
|
35
|
+
const { waitMined, verify } = { ...this.Ae.defaults, ...options }
|
|
38
36
|
if (verify) {
|
|
39
37
|
const validation = await verifyTransaction(tx, this.selectedNode.instance)
|
|
40
38
|
if (validation.length) {
|
|
@@ -140,7 +138,7 @@ async function topBlock () {
|
|
|
140
138
|
return this.api.getTopHeader()
|
|
141
139
|
}
|
|
142
140
|
|
|
143
|
-
async function poll (th, { blocks = 10, interval =
|
|
141
|
+
async function poll (th, { blocks = 10, interval = 500, allowUnsynced = false } = {}) {
|
|
144
142
|
const max = await this.height() + blocks
|
|
145
143
|
do {
|
|
146
144
|
const tx = await this.tx(th).catch(_ => null)
|
package/src/channel/handlers.js
CHANGED
|
@@ -603,7 +603,6 @@ export async function awaitingCallContractForceProgressUpdate (channel, message,
|
|
|
603
603
|
}
|
|
604
604
|
|
|
605
605
|
export function awaitingForceProgressCompletion (channel, message, state) {
|
|
606
|
-
console.log('From force progress await completion ->', message)
|
|
607
606
|
if (message.method === 'channels.on_chain_tx') {
|
|
608
607
|
if (state.onOnChainTx) {
|
|
609
608
|
state.onOnChainTx(message.params.data)
|
package/src/channel/index.js
CHANGED
|
@@ -39,7 +39,6 @@ import {
|
|
|
39
39
|
disconnect as channelDisconnect,
|
|
40
40
|
fsmId as channelFsmId
|
|
41
41
|
} from './internal'
|
|
42
|
-
import * as R from 'ramda'
|
|
43
42
|
|
|
44
43
|
function snakeToPascalObjKeys (obj) {
|
|
45
44
|
return Object.entries(obj).reduce((result, [key, val]) => ({
|
|
@@ -238,10 +237,10 @@ async function poi ({ accounts, contracts }) {
|
|
|
238
237
|
* )
|
|
239
238
|
*/
|
|
240
239
|
async function balances (accounts) {
|
|
241
|
-
return
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
240
|
+
return Object.fromEntries(
|
|
241
|
+
(await call(this, 'channels.get.balances', { accounts }))
|
|
242
|
+
.map(item => [item.account, item.balance])
|
|
243
|
+
)
|
|
245
244
|
}
|
|
246
245
|
|
|
247
246
|
/**
|