@aeternity/aepp-sdk 10.0.0-beta.1 → 11.0.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/README.md +15 -14
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +7 -27
- 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 → base.mjs} +23 -11
- package/es/account/base.mjs.map +1 -0
- package/es/account/{memory.js → memory.mjs} +29 -14
- package/es/account/memory.mjs.map +1 -0
- package/es/account/{multiple.js → multiple.mjs} +14 -11
- package/es/account/multiple.mjs.map +1 -0
- package/es/ae/{aens.js → aens.mjs} +69 -59
- 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.js → index.mjs} +12 -10
- package/es/ae/index.mjs.map +1 -0
- package/es/ae/{oracle.js → oracle.mjs} +37 -20
- 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} +28 -8
- package/es/chain/index.mjs.map +1 -0
- package/es/chain/{node.js → node.mjs} +133 -90
- package/es/chain/node.mjs.map +1 -0
- package/es/channel/{handlers.js → handlers.mjs} +18 -20
- package/es/channel/handlers.mjs.map +1 -0
- package/es/channel/{index.js → index.mjs} +43 -22
- package/es/channel/index.mjs.map +1 -0
- package/es/channel/{internal.js → internal.mjs} +51 -35
- 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.js → index.mjs} +40 -28
- package/es/contract/ga/index.mjs.map +1 -0
- package/es/encoder.d.ts +26 -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.js → index.mjs} +15 -12
- package/es/node-pool/index.mjs.map +1 -0
- package/es/{node.js → node.mjs} +17 -11
- package/es/node.mjs.map +1 -0
- package/es/tx/builder/constants.mjs +108 -0
- package/es/tx/builder/constants.mjs.map +1 -0
- 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 +321 -0
- package/es/tx/builder/helpers.mjs.map +1 -0
- package/es/tx/builder/{index.js → index.mjs} +92 -74
- package/es/tx/builder/index.mjs.map +1 -0
- package/es/tx/builder/{schema.js → schema.mjs} +16 -172
- package/es/tx/builder/schema.mjs.map +1 -0
- package/es/tx/{index.js → index.mjs} +106 -14
- package/es/tx/index.mjs.map +1 -0
- package/es/tx/{tx-object.js → tx-object.mjs} +31 -18
- package/es/tx/tx-object.mjs.map +1 -0
- package/es/tx/{tx.js → tx.mjs} +15 -14
- package/es/tx/tx.mjs.map +1 -0
- package/es/tx/{validator.js → validator.mjs} +72 -33
- 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} +10 -8
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/connection/{browser-window-message.js → browser-window-message.mjs} +25 -17
- 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} +15 -8
- package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/{helpers.js → helpers.mjs} +3 -14
- package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/{aepp-rpc.js → aepp-rpc.mjs} +126 -72
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/{rpc-client.js → rpc-client.mjs} +23 -14
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/{wallet-rpc.js → wallet-rpc.mjs} +116 -91
- 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.js → wallet-detector.mjs} +6 -5
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
- package/es/utils/{amount-formatter.js → amount-formatter.mjs} +14 -7
- package/es/utils/amount-formatter.mjs.map +1 -0
- package/es/utils/{async-init.js → async-init.mjs} +8 -11
- package/es/utils/async-init.mjs.map +1 -0
- package/es/utils/{bignumber.js → bignumber.mjs} +2 -9
- package/es/utils/bignumber.mjs.map +1 -0
- package/es/utils/{bytes.js → bytes.mjs} +16 -8
- 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.js → crypto.mjs} +42 -156
- package/es/utils/crypto.mjs.map +1 -0
- package/es/utils/encoder.mjs +106 -0
- package/es/utils/encoder.mjs.map +1 -0
- package/es/utils/errors.mjs +689 -0
- package/es/utils/errors.mjs.map +1 -0
- package/es/utils/{hd-wallet.js → hd-wallet.mjs} +33 -34
- package/es/utils/hd-wallet.mjs.map +1 -0
- package/es/utils/{json-big.js → json-big.mjs} +1 -1
- package/es/utils/{json-big.js.map → json-big.mjs.map} +1 -1
- package/es/utils/{keystore.js → keystore.mjs} +63 -51
- package/es/utils/keystore.mjs.map +1 -0
- package/es/utils/{mptree.js → mptree.mjs} +21 -12
- package/es/utils/mptree.mjs.map +1 -0
- package/es/utils/{other.js → other.mjs} +2 -2
- package/es/utils/other.mjs.map +1 -0
- package/es/utils/{semver-satisfies.js → semver-satisfies.mjs} +1 -1
- package/es/utils/{semver-satisfies.js.map → semver-satisfies.mjs.map} +1 -1
- package/es/utils/{string.js → string.mjs} +1 -1
- package/es/utils/{string.js.map → string.mjs.map} +1 -1
- package/es/utils/{swagger.js → swagger.mjs} +49 -15
- package/es/utils/swagger.mjs.map +1 -0
- package/package.json +49 -58
- package/src/account/base.js +3 -1
- package/src/account/memory.js +13 -8
- package/src/account/multiple.js +16 -6
- package/src/ae/aens.js +52 -58
- package/src/ae/aepp.js +2 -2
- package/src/ae/contract.js +21 -154
- package/src/ae/index.js +6 -4
- package/src/ae/oracle.js +33 -14
- 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 -65
- package/src/channel/handlers.js +30 -20
- package/src/channel/index.js +46 -16
- package/src/channel/internal.js +35 -30
- package/src/contract/aci.js +376 -0
- package/src/contract/compiler.js +22 -113
- package/src/contract/ga/helpers.js +10 -6
- package/src/contract/ga/index.js +31 -24
- package/src/index.js +9 -8
- package/src/node-pool/index.js +13 -10
- package/src/node.js +11 -10
- package/src/tx/builder/constants.js +100 -0
- package/src/tx/builder/field-types.js +61 -0
- package/src/tx/builder/helpers.js +99 -103
- package/src/tx/builder/index.js +81 -40
- package/src/tx/builder/schema.js +44 -132
- package/src/tx/index.js +101 -12
- package/src/tx/tx-object.js +35 -15
- package/src/tx/tx.js +110 -35
- package/src/tx/validator.js +25 -5
- 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 +106 -57
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +24 -11
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +95 -53
- 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 +1 -9
- package/src/utils/bytes.ts +3 -2
- package/src/utils/crypto-ts.ts +2 -2
- package/src/utils/crypto.js +11 -155
- package/src/utils/encoder.ts +101 -0
- 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/swagger.js +68 -45
- package/es/account/base.js.map +0 -1
- package/es/account/memory.js.map +0 -1
- package/es/account/multiple.js.map +0 -1
- package/es/ae/aens.js.map +0 -1
- package/es/ae/aepp.js.map +0 -1
- package/es/ae/contract.js +0 -308
- package/es/ae/contract.js.map +0 -1
- package/es/ae/index.js.map +0 -1
- 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.map +0 -1
- package/es/channel/handlers.js.map +0 -1
- package/es/channel/index.js.map +0 -1
- 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 -356
- package/es/contract/aci/index.js.map +0 -1
- package/es/contract/aci/transformation.js +0 -66
- package/es/contract/aci/transformation.js.map +0 -1
- package/es/contract/compiler.js +0 -242
- package/es/contract/compiler.js.map +0 -1
- package/es/contract/ga/helpers.js +0 -22
- package/es/contract/ga/helpers.js.map +0 -1
- 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 -56
- package/es/index.js.map +0 -1
- package/es/node-pool/index.js.map +0 -1
- package/es/node.js.map +0 -1
- package/es/tx/builder/helpers.js +0 -318
- package/es/tx/builder/helpers.js.map +0 -1
- package/es/tx/builder/index.js.map +0 -1
- package/es/tx/builder/schema.js.map +0 -1
- package/es/tx/index.js.map +0 -1
- package/es/tx/tx-object.js.map +0 -1
- package/es/tx/tx.js.map +0 -1
- 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.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.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/schema.js +0 -107
- package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
- package/es/utils/amount-formatter.js.map +0 -1
- package/es/utils/async-init.js.map +0 -1
- 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.map +0 -1
- package/es/utils/hd-wallet.js.map +0 -1
- package/es/utils/keystore.js.map +0 -1
- package/es/utils/mptree.js.map +0 -1
- package/es/utils/other.js.map +0 -1
- package/es/utils/swagger.js.map +0 -1
- package/src/contract/aci/index.js +0 -310
- package/src/contract/aci/transformation.js +0 -72
- package/src/contract/index.js +0 -159
- package/src/utils/aepp-wallet-communication/schema.js +0 -108
package/src/ae/aens.js
CHANGED
|
@@ -27,16 +27,10 @@
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
import { salt } from '../utils/crypto'
|
|
30
|
-
import {
|
|
31
|
-
commitmentHash,
|
|
32
|
-
ensureNameValid,
|
|
33
|
-
getMinimumNameFee,
|
|
34
|
-
classify,
|
|
35
|
-
isAuctionName,
|
|
36
|
-
validatePointers, encode, produceNameId
|
|
37
|
-
} from '../tx/builder/helpers'
|
|
30
|
+
import { commitmentHash, ensureNameValid, isAuctionName } from '../tx/builder/helpers'
|
|
38
31
|
import Ae from './'
|
|
39
|
-
import { CLIENT_TTL,
|
|
32
|
+
import { CLIENT_TTL, NAME_TTL } from '../tx/builder/schema'
|
|
33
|
+
import { ArgumentError } from '../utils/errors'
|
|
40
34
|
|
|
41
35
|
/**
|
|
42
36
|
* Revoke a name
|
|
@@ -46,11 +40,11 @@ import { CLIENT_TTL, NAME_FEE, NAME_TTL } from '../tx/builder/schema'
|
|
|
46
40
|
* @category async
|
|
47
41
|
* @param {String} name Name hash
|
|
48
42
|
* @param {Object} [options={}] options
|
|
49
|
-
* @param {
|
|
50
|
-
* using provided KeyPair(Can be keypair object or MemoryAccount)
|
|
51
|
-
* @param {
|
|
52
|
-
* @param {
|
|
53
|
-
* @param {
|
|
43
|
+
* @param {String|Object} [options.onAccount] Make operation on specific account from sdk (you pass
|
|
44
|
+
* publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)
|
|
45
|
+
* @param {Number|String|BigNumber} [options.fee] fee
|
|
46
|
+
* @param {Number|String|BigNumber} [options.ttl] ttl
|
|
47
|
+
* @param {Number|String|BigNumber} [options.nonce] nonce
|
|
54
48
|
* @return {Promise<Object>} Transaction result
|
|
55
49
|
* @example
|
|
56
50
|
* const name = 'test.chain'
|
|
@@ -66,7 +60,7 @@ async function revoke (name, options = {}) {
|
|
|
66
60
|
|
|
67
61
|
const nameRevokeTx = await this.nameRevokeTx({
|
|
68
62
|
...opt,
|
|
69
|
-
nameId:
|
|
63
|
+
nameId: name,
|
|
70
64
|
accountId: await this.address(opt)
|
|
71
65
|
})
|
|
72
66
|
|
|
@@ -80,16 +74,19 @@ async function revoke (name, options = {}) {
|
|
|
80
74
|
* @category async
|
|
81
75
|
* @alias module:@aeternity/aepp-sdk/es/ae/aens
|
|
82
76
|
* @param {String} name AENS name
|
|
83
|
-
* @param {
|
|
77
|
+
* @param {Object.<string, string>} pointers Map of pointer keys to corresponding addresses
|
|
84
78
|
* @param {Object} [options={}]
|
|
85
|
-
* @param {Boolean} [options.extendPointers
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* @param {
|
|
90
|
-
* @param {
|
|
91
|
-
* @param {
|
|
92
|
-
* @param {
|
|
79
|
+
* @param {Boolean} [options.extendPointers] Get the pointers from the node and merge with provided
|
|
80
|
+
* ones. Pointers with the same type will be overwritten
|
|
81
|
+
* @param {String|Object} [options.onAccount] Make operation on specific account from sdk (you
|
|
82
|
+
* pass publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)
|
|
83
|
+
* @param {Number|String|BigNumber} [options.fee] fee
|
|
84
|
+
* @param {Number|String|BigNumber} [options.ttl] ttl
|
|
85
|
+
* @param {Number|String|BigNumber} [options.nonce] nonce
|
|
86
|
+
* @param {Number|String|BigNumber} [options.nameTtl=50000] Name ttl represented in number of
|
|
87
|
+
* blocks (Max value is 50000 blocks)
|
|
88
|
+
* @param {Number|String|BigNumber} [options.clientTtl=84600] a suggestion as to how long any
|
|
89
|
+
* clients should cache this information
|
|
93
90
|
* @return {Promise<Object>}
|
|
94
91
|
* @throws Invalid pointer array error
|
|
95
92
|
* @example
|
|
@@ -99,22 +96,23 @@ async function revoke (name, options = {}) {
|
|
|
99
96
|
*
|
|
100
97
|
* await sdkInstance.aensUpdate(name, pointersArray, { nameTtl, ttl, fee, nonce, clientTtl })
|
|
101
98
|
* // or
|
|
102
|
-
* await nameObject.update(
|
|
99
|
+
* await nameObject.update(pointers, { nameTtl, ttl, fee, nonce, clientTtl })
|
|
103
100
|
*/
|
|
104
|
-
async function update (name, pointers =
|
|
101
|
+
async function update (name, pointers = {}, options = {}) {
|
|
105
102
|
ensureNameValid(name)
|
|
106
103
|
const opt = { ...this.Ae.defaults, ...options }
|
|
107
|
-
|
|
104
|
+
const allPointers = {
|
|
105
|
+
...options.extendPointers && Object.fromEntries(
|
|
106
|
+
(await this.getName(name)).pointers.map(({ key, id }) => [key, id])
|
|
107
|
+
),
|
|
108
|
+
...pointers
|
|
109
|
+
}
|
|
108
110
|
|
|
109
|
-
pointers = [
|
|
110
|
-
...options.extendPointers ? (await this.getName(name)).pointers : [],
|
|
111
|
-
...pointers.map(p => Object.fromEntries([['id', p], ['key', classify(p)]]))
|
|
112
|
-
].reduce((acc, el) => [...acc.filter(p => p.key !== el.key), el], [])
|
|
113
111
|
const nameUpdateTx = await this.nameUpdateTx({
|
|
114
112
|
...opt,
|
|
115
|
-
nameId:
|
|
113
|
+
nameId: name,
|
|
116
114
|
accountId: await this.address(opt),
|
|
117
|
-
pointers
|
|
115
|
+
pointers: Object.entries(allPointers).map(([key, id]) => ({ key, id }))
|
|
118
116
|
})
|
|
119
117
|
|
|
120
118
|
return this.send(nameUpdateTx, opt)
|
|
@@ -129,11 +127,11 @@ async function update (name, pointers = [], options = { extendPointers: false })
|
|
|
129
127
|
* @param {String} name AENS name
|
|
130
128
|
* @param {String} account Recipient account publick key
|
|
131
129
|
* @param {Object} [options={}]
|
|
132
|
-
* @param {
|
|
133
|
-
* using provided KeyPair(Can be keypair object or MemoryAccount)
|
|
134
|
-
* @param {
|
|
135
|
-
* @param {
|
|
136
|
-
* @param {
|
|
130
|
+
* @param {String|Object} [options.onAccount] Make operation on specific account from sdk (you pass
|
|
131
|
+
* publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)
|
|
132
|
+
* @param {Number|String|BigNumber} [options.fee] fee
|
|
133
|
+
* @param {Number|String|BigNumber} [options.ttl] ttl
|
|
134
|
+
* @param {Number|String|BigNumber} [options.nonce] nonce
|
|
137
135
|
* @return {Promise<Object>} Transaction result
|
|
138
136
|
* @example
|
|
139
137
|
* const name = 'test.chain'
|
|
@@ -150,7 +148,7 @@ async function transfer (name, account, options = {}) {
|
|
|
150
148
|
|
|
151
149
|
const nameTransferTx = await this.nameTransferTx({
|
|
152
150
|
...opt,
|
|
153
|
-
nameId:
|
|
151
|
+
nameId: name,
|
|
154
152
|
accountId: await this.address(opt),
|
|
155
153
|
recipientId: account
|
|
156
154
|
})
|
|
@@ -186,7 +184,7 @@ async function query (name, opt = {}) {
|
|
|
186
184
|
|
|
187
185
|
return Object.freeze(Object.assign(o, {
|
|
188
186
|
pointers: o.pointers || [],
|
|
189
|
-
update: async (pointers
|
|
187
|
+
update: async (pointers, options = {}) => {
|
|
190
188
|
return {
|
|
191
189
|
...(await this.aensUpdate(name, pointers, { ...opt, ...options })),
|
|
192
190
|
...(await this.aensQuery(name))
|
|
@@ -200,11 +198,13 @@ async function query (name, opt = {}) {
|
|
|
200
198
|
},
|
|
201
199
|
revoke: async (options = {}) => this.aensRevoke(name, { ...opt, ...options }),
|
|
202
200
|
extendTtl: async (nameTtl = NAME_TTL, options = {}) => {
|
|
203
|
-
if (
|
|
201
|
+
if (typeof nameTtl !== 'number' || nameTtl > NAME_TTL || nameTtl <= 0) {
|
|
202
|
+
throw new ArgumentError('nameTtl', `a number between 1 and ${NAME_TTL} blocks`, nameTtl)
|
|
203
|
+
}
|
|
204
204
|
|
|
205
205
|
return {
|
|
206
|
-
...
|
|
207
|
-
...
|
|
206
|
+
...await this.aensUpdate(name, {}, { ...opt, ...options, nameTtl, extendPointers: true }),
|
|
207
|
+
...await this.aensQuery(name)
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
210
|
}))
|
|
@@ -220,8 +220,8 @@ async function query (name, opt = {}) {
|
|
|
220
220
|
* @param {String} name
|
|
221
221
|
* @param {Number} salt Salt from pre-claim, or 0 if it's a bid
|
|
222
222
|
* @param {Object} [options] options
|
|
223
|
-
* @param {String|Object} [options.onAccount]
|
|
224
|
-
* using provided KeyPair(Can be keypair object or MemoryAccount)
|
|
223
|
+
* @param {String|Object} [options.onAccount] Make operation on specific account from sdk (you pass
|
|
224
|
+
* publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)
|
|
225
225
|
* @param {Number|String|BigNumber} [options.fee] fee
|
|
226
226
|
* @param {Number|String|BigNumber} [options.ttl] ttl
|
|
227
227
|
* @param {Number|String|BigNumber} [options.nonce] nonce
|
|
@@ -237,16 +237,11 @@ async function claim (name, salt, options) {
|
|
|
237
237
|
ensureNameValid(name)
|
|
238
238
|
const opt = { ...this.Ae.defaults, ...options }
|
|
239
239
|
|
|
240
|
-
const minNameFee = getMinimumNameFee(name)
|
|
241
|
-
if (opt.nameFee !== this.Ae.defaults.nameFee && minNameFee.gt(opt.nameFee)) {
|
|
242
|
-
throw new Error(`the provided fee ${opt.nameFee} is not enough to execute the claim, required: ${minNameFee}`)
|
|
243
|
-
}
|
|
244
|
-
opt.nameFee = opt.nameFee !== this.Ae.defaults.nameFee ? opt.nameFee : minNameFee
|
|
245
240
|
const claimTx = await this.nameClaimTx({
|
|
246
241
|
...opt,
|
|
247
242
|
accountId: await this.address(opt),
|
|
248
243
|
nameSalt: salt,
|
|
249
|
-
name
|
|
244
|
+
name
|
|
250
245
|
})
|
|
251
246
|
|
|
252
247
|
const result = await this.send(claimTx, opt)
|
|
@@ -265,8 +260,8 @@ async function claim (name, salt, options) {
|
|
|
265
260
|
* @alias module:@aeternity/aepp-sdk/es/ae/aens
|
|
266
261
|
* @param {String} name
|
|
267
262
|
* @param {Object} [options={}]
|
|
268
|
-
* @param {String|Object} [options.onAccount]
|
|
269
|
-
* using provided KeyPair(Can be keypair object or MemoryAccount)
|
|
263
|
+
* @param {String|Object} [options.onAccount] Make operation on specific account from sdk (you pass
|
|
264
|
+
* publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)
|
|
270
265
|
* @param {Number|String|BigNumber} [options.fee] fee
|
|
271
266
|
* @param {Number|String|BigNumber} [options.ttl] ttl
|
|
272
267
|
* @param {Number|String|BigNumber} [options.nonce] nonce
|
|
@@ -316,8 +311,8 @@ async function preclaim (name, options = {}) {
|
|
|
316
311
|
* @param {String} name Domain name
|
|
317
312
|
* @param {String|Number} nameFee Name fee (bid fee)
|
|
318
313
|
* @param {Object} [options={}]
|
|
319
|
-
* @param {String|Object} [options.onAccount]
|
|
320
|
-
* using provided KeyPair(Can be keypair object or MemoryAccount)
|
|
314
|
+
* @param {String|Object} [options.onAccount] Make operation on specific account from sdk (you pass
|
|
315
|
+
* publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)
|
|
321
316
|
* @param {Number|String|BigNumber} [options.fee] fee
|
|
322
317
|
* @param {Number|String|BigNumber} [options.ttl] ttl
|
|
323
318
|
* @param {Number|String|BigNumber} [options.nonce] nonce
|
|
@@ -328,7 +323,7 @@ async function preclaim (name, options = {}) {
|
|
|
328
323
|
*
|
|
329
324
|
* await sdkInstance.aensBid(name, 213109412839123, { ttl, fee, nonce })
|
|
330
325
|
*/
|
|
331
|
-
async function bid (name, nameFee
|
|
326
|
+
async function bid (name, nameFee, options = {}) {
|
|
332
327
|
return this.aensClaim(name, 0, { ...options, nameFee, vsn: 2 })
|
|
333
328
|
}
|
|
334
329
|
|
|
@@ -357,8 +352,7 @@ const Aens = Ae.compose({
|
|
|
357
352
|
Ae: {
|
|
358
353
|
defaults: {
|
|
359
354
|
clientTtl: CLIENT_TTL,
|
|
360
|
-
nameTtl: NAME_TTL
|
|
361
|
-
nameFee: NAME_FEE
|
|
355
|
+
nameTtl: NAME_TTL // aec_governance:name_claim_max_expiration() => 50000
|
|
362
356
|
}
|
|
363
357
|
}
|
|
364
358
|
}
|
package/src/ae/aepp.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
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
import Ae from './'
|
|
26
26
|
import Aens from './aens'
|
|
27
|
-
import
|
|
27
|
+
import Contract from './contract'
|
|
28
28
|
import AeppRpc from '../utils/aepp-wallet-communication/rpc/aepp-rpc'
|
|
29
29
|
import Chain from '../chain/node'
|
|
30
30
|
import Tx from '../tx/tx'
|
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,128 +27,11 @@
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
import Ae from './'
|
|
30
|
-
import
|
|
31
|
-
import ContractBase from '../contract'
|
|
30
|
+
import ContractCompilerHttp from '../contract/compiler'
|
|
32
31
|
import getContractInstance from '../contract/aci'
|
|
33
|
-
import
|
|
34
|
-
import { AMOUNT, DEPOSIT, GAS, MIN_GAS_PRICE } from '../tx/builder/schema'
|
|
32
|
+
import { AMOUNT, MIN_GAS_PRICE } from '../tx/builder/schema'
|
|
35
33
|
import { decode, produceNameId } from '../tx/builder/helpers'
|
|
36
34
|
|
|
37
|
-
/**
|
|
38
|
-
* Static contract call(using dry-run)
|
|
39
|
-
* @function
|
|
40
|
-
* @alias module:@aeternity/aepp-sdk/es/ae/contract
|
|
41
|
-
* @category async
|
|
42
|
-
* @deprecated
|
|
43
|
-
* @param {String} source Contract source code
|
|
44
|
-
* @param {String} contractAddress Contract address
|
|
45
|
-
* @param {String} name Name of function to call
|
|
46
|
-
* @param {Array} args Arguments array for call/deploy transaction
|
|
47
|
-
* @param {Object} [options]
|
|
48
|
-
* @param {Number|String} [options.top] Block height or hash on which you want to call contract
|
|
49
|
-
* @param {String} [options.bytecode] Block hash on which you want to call contract
|
|
50
|
-
* @param {Object} [options.filesystem] Contract external namespaces map
|
|
51
|
-
* @return {Promise<Object>} Result object
|
|
52
|
-
* @example
|
|
53
|
-
* const callResult = await client.contractCallStatic(source, address, fnName, args)
|
|
54
|
-
* {
|
|
55
|
-
* result: TX_DATA,
|
|
56
|
-
* decode: (type) => Decode call result
|
|
57
|
-
* }
|
|
58
|
-
*/
|
|
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 })
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Call contract function
|
|
66
|
-
* @function
|
|
67
|
-
* @alias module:@aeternity/aepp-sdk/es/ae/contract
|
|
68
|
-
* @category async
|
|
69
|
-
* @deprecated
|
|
70
|
-
* @param {String} source Contract source code
|
|
71
|
-
* @param {String} contractAddress Contract address or AENS name
|
|
72
|
-
* @param {String} name Name of function to call
|
|
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
|
|
77
|
-
* @example
|
|
78
|
-
* const callResult = await client.contractCall(source, address, fnName, args = [], options)
|
|
79
|
-
* {
|
|
80
|
-
* hash: TX_HASH,
|
|
81
|
-
* result: TX_DATA,
|
|
82
|
-
* decode: (type) => Decode call result
|
|
83
|
-
* }
|
|
84
|
-
*/
|
|
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)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Deploy contract to the node
|
|
92
|
-
* @function
|
|
93
|
-
* @alias module:@aeternity/aepp-sdk/es/ae/contract
|
|
94
|
-
* @category async
|
|
95
|
-
* @deprecated
|
|
96
|
-
* @param {String} code Compiled contract
|
|
97
|
-
* @param {String} source Contract source code
|
|
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)
|
|
100
|
-
* @param {Object} [options.filesystem={}] Contract external namespaces map* @return {Promise<Object>} Result object
|
|
101
|
-
* @return {Promise<Object>} Result object
|
|
102
|
-
* @example
|
|
103
|
-
* const deployed = await client.contractDeploy(bytecode, source, init = [], options)
|
|
104
|
-
* {
|
|
105
|
-
* owner: OWNER_PUB_KEY,
|
|
106
|
-
* transaction: TX_HASH,
|
|
107
|
-
* address: CONTRACT_ADDRESS,
|
|
108
|
-
* createdAt: Date,
|
|
109
|
-
* result: DEPLOY_TX_DATA,
|
|
110
|
-
* call: (fnName, args = [], options) => Call contract function,
|
|
111
|
-
* callStatic: (fnName, args = [], options) => Static all contract function
|
|
112
|
-
* }
|
|
113
|
-
*/
|
|
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)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Compile contract source code
|
|
122
|
-
* @function
|
|
123
|
-
* @alias module:@aeternity/aepp-sdk/es/ae/contract
|
|
124
|
-
* @category async
|
|
125
|
-
* @param {String} source Contract sourece code
|
|
126
|
-
* @param {Object} [options={}] Transaction options (fee, ttl, gas, amount, deposit)
|
|
127
|
-
* @param {Object} [options.filesystem={}] Contract external namespaces map* @return {Promise<Object>} Result object
|
|
128
|
-
* @return {Promise<Object>} Result object
|
|
129
|
-
* @example
|
|
130
|
-
* const compiled = await client.contractCompile(SOURCE_CODE)
|
|
131
|
-
* {
|
|
132
|
-
* bytecode: CONTRACT_BYTE_CODE,
|
|
133
|
-
* deploy: (init = [], options = {}) => Deploy Contract,
|
|
134
|
-
* encodeCall: (fnName, args = []) => Prepare callData
|
|
135
|
-
* }
|
|
136
|
-
*/
|
|
137
|
-
async function contractCompile (source, options = {}) {
|
|
138
|
-
const opt = { ...this.Ae.defaults, ...options }
|
|
139
|
-
const bytecode = await this.compileContractAPI(source, options)
|
|
140
|
-
return Object.freeze({
|
|
141
|
-
encodeCall: (name, args) => this.contractEncodeCallDataAPI(source, name, args, opt),
|
|
142
|
-
deploy: (init, options) => this.contractDeploy(bytecode, source, init, { ...opt, ...options }),
|
|
143
|
-
deployStatic: (init, options) => this.contractCallStatic(source, null, 'init', init, {
|
|
144
|
-
...opt,
|
|
145
|
-
...options,
|
|
146
|
-
bytecode
|
|
147
|
-
}),
|
|
148
|
-
bytecode
|
|
149
|
-
})
|
|
150
|
-
}
|
|
151
|
-
|
|
152
35
|
/**
|
|
153
36
|
* Utility method to create a delegate signature for a contract
|
|
154
37
|
* @function
|
|
@@ -163,7 +46,6 @@ async function delegateSignatureCommon (ids = [], opt = {}) {
|
|
|
163
46
|
const signature = await this.sign(
|
|
164
47
|
Buffer.concat([
|
|
165
48
|
Buffer.from(this.getNetworkId(opt)),
|
|
166
|
-
...(Object.prototype.hasOwnProperty.call(opt, 'onAccount') ? [decode(await this.address(opt))] : []),
|
|
167
49
|
...ids.map(e => decode(e))
|
|
168
50
|
]),
|
|
169
51
|
opt
|
|
@@ -172,7 +54,8 @@ async function delegateSignatureCommon (ids = [], opt = {}) {
|
|
|
172
54
|
}
|
|
173
55
|
|
|
174
56
|
/**
|
|
175
|
-
* 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.
|
|
176
59
|
* @function
|
|
177
60
|
* @alias module:@aeternity/aepp-sdk/es/ae/contract
|
|
178
61
|
* @category async
|
|
@@ -181,19 +64,24 @@ async function delegateSignatureCommon (ids = [], opt = {}) {
|
|
|
181
64
|
* @param {{ onAccount: String | Object }} [opt={}] opt Options
|
|
182
65
|
* @return {Promise<String>} Signature for delegation
|
|
183
66
|
* @example
|
|
184
|
-
* const
|
|
67
|
+
* const aeSdk = await Universal({ ... })
|
|
185
68
|
* const contractId = 'ct_asd2ks...' // contract address
|
|
186
69
|
* const name = 'example.chain' // AENS name
|
|
187
|
-
* const onAccount = await
|
|
70
|
+
* const onAccount = await aeSdk.address() // Sign with a specific account
|
|
188
71
|
* // Preclaim signature
|
|
189
72
|
* const params = { contractId }
|
|
190
|
-
* const preclaimSig = await
|
|
73
|
+
* const preclaimSig = await aeSdk.createAensDelegationSignature(params, { onAccount: current })
|
|
191
74
|
* // Claim, transfer and revoke signature
|
|
192
75
|
* const params = { contractId, name }
|
|
193
|
-
* const aensDelegationSig = await contract.createAensDelegationSignature(
|
|
76
|
+
* const aensDelegationSig = await contract.createAensDelegationSignature(
|
|
77
|
+
* params, name, { onAccount: current }
|
|
78
|
+
* )
|
|
194
79
|
*/
|
|
195
80
|
async function createAensDelegationSignature ({ contractId, name }, opt = {}) {
|
|
196
|
-
return this.delegateSignatureCommon(
|
|
81
|
+
return this.delegateSignatureCommon(
|
|
82
|
+
[await this.address(opt), ...name ? [produceNameId(name)] : [], contractId],
|
|
83
|
+
opt
|
|
84
|
+
)
|
|
197
85
|
}
|
|
198
86
|
|
|
199
87
|
/**
|
|
@@ -206,10 +94,10 @@ async function createAensDelegationSignature ({ contractId, name }, opt = {}) {
|
|
|
206
94
|
* @param {{ onAccount: String | Object }} [opt={}] opt Options
|
|
207
95
|
* @return {Promise<String>} Signature for delegation
|
|
208
96
|
* @example
|
|
209
|
-
* const
|
|
97
|
+
* const aeSdk = await Universal({ ... })
|
|
210
98
|
* const contractId = 'ct_asd2ks...' // contract address
|
|
211
99
|
* const queryId = 'oq_...' // Oracle Query Id
|
|
212
|
-
* const onAccount = await
|
|
100
|
+
* const onAccount = await aeSdk.address() // Sign with a specific account
|
|
213
101
|
* // Oracle register and extend signature
|
|
214
102
|
* const params = { contractId }
|
|
215
103
|
* const oracleDelegationSig = await contract.createOracleDelegationSignature(params, { onAccount })
|
|
@@ -218,7 +106,7 @@ async function createAensDelegationSignature ({ contractId, name }, opt = {}) {
|
|
|
218
106
|
* const respondSig = await contract.createOracleDelegationSignature(params, queryId)
|
|
219
107
|
*/
|
|
220
108
|
async function createOracleDelegationSignature ({ contractId, queryId }, opt = {}) {
|
|
221
|
-
return this.delegateSignatureCommon([
|
|
109
|
+
return this.delegateSignatureCommon([queryId ?? await this.address(opt), contractId], opt)
|
|
222
110
|
}
|
|
223
111
|
|
|
224
112
|
/**
|
|
@@ -232,31 +120,16 @@ async function createOracleDelegationSignature ({ contractId, queryId }, opt = {
|
|
|
232
120
|
* @param {Object} [options={}] - Initializer object
|
|
233
121
|
* @return {Object} Contract instance
|
|
234
122
|
* @example
|
|
235
|
-
* import Transaction from '@aeternity/aepp-sdk
|
|
236
|
-
* import MemoryAccount from '@aeternity/aepp-sdk/es/account/memory
|
|
237
|
-
* import ChainNode from '@aeternity/aepp-sdk/es/chain/node
|
|
238
|
-
* import ContractCompilerAPI from '@aeternity/aepp-sdk/es/contract/compiler
|
|
239
|
-
* // or using bundle
|
|
240
|
-
* import {
|
|
241
|
-
* Transaction,
|
|
242
|
-
* MemoryAccount,
|
|
243
|
-
* ChainNode,
|
|
244
|
-
* ContractCompilerAPI
|
|
245
|
-
* } from '@aeternity/aepp-sdk
|
|
123
|
+
* import { Transaction, MemoryAccount, ChainNode } from '@aeternity/aepp-sdk
|
|
246
124
|
*
|
|
247
125
|
* const ContractWithAE = await Contract
|
|
248
126
|
* .compose(Transaction, MemoryAccount, ChainNode) // AE implementation
|
|
249
|
-
* .compose(ContractCompilerAPI) // ContractBase implementation
|
|
250
127
|
* const client = await ContractWithAe({ url, internalUrl, compilerUrl, keypair, ... })
|
|
251
128
|
*
|
|
252
129
|
*/
|
|
253
|
-
export
|
|
130
|
+
export default Ae.compose(ContractCompilerHttp, {
|
|
254
131
|
methods: {
|
|
255
132
|
getContractInstance,
|
|
256
|
-
contractCompile,
|
|
257
|
-
contractCallStatic,
|
|
258
|
-
contractDeploy,
|
|
259
|
-
contractCall,
|
|
260
133
|
// Delegation for contract
|
|
261
134
|
delegateSignatureCommon,
|
|
262
135
|
// AENS
|
|
@@ -267,15 +140,9 @@ export const ContractAPI = Ae.compose(ContractBase, {
|
|
|
267
140
|
deepProps: {
|
|
268
141
|
Ae: {
|
|
269
142
|
defaults: {
|
|
270
|
-
deposit: DEPOSIT,
|
|
271
143
|
gasPrice: MIN_GAS_PRICE,
|
|
272
|
-
amount: AMOUNT
|
|
273
|
-
gas: GAS
|
|
144
|
+
amount: AMOUNT
|
|
274
145
|
}
|
|
275
146
|
}
|
|
276
147
|
}
|
|
277
148
|
})
|
|
278
|
-
|
|
279
|
-
export const Contract = ContractAPI.compose(NodePool)
|
|
280
|
-
export const ContractWithCompiler = Contract.compose(ContractCompilerAPI)
|
|
281
|
-
export default ContractWithCompiler
|
package/src/ae/index.js
CHANGED
|
@@ -29,6 +29,7 @@ import AccountBase from '../account/base'
|
|
|
29
29
|
import TxBuilder from '../tx/builder'
|
|
30
30
|
import BigNumber from 'bignumber.js'
|
|
31
31
|
import { AE_AMOUNT_FORMATS } from '../utils/amount-formatter'
|
|
32
|
+
import { ArgumentError } from '../utils/errors'
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
35
|
* Sign and post a transaction to the chain
|
|
@@ -37,7 +38,8 @@ import { AE_AMOUNT_FORMATS } from '../utils/amount-formatter'
|
|
|
37
38
|
* @rtype (tx: String, options: Object) => Promise[String]
|
|
38
39
|
* @param {String} tx - Transaction
|
|
39
40
|
* @param {Object} [options={}] options - Options
|
|
40
|
-
* @param {Object} [options.verify=true]
|
|
41
|
+
* @param {Object} [options.verify=true] - Verify transaction before broadcast, throw error if not
|
|
42
|
+
* valid
|
|
41
43
|
* @return {Object} Transaction
|
|
42
44
|
*/
|
|
43
45
|
async function send (tx, options = {}) {
|
|
@@ -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,11 +27,11 @@
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
import Ae from './'
|
|
30
|
-
import { decodeBase64Check } from '../utils/crypto'
|
|
31
30
|
import { pause } from '../utils/other'
|
|
32
31
|
import { oracleQueryId, decode } from '../tx/builder/helpers'
|
|
33
32
|
import { unpackTx } from '../tx/builder'
|
|
34
33
|
import { ORACLE_TTL, QUERY_FEE, QUERY_TTL, RESPONSE_TTL } from '../tx/builder/schema'
|
|
34
|
+
import { RequestTimedOutError } from '../utils/errors'
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* Constructor for Oracle Object (helper object for using Oracle)
|
|
@@ -67,7 +67,11 @@ async function getOracleObject (oracleId) {
|
|
|
67
67
|
* @param {Number} [options.interval] Poll interval(default: 5000)
|
|
68
68
|
* @return {Function} stopPolling - Stop polling function
|
|
69
69
|
*/
|
|
70
|
-
function pollForQueries (
|
|
70
|
+
function pollForQueries (
|
|
71
|
+
oracleId,
|
|
72
|
+
onQuery,
|
|
73
|
+
{ interval = this._getPollInterval('microblock') } = {}
|
|
74
|
+
) {
|
|
71
75
|
const knownQueryIds = new Set()
|
|
72
76
|
const checkNewQueries = async () => {
|
|
73
77
|
const queries = ((await this.api.getOracleQueriesByPubkey(oracleId)).oracleQueries || [])
|
|
@@ -76,9 +80,15 @@ function pollForQueries (oracleId, onQuery, { interval = 5000 } = {}) {
|
|
|
76
80
|
if (queries.length) onQuery(queries)
|
|
77
81
|
}
|
|
78
82
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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 }
|
|
82
92
|
}
|
|
83
93
|
|
|
84
94
|
/**
|
|
@@ -95,11 +105,16 @@ async function getQueryObject (oracleId, queryId) {
|
|
|
95
105
|
const q = await this.api.getOracleQueryByPubkeyAndQueryId(oracleId, queryId)
|
|
96
106
|
return {
|
|
97
107
|
...q,
|
|
98
|
-
decodedQuery:
|
|
99
|
-
decodedResponse:
|
|
108
|
+
decodedQuery: decode(q.query).toString(),
|
|
109
|
+
decodedResponse: decode(q.response).toString(),
|
|
100
110
|
respond: this.respondToQuery.bind(this, oracleId, queryId),
|
|
101
111
|
pollForResponse: this.pollForQueryResponse.bind(this, oracleId, queryId),
|
|
102
|
-
|
|
112
|
+
/**
|
|
113
|
+
* @deprecated use TxBuilderHelper.decode instead
|
|
114
|
+
* @param data
|
|
115
|
+
* @returns {Buffer}
|
|
116
|
+
*/
|
|
117
|
+
decode: (data) => decode(data)
|
|
103
118
|
}
|
|
104
119
|
}
|
|
105
120
|
|
|
@@ -116,7 +131,11 @@ async function getQueryObject (oracleId, queryId) {
|
|
|
116
131
|
* @param {Object} [options.interval] Poll interval(default: 5000)
|
|
117
132
|
* @return {Promise<Object>} OracleQuery object
|
|
118
133
|
*/
|
|
119
|
-
export async function pollForQueryResponse (
|
|
134
|
+
export async function pollForQueryResponse (
|
|
135
|
+
oracleId,
|
|
136
|
+
queryId,
|
|
137
|
+
{ attempts = 20, interval = this._getPollInterval('microblock') } = {}
|
|
138
|
+
) {
|
|
120
139
|
for (let i = 0; i < attempts; i++) {
|
|
121
140
|
if (i) await pause(interval)
|
|
122
141
|
const { response } = await this.api.getOracleQueryByPubkeyAndQueryId(oracleId, queryId)
|
|
@@ -125,7 +144,7 @@ export async function pollForQueryResponse (oracleId, queryId, { attempts = 20,
|
|
|
125
144
|
return String(responseBuffer)
|
|
126
145
|
}
|
|
127
146
|
}
|
|
128
|
-
throw new
|
|
147
|
+
throw new RequestTimedOutError((attempts - 1) * interval)
|
|
129
148
|
}
|
|
130
149
|
|
|
131
150
|
/**
|
|
@@ -137,10 +156,10 @@ export async function pollForQueryResponse (oracleId, queryId, { attempts = 20,
|
|
|
137
156
|
* @param {String} queryFormat Format of query
|
|
138
157
|
* @param {String} responseFormat Format of query response
|
|
139
158
|
* @param {Object} [options={}] Options
|
|
140
|
-
* @param {String|Number} [options.queryFee]
|
|
141
|
-
* @param {Object} [options.oracleTtl]
|
|
142
|
-
* @param {Number} [options.abiVersion]
|
|
143
|
-
* @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
|
|
144
163
|
* @param {Number|String} [options.ttl] Transaction time to leave
|
|
145
164
|
* @return {Promise<Object>} Oracle object
|
|
146
165
|
*/
|
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
|
+
)
|