@aeternity/aepp-sdk 12.0.0 → 12.1.2
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 -15
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +2 -1
- package/dist/aepp-sdk.browser.js.LICENSE.txt +1 -0
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +20765 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdk.d.ts +7 -7
- package/es/AeSdk.mjs.map +1 -1
- package/es/AeSdkAepp.d.ts +4 -3
- package/es/AeSdkAepp.mjs +2 -1
- package/es/AeSdkAepp.mjs.map +1 -1
- package/es/AeSdkBase.d.ts +22 -21
- package/es/AeSdkBase.mjs +25 -21
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkWallet.d.ts +4 -3
- package/es/AeSdkWallet.mjs +5 -1
- package/es/AeSdkWallet.mjs.map +1 -1
- package/es/Node.d.ts +7 -10
- package/es/Node.mjs +63 -57
- package/es/Node.mjs.map +1 -1
- package/es/account/Base.d.ts +7 -4
- package/es/account/Base.mjs +3 -3
- package/es/account/Base.mjs.map +1 -1
- package/es/account/Memory.d.ts +5 -4
- package/es/account/Memory.mjs +24 -2
- package/es/account/Memory.mjs.map +1 -1
- package/es/account/Rpc.d.ts +6 -6
- package/es/account/Rpc.mjs +3 -2
- package/es/account/Rpc.mjs.map +1 -1
- package/es/aens.d.ts +27 -14
- package/es/aens.mjs +27 -21
- package/es/aens.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/Browser.d.ts +2 -1
- package/es/aepp-wallet-communication/connection/Browser.mjs +5 -2
- package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +5 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection-proxy.d.ts +1 -0
- package/es/aepp-wallet-communication/connection-proxy.mjs +1 -0
- package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +1 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +5 -5
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/types.d.ts +8 -8
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
- package/es/aepp-wallet-communication/schema.d.ts +17 -2
- package/es/aepp-wallet-communication/schema.mjs +54 -17
- package/es/aepp-wallet-communication/schema.mjs.map +1 -1
- package/es/aepp-wallet-communication/wallet-detector.d.ts +2 -1
- package/es/aepp-wallet-communication/wallet-detector.mjs +2 -3
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
- package/es/apis/node/models/index.d.ts +6 -2
- package/es/apis/node/models/index.mjs.map +1 -1
- package/es/apis/node/models/mappers.mjs +4 -2
- package/es/apis/node/models/mappers.mjs.map +1 -1
- package/es/chain.d.ts +92 -64
- package/es/chain.mjs +190 -154
- package/es/chain.mjs.map +1 -1
- package/es/channel/handlers.d.ts +3 -3
- package/es/channel/handlers.mjs +42 -44
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/index.d.ts +43 -52
- package/es/channel/index.mjs +46 -49
- package/es/channel/index.mjs.map +1 -1
- package/es/channel/internal.d.ts +16 -15
- package/es/channel/internal.mjs +67 -62
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Compiler.d.ts +1 -0
- package/es/contract/Compiler.mjs +5 -4
- package/es/contract/Compiler.mjs.map +1 -1
- package/es/contract/aci.d.ts +17 -15
- package/es/contract/aci.mjs +58 -45
- package/es/contract/aci.mjs.map +1 -1
- package/es/contract/ga.d.ts +16 -15
- package/es/contract/ga.mjs +12 -7
- package/es/contract/ga.mjs.map +1 -1
- package/es/contract/methods.d.ts +9 -6
- package/es/contract/methods.mjs +9 -6
- package/es/contract/methods.mjs.map +1 -1
- package/es/deprecated/index.d.ts +143 -0
- package/es/deprecated/index.mjs +162 -0
- package/es/deprecated/index.mjs.map +1 -0
- package/es/deprecated/methods.d.ts +18 -0
- package/es/deprecated/methods.mjs +26 -0
- package/es/deprecated/methods.mjs.map +1 -0
- package/es/index.d.ts +4 -1
- package/es/index.mjs +4 -1
- package/es/index.mjs.map +1 -1
- package/es/oracle.d.ts +69 -62
- package/es/oracle.mjs +121 -103
- package/es/oracle.mjs.map +1 -1
- package/es/spend.d.ts +16 -15
- package/es/spend.mjs +19 -30
- package/es/spend.mjs.map +1 -1
- package/es/tx/builder/address.d.ts +25 -0
- package/es/tx/builder/address.mjs +45 -0
- package/es/tx/builder/address.mjs.map +1 -0
- package/es/tx/builder/constants.d.ts +55 -26
- package/es/tx/builder/constants.mjs +60 -38
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/field-types/coin-amount.d.ts +13 -0
- package/es/tx/builder/field-types/coin-amount.mjs +26 -0
- package/es/tx/builder/field-types/coin-amount.mjs.map +1 -0
- package/es/tx/builder/field-types/deposit.d.ts +15 -0
- package/es/tx/builder/field-types/deposit.mjs +19 -0
- package/es/tx/builder/field-types/deposit.mjs.map +1 -0
- package/es/tx/builder/field-types/fee.d.ts +25 -0
- package/es/tx/{min-fee.mjs → builder/field-types/fee.mjs} +62 -60
- package/es/tx/builder/field-types/fee.mjs.map +1 -0
- package/es/tx/builder/field-types/field.d.ts +6 -0
- package/es/tx/builder/field-types/field.mjs +15 -0
- package/es/tx/builder/field-types/field.mjs.map +1 -0
- package/es/tx/builder/field-types/gas-limit.d.ts +12 -0
- package/es/tx/builder/field-types/gas-limit.mjs +33 -0
- package/es/tx/builder/field-types/gas-limit.mjs.map +1 -0
- package/es/tx/builder/field-types/gas-price.d.ts +8 -0
- package/es/tx/builder/field-types/gas-price.mjs +18 -0
- package/es/tx/builder/field-types/gas-price.mjs.map +1 -0
- package/es/tx/builder/field-types/index.d.ts +70 -0
- package/es/tx/builder/field-types/index.mjs +25 -0
- package/es/tx/builder/field-types/index.mjs.map +1 -0
- package/es/tx/builder/field-types/name-fee.d.ts +20 -0
- package/es/tx/builder/field-types/name-fee.mjs +24 -0
- package/es/tx/builder/field-types/name-fee.mjs.map +1 -0
- package/es/tx/builder/field-types/name-id.d.ts +14 -0
- package/es/tx/builder/field-types/name-id.mjs +19 -0
- package/es/tx/builder/field-types/name-id.mjs.map +1 -0
- package/es/tx/builder/field-types/name.d.ts +13 -0
- package/es/tx/builder/field-types/name.mjs +18 -0
- package/es/tx/builder/field-types/name.mjs.map +1 -0
- package/es/tx/builder/field-types/short-u-int.d.ts +6 -0
- package/es/tx/builder/field-types/short-u-int.mjs +12 -0
- package/es/tx/builder/field-types/short-u-int.mjs.map +1 -0
- package/es/tx/builder/field-types/u-int.d.ts +8 -0
- package/es/tx/builder/field-types/u-int.mjs +14 -0
- package/es/tx/builder/field-types/u-int.mjs.map +1 -0
- package/es/tx/builder/helpers.d.ts +27 -33
- package/es/tx/builder/helpers.mjs +41 -47
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +25 -12
- package/es/tx/builder/index.mjs +74 -83
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +995 -144
- package/es/tx/builder/schema.mjs +121 -170
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +28 -27
- package/es/tx/index.mjs +97 -117
- package/es/tx/index.mjs.map +1 -1
- package/es/tx/validator.d.ts +4 -3
- package/es/tx/validator.mjs +79 -92
- package/es/tx/validator.mjs.map +1 -1
- package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -1
- package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -1
- package/es/typings/bip32-path/index.d.mjs.map +1 -1
- package/es/typings/blakejs/index.d.mjs.map +1 -1
- package/es/typings/sha-js/index.d.mjs +2 -0
- package/es/typings/sha-js/index.d.mjs.map +1 -0
- package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -1
- package/es/utils/amount-formatter.d.ts +9 -9
- package/es/utils/amount-formatter.mjs +17 -17
- package/es/utils/amount-formatter.mjs.map +1 -1
- package/es/utils/autorest.mjs +7 -7
- package/es/utils/autorest.mjs.map +1 -1
- package/es/utils/bignumber.mjs +2 -1
- package/es/utils/bignumber.mjs.map +1 -1
- package/es/utils/bytes.mjs +1 -1
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.d.ts +8 -23
- package/es/utils/crypto.mjs +15 -41
- package/es/utils/crypto.mjs.map +1 -1
- package/es/utils/encoder-types.d.ts +61 -0
- package/es/utils/encoder-types.mjs +36 -0
- package/es/utils/encoder-types.mjs.map +1 -0
- package/es/utils/encoder.d.ts +6 -7
- package/es/utils/encoder.mjs +42 -26
- package/es/utils/encoder.mjs.map +1 -1
- package/es/utils/errors.d.ts +1 -11
- package/es/utils/errors.mjs +4 -20
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.d.ts +18 -2
- package/es/utils/hd-wallet.mjs +64 -34
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/json-big.mjs +2 -2
- package/es/utils/json-big.mjs.map +1 -1
- package/es/utils/keystore.mjs +4 -2
- package/es/utils/keystore.mjs.map +1 -1
- package/es/utils/mptree.d.ts +2 -2
- package/es/utils/mptree.mjs +11 -6
- package/es/utils/mptree.mjs.map +1 -1
- package/es/utils/other.d.ts +8 -2
- package/es/utils/other.mjs +15 -3
- package/es/utils/other.mjs.map +1 -1
- package/es/utils/semver-satisfies.d.ts +1 -1
- package/es/utils/semver-satisfies.mjs +2 -2
- package/es/utils/semver-satisfies.mjs.map +1 -1
- package/es/utils/string.mjs.map +1 -1
- package/package.json +36 -34
- package/src/AeSdk.ts +30 -27
- package/src/AeSdkAepp.ts +93 -84
- package/src/AeSdkBase.ts +148 -130
- package/src/AeSdkWallet.ts +172 -156
- package/src/Node.ts +108 -102
- package/src/account/Base.ts +42 -32
- package/src/account/Memory.ts +45 -30
- package/src/account/Rpc.ts +32 -30
- package/src/aens.ts +124 -108
- package/src/aepp-wallet-communication/connection/Browser.ts +18 -15
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +22 -21
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +63 -52
- package/src/aepp-wallet-communication/connection-proxy.ts +8 -7
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +67 -61
- package/src/aepp-wallet-communication/rpc/types.ts +32 -32
- package/src/aepp-wallet-communication/schema.ts +117 -74
- package/src/aepp-wallet-communication/wallet-detector.ts +29 -28
- package/src/apis/node/code-model-v4.yaml +54 -20
- package/src/apis/node/models/index.ts +6 -2
- package/src/apis/node/models/mappers.ts +4 -2
- package/src/chain.ts +286 -228
- package/src/channel/handlers.ts +424 -372
- package/src/channel/index.ts +285 -251
- package/src/channel/internal.ts +248 -232
- package/src/contract/Compiler.ts +22 -21
- package/src/contract/aci.ts +267 -258
- package/src/contract/ga.ts +93 -72
- package/src/contract/methods.ts +32 -27
- package/src/deprecated/index.ts +172 -0
- package/src/deprecated/methods.ts +25 -0
- package/src/index.ts +37 -32
- package/src/oracle.ts +211 -189
- package/src/spend.ts +82 -70
- package/src/tx/builder/address.ts +50 -0
- package/src/tx/builder/constants.ts +82 -52
- package/src/tx/builder/field-types/coin-amount.ts +27 -0
- package/src/tx/builder/field-types/deposit.ts +21 -0
- package/src/tx/builder/field-types/fee.ts +143 -0
- package/src/tx/builder/field-types/field.ts +9 -0
- package/src/tx/builder/field-types/gas-limit.ts +41 -0
- package/src/tx/builder/field-types/gas-price.ts +16 -0
- package/src/tx/builder/field-types/index.ts +45 -0
- package/src/tx/builder/field-types/name-fee.ts +32 -0
- package/src/tx/builder/field-types/name-id.ts +20 -0
- package/src/tx/builder/field-types/name.ts +18 -0
- package/src/tx/builder/field-types/short-u-int.ts +11 -0
- package/src/tx/builder/field-types/u-int.ts +16 -0
- package/src/tx/builder/helpers.ts +112 -117
- package/src/tx/builder/index.ts +203 -197
- package/src/tx/builder/schema.ts +421 -465
- package/src/tx/index.ts +128 -135
- package/src/tx/validator.ts +165 -161
- package/src/typings/@aeternity__argon2-browser/index.d.ts +1 -1
- package/src/typings/@aeternity__uuid/index.d.ts +3 -1
- package/src/typings/bip32-path/index.d.ts +6 -6
- package/src/typings/blakejs/index.d.ts +4 -32
- package/src/typings/sha-js/index.d.ts +5 -0
- package/src/typings/tweetnacl-auth/index.d.ts +2 -2
- package/src/utils/amount-formatter.ts +41 -41
- package/src/utils/autorest.ts +57 -54
- package/src/utils/bignumber.ts +7 -6
- package/src/utils/bytes.ts +19 -19
- package/src/utils/crypto.ts +82 -94
- package/src/utils/encoder-types.ts +63 -0
- package/src/utils/encoder.ts +104 -56
- package/src/utils/errors.ts +246 -264
- package/src/utils/hd-wallet.ts +114 -82
- package/src/utils/json-big.ts +16 -15
- package/src/utils/keystore.ts +65 -62
- package/src/utils/mptree.ts +59 -56
- package/src/utils/other.ts +26 -18
- package/src/utils/semver-satisfies.ts +15 -11
- package/src/utils/string.ts +10 -10
- package/es/tx/builder/field-types.d.ts +0 -62
- package/es/tx/builder/field-types.mjs +0 -126
- package/es/tx/builder/field-types.mjs.map +0 -1
- package/es/tx/min-fee.d.ts +0 -20
- package/es/tx/min-fee.mjs.map +0 -1
- package/src/tx/builder/field-types.ts +0 -111
- package/src/tx/min-fee.ts +0 -136
package/src/oracle.ts
CHANGED
|
@@ -23,74 +23,33 @@
|
|
|
23
23
|
* repository.
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
26
|
+
import BigNumber from 'bignumber.js';
|
|
27
|
+
import { send, SendOptions } from './spend';
|
|
28
|
+
import { mapObject, pause } from './utils/other';
|
|
29
|
+
import { oracleQueryId } from './tx/builder/helpers';
|
|
30
|
+
import { unpackTx } from './tx/builder';
|
|
30
31
|
import {
|
|
31
32
|
ORACLE_TTL,
|
|
32
33
|
ORACLE_TTL_TYPES,
|
|
33
34
|
QUERY_FEE,
|
|
34
35
|
QUERY_TTL,
|
|
35
36
|
RESPONSE_TTL,
|
|
36
|
-
|
|
37
|
-
} from './tx/builder/
|
|
38
|
-
import { RequestTimedOutError } from './utils/errors'
|
|
39
|
-
import {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
import
|
|
43
|
-
import
|
|
44
|
-
import
|
|
45
|
-
|
|
46
|
-
type OracleQueries = Awaited<ReturnType<Node['getOracleQueriesByPubkey']>>['oracleQueries']
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Constructor for Oracle Object (helper object for using Oracle)
|
|
50
|
-
* @param oracleId - Oracle public key
|
|
51
|
-
* @param options - Options
|
|
52
|
-
* @returns Oracle object
|
|
53
|
-
*/
|
|
54
|
-
export async function getOracleObject (
|
|
55
|
-
oracleId: EncodedData<'ok'>, options: { onNode: Node, onAccount: AccountBase }
|
|
56
|
-
): Promise<GetOracleObjectReturnType> {
|
|
57
|
-
return {
|
|
58
|
-
...await options.onNode.getOracleByPubkey(oracleId),
|
|
59
|
-
queries: (await options.onNode.getOracleQueriesByPubkey(oracleId)).oracleQueries,
|
|
60
|
-
...mapObject<Function, Function>(
|
|
61
|
-
{
|
|
62
|
-
pollQueries: pollForQueries,
|
|
63
|
-
postQuery: postQueryToOracle,
|
|
64
|
-
respondToQuery,
|
|
65
|
-
extendOracle: extendOracleTtl,
|
|
66
|
-
getQuery: getQueryObject
|
|
67
|
-
},
|
|
68
|
-
([name, handler]) => [
|
|
69
|
-
name,
|
|
70
|
-
function (...args: any) {
|
|
71
|
-
const lastArg = args[args.length - 1]
|
|
72
|
-
if (lastArg != null && typeof lastArg === 'object' && lastArg.constructor === Object) {
|
|
73
|
-
Object.assign(lastArg, { ...options, ...lastArg })
|
|
74
|
-
} else args.push(options)
|
|
75
|
-
return handler(oracleId, ...args)
|
|
76
|
-
}
|
|
77
|
-
])
|
|
78
|
-
} as any
|
|
79
|
-
}
|
|
37
|
+
} from './tx/builder/schema';
|
|
38
|
+
import { Tag } from './tx/builder/constants';
|
|
39
|
+
import { RequestTimedOutError } from './utils/errors';
|
|
40
|
+
import {
|
|
41
|
+
decode, encode, Encoded, Encoding,
|
|
42
|
+
} from './utils/encoder';
|
|
43
|
+
import { _getPollInterval } from './chain';
|
|
44
|
+
import { _buildTx, BuildTxOptions } from './tx';
|
|
45
|
+
import Node from './Node';
|
|
46
|
+
import AccountBase from './account/Base';
|
|
80
47
|
|
|
81
|
-
|
|
82
|
-
id: EncodedData<'ok'>
|
|
83
|
-
queries: OracleQueries
|
|
84
|
-
// TODO: replace getOracleObject with a class
|
|
85
|
-
pollQueries: (cb: Parameters<typeof pollForQueries>[1]) => ReturnType<typeof pollForQueries>
|
|
86
|
-
postQuery: Function
|
|
87
|
-
respondToQuery: Function
|
|
88
|
-
extendOracle: Function
|
|
89
|
-
getQuery: Function
|
|
90
|
-
}
|
|
48
|
+
type OracleQueries = Awaited<ReturnType<Node['getOracleQueriesByPubkey']>>['oracleQueries'];
|
|
91
49
|
|
|
92
50
|
/**
|
|
93
51
|
* Poll for oracle queries
|
|
52
|
+
* @category oracle
|
|
94
53
|
* @param oracleId - Oracle public key
|
|
95
54
|
* @param onQuery - OnQuery callback
|
|
96
55
|
* @param options - Options object
|
|
@@ -98,20 +57,20 @@ interface GetOracleObjectReturnType extends Awaited<ReturnType<Node['getOracleBy
|
|
|
98
57
|
* @param options.onNode - Node to use
|
|
99
58
|
* @returns Callback to stop polling function
|
|
100
59
|
*/
|
|
101
|
-
export function pollForQueries
|
|
102
|
-
oracleId:
|
|
60
|
+
export function pollForQueries(
|
|
61
|
+
oracleId: Encoded.OracleAddress,
|
|
103
62
|
onQuery: (queries: OracleQueries) => void,
|
|
104
|
-
{ interval, onNode, ...options }: { interval?: number
|
|
105
|
-
& Parameters<typeof _getPollInterval>[1]
|
|
63
|
+
{ interval, onNode, ...options }: { interval?: number; onNode: Node }
|
|
64
|
+
& Parameters<typeof _getPollInterval>[1],
|
|
106
65
|
): () => void {
|
|
107
|
-
interval ??= _getPollInterval('microblock', options)
|
|
108
|
-
const knownQueryIds = new Set()
|
|
66
|
+
interval ??= _getPollInterval('microblock', options);
|
|
67
|
+
const knownQueryIds = new Set();
|
|
109
68
|
const checkNewQueries = async (): Promise<void> => {
|
|
110
69
|
const queries = ((await onNode.getOracleQueriesByPubkey(oracleId)).oracleQueries ?? [])
|
|
111
|
-
.filter(({ id }) => !knownQueryIds.has(id))
|
|
112
|
-
queries.forEach(({ id }) => knownQueryIds.add(id))
|
|
113
|
-
if (queries.length > 0) onQuery(queries)
|
|
114
|
-
}
|
|
70
|
+
.filter(({ id }) => !knownQueryIds.has(id));
|
|
71
|
+
queries.forEach(({ id }) => knownQueryIds.add(id));
|
|
72
|
+
if (queries.length > 0) onQuery(queries);
|
|
73
|
+
};
|
|
115
74
|
|
|
116
75
|
let stopped = false;
|
|
117
76
|
|
|
@@ -119,114 +78,81 @@ export function pollForQueries (
|
|
|
119
78
|
(async () => {
|
|
120
79
|
while (!stopped) { // eslint-disable-line no-unmodified-loop-condition
|
|
121
80
|
// TODO: allow to handle this error somehow
|
|
122
|
-
await checkNewQueries().catch(console.error)
|
|
123
|
-
await pause(interval)
|
|
81
|
+
await checkNewQueries().catch(console.error);
|
|
82
|
+
await pause(interval);
|
|
124
83
|
}
|
|
125
|
-
})()
|
|
126
|
-
return () => { stopped = true }
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Constructor for OracleQuery Object (helper object for using OracleQuery)
|
|
131
|
-
* @param oracleId - Oracle public key
|
|
132
|
-
* @param queryId - Oracle Query id
|
|
133
|
-
* @param options - Options
|
|
134
|
-
* @returns OracleQuery object
|
|
135
|
-
*/
|
|
136
|
-
export async function getQueryObject (
|
|
137
|
-
oracleId: EncodedData<'ok'>,
|
|
138
|
-
queryId: EncodedData<'oq'>,
|
|
139
|
-
options: RespondToQueryOptions & Parameters<typeof pollForQueryResponse>[2]
|
|
140
|
-
): Promise<GetQueryObjectReturnType> {
|
|
141
|
-
const record = await options.onNode.getOracleQueryByPubkeyAndQueryId(oracleId, queryId)
|
|
142
|
-
return {
|
|
143
|
-
...record,
|
|
144
|
-
decodedQuery: decode(record.query as EncodedData<'oq'>).toString(),
|
|
145
|
-
decodedResponse: decode(record.response as EncodedData<'or'>).toString(),
|
|
146
|
-
respond: async (response, opt) =>
|
|
147
|
-
await respondToQuery(oracleId, queryId, response, { ...options, ...opt }),
|
|
148
|
-
pollForResponse: async (opt) =>
|
|
149
|
-
await pollForQueryResponse(oracleId, queryId, { ...options, ...opt })
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
interface GetQueryObjectReturnType extends Awaited<ReturnType<Node['getOracleQueryByPubkeyAndQueryId']>> {
|
|
154
|
-
decodedQuery: string
|
|
155
|
-
decodedResponse: string
|
|
156
|
-
respond: (response: string, options?: Parameters<typeof respondToQuery>[3]) =>
|
|
157
|
-
ReturnType<typeof respondToQuery>
|
|
158
|
-
pollForResponse: (options?: Parameters<typeof pollForQueryResponse>[2]) =>
|
|
159
|
-
ReturnType<typeof pollForQueryResponse>
|
|
84
|
+
})();
|
|
85
|
+
return () => { stopped = true; };
|
|
160
86
|
}
|
|
161
87
|
|
|
162
88
|
/**
|
|
163
89
|
* Poll for oracle query response
|
|
90
|
+
* @category oracle
|
|
164
91
|
* @param oracleId - Oracle public key
|
|
165
92
|
* @param queryId - Oracle Query id
|
|
166
93
|
* @param options - Options object
|
|
167
|
-
* @param options.attempts - Poll attempts
|
|
168
94
|
* @param options.interval - Poll interval
|
|
169
95
|
* @param options.onNode - Node to use
|
|
170
96
|
* @returns OracleQuery object
|
|
171
97
|
*/
|
|
172
|
-
export async function pollForQueryResponse
|
|
173
|
-
oracleId:
|
|
174
|
-
queryId:
|
|
175
|
-
{
|
|
176
|
-
{
|
|
98
|
+
export async function pollForQueryResponse(
|
|
99
|
+
oracleId: Encoded.OracleAddress,
|
|
100
|
+
queryId: Encoded.OracleQueryId,
|
|
101
|
+
{ interval, onNode, ...options }:
|
|
102
|
+
{ interval?: number; onNode: Node } & Parameters<typeof _getPollInterval>[1],
|
|
177
103
|
): Promise<string> {
|
|
178
|
-
interval ??= _getPollInterval('microblock', options)
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (
|
|
184
|
-
|
|
185
|
-
|
|
104
|
+
interval ??= _getPollInterval('microblock', options);
|
|
105
|
+
let height;
|
|
106
|
+
let ttl;
|
|
107
|
+
let response;
|
|
108
|
+
do {
|
|
109
|
+
if (height != null) await pause(interval);
|
|
110
|
+
({ response, ttl } = await onNode.getOracleQueryByPubkeyAndQueryId(oracleId, queryId));
|
|
111
|
+
const responseBuffer = decode(response as Encoded.OracleResponse);
|
|
112
|
+
if (responseBuffer.length > 0) return responseBuffer.toString();
|
|
113
|
+
height = await this.getHeight();
|
|
114
|
+
} while (ttl >= height);
|
|
115
|
+
throw new RequestTimedOutError(height);
|
|
186
116
|
}
|
|
187
117
|
|
|
188
118
|
/**
|
|
189
|
-
*
|
|
190
|
-
* @
|
|
191
|
-
* @param
|
|
119
|
+
* Constructor for OracleQuery Object (helper object for using OracleQuery)
|
|
120
|
+
* @category oracle
|
|
121
|
+
* @param oracleId - Oracle public key
|
|
122
|
+
* @param queryId - Oracle Query id
|
|
192
123
|
* @param options - Options
|
|
193
|
-
* @
|
|
194
|
-
* @param options - Options object
|
|
195
|
-
* @param options.abiVersion - Always 0 (do not use virtual machine)
|
|
196
|
-
* @param options.fee - Transaction fee
|
|
197
|
-
* @param options.ttl - Transaction time to leave
|
|
198
|
-
* @returns Oracle object
|
|
124
|
+
* @returns OracleQuery object
|
|
199
125
|
*/
|
|
200
|
-
export async function
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
oracleTtlValue: ORACLE_TTL.value,
|
|
207
|
-
oracleTtlType: ORACLE_TTL.type,
|
|
208
|
-
...options,
|
|
209
|
-
accountId,
|
|
210
|
-
queryFormat,
|
|
211
|
-
responseFormat
|
|
212
|
-
})
|
|
126
|
+
export async function getQueryObject(
|
|
127
|
+
oracleId: Encoded.OracleAddress,
|
|
128
|
+
queryId: Encoded.OracleQueryId,
|
|
129
|
+
options: RespondToQueryOptions & Parameters<typeof pollForQueryResponse>[2],
|
|
130
|
+
): Promise<GetQueryObjectReturnType> {
|
|
131
|
+
const record = await options.onNode.getOracleQueryByPubkeyAndQueryId(oracleId, queryId);
|
|
213
132
|
return {
|
|
214
|
-
...
|
|
215
|
-
|
|
216
|
-
|
|
133
|
+
...record,
|
|
134
|
+
decodedQuery: decode(record.query as Encoded.OracleQueryId).toString(),
|
|
135
|
+
decodedResponse: decode(record.response as Encoded.OracleResponse).toString(),
|
|
136
|
+
respond: async (response, opt) => (
|
|
137
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
138
|
+
respondToQuery(oracleId, queryId, response, { ...options, ...opt })
|
|
139
|
+
),
|
|
140
|
+
pollForResponse: async (opt) => pollForQueryResponse(oracleId, queryId, { ...options, ...opt }),
|
|
141
|
+
};
|
|
217
142
|
}
|
|
218
143
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
144
|
+
interface GetQueryObjectReturnType extends Awaited<ReturnType<Node['getOracleQueryByPubkeyAndQueryId']>> {
|
|
145
|
+
decodedQuery: string;
|
|
146
|
+
decodedResponse: string;
|
|
147
|
+
respond: (response: string, options?: Parameters<typeof respondToQuery>[3]) =>
|
|
148
|
+
ReturnType<typeof respondToQuery>;
|
|
149
|
+
pollForResponse: (options?: Parameters<typeof pollForQueryResponse>[2]) =>
|
|
150
|
+
ReturnType<typeof pollForQueryResponse>;
|
|
225
151
|
}
|
|
226
|
-
interface RegisterOracleOptions extends RegisterOracleOptionsType {}
|
|
227
152
|
|
|
228
153
|
/**
|
|
229
154
|
* Post query to oracle
|
|
155
|
+
* @category oracle
|
|
230
156
|
* @param oracleId - Oracle public key
|
|
231
157
|
* @param query - Oracle query object
|
|
232
158
|
* @param options - Options object
|
|
@@ -237,13 +163,15 @@ interface RegisterOracleOptions extends RegisterOracleOptionsType {}
|
|
|
237
163
|
* @param options.ttl - Transaction time to leave
|
|
238
164
|
* @returns Query object
|
|
239
165
|
*/
|
|
240
|
-
export async function postQueryToOracle
|
|
241
|
-
|
|
166
|
+
export async function postQueryToOracle(
|
|
167
|
+
oracleId: Encoded.OracleAddress,
|
|
168
|
+
query: string,
|
|
169
|
+
options: PostQueryToOracleOptions,
|
|
242
170
|
): Promise<Awaited<ReturnType<typeof send>> & Awaited<ReturnType<typeof getQueryObject>>> {
|
|
243
|
-
options.queryFee ??= (await options.onNode.getOracleByPubkey(oracleId)).queryFee.toString()
|
|
244
|
-
const senderId = await options.onAccount.address(options)
|
|
171
|
+
options.queryFee ??= (await options.onNode.getOracleByPubkey(oracleId)).queryFee.toString();
|
|
172
|
+
const senderId = await options.onAccount.address(options);
|
|
245
173
|
|
|
246
|
-
const oracleQueryTx = await _buildTx(
|
|
174
|
+
const oracleQueryTx = await _buildTx(Tag.OracleQueryTx, {
|
|
247
175
|
queryTtlType: QUERY_TTL.type,
|
|
248
176
|
queryTtlValue: QUERY_TTL.value,
|
|
249
177
|
responseTtlType: RESPONSE_TTL.type,
|
|
@@ -251,29 +179,30 @@ export async function postQueryToOracle (oracleId: EncodedData<'ok'>,
|
|
|
251
179
|
...options,
|
|
252
180
|
oracleId,
|
|
253
181
|
senderId,
|
|
254
|
-
query
|
|
255
|
-
})
|
|
256
|
-
const nonce = unpackTx(oracleQueryTx,
|
|
257
|
-
const queryId = oracleQueryId(senderId, nonce, oracleId)
|
|
182
|
+
query,
|
|
183
|
+
});
|
|
184
|
+
const { nonce } = unpackTx(oracleQueryTx, Tag.OracleQueryTx).tx;
|
|
185
|
+
const queryId = oracleQueryId(senderId, nonce, oracleId);
|
|
258
186
|
return {
|
|
259
187
|
...await send(oracleQueryTx, options),
|
|
260
|
-
...await getQueryObject(oracleId, queryId, options)
|
|
261
|
-
}
|
|
188
|
+
...await getQueryObject(oracleId, queryId, options),
|
|
189
|
+
};
|
|
262
190
|
}
|
|
263
191
|
|
|
264
192
|
type PostQueryToOracleOptionsType = Parameters<typeof send>[1]
|
|
265
193
|
& Parameters<typeof getQueryObject>[2]
|
|
266
|
-
& BuildTxOptions<
|
|
194
|
+
& BuildTxOptions<Tag.OracleQueryTx, 'oracleId' | 'senderId' | 'query' | 'queryTtlType' | 'queryTtlValue' | 'responseTtlType' | 'responseTtlValue'>
|
|
267
195
|
& {
|
|
268
|
-
queryTtlType?: ORACLE_TTL_TYPES
|
|
269
|
-
queryTtlValue?: number
|
|
270
|
-
responseTtlType?: ORACLE_TTL_TYPES
|
|
271
|
-
responseTtlValue?: number
|
|
272
|
-
}
|
|
196
|
+
queryTtlType?: ORACLE_TTL_TYPES;
|
|
197
|
+
queryTtlValue?: number;
|
|
198
|
+
responseTtlType?: ORACLE_TTL_TYPES;
|
|
199
|
+
responseTtlValue?: number;
|
|
200
|
+
};
|
|
273
201
|
interface PostQueryToOracleOptions extends PostQueryToOracleOptionsType {}
|
|
274
202
|
|
|
275
203
|
/**
|
|
276
204
|
* Extend oracle ttl
|
|
205
|
+
* @category oracle
|
|
277
206
|
* @param oracleId - Oracle public key
|
|
278
207
|
* @param options - Options object
|
|
279
208
|
* @param options.fee - fee Transaction fee
|
|
@@ -282,30 +211,32 @@ interface PostQueryToOracleOptions extends PostQueryToOracleOptionsType {}
|
|
|
282
211
|
* @param options.oracleTtlValue - Oracle time to leave for extend
|
|
283
212
|
* @returns Oracle object
|
|
284
213
|
*/
|
|
285
|
-
export async function extendOracleTtl
|
|
286
|
-
oracleId:
|
|
287
|
-
options: ExtendOracleTtlOptions
|
|
214
|
+
export async function extendOracleTtl(
|
|
215
|
+
oracleId: Encoded.OracleAddress,
|
|
216
|
+
options: ExtendOracleTtlOptions,
|
|
288
217
|
): Promise<Awaited<ReturnType<typeof send>> & Awaited<ReturnType<typeof getOracleObject>>> {
|
|
289
|
-
const oracleExtendTx = await _buildTx(
|
|
218
|
+
const oracleExtendTx = await _buildTx(Tag.OracleExtendTx, {
|
|
290
219
|
oracleTtlType: ORACLE_TTL.type,
|
|
291
220
|
oracleTtlValue: ORACLE_TTL.value,
|
|
292
221
|
...options,
|
|
293
222
|
callerId: await options.onAccount.address(options),
|
|
294
|
-
oracleId
|
|
295
|
-
})
|
|
223
|
+
oracleId,
|
|
224
|
+
});
|
|
296
225
|
return {
|
|
297
226
|
...await send(oracleExtendTx, options),
|
|
298
|
-
|
|
299
|
-
|
|
227
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
228
|
+
...await getOracleObject(oracleId, options),
|
|
229
|
+
};
|
|
300
230
|
}
|
|
301
231
|
|
|
302
232
|
type ExtendOracleTtlOptionsType = SendOptions & Parameters<typeof getOracleObject>[1]
|
|
303
|
-
& BuildTxOptions<
|
|
304
|
-
& { oracleTtlType?: ORACLE_TTL_TYPES
|
|
233
|
+
& BuildTxOptions<Tag.OracleExtendTx, 'oracleTtlType' | 'oracleTtlValue' | 'callerId' | 'oracleId'>
|
|
234
|
+
& { oracleTtlType?: ORACLE_TTL_TYPES; oracleTtlValue?: number };
|
|
305
235
|
interface ExtendOracleTtlOptions extends ExtendOracleTtlOptionsType {}
|
|
306
236
|
|
|
307
237
|
/**
|
|
308
238
|
* Extend oracle ttl
|
|
239
|
+
* @category oracle
|
|
309
240
|
* @param oracleId - Oracle public key
|
|
310
241
|
* @param queryId - Oracle query id
|
|
311
242
|
* @param response - Oracle query response
|
|
@@ -315,28 +246,119 @@ interface ExtendOracleTtlOptions extends ExtendOracleTtlOptionsType {}
|
|
|
315
246
|
* @param options.ttl - Transaction time to leave
|
|
316
247
|
* @returns Oracle object
|
|
317
248
|
*/
|
|
318
|
-
export async function respondToQuery
|
|
319
|
-
oracleId:
|
|
320
|
-
queryId:
|
|
249
|
+
export async function respondToQuery(
|
|
250
|
+
oracleId: Encoded.OracleAddress,
|
|
251
|
+
queryId: Encoded.OracleQueryId,
|
|
321
252
|
response: string,
|
|
322
|
-
options: RespondToQueryOptions
|
|
253
|
+
options: RespondToQueryOptions,
|
|
323
254
|
): Promise<Awaited<ReturnType<typeof send>> & Awaited<ReturnType<typeof getOracleObject>>> {
|
|
324
|
-
const oracleRespondTx = await _buildTx(
|
|
255
|
+
const oracleRespondTx = await _buildTx(Tag.OracleResponseTx, {
|
|
325
256
|
responseTtlType: RESPONSE_TTL.type,
|
|
326
257
|
responseTtlValue: RESPONSE_TTL.value,
|
|
327
258
|
...options,
|
|
328
259
|
callerId: await options.onAccount.address(options),
|
|
329
260
|
oracleId,
|
|
330
261
|
queryId,
|
|
331
|
-
response
|
|
332
|
-
})
|
|
262
|
+
response,
|
|
263
|
+
});
|
|
333
264
|
return {
|
|
334
265
|
...await send(oracleRespondTx, options),
|
|
335
|
-
|
|
336
|
-
|
|
266
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
267
|
+
...await getOracleObject(oracleId, options),
|
|
268
|
+
};
|
|
337
269
|
}
|
|
338
270
|
|
|
339
271
|
type RespondToQueryOptionsType = SendOptions & Parameters<typeof getOracleObject>[1]
|
|
340
|
-
& BuildTxOptions<
|
|
341
|
-
& { responseTtlType?: ORACLE_TTL_TYPES
|
|
272
|
+
& BuildTxOptions<Tag.OracleResponseTx, 'callerId' | 'oracleId' | 'queryId' | 'response' | 'responseTtlType' | 'responseTtlValue'>
|
|
273
|
+
& { responseTtlType?: ORACLE_TTL_TYPES; responseTtlValue?: number };
|
|
342
274
|
interface RespondToQueryOptions extends RespondToQueryOptionsType {}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Constructor for Oracle Object (helper object for using Oracle)
|
|
278
|
+
* @category oracle
|
|
279
|
+
* @param oracleId - Oracle public key
|
|
280
|
+
* @param options - Options
|
|
281
|
+
* @returns Oracle object
|
|
282
|
+
*/
|
|
283
|
+
export async function getOracleObject(
|
|
284
|
+
oracleId: Encoded.OracleAddress,
|
|
285
|
+
options: { onNode: Node; onAccount: AccountBase },
|
|
286
|
+
): Promise<GetOracleObjectReturnType> {
|
|
287
|
+
return {
|
|
288
|
+
...await options.onNode.getOracleByPubkey(oracleId),
|
|
289
|
+
queries: (await options.onNode.getOracleQueriesByPubkey(oracleId)).oracleQueries,
|
|
290
|
+
...mapObject<Function, Function>(
|
|
291
|
+
{
|
|
292
|
+
pollQueries: pollForQueries,
|
|
293
|
+
postQuery: postQueryToOracle,
|
|
294
|
+
respondToQuery,
|
|
295
|
+
extendOracle: extendOracleTtl,
|
|
296
|
+
getQuery: getQueryObject,
|
|
297
|
+
},
|
|
298
|
+
([name, handler]) => [
|
|
299
|
+
name,
|
|
300
|
+
(...args: any) => {
|
|
301
|
+
const lastArg = args[args.length - 1];
|
|
302
|
+
if (lastArg != null && typeof lastArg === 'object' && lastArg.constructor === Object) {
|
|
303
|
+
Object.assign(lastArg, { ...options, ...lastArg });
|
|
304
|
+
} else args.push(options);
|
|
305
|
+
return handler(oracleId, ...args);
|
|
306
|
+
},
|
|
307
|
+
],
|
|
308
|
+
),
|
|
309
|
+
} as any;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
interface GetOracleObjectReturnType extends Awaited<ReturnType<Node['getOracleByPubkey']>> {
|
|
313
|
+
id: Encoded.OracleAddress;
|
|
314
|
+
queries: OracleQueries;
|
|
315
|
+
// TODO: replace getOracleObject with a class
|
|
316
|
+
pollQueries: (cb: Parameters<typeof pollForQueries>[1]) => ReturnType<typeof pollForQueries>;
|
|
317
|
+
postQuery: Function;
|
|
318
|
+
respondToQuery: Function;
|
|
319
|
+
extendOracle: Function;
|
|
320
|
+
getQuery: Function;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Register oracle
|
|
325
|
+
* @category oracle
|
|
326
|
+
* @param queryFormat - Format of query
|
|
327
|
+
* @param responseFormat - Format of query response
|
|
328
|
+
* @param options - Options
|
|
329
|
+
* @param options.queryFee - Oracle query Fee
|
|
330
|
+
* @param options - Options object
|
|
331
|
+
* @param options.abiVersion - Always 0 (do not use virtual machine)
|
|
332
|
+
* @param options.fee - Transaction fee
|
|
333
|
+
* @param options.ttl - Transaction time to leave
|
|
334
|
+
* @returns Oracle object
|
|
335
|
+
*/
|
|
336
|
+
export async function registerOracle(
|
|
337
|
+
queryFormat: string,
|
|
338
|
+
responseFormat: string,
|
|
339
|
+
options: RegisterOracleOptions,
|
|
340
|
+
): Promise<Awaited<ReturnType<typeof send>> & Awaited<ReturnType<typeof getOracleObject>>> {
|
|
341
|
+
const accountId = await options.onAccount.address(options);
|
|
342
|
+
const oracleRegisterTx = await _buildTx(Tag.OracleRegisterTx, {
|
|
343
|
+
queryFee: QUERY_FEE,
|
|
344
|
+
oracleTtlValue: ORACLE_TTL.value,
|
|
345
|
+
oracleTtlType: ORACLE_TTL.type,
|
|
346
|
+
...options,
|
|
347
|
+
accountId,
|
|
348
|
+
queryFormat,
|
|
349
|
+
responseFormat,
|
|
350
|
+
});
|
|
351
|
+
return {
|
|
352
|
+
...await send(oracleRegisterTx, options),
|
|
353
|
+
...await getOracleObject(encode(decode(accountId), Encoding.OracleAddress), options),
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
type RegisterOracleOptionsType = SendOptions & Parameters<typeof getOracleObject>[1]
|
|
358
|
+
& BuildTxOptions<Tag.OracleRegisterTx, 'accountId' | 'queryFormat' | 'responseFormat' | 'queryFee' | 'oracleTtlType' | 'oracleTtlValue'>
|
|
359
|
+
& {
|
|
360
|
+
queryFee?: number | string | BigNumber;
|
|
361
|
+
oracleTtlType?: ORACLE_TTL_TYPES;
|
|
362
|
+
oracleTtlValue?: number;
|
|
363
|
+
};
|
|
364
|
+
interface RegisterOracleOptions extends RegisterOracleOptionsType {}
|