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