@aeternity/aepp-sdk 12.0.0 → 12.1.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/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 +20764 -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 +35 -33
- 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 +170 -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/es/oracle.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oracle.mjs","names":["send","mapObject","pause","oracleQueryId","decode","encode","unpackTx","ORACLE_TTL","QUERY_FEE","QUERY_TTL","RESPONSE_TTL","TX_TYPE","RequestTimedOutError","_getPollInterval","_buildTx","getOracleObject","oracleId","options","onNode","getOracleByPubkey","queries","getOracleQueriesByPubkey","oracleQueries","pollQueries","pollForQueries","postQuery","postQueryToOracle","respondToQuery","extendOracle","extendOracleTtl","getQuery","getQueryObject","name","handler","args","lastArg","length","constructor","Object","assign","push","onQuery","interval","knownQueryIds","Set","checkNewQueries","filter","id","has","forEach","add","stopped","catch","console","error","queryId","record","getOracleQueryByPubkeyAndQueryId","decodedQuery","query","toString","decodedResponse","response","respond","opt","pollForResponse","pollForQueryResponse","attempts","i","responseBuffer","registerOracle","queryFormat","responseFormat","accountId","onAccount","address","oracleRegisterTx","oracleRegister","queryFee","oracleTtlValue","value","oracleTtlType","type","senderId","oracleQueryTx","oracleQuery","queryTtlType","queryTtlValue","responseTtlType","responseTtlValue","nonce","tx","oracleExtendTx","oracleExtend","callerId","oracleRespondTx","oracleResponse"],"sources":["../src/oracle.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2022 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Oracle methods - routines to interact with the æternity oracle system\n *\n * The high-level description of the oracle system is\n * https://github.com/aeternity/protocol/blob/master/ORACLE.md in the protocol\n * repository.\n */\n\nimport { send, SendOptions } from './spend'\nimport { mapObject, pause } from './utils/other'\nimport { oracleQueryId, decode, encode } from './tx/builder/helpers'\nimport { unpackTx } from './tx/builder'\nimport {\n ORACLE_TTL,\n ORACLE_TTL_TYPES,\n QUERY_FEE,\n QUERY_TTL,\n RESPONSE_TTL,\n TX_TYPE\n} from './tx/builder/schema'\nimport { RequestTimedOutError } from './utils/errors'\nimport { EncodedData } from './utils/encoder'\nimport { _getPollInterval } from './chain'\nimport { _buildTx, BuildTxOptions } from './tx'\nimport Node from './Node'\nimport BigNumber from 'bignumber.js'\nimport AccountBase from './account/Base'\n\ntype OracleQueries = Awaited<ReturnType<Node['getOracleQueriesByPubkey']>>['oracleQueries']\n\n/**\n * Constructor for Oracle Object (helper object for using Oracle)\n * @param oracleId - Oracle public key\n * @param options - Options\n * @returns Oracle object\n */\nexport async function getOracleObject (\n oracleId: EncodedData<'ok'>, options: { onNode: Node, onAccount: AccountBase }\n): Promise<GetOracleObjectReturnType> {\n return {\n ...await options.onNode.getOracleByPubkey(oracleId),\n queries: (await options.onNode.getOracleQueriesByPubkey(oracleId)).oracleQueries,\n ...mapObject<Function, Function>(\n {\n pollQueries: pollForQueries,\n postQuery: postQueryToOracle,\n respondToQuery,\n extendOracle: extendOracleTtl,\n getQuery: getQueryObject\n },\n ([name, handler]) => [\n name,\n function (...args: any) {\n const lastArg = args[args.length - 1]\n if (lastArg != null && typeof lastArg === 'object' && lastArg.constructor === Object) {\n Object.assign(lastArg, { ...options, ...lastArg })\n } else args.push(options)\n return handler(oracleId, ...args)\n }\n ])\n } as any\n}\n\ninterface GetOracleObjectReturnType extends Awaited<ReturnType<Node['getOracleByPubkey']>> {\n id: EncodedData<'ok'>\n queries: OracleQueries\n // TODO: replace getOracleObject with a class\n pollQueries: (cb: Parameters<typeof pollForQueries>[1]) => ReturnType<typeof pollForQueries>\n postQuery: Function\n respondToQuery: Function\n extendOracle: Function\n getQuery: Function\n}\n\n/**\n * Poll for oracle queries\n * @param oracleId - Oracle public key\n * @param onQuery - OnQuery callback\n * @param options - Options object\n * @param options.interval - Poll interval(default: 5000)\n * @param options.onNode - Node to use\n * @returns Callback to stop polling function\n */\nexport function pollForQueries (\n oracleId: EncodedData<'ok'>,\n onQuery: (queries: OracleQueries) => void,\n { interval, onNode, ...options }: { interval?: number, onNode: Node }\n & Parameters<typeof _getPollInterval>[1]\n): () => void {\n interval ??= _getPollInterval('microblock', options)\n const knownQueryIds = new Set()\n const checkNewQueries = async (): Promise<void> => {\n const queries = ((await onNode.getOracleQueriesByPubkey(oracleId)).oracleQueries ?? [])\n .filter(({ id }) => !knownQueryIds.has(id))\n queries.forEach(({ id }) => knownQueryIds.add(id))\n if (queries.length > 0) onQuery(queries)\n }\n\n let stopped = false;\n\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n (async () => {\n while (!stopped) { // eslint-disable-line no-unmodified-loop-condition\n // TODO: allow to handle this error somehow\n await checkNewQueries().catch(console.error)\n await pause(interval)\n }\n })()\n return () => { stopped = true }\n}\n\n/**\n * Constructor for OracleQuery Object (helper object for using OracleQuery)\n * @param oracleId - Oracle public key\n * @param queryId - Oracle Query id\n * @param options - Options\n * @returns OracleQuery object\n */\nexport async function getQueryObject (\n oracleId: EncodedData<'ok'>,\n queryId: EncodedData<'oq'>,\n options: RespondToQueryOptions & Parameters<typeof pollForQueryResponse>[2]\n): Promise<GetQueryObjectReturnType> {\n const record = await options.onNode.getOracleQueryByPubkeyAndQueryId(oracleId, queryId)\n return {\n ...record,\n decodedQuery: decode(record.query as EncodedData<'oq'>).toString(),\n decodedResponse: decode(record.response as EncodedData<'or'>).toString(),\n respond: async (response, opt) =>\n await respondToQuery(oracleId, queryId, response, { ...options, ...opt }),\n pollForResponse: async (opt) =>\n await pollForQueryResponse(oracleId, queryId, { ...options, ...opt })\n }\n}\n\ninterface GetQueryObjectReturnType extends Awaited<ReturnType<Node['getOracleQueryByPubkeyAndQueryId']>> {\n decodedQuery: string\n decodedResponse: string\n respond: (response: string, options?: Parameters<typeof respondToQuery>[3]) =>\n ReturnType<typeof respondToQuery>\n pollForResponse: (options?: Parameters<typeof pollForQueryResponse>[2]) =>\n ReturnType<typeof pollForQueryResponse>\n}\n\n/**\n * Poll for oracle query response\n * @param oracleId - Oracle public key\n * @param queryId - Oracle Query id\n * @param options - Options object\n * @param options.attempts - Poll attempts\n * @param options.interval - Poll interval\n * @param options.onNode - Node to use\n * @returns OracleQuery object\n */\nexport async function pollForQueryResponse (\n oracleId: EncodedData<'ok'>,\n queryId: EncodedData<'oq'>,\n { attempts = 20, interval, onNode, ...options }:\n { attempts?: number, interval?: number, onNode: Node } & Parameters<typeof _getPollInterval>[1]\n): Promise<string> {\n interval ??= _getPollInterval('microblock', options)\n for (let i = 0; i < attempts; i++) {\n if (i > 0) await pause(interval)\n const { response } = await onNode.getOracleQueryByPubkeyAndQueryId(oracleId, queryId)\n const responseBuffer = decode(response as EncodedData<'or'>)\n if (responseBuffer.length > 0) return responseBuffer.toString()\n }\n throw new RequestTimedOutError((attempts - 1) * interval)\n}\n\n/**\n * Register oracle\n * @param queryFormat - Format of query\n * @param responseFormat - Format of query response\n * @param options - Options\n * @param options.queryFee - Oracle query Fee\n * @param options - Options object\n * @param options.abiVersion - Always 0 (do not use virtual machine)\n * @param options.fee - Transaction fee\n * @param options.ttl - Transaction time to leave\n * @returns Oracle object\n */\nexport async function registerOracle (\n queryFormat: string, responseFormat: string, options: RegisterOracleOptions\n): Promise<Awaited<ReturnType<typeof send>> & Awaited<ReturnType<typeof getOracleObject>>> {\n const accountId = await options.onAccount.address(options)\n const oracleRegisterTx = await _buildTx(TX_TYPE.oracleRegister, {\n queryFee: QUERY_FEE,\n oracleTtlValue: ORACLE_TTL.value,\n oracleTtlType: ORACLE_TTL.type,\n ...options,\n accountId,\n queryFormat,\n responseFormat\n })\n return {\n ...await send(oracleRegisterTx, options),\n ...await getOracleObject(encode(decode(accountId), 'ok'), options)\n }\n}\n\ntype RegisterOracleOptionsType = SendOptions & Parameters<typeof getOracleObject>[1]\n& BuildTxOptions<TX_TYPE.oracleRegister, 'accountId' | 'queryFormat' | 'responseFormat' | 'queryFee' | 'oracleTtlType' | 'oracleTtlValue'>\n& {\n queryFee?: number | string | BigNumber\n oracleTtlType?: ORACLE_TTL_TYPES\n oracleTtlValue?: number\n}\ninterface RegisterOracleOptions extends RegisterOracleOptionsType {}\n\n/**\n * Post query to oracle\n * @param oracleId - Oracle public key\n * @param query - Oracle query object\n * @param options - Options object\n * @param options.queryTtl - queryTtl Oracle query time to leave\n * @param options.responseTtl - queryFee Oracle query response time to leave\n * @param options.queryFee - queryFee Oracle query fee\n * @param options.fee - fee Transaction fee\n * @param options.ttl - Transaction time to leave\n * @returns Query object\n */\nexport async function postQueryToOracle (oracleId: EncodedData<'ok'>,\n query: string, options: PostQueryToOracleOptions\n): Promise<Awaited<ReturnType<typeof send>> & Awaited<ReturnType<typeof getQueryObject>>> {\n options.queryFee ??= (await options.onNode.getOracleByPubkey(oracleId)).queryFee.toString()\n const senderId = await options.onAccount.address(options)\n\n const oracleQueryTx = await _buildTx(TX_TYPE.oracleQuery, {\n queryTtlType: QUERY_TTL.type,\n queryTtlValue: QUERY_TTL.value,\n responseTtlType: RESPONSE_TTL.type,\n responseTtlValue: RESPONSE_TTL.value,\n ...options,\n oracleId,\n senderId,\n query\n })\n const nonce = unpackTx(oracleQueryTx, TX_TYPE.oracleQuery).tx.nonce\n const queryId = oracleQueryId(senderId, nonce, oracleId)\n return {\n ...await send(oracleQueryTx, options),\n ...await getQueryObject(oracleId, queryId, options)\n }\n}\n\ntype PostQueryToOracleOptionsType = Parameters<typeof send>[1]\n& Parameters<typeof getQueryObject>[2]\n& BuildTxOptions<TX_TYPE.oracleQuery, 'oracleId' | 'senderId' | 'query' | 'queryTtlType' | 'queryTtlValue' | 'responseTtlType' | 'responseTtlValue'>\n& {\n queryTtlType?: ORACLE_TTL_TYPES\n queryTtlValue?: number\n responseTtlType?: ORACLE_TTL_TYPES\n responseTtlValue?: number\n}\ninterface PostQueryToOracleOptions extends PostQueryToOracleOptionsType {}\n\n/**\n * Extend oracle ttl\n * @param oracleId - Oracle public key\n * @param options - Options object\n * @param options.fee - fee Transaction fee\n * @param options.ttl - Transaction time to leave\n * @param options.oracleTtlType - Oracle time to leave for extend\n * @param options.oracleTtlValue - Oracle time to leave for extend\n * @returns Oracle object\n */\nexport async function extendOracleTtl (\n oracleId: EncodedData<'ok'>,\n options: ExtendOracleTtlOptions\n): Promise<Awaited<ReturnType<typeof send>> & Awaited<ReturnType<typeof getOracleObject>>> {\n const oracleExtendTx = await _buildTx(TX_TYPE.oracleExtend, {\n oracleTtlType: ORACLE_TTL.type,\n oracleTtlValue: ORACLE_TTL.value,\n ...options,\n callerId: await options.onAccount.address(options),\n oracleId\n })\n return {\n ...await send(oracleExtendTx, options),\n ...await getOracleObject(oracleId, options)\n }\n}\n\ntype ExtendOracleTtlOptionsType = SendOptions & Parameters<typeof getOracleObject>[1]\n& BuildTxOptions<TX_TYPE.oracleExtend, 'oracleTtlType' | 'oracleTtlValue' | 'callerId' | 'oracleId'>\n& { oracleTtlType?: ORACLE_TTL_TYPES, oracleTtlValue?: number }\ninterface ExtendOracleTtlOptions extends ExtendOracleTtlOptionsType {}\n\n/**\n * Extend oracle ttl\n * @param oracleId - Oracle public key\n * @param queryId - Oracle query id\n * @param response - Oracle query response\n * @param options - Options object\n * @param options.responseTtl - responseTtl Query response time to leave\n * @param options.fee - Transaction fee\n * @param options.ttl - Transaction time to leave\n * @returns Oracle object\n */\nexport async function respondToQuery (\n oracleId: EncodedData<'ok'>,\n queryId: EncodedData<'oq'>,\n response: string,\n options: RespondToQueryOptions\n): Promise<Awaited<ReturnType<typeof send>> & Awaited<ReturnType<typeof getOracleObject>>> {\n const oracleRespondTx = await _buildTx(TX_TYPE.oracleResponse, {\n responseTtlType: RESPONSE_TTL.type,\n responseTtlValue: RESPONSE_TTL.value,\n ...options,\n callerId: await options.onAccount.address(options),\n oracleId,\n queryId,\n response\n })\n return {\n ...await send(oracleRespondTx, options),\n ...await getOracleObject(oracleId, options)\n }\n}\n\ntype RespondToQueryOptionsType = SendOptions & Parameters<typeof getOracleObject>[1]\n& BuildTxOptions<TX_TYPE.oracleResponse, 'callerId' | 'oracleId' | 'queryId' | 'response' | 'responseTtlType' | 'responseTtlValue'>\n& { responseTtlType?: ORACLE_TTL_TYPES, responseTtlValue?: number }\ninterface RespondToQueryOptions extends RespondToQueryOptionsType {}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;SAESA,I;SACAC,S,EAAWC,K;SACXC,a,EAAeC,M,EAAQC,M;SACvBC,Q;SAEPC,U,EAEAC,S,EACAC,S,EACAC,Y,EACAC,O;SAEOC,oB;SAEAC,gB;SACAC,Q;;AAOT;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,eAAf,CACLC,QADK,EACwBC,OADxB,EAE+B;EACpC,OAAO,EACL,IAAG,MAAMA,OAAO,CAACC,MAAR,CAAeC,iBAAf,CAAiCH,QAAjC,CAAT,CADK;IAELI,OAAO,EAAE,CAAC,MAAMH,OAAO,CAACC,MAAR,CAAeG,wBAAf,CAAwCL,QAAxC,CAAP,EAA0DM,aAF9D;IAGL,GAAGrB,SAAS,CACV;MACEsB,WAAW,EAAEC,cADf;MAEEC,SAAS,EAAEC,iBAFb;MAGEC,cAHF;MAIEC,YAAY,EAAEC,eAJhB;MAKEC,QAAQ,EAAEC;IALZ,CADU,EAQV;MAAA,IAAC,CAACC,IAAD,EAAOC,OAAP,CAAD;MAAA,OAAqB,CACnBD,IADmB,EAEnB,YAAwB;QAAA,kCAAXE,IAAW;UAAXA,IAAW;QAAA;;QACtB,MAAMC,OAAO,GAAGD,IAAI,CAACA,IAAI,CAACE,MAAL,GAAc,CAAf,CAApB;;QACA,I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edOutError","decode","encode","Encoding","_getPollInterval","_buildTx","pollForQueries","oracleId","onQuery","interval","onNode","options","knownQueryIds","Set","checkNewQueries","queries","getOracleQueriesByPubkey","oracleQueries","filter","id","has","forEach","add","length","stopped","catch","console","error","pollForQueryResponse","queryId","height","ttl","response","getOracleQueryByPubkeyAndQueryId","responseBuffer","toString","getHeight","getQueryObject","record","decodedQuery","query","decodedResponse","respond","opt","respondToQuery","pollForResponse","postQueryToOracle","queryFee","getOracleByPubkey","senderId","onAccount","address","oracleQueryTx","OracleQueryTx","queryTtlType","type","queryTtlValue","value","responseTtlType","responseTtlValue","nonce","tx","extendOracleTtl","oracleExtendTx","OracleExtendTx","oracleTtlType","oracleTtlValue","callerId","getOracleObject","oracleRespondTx","OracleResponseTx","pollQueries","postQuery","extendOracle","getQuery","name","handler","args","lastArg","constructor","Object","assign","push","registerOracle","queryFormat","responseFormat","accountId","oracleRegisterTx","OracleRegisterTx","OracleAddress"],"sources":["../src/oracle.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2022 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Oracle methods - routines to interact with the æternity oracle system\n *\n * The high-level description of the oracle system is\n * https://github.com/aeternity/protocol/blob/master/ORACLE.md in the protocol\n * repository.\n */\n\nimport BigNumber from 'bignumber.js';\nimport { send, SendOptions } from './spend';\nimport { mapObject, pause } from './utils/other';\nimport { oracleQueryId } from './tx/builder/helpers';\nimport { unpackTx } from './tx/builder';\nimport {\n ORACLE_TTL,\n ORACLE_TTL_TYPES,\n QUERY_FEE,\n QUERY_TTL,\n RESPONSE_TTL,\n} from './tx/builder/schema';\nimport { Tag } from './tx/builder/constants';\nimport { RequestTimedOutError } from './utils/errors';\nimport {\n decode, encode, Encoded, Encoding,\n} from './utils/encoder';\nimport { _getPollInterval } from './chain';\nimport { _buildTx, BuildTxOptions } from './tx';\nimport Node from './Node';\nimport AccountBase from './account/Base';\n\ntype OracleQueries = Awaited<ReturnType<Node['getOracleQueriesByPubkey']>>['oracleQueries'];\n\n/**\n * Poll for oracle queries\n * @category oracle\n * @param oracleId - Oracle public key\n * @param onQuery - OnQuery callback\n * @param options - Options object\n * @param options.interval - Poll interval(default: 5000)\n * @param options.onNode - Node to use\n * @returns Callback to stop polling function\n */\nexport function pollForQueries(\n oracleId: Encoded.OracleAddress,\n onQuery: (queries: OracleQueries) => void,\n { interval, onNode, ...options }: { interval?: number; onNode: Node }\n & Parameters<typeof _getPollInterval>[1],\n): () => void {\n interval ??= _getPollInterval('microblock', options);\n const knownQueryIds = new Set();\n const checkNewQueries = async (): Promise<void> => {\n const queries = ((await onNode.getOracleQueriesByPubkey(oracleId)).oracleQueries ?? [])\n .filter(({ id }) => !knownQueryIds.has(id));\n queries.forEach(({ id }) => knownQueryIds.add(id));\n if (queries.length > 0) onQuery(queries);\n };\n\n let stopped = false;\n\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n (async () => {\n while (!stopped) { // eslint-disable-line no-unmodified-loop-condition\n // TODO: allow to handle this error somehow\n await checkNewQueries().catch(console.error);\n await pause(interval);\n }\n })();\n return () => { stopped = true; };\n}\n\n/**\n * Poll for oracle query response\n * @category oracle\n * @param oracleId - Oracle public key\n * @param queryId - Oracle Query id\n * @param options - Options object\n * @param options.interval - Poll interval\n * @param options.onNode - Node to use\n * @returns OracleQuery object\n */\nexport async function pollForQueryResponse(\n oracleId: Encoded.OracleAddress,\n queryId: Encoded.OracleQueryId,\n { interval, onNode, ...options }:\n { interval?: number; onNode: Node } & Parameters<typeof _getPollInterval>[1],\n): Promise<string> {\n interval ??= _getPollInterval('microblock', options);\n let height;\n let ttl;\n let response;\n do {\n if (height != null) await pause(interval);\n ({ response, ttl } = await onNode.getOracleQueryByPubkeyAndQueryId(oracleId, queryId));\n const responseBuffer = decode(response as Encoded.OracleResponse);\n if (responseBuffer.length > 0) return responseBuffer.toString();\n height = await this.getHeight();\n } while (ttl >= height);\n throw new RequestTimedOutError(height);\n}\n\n/**\n * Constructor for OracleQuery Object (helper object for using OracleQuery)\n * @category oracle\n * @param oracleId - Oracle public key\n * @param queryId - Oracle Query id\n * @param options - Options\n * @returns OracleQuery object\n */\nexport async function getQueryObject(\n oracleId: Encoded.OracleAddress,\n queryId: Encoded.OracleQueryId,\n options: RespondToQueryOptions & Parameters<typeof pollForQueryResponse>[2],\n): Promise<GetQueryObjectReturnType> {\n const record = await options.onNode.getOracleQueryByPubkeyAndQueryId(oracleId, queryId);\n return {\n ...record,\n decodedQuery: decode(record.query as Encoded.OracleQueryId).toString(),\n decodedResponse: decode(record.response as Encoded.OracleResponse).toString(),\n respond: async (response, opt) => (\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n respondToQuery(oracleId, queryId, response, { ...options, ...opt })\n ),\n pollForResponse: async (opt) => pollForQueryResponse(oracleId, queryId, { ...options, ...opt }),\n };\n}\n\ninterface GetQueryObjectReturnType extends Awaited<ReturnType<Node['getOracleQueryByPubkeyAndQueryId']>> {\n decodedQuery: string;\n decodedResponse: string;\n respond: (response: string, options?: Parameters<typeof respondToQuery>[3]) =>\n ReturnType<typeof respondToQuery>;\n pollForResponse: (options?: Parameters<typeof pollForQueryResponse>[2]) =>\n ReturnType<typeof pollForQueryResponse>;\n}\n\n/**\n * Post query to oracle\n * @category oracle\n * @param oracleId - Oracle public key\n * @param query - Oracle query object\n * @param options - Options object\n * @param options.queryTtl - queryTtl Oracle query time to leave\n * @param options.responseTtl - queryFee Oracle query response time to leave\n * @param options.queryFee - queryFee Oracle query fee\n * @param options.fee - fee Transaction fee\n * @param options.ttl - Transaction time to leave\n * @returns Query object\n */\nexport async function postQueryToOracle(\n oracleId: Encoded.OracleAddress,\n query: string,\n options: PostQueryToOracleOptions,\n): Promise<Awaited<ReturnType<typeof send>> & Awaited<ReturnType<typeof getQueryObject>>> {\n options.queryFee ??= (await options.onNode.getOracleByPubkey(oracleId)).queryFee.toString();\n const senderId = await options.onAccount.address(options);\n\n const oracleQueryTx = await _buildTx(Tag.OracleQueryTx, {\n queryTtlType: QUERY_TTL.type,\n queryTtlValue: QUERY_TTL.value,\n responseTtlType: RESPONSE_TTL.type,\n responseTtlValue: RESPONSE_TTL.value,\n ...options,\n oracleId,\n senderId,\n query,\n });\n const { nonce } = unpackTx(oracleQueryTx, Tag.OracleQueryTx).tx;\n const queryId = oracleQueryId(senderId, nonce, oracleId);\n return {\n ...await send(oracleQueryTx, options),\n ...await getQueryObject(oracleId, queryId, options),\n };\n}\n\ntype PostQueryToOracleOptionsType = Parameters<typeof send>[1]\n& Parameters<typeof getQueryObject>[2]\n& BuildTxOptions<Tag.OracleQueryTx, 'oracleId' | 'senderId' | 'query' | 'queryTtlType' | 'queryTtlValue' | 'responseTtlType' | 'responseTtlValue'>\n& {\n queryTtlType?: ORACLE_TTL_TYPES;\n queryTtlValue?: number;\n responseTtlType?: ORACLE_TTL_TYPES;\n responseTtlValue?: number;\n};\ninterface PostQueryToOracleOptions extends PostQueryToOracleOptionsType {}\n\n/**\n * Extend oracle ttl\n * @category oracle\n * @param oracleId - Oracle public key\n * @param options - Options object\n * @param options.fee - fee Transaction fee\n * @param options.ttl - Transaction time to leave\n * @param options.oracleTtlType - Oracle time to leave for extend\n * @param options.oracleTtlValue - Oracle time to leave for extend\n * @returns Oracle object\n */\nexport async function extendOracleTtl(\n oracleId: Encoded.OracleAddress,\n options: ExtendOracleTtlOptions,\n): Promise<Awaited<ReturnType<typeof send>> & Awaited<ReturnType<typeof getOracleObject>>> {\n const oracleExtendTx = await _buildTx(Tag.OracleExtendTx, {\n oracleTtlType: ORACLE_TTL.type,\n oracleTtlValue: ORACLE_TTL.value,\n ...options,\n callerId: await options.onAccount.address(options),\n oracleId,\n });\n return {\n ...await send(oracleExtendTx, options),\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n ...await getOracleObject(oracleId, options),\n };\n}\n\ntype ExtendOracleTtlOptionsType = SendOptions & Parameters<typeof getOracleObject>[1]\n& BuildTxOptions<Tag.OracleExtendTx, 'oracleTtlType' | 'oracleTtlValue' | 'callerId' | 'oracleId'>\n& { oracleTtlType?: ORACLE_TTL_TYPES; oracleTtlValue?: number };\ninterface ExtendOracleTtlOptions extends ExtendOracleTtlOptionsType {}\n\n/**\n * Extend oracle ttl\n * @category oracle\n * @param oracleId - Oracle public key\n * @param queryId - Oracle query id\n * @param response - Oracle query response\n * @param options - Options object\n * @param options.responseTtl - responseTtl Query response time to leave\n * @param options.fee - Transaction fee\n * @param options.ttl - Transaction time to leave\n * @returns Oracle object\n */\nexport async function respondToQuery(\n oracleId: Encoded.OracleAddress,\n queryId: Encoded.OracleQueryId,\n response: string,\n options: RespondToQueryOptions,\n): Promise<Awaited<ReturnType<typeof send>> & Awaited<ReturnType<typeof getOracleObject>>> {\n const oracleRespondTx = await _buildTx(Tag.OracleResponseTx, {\n responseTtlType: RESPONSE_TTL.type,\n responseTtlValue: RESPONSE_TTL.value,\n ...options,\n callerId: await options.onAccount.address(options),\n oracleId,\n queryId,\n response,\n });\n return {\n ...await send(oracleRespondTx, options),\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n ...await getOracleObject(oracleId, options),\n };\n}\n\ntype RespondToQueryOptionsType = SendOptions & Parameters<typeof getOracleObject>[1]\n& BuildTxOptions<Tag.OracleResponseTx, 'callerId' | 'oracleId' | 'queryId' | 'response' | 'responseTtlType' | 'responseTtlValue'>\n& { responseTtlType?: ORACLE_TTL_TYPES; responseTtlValue?: number };\ninterface RespondToQueryOptions extends RespondToQueryOptionsType {}\n\n/**\n * Constructor for Oracle Object (helper object for using Oracle)\n * @category oracle\n * @param oracleId - Oracle public key\n * @param options - Options\n * @returns Oracle object\n */\nexport async function getOracleObject(\n oracleId: Encoded.OracleAddress,\n options: { onNode: Node; onAccount: AccountBase },\n): Promise<GetOracleObjectReturnType> {\n return {\n ...await options.onNode.getOracleByPubkey(oracleId),\n queries: (await options.onNode.getOracleQueriesByPubkey(oracleId)).oracleQueries,\n ...mapObject<Function, Function>(\n {\n pollQueries: pollForQueries,\n postQuery: postQueryToOracle,\n respondToQuery,\n extendOracle: extendOracleTtl,\n getQuery: getQueryObject,\n },\n ([name, handler]) => [\n name,\n (...args: any) => {\n const lastArg = args[args.length - 1];\n if (lastArg != null && typeof lastArg === 'object' && lastArg.constructor === Object) {\n Object.assign(lastArg, { ...options, ...lastArg });\n } else args.push(options);\n return handler(oracleId, ...args);\n },\n ],\n ),\n } as any;\n}\n\ninterface GetOracleObjectReturnType extends Awaited<ReturnType<Node['getOracleByPubkey']>> {\n id: Encoded.OracleAddress;\n queries: OracleQueries;\n // TODO: replace getOracleObject with a class\n pollQueries: (cb: Parameters<typeof pollForQueries>[1]) => ReturnType<typeof pollForQueries>;\n postQuery: Function;\n respondToQuery: Function;\n extendOracle: Function;\n getQuery: Function;\n}\n\n/**\n * Register oracle\n * @category oracle\n * @param queryFormat - Format of query\n * @param responseFormat - Format of query response\n * @param options - Options\n * @param options.queryFee - Oracle query Fee\n * @param options - Options object\n * @param options.abiVersion - Always 0 (do not use virtual machine)\n * @param options.fee - Transaction fee\n * @param options.ttl - Transaction time to leave\n * @returns Oracle object\n */\nexport async function registerOracle(\n queryFormat: string,\n responseFormat: string,\n options: RegisterOracleOptions,\n): Promise<Awaited<ReturnType<typeof send>> & Awaited<ReturnType<typeof getOracleObject>>> {\n const accountId = await options.onAccount.address(options);\n const oracleRegisterTx = await _buildTx(Tag.OracleRegisterTx, {\n queryFee: QUERY_FEE,\n oracleTtlValue: ORACLE_TTL.value,\n oracleTtlType: ORACLE_TTL.type,\n ...options,\n accountId,\n queryFormat,\n responseFormat,\n });\n return {\n ...await send(oracleRegisterTx, options),\n ...await getOracleObject(encode(decode(accountId), Encoding.OracleAddress), options),\n };\n}\n\ntype RegisterOracleOptionsType = SendOptions & Parameters<typeof getOracleObject>[1]\n& BuildTxOptions<Tag.OracleRegisterTx, 'accountId' | 'queryFormat' | 'responseFormat' | 'queryFee' | 'oracleTtlType' | 'oracleTtlValue'>\n& {\n queryFee?: number | string | BigNumber;\n oracleTtlType?: ORACLE_TTL_TYPES;\n oracleTtlValue?: number;\n};\ninterface RegisterOracleOptions extends RegisterOracleOptionsType {}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;SAGSA,I;SACAC,S,EAAWC,K;SACXC,a;SACAC,Q;SAEPC,U,EAEAC,S,EACAC,S,EACAC,Y;SAEOC,G;SACAC,oB;SAEPC,M,EAAQC,M,EAAiBC,Q;SAElBC,gB;SACAC,Q;;AAMT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAT,CACLC,QADK,EAELC,OAFK,QAKO;EAAA;;EAAA,IAFZ;IAAEC,QAAF;IAAYC,MAAZ;IAAoB,GAAGC;EAAvB,CAEY;EACZ,aAAAF,QAAQ,UAAR,uCAAAA,QAAQ,GAAKL,gBAAgB,CAAC,YAAD,EAAeO,OAAf,CAA7B;EACA,MAAMC,aAAa,GAAG,IAAIC,GAAJ,EAAtB;;EACA,MAAMC,eAAe,GAAG,YAA2B;IAAA;;IACjD,MAAMC,OAAO,GAAG,0BA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CAACiG,gBAAD,EAAmB5E,OAAnB,CAAb,CADK;IAEL,IAAG,MAAMyD,eAAe,CAAClE,MAAM,CAACD,MAAM,CAACqF,SAAD,CAAP,EAAoBnF,QAAQ,CAACsF,aAA7B,CAAP,EAAoD9E,OAApD,CAAxB;EAFK,CAAP;AAID"}
|
package/es/spend.d.ts
CHANGED
|
@@ -1,61 +1,62 @@
|
|
|
1
1
|
import { sendTransaction, resolveName } from './chain';
|
|
2
2
|
import { BuildTxOptions } from './tx';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { TX_TYPE, AensName } from './tx/builder/schema';
|
|
3
|
+
import { Encoded } from './utils/encoder';
|
|
4
|
+
import { Tag, AensName } from './tx/builder/constants';
|
|
6
5
|
import AccountBase from './account/Base';
|
|
7
6
|
/**
|
|
8
7
|
* Sign and post a transaction to the chain
|
|
8
|
+
* @category chain
|
|
9
9
|
* @param tx - Transaction
|
|
10
10
|
* @param options - Options
|
|
11
11
|
* @param options.verify - Verify transaction before broadcast, throw error if not
|
|
12
12
|
* valid
|
|
13
13
|
* @returns Transaction
|
|
14
14
|
*/
|
|
15
|
-
export declare function send(tx:
|
|
16
|
-
declare type SendOptionsType = Parameters<AccountBase['signTransaction']>[1] & Parameters<typeof sendTransaction>[1] &
|
|
15
|
+
export declare function send(tx: Encoded.Transaction, options: SendOptions): Promise<SendReturnType>;
|
|
16
|
+
declare type SendOptionsType = Parameters<AccountBase['signTransaction']>[1] & Parameters<typeof sendTransaction>[1] & {
|
|
17
|
+
onAccount: AccountBase;
|
|
18
|
+
};
|
|
17
19
|
export interface SendOptions extends SendOptionsType {
|
|
18
20
|
}
|
|
19
21
|
interface SendReturnType extends Awaited<ReturnType<typeof sendTransaction>> {
|
|
20
22
|
}
|
|
21
|
-
export declare function signUsingGA(tx: EncodedData<'tx'>, { authData, authFun, ...options }: {
|
|
22
|
-
authData: Parameters<typeof createMetaTx>[1];
|
|
23
|
-
authFun: Parameters<typeof createMetaTx>[2];
|
|
24
|
-
} & Parameters<typeof createMetaTx>[3]): Promise<EncodedData<'tx'>>;
|
|
25
23
|
/**
|
|
26
24
|
* Send coins to another account
|
|
25
|
+
* @category chain
|
|
27
26
|
* @param amount - Amount to spend
|
|
28
27
|
* @param recipientIdOrName - Address or name of recipient account
|
|
29
28
|
* @param options - Options
|
|
30
29
|
* @returns Transaction
|
|
31
30
|
*/
|
|
32
|
-
export declare function spend(amount: number | string, recipientIdOrName:
|
|
33
|
-
declare type SpendOptionsType = BuildTxOptions<
|
|
31
|
+
export declare function spend(amount: number | string, recipientIdOrName: Encoded.AccountAddress | AensName, options: SpendOptions): ReturnType<typeof send>;
|
|
32
|
+
declare type SpendOptionsType = BuildTxOptions<Tag.SpendTx, 'senderId' | 'recipientId' | 'amount'> & Parameters<typeof resolveName>[2] & {
|
|
34
33
|
onAccount: AccountBase;
|
|
35
34
|
} & SendOptions;
|
|
36
35
|
interface SpendOptions extends SpendOptionsType {
|
|
37
36
|
}
|
|
38
37
|
/**
|
|
39
38
|
* Send a fraction of coin balance to another account
|
|
39
|
+
* @category chain
|
|
40
40
|
* @param fraction - Fraction of balance to spend (between 0 and 1)
|
|
41
41
|
* @param recipientIdOrName - Address or name of recipient account
|
|
42
42
|
* @param options - Options
|
|
43
43
|
* @returns Transaction
|
|
44
44
|
*/
|
|
45
|
-
export declare function transferFunds(fraction: number | string, recipientIdOrName: AensName |
|
|
46
|
-
declare type TransferFundsOptionsType = BuildTxOptions<
|
|
45
|
+
export declare function transferFunds(fraction: number | string, recipientIdOrName: AensName | Encoded.AccountAddress, options: TransferFundsOptions): ReturnType<typeof send>;
|
|
46
|
+
declare type TransferFundsOptionsType = BuildTxOptions<Tag.SpendTx, 'senderId' | 'recipientId' | 'amount'> & Parameters<typeof resolveName>[2] & {
|
|
47
47
|
onAccount: AccountBase;
|
|
48
48
|
} & SendOptions;
|
|
49
49
|
interface TransferFundsOptions extends TransferFundsOptionsType {
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Submit transaction of another account paying for it (fee and gas)
|
|
53
|
+
* @category chain
|
|
53
54
|
* @param transaction - tx_<base64>-encoded transaction
|
|
54
55
|
* @param options - Options
|
|
55
56
|
* @returns Object Transaction
|
|
56
57
|
*/
|
|
57
|
-
export declare function payForTransaction(transaction:
|
|
58
|
-
interface PayForTransactionOptions extends BuildTxOptions<
|
|
58
|
+
export declare function payForTransaction(transaction: Encoded.Transaction, options: PayForTransactionOptions): ReturnType<typeof send>;
|
|
59
|
+
interface PayForTransactionOptions extends BuildTxOptions<Tag.PayingForTx, 'payerId' | 'tx'>, SendOptions {
|
|
59
60
|
onAccount: AccountBase;
|
|
60
61
|
}
|
|
61
62
|
export {};
|
package/es/spend.mjs
CHANGED
|
@@ -14,16 +14,16 @@
|
|
|
14
14
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
15
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
*/
|
|
17
|
+
import BigNumber from 'bignumber.js';
|
|
17
18
|
import { sendTransaction, getAccount, getBalance, resolveName } from "./chain.mjs";
|
|
18
19
|
import { _buildTx } from "./tx/index.mjs";
|
|
19
20
|
import { buildTxHash, unpackTx } from "./tx/builder/index.mjs";
|
|
20
|
-
import BigNumber from 'bignumber.js';
|
|
21
21
|
import { ArgumentError } from "./utils/errors.mjs";
|
|
22
|
-
import {
|
|
23
|
-
import { TX_TYPE } from "./tx/builder/schema.mjs";
|
|
22
|
+
import { Tag } from "./tx/builder/constants.mjs";
|
|
24
23
|
|
|
25
24
|
/**
|
|
26
25
|
* Sign and post a transaction to the chain
|
|
26
|
+
* @category chain
|
|
27
27
|
* @param tx - Transaction
|
|
28
28
|
* @param options - Options
|
|
29
29
|
* @param options.verify - Verify transaction before broadcast, throw error if not
|
|
@@ -31,41 +31,28 @@ import { TX_TYPE } from "./tx/builder/schema.mjs";
|
|
|
31
31
|
* @returns Transaction
|
|
32
32
|
*/
|
|
33
33
|
export async function send(tx, options) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
const signed = contractId != null // TODO: not required arguments become required depending on account type, can ga be extracted?
|
|
41
|
-
? await signUsingGA(tx, {
|
|
42
|
-
authData: {},
|
|
43
|
-
...options,
|
|
44
|
-
authFun: authFun
|
|
45
|
-
}) : await options.onAccount.signTransaction(tx, options);
|
|
34
|
+
// TODO: detect authFun in AccountGa
|
|
35
|
+
const authFun = options.innerTx === true ? undefined : (await getAccount(await options.onAccount.address(options), options)).authFun;
|
|
36
|
+
const signed = await options.onAccount.signTransaction(tx, { ...options,
|
|
37
|
+
authFun,
|
|
38
|
+
networkId: (await options.onNode.getStatus()).networkId
|
|
39
|
+
});
|
|
46
40
|
return options.innerTx === true ? {
|
|
47
41
|
hash: buildTxHash(signed),
|
|
48
42
|
rawTx: signed
|
|
49
|
-
} :
|
|
50
|
-
}
|
|
51
|
-
export async function signUsingGA(tx, _ref) {
|
|
52
|
-
let {
|
|
53
|
-
authData,
|
|
54
|
-
authFun,
|
|
55
|
-
...options
|
|
56
|
-
} = _ref;
|
|
57
|
-
return await createMetaTx(tx, authData, authFun, options);
|
|
43
|
+
} : sendTransaction(signed, options);
|
|
58
44
|
}
|
|
45
|
+
|
|
59
46
|
/**
|
|
60
47
|
* Send coins to another account
|
|
48
|
+
* @category chain
|
|
61
49
|
* @param amount - Amount to spend
|
|
62
50
|
* @param recipientIdOrName - Address or name of recipient account
|
|
63
51
|
* @param options - Options
|
|
64
52
|
* @returns Transaction
|
|
65
53
|
*/
|
|
66
|
-
|
|
67
54
|
export async function spend(amount, recipientIdOrName, options) {
|
|
68
|
-
return
|
|
55
|
+
return send(await _buildTx(Tag.SpendTx, { ...options,
|
|
69
56
|
senderId: await options.onAccount.address(options),
|
|
70
57
|
recipientId: await resolveName(recipientIdOrName, 'account_pubkey', options),
|
|
71
58
|
amount
|
|
@@ -75,6 +62,7 @@ export async function spend(amount, recipientIdOrName, options) {
|
|
|
75
62
|
|
|
76
63
|
/**
|
|
77
64
|
* Send a fraction of coin balance to another account
|
|
65
|
+
* @category chain
|
|
78
66
|
* @param fraction - Fraction of balance to spend (between 0 and 1)
|
|
79
67
|
* @param recipientIdOrName - Address or name of recipient account
|
|
80
68
|
* @param options - Options
|
|
@@ -93,14 +81,14 @@ export async function transferFunds(fraction, recipientIdOrName, options) {
|
|
|
93
81
|
tx: {
|
|
94
82
|
fee
|
|
95
83
|
}
|
|
96
|
-
} = unpackTx(await _buildTx(
|
|
84
|
+
} = unpackTx(await _buildTx(Tag.SpendTx, { ...options,
|
|
97
85
|
senderId,
|
|
98
86
|
recipientId,
|
|
99
87
|
amount: desiredAmount
|
|
100
|
-
}),
|
|
88
|
+
}), Tag.SpendTx); // Reducing of the amount may reduce transaction fee, so this is not completely accurate
|
|
101
89
|
|
|
102
90
|
const amount = desiredAmount.plus(fee).gt(balance) ? balance.minus(fee) : desiredAmount;
|
|
103
|
-
return
|
|
91
|
+
return send(await _buildTx(Tag.SpendTx, { ...options,
|
|
104
92
|
senderId,
|
|
105
93
|
recipientId,
|
|
106
94
|
amount
|
|
@@ -109,12 +97,13 @@ export async function transferFunds(fraction, recipientIdOrName, options) {
|
|
|
109
97
|
|
|
110
98
|
/**
|
|
111
99
|
* Submit transaction of another account paying for it (fee and gas)
|
|
100
|
+
* @category chain
|
|
112
101
|
* @param transaction - tx_<base64>-encoded transaction
|
|
113
102
|
* @param options - Options
|
|
114
103
|
* @returns Object Transaction
|
|
115
104
|
*/
|
|
116
105
|
export async function payForTransaction(transaction, options) {
|
|
117
|
-
return
|
|
106
|
+
return send(await _buildTx(Tag.PayingForTx, { ...options,
|
|
118
107
|
payerId: await options.onAccount.address(options),
|
|
119
108
|
tx: transaction
|
|
120
109
|
}), options);
|
package/es/spend.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spend.mjs","names":["sendTransaction","getAccount","getBalance","resolveName","_buildTx","buildTxHash","unpackTx","
|
|
1
|
+
{"version":3,"file":"spend.mjs","names":["BigNumber","sendTransaction","getAccount","getBalance","resolveName","_buildTx","buildTxHash","unpackTx","ArgumentError","Tag","send","tx","options","authFun","innerTx","undefined","onAccount","address","signed","signTransaction","networkId","onNode","getStatus","hash","rawTx","spend","amount","recipientIdOrName","SpendTx","senderId","recipientId","transferFunds","fraction","balance","bind","desiredAmount","times","integerValue","ROUND_HALF_UP","fee","plus","gt","minus","payForTransaction","transaction","PayingForTx","payerId"],"sources":["../src/spend.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2022 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\nimport BigNumber from 'bignumber.js';\nimport {\n sendTransaction, getAccount, getBalance, resolveName,\n} from './chain';\nimport { _buildTx, BuildTxOptions } from './tx';\nimport { buildTxHash, unpackTx } from './tx/builder';\nimport { ArgumentError } from './utils/errors';\nimport { Encoded, Encoding } from './utils/encoder';\nimport { Tag, AensName } from './tx/builder/constants';\nimport AccountBase from './account/Base';\n\n/**\n * Sign and post a transaction to the chain\n * @category chain\n * @param tx - Transaction\n * @param options - Options\n * @param options.verify - Verify transaction before broadcast, throw error if not\n * valid\n * @returns Transaction\n */\nexport async function send(\n tx: Encoded.Transaction,\n options: SendOptions,\n): Promise<SendReturnType> {\n // TODO: detect authFun in AccountGa\n const authFun = options.innerTx === true\n ? undefined\n : (await getAccount(await options.onAccount.address(options), options)).authFun;\n\n const signed = await options.onAccount.signTransaction(tx, {\n ...options,\n authFun,\n networkId: (await options.onNode.getStatus()).networkId,\n });\n\n return options.innerTx === true\n ? { hash: buildTxHash(signed), rawTx: signed }\n : sendTransaction(signed, options);\n}\n\ntype SendOptionsType = Parameters<AccountBase['signTransaction']>[1]\n& Parameters<typeof sendTransaction>[1] & { onAccount: AccountBase };\nexport interface SendOptions extends SendOptionsType {}\ninterface SendReturnType extends Awaited<ReturnType<typeof sendTransaction>> {}\n\n/**\n * Send coins to another account\n * @category chain\n * @param amount - Amount to spend\n * @param recipientIdOrName - Address or name of recipient account\n * @param options - Options\n * @returns Transaction\n */\nexport async function spend(\n amount: number | string,\n recipientIdOrName: Encoded.AccountAddress | AensName,\n options: SpendOptions,\n): ReturnType<typeof send> {\n return send(\n await _buildTx(Tag.SpendTx, {\n ...options,\n senderId: await options.onAccount.address(options),\n recipientId: await resolveName<Encoding.AccountAddress>(\n recipientIdOrName,\n 'account_pubkey',\n options,\n ),\n amount,\n }),\n options,\n );\n}\n\ntype SpendOptionsType = BuildTxOptions<Tag.SpendTx, 'senderId' | 'recipientId' | 'amount'>\n& Parameters<typeof resolveName>[2] & { onAccount: AccountBase } & SendOptions;\ninterface SpendOptions extends SpendOptionsType {}\n\n// TODO: Rename to spendFraction\n/**\n * Send a fraction of coin balance to another account\n * @category chain\n * @param fraction - Fraction of balance to spend (between 0 and 1)\n * @param recipientIdOrName - Address or name of recipient account\n * @param options - Options\n * @returns Transaction\n */\nexport async function transferFunds(\n fraction: number | string,\n recipientIdOrName: AensName | Encoded.AccountAddress,\n options: TransferFundsOptions,\n): ReturnType<typeof send> {\n if (fraction < 0 || fraction > 1) {\n throw new ArgumentError('fraction', 'a number between 0 and 1', fraction);\n }\n const recipientId = await resolveName<Encoding.AccountAddress>(\n recipientIdOrName,\n 'account_pubkey',\n options,\n );\n const senderId = await options.onAccount.address(options);\n const balance = new BigNumber(\n await getBalance.bind(options.onAccount)(senderId, options),\n );\n const desiredAmount = balance.times(fraction).integerValue(BigNumber.ROUND_HALF_UP);\n const { tx: { fee } } = unpackTx(\n await _buildTx(Tag.SpendTx, {\n ...options, senderId, recipientId, amount: desiredAmount,\n }),\n Tag.SpendTx,\n );\n // Reducing of the amount may reduce transaction fee, so this is not completely accurate\n const amount = desiredAmount.plus(fee).gt(balance) ? balance.minus(fee) : desiredAmount;\n return send(\n await _buildTx(Tag.SpendTx, {\n ...options, senderId, recipientId, amount,\n }),\n options,\n );\n}\n\ntype TransferFundsOptionsType = BuildTxOptions<Tag.SpendTx, 'senderId' | 'recipientId' | 'amount'>\n& Parameters<typeof resolveName>[2] & { onAccount: AccountBase } & SendOptions;\ninterface TransferFundsOptions extends TransferFundsOptionsType {}\n\n/**\n * Submit transaction of another account paying for it (fee and gas)\n * @category chain\n * @param transaction - tx_<base64>-encoded transaction\n * @param options - Options\n * @returns Object Transaction\n */\nexport async function payForTransaction(\n transaction: Encoded.Transaction,\n options: PayForTransactionOptions,\n): ReturnType<typeof send> {\n return send(\n await _buildTx(\n Tag.PayingForTx,\n { ...options, payerId: await options.onAccount.address(options), tx: transaction },\n ),\n options,\n );\n}\n\ninterface PayForTransactionOptions extends\n BuildTxOptions<Tag.PayingForTx, 'payerId' | 'tx'>, SendOptions {\n onAccount: AccountBase;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAP,MAAsB,cAAtB;SAEEC,e,EAAiBC,U,EAAYC,U,EAAYC,W;SAElCC,Q;SACAC,W,EAAaC,Q;SACbC,a;SAEAC,G;;AAGT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,IAAf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AAOF,IAAI,CACT,MAAML,QAAQ,CACZI,GAAG,CAACoC,WADQ,EAEZ,EAAE,GAAGjC,OAAL;IAAckC,OAAO,EAAE,MAAMlC,OAAO,CAACI,SAAR,CAAkBC,OAAlB,CAA0BL,OAA1B,CAA7B;IAAiED,EAAE,EAAEiC;EAArE,CAFY,CADL,EAKThC,OALS,CAAX;AAOD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Encoded } from '../../utils/encoder';
|
|
3
|
+
/**
|
|
4
|
+
* Map of prefix to ID tag constant
|
|
5
|
+
* @see {@link https://github.com/aeternity/protocol/blob/master/serializations.md#the-id-type}
|
|
6
|
+
* @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_id.erl#L97-L102}
|
|
7
|
+
* @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_api_encoder.erl#L163-L168}
|
|
8
|
+
*/
|
|
9
|
+
declare const idTagToEncoding: readonly [Encoded.Encoding.AccountAddress, Encoded.Encoding.Name, Encoded.Encoding.Commitment, Encoded.Encoding.OracleAddress, Encoded.Encoding.ContractAddress, Encoded.Encoding.Channel];
|
|
10
|
+
declare type AddressEncodings = typeof idTagToEncoding[number];
|
|
11
|
+
/**
|
|
12
|
+
* Utility function to create and _id type
|
|
13
|
+
* @category transaction builder
|
|
14
|
+
* @param hashId - Encoded hash
|
|
15
|
+
* @returns Buffer Buffer with ID tag and decoded HASh
|
|
16
|
+
*/
|
|
17
|
+
export declare function writeId(hashId: Encoded.Generic<AddressEncodings>): Buffer;
|
|
18
|
+
/**
|
|
19
|
+
* Utility function to read and _id type
|
|
20
|
+
* @category transaction builder
|
|
21
|
+
* @param buf - Data
|
|
22
|
+
* @returns Encoided hash string with prefix
|
|
23
|
+
*/
|
|
24
|
+
export declare function readId(buf: Buffer): Encoded.Generic<AddressEncodings>;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import _buffer from "buffer";
|
|
2
|
+
const {
|
|
3
|
+
Buffer: _Buffer
|
|
4
|
+
} = _buffer;
|
|
5
|
+
import { ArgumentError, PrefixNotFoundError, TagNotFoundError } from "../../utils/errors.mjs";
|
|
6
|
+
import { toBytes } from "../../utils/bytes.mjs";
|
|
7
|
+
import { decode, encode, Encoding } from "../../utils/encoder.mjs";
|
|
8
|
+
import { isItemOfArray } from "../../utils/other.mjs";
|
|
9
|
+
/**
|
|
10
|
+
* Map of prefix to ID tag constant
|
|
11
|
+
* @see {@link https://github.com/aeternity/protocol/blob/master/serializations.md#the-id-type}
|
|
12
|
+
* @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_id.erl#L97-L102}
|
|
13
|
+
* @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_api_encoder.erl#L163-L168}
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const idTagToEncoding = [Encoding.AccountAddress, Encoding.Name, Encoding.Commitment, Encoding.OracleAddress, Encoding.ContractAddress, Encoding.Channel];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Utility function to create and _id type
|
|
20
|
+
* @category transaction builder
|
|
21
|
+
* @param hashId - Encoded hash
|
|
22
|
+
* @returns Buffer Buffer with ID tag and decoded HASh
|
|
23
|
+
*/
|
|
24
|
+
export function writeId(hashId) {
|
|
25
|
+
if (typeof hashId !== 'string') throw new ArgumentError('hashId', 'a string', hashId);
|
|
26
|
+
const encoding = hashId.slice(0, 2);
|
|
27
|
+
if (!isItemOfArray(encoding, idTagToEncoding)) throw new TagNotFoundError(encoding);
|
|
28
|
+
const idTag = idTagToEncoding.indexOf(encoding) + 1;
|
|
29
|
+
return _Buffer.from([...toBytes(idTag), ...decode(hashId)]);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Utility function to read and _id type
|
|
33
|
+
* @category transaction builder
|
|
34
|
+
* @param buf - Data
|
|
35
|
+
* @returns Encoided hash string with prefix
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
export function readId(buf) {
|
|
39
|
+
const idTag = _Buffer.from(buf).readUIntBE(0, 1);
|
|
40
|
+
|
|
41
|
+
const encoding = idTagToEncoding[idTag - 1];
|
|
42
|
+
if (encoding == null) throw new PrefixNotFoundError(idTag);
|
|
43
|
+
return encode(buf.slice(1, buf.length), encoding);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=address.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.mjs","names":["ArgumentError","PrefixNotFoundError","TagNotFoundError","toBytes","decode","encode","Encoding","isItemOfArray","idTagToEncoding","AccountAddress","Name","Commitment","OracleAddress","ContractAddress","Channel","writeId","hashId","encoding","slice","idTag","indexOf","from","readId","buf","readUIntBE","length"],"sources":["../../../src/tx/builder/address.ts"],"sourcesContent":["import { ArgumentError, PrefixNotFoundError, TagNotFoundError } from '../../utils/errors';\nimport { toBytes } from '../../utils/bytes';\nimport {\n decode, encode, Encoded, Encoding,\n} from '../../utils/encoder';\nimport { isItemOfArray } from '../../utils/other';\n\n/**\n * Map of prefix to ID tag constant\n * @see {@link https://github.com/aeternity/protocol/blob/master/serializations.md#the-id-type}\n * @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_id.erl#L97-L102}\n * @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_api_encoder.erl#L163-L168}\n */\nconst idTagToEncoding = [\n Encoding.AccountAddress,\n Encoding.Name,\n Encoding.Commitment,\n Encoding.OracleAddress,\n Encoding.ContractAddress,\n Encoding.Channel,\n] as const;\n\ntype AddressEncodings = typeof idTagToEncoding[number];\n\n/**\n * Utility function to create and _id type\n * @category transaction builder\n * @param hashId - Encoded hash\n * @returns Buffer Buffer with ID tag and decoded HASh\n */\nexport function writeId(hashId: Encoded.Generic<AddressEncodings>): Buffer {\n if (typeof hashId !== 'string') throw new ArgumentError('hashId', 'a string', hashId);\n const encoding = hashId.slice(0, 2);\n if (!isItemOfArray(encoding, idTagToEncoding)) throw new TagNotFoundError(encoding);\n const idTag = idTagToEncoding.indexOf(encoding) + 1;\n return Buffer.from([...toBytes(idTag), ...decode(hashId)]);\n}\n\n/**\n * Utility function to read and _id type\n * @category transaction builder\n * @param buf - Data\n * @returns Encoided hash string with prefix\n */\nexport function readId(buf: Buffer): Encoded.Generic<AddressEncodings> {\n const idTag = Buffer.from(buf).readUIntBE(0, 1);\n const encoding = idTagToEncoding[idTag - 1];\n if (encoding == null) throw new PrefixNotFoundError(idTag);\n return encode(buf.slice(1, buf.length), encoding);\n}\n"],"mappings":";;;;SAASA,a,EAAeC,mB,EAAqBC,gB;SACpCC,O;SAEPC,M,EAAQC,M,EAAiBC,Q;SAElBC,a;AAET;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,eAAe,GAAG,CACtBF,QAAQ,CAACG,cADa,EAEtBH,QAAQ,CAACI,IAFa,EAGtBJ,QAAQ,CAACK,UAHa,EAItBL,QAAQ,CAACM,aAJa,EAKtBN,QAAQ,CAACO,eALa,EAMtBP,QAAQ,CAACQ,OANa,CAAxB;;AAWA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,OAAT,CAAiBC,MAAjB,EAAoE;EACzE,IAAI,OAAOA,MAAP,KAAkB,QAAtB,EAAgC,MAAM,IAAIhB,aAAJ,CAAkB,QAAlB,EAA4B,UAA5B,EAAwCgB,MAAxC,CAAN;EAChC,MAAMC,QAAQ,GAAGD,MAAM,CAACE,KAAP,CAAa,CAAb,EAAgB,CAAhB,CAAjB;EACA,IAAI,CAACX,aAAa,CAACU,QAAD,EAAWT,eAAX,CAAlB,EAA+C,MAAM,IAAIN,gBAAJ,CAAqBe,QAArB,CAAN;EAC/C,MAAME,KAAK,GAAGX,eAAe,CAACY,OAAhB,CAAwBH,QAAxB,IAAoC,CAAlD;EACA,OAAO,QAAOI,IAAP,CAAY,CAAC,GAAGlB,OAAO,CAACgB,KAAD,CAAX,EAAoB,GAAGf,MAAM,CAACY,MAAD,CAA7B,CAAZ,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASM,MAAT,CAAgBC,GAAhB,EAAgE;EACrE,MAAMJ,KAAK,GAAG,QAAOE,IAAP,CAAYE,GAAZ,EAAiBC,UAAjB,CAA4B,CAA5B,EAA+B,CAA/B,CAAd;;EACA,MAAMP,QAAQ,GAAGT,eAAe,CAACW,KAAK,GAAG,CAAT,CAAhC;EACA,IAAIF,QAAQ,IAAI,IAAhB,EAAsB,MAAM,IAAIhB,mBAAJ,CAAwBkB,KAAxB,CAAN;EACtB,OAAOd,MAAM,CAACkB,GAAG,CAACL,KAAJ,CAAU,CAAV,EAAaK,GAAG,CAACE,MAAjB,CAAD,EAA2BR,QAA3B,CAAb;AACD"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { EncodingType } from './../../utils/encoder';
|
|
2
1
|
import BigNumber from 'bignumber.js';
|
|
3
2
|
export declare type AensName = `${string}.chain`;
|
|
4
3
|
export declare const NAME_TTL = 180000;
|
|
@@ -11,31 +10,61 @@ export declare const NAME_FEE_BID_INCREMENT = 0.05;
|
|
|
11
10
|
export declare const NAME_BID_TIMEOUT_BLOCKS = 480;
|
|
12
11
|
export declare const NAME_MAX_LENGTH_FEE = 31;
|
|
13
12
|
export declare const NAME_BID_MAX_LENGTH = 12;
|
|
14
|
-
export declare enum POINTER_KEY_BY_PREFIX {
|
|
15
|
-
ak = "account_pubkey",
|
|
16
|
-
ok = "oracle_pubkey",
|
|
17
|
-
ct = "contract_pubkey",
|
|
18
|
-
ch = "channel"
|
|
19
|
-
}
|
|
20
13
|
export declare const NAME_BID_RANGES: {
|
|
21
14
|
[k: string]: BigNumber;
|
|
22
15
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Enum with tag types
|
|
18
|
+
* @category transaction builder
|
|
19
|
+
* @see {@link https://github.com/aeternity/protocol/blob/0f6dee3d9d1e8e2469816798f5c7587a6c918f94/serializations.md#binary-serialization}
|
|
20
|
+
* @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_chain_objects.erl#L39-L97}
|
|
21
|
+
*/
|
|
22
|
+
export declare enum Tag {
|
|
23
|
+
Account = 10,
|
|
24
|
+
SignedTx = 11,
|
|
25
|
+
SpendTx = 12,
|
|
26
|
+
OracleRegisterTx = 22,
|
|
27
|
+
OracleQueryTx = 23,
|
|
28
|
+
OracleResponseTx = 24,
|
|
29
|
+
OracleExtendTx = 25,
|
|
30
|
+
NameClaimTx = 32,
|
|
31
|
+
NamePreclaimTx = 33,
|
|
32
|
+
NameUpdateTx = 34,
|
|
33
|
+
NameRevokeTx = 35,
|
|
34
|
+
NameTransferTx = 36,
|
|
35
|
+
Contract = 40,
|
|
36
|
+
ContractCall = 41,
|
|
37
|
+
ContractCreateTx = 42,
|
|
38
|
+
ContractCallTx = 43,
|
|
39
|
+
ChannelCreateTx = 50,
|
|
40
|
+
ChannelDepositTx = 51,
|
|
41
|
+
ChannelWithdrawTx = 52,
|
|
42
|
+
ChannelForceProgressTx = 521,
|
|
43
|
+
ChannelCloseMutualTx = 53,
|
|
44
|
+
ChannelCloseSoloTx = 54,
|
|
45
|
+
ChannelSlashTx = 55,
|
|
46
|
+
ChannelSettleTx = 56,
|
|
47
|
+
ChannelOffChainTx = 57,
|
|
48
|
+
ChannelOffChainUpdateTransfer = 570,
|
|
49
|
+
ChannelOffChainUpdateDeposit = 571,
|
|
50
|
+
ChannelOffChainUpdateWithdraw = 572,
|
|
51
|
+
ChannelOffChainUpdateCreateContract = 573,
|
|
52
|
+
ChannelOffChainUpdateCallContract = 574,
|
|
53
|
+
ChannelClientReconnectTx = 575,
|
|
54
|
+
Channel = 58,
|
|
55
|
+
ChannelSnapshotSoloTx = 59,
|
|
56
|
+
TreesPoi = 60,
|
|
57
|
+
StateTrees = 62,
|
|
58
|
+
Mtree = 63,
|
|
59
|
+
MtreeValue = 64,
|
|
60
|
+
ContractsMtree = 621,
|
|
61
|
+
CallsMtree = 622,
|
|
62
|
+
ChannelsMtree = 623,
|
|
63
|
+
NameserviceMtree = 624,
|
|
64
|
+
OraclesMtree = 625,
|
|
65
|
+
AccountsMtree = 626,
|
|
66
|
+
CompilerSophia = 70,
|
|
67
|
+
GaAttachTx = 80,
|
|
68
|
+
GaMetaTx = 81,
|
|
69
|
+
PayingForTx = 82
|
|
70
|
+
}
|