@aeternity/aepp-sdk 13.0.0-alpha.0 → 13.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/aesophia_cli +0 -0
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +1 -1
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +4206 -1127
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdkBase.d.ts +3 -3
- package/es/AeSdkBase.mjs +4 -0
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkMethods.d.ts +3 -4
- package/es/AeSdkMethods.mjs.map +1 -1
- package/es/Node.d.ts +4 -3
- package/es/Node.mjs +1 -1
- package/es/Node.mjs.map +1 -1
- package/es/account/Base.d.ts +2 -2
- package/es/account/Base.mjs.map +1 -1
- package/es/account/Generalized.mjs +5 -3
- package/es/account/Generalized.mjs.map +1 -1
- package/es/account/Ledger.mjs +2 -1
- package/es/account/Ledger.mjs.map +1 -1
- package/es/account/Memory.mjs +2 -1
- package/es/account/Memory.mjs.map +1 -1
- package/es/aens.d.ts +1 -1
- package/es/aens.mjs +5 -1
- package/es/aens.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +19 -4
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
- package/es/chain.d.ts +9 -1
- package/es/chain.mjs +4 -1
- package/es/chain.mjs.map +1 -1
- package/es/channel/Base.d.ts +6 -1
- package/es/channel/Base.mjs +9 -6
- package/es/channel/Base.mjs.map +1 -1
- package/es/channel/Contract.d.ts +8 -7
- package/es/channel/Contract.mjs +1 -1
- package/es/channel/Contract.mjs.map +1 -1
- package/es/channel/Spend.d.ts +3 -1
- package/es/channel/Spend.mjs +4 -2
- package/es/channel/Spend.mjs.map +1 -1
- package/es/channel/handlers.mjs +11 -9
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/internal.mjs +3 -1
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Contract.d.ts +21 -46
- package/es/contract/Contract.mjs +69 -52
- package/es/contract/Contract.mjs.map +1 -1
- package/es/contract/compiler/Base.d.ts +81 -0
- package/es/contract/compiler/Base.mjs +5 -0
- package/es/contract/compiler/Base.mjs.map +1 -0
- package/es/contract/compiler/Cli.d.ts +23 -0
- package/es/contract/compiler/Cli.mjs +155 -0
- package/es/contract/compiler/Cli.mjs.map +1 -0
- package/es/contract/compiler/Http.d.ts +32 -0
- package/es/contract/{CompilerHttp.mjs → compiler/Http.mjs} +64 -9
- package/es/contract/compiler/Http.mjs.map +1 -0
- package/es/contract/compiler/HttpNode.d.ts +17 -0
- package/es/contract/compiler/HttpNode.mjs +26 -0
- package/es/contract/compiler/HttpNode.mjs.map +1 -0
- package/es/contract/compiler/getFileSystem.d.ts +6 -0
- package/es/contract/compiler/getFileSystem.mjs +40 -0
- package/es/contract/compiler/getFileSystem.mjs.map +1 -0
- package/es/contract/ga.d.ts +5 -4
- package/es/contract/ga.mjs +11 -2
- package/es/contract/ga.mjs.map +1 -1
- package/es/index-browser.d.ts +39 -0
- package/es/index-browser.mjs +55 -0
- package/es/index-browser.mjs.map +1 -0
- package/es/index.d.ts +4 -38
- package/es/index.mjs +4 -53
- package/es/index.mjs.map +1 -1
- package/es/oracle.mjs +1 -1
- package/es/oracle.mjs.map +1 -1
- package/es/spend.mjs +1 -3
- package/es/spend.mjs.map +1 -1
- package/es/tx/builder/constants.d.ts +28 -1
- package/es/tx/builder/constants.mjs +32 -3
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/field-types/abi-version.d.ts +10 -0
- package/es/tx/builder/field-types/abi-version.mjs +20 -0
- package/es/tx/builder/field-types/abi-version.mjs.map +1 -0
- package/es/tx/builder/field-types/address.d.ts +5 -6
- package/es/tx/builder/field-types/address.mjs +17 -8
- package/es/tx/builder/field-types/address.mjs.map +1 -1
- package/es/tx/builder/field-types/array.d.ts +7 -0
- package/es/tx/builder/field-types/array.mjs +11 -0
- package/es/tx/builder/field-types/array.mjs.map +1 -0
- package/es/tx/builder/field-types/boolean.d.ts +6 -0
- package/es/tx/builder/field-types/boolean.mjs +13 -0
- package/es/tx/builder/field-types/boolean.mjs.map +1 -0
- package/es/tx/builder/field-types/coin-amount.d.ts +1 -1
- package/es/tx/builder/field-types/coin-amount.mjs.map +1 -1
- package/es/tx/builder/field-types/ct-version.d.ts +30 -0
- package/es/tx/builder/field-types/ct-version.mjs +48 -0
- package/es/tx/builder/field-types/ct-version.mjs.map +1 -0
- package/es/tx/builder/field-types/deposit.d.ts +1 -1
- package/es/tx/builder/field-types/deposit.mjs.map +1 -1
- package/es/tx/builder/field-types/encoded.d.ts +6 -0
- package/es/tx/builder/field-types/encoded.mjs +21 -0
- package/es/tx/builder/field-types/encoded.mjs.map +1 -0
- package/es/tx/builder/field-types/entry.d.ts +11 -0
- package/es/tx/builder/field-types/entry.mjs +31 -0
- package/es/tx/builder/field-types/entry.mjs.map +1 -0
- package/es/tx/builder/field-types/enumeration.d.ts +5 -3
- package/es/tx/builder/field-types/enumeration.mjs +11 -2
- package/es/tx/builder/field-types/enumeration.mjs.map +1 -1
- package/es/tx/builder/field-types/fee.d.ts +10 -7
- package/es/tx/builder/field-types/fee.mjs +24 -20
- package/es/tx/builder/field-types/fee.mjs.map +1 -1
- package/es/tx/builder/field-types/gas-limit.d.ts +5 -2
- package/es/tx/builder/field-types/gas-limit.mjs +9 -6
- package/es/tx/builder/field-types/gas-limit.mjs.map +1 -1
- package/es/tx/builder/field-types/gas-price.d.ts +1 -1
- package/es/tx/builder/field-types/index.d.ts +66 -28
- package/es/tx/builder/field-types/index.mjs +30 -12
- package/es/tx/builder/field-types/index.mjs.map +1 -1
- package/es/tx/builder/field-types/mptree.d.ts +37 -0
- package/es/tx/builder/field-types/mptree.mjs +268 -0
- package/es/tx/builder/field-types/mptree.mjs.map +1 -0
- package/es/tx/builder/field-types/name-fee.d.ts +1 -2
- package/es/tx/builder/field-types/name-fee.mjs.map +1 -1
- package/es/tx/builder/field-types/name-id.mjs +2 -1
- package/es/tx/builder/field-types/name-id.mjs.map +1 -1
- package/es/tx/builder/field-types/pointers.mjs +2 -2
- package/es/tx/builder/field-types/pointers.mjs.map +1 -1
- package/es/tx/builder/field-types/raw.d.ts +6 -0
- package/es/tx/builder/field-types/raw.mjs +13 -0
- package/es/tx/builder/field-types/raw.mjs.map +1 -0
- package/es/tx/builder/field-types/short-u-int-const.d.ts +5 -0
- package/es/tx/builder/field-types/short-u-int-const.mjs +16 -0
- package/es/tx/builder/field-types/short-u-int-const.mjs.map +1 -0
- package/es/tx/builder/field-types/string.d.ts +6 -0
- package/es/tx/builder/field-types/string.mjs +10 -0
- package/es/tx/builder/field-types/string.mjs.map +1 -0
- package/es/tx/builder/field-types/u-int.d.ts +1 -2
- package/es/tx/builder/field-types/u-int.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +11 -29
- package/es/tx/builder/index.mjs +50 -211
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +2111 -571
- package/es/tx/builder/schema.mjs +57 -125
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +5 -20
- package/es/tx/index.mjs +31 -88
- package/es/tx/index.mjs.map +1 -1
- package/es/tx/validator.d.ts +3 -5
- package/es/tx/validator.mjs +82 -95
- package/es/tx/validator.mjs.map +1 -1
- package/es/utils/bytes.mjs +1 -1
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/errors.d.ts +3 -8
- package/es/utils/errors.mjs +1 -11
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/other.d.ts +1 -1
- package/package.json +35 -27
- package/src/AeSdkBase.ts +6 -3
- package/src/AeSdkMethods.ts +3 -4
- package/src/Node.ts +6 -3
- package/src/account/Base.ts +2 -2
- package/src/account/Generalized.ts +2 -2
- package/src/account/Ledger.ts +1 -1
- package/src/account/Memory.ts +1 -1
- package/src/aens.ts +3 -2
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +18 -7
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +2 -2
- package/src/chain.ts +5 -3
- package/src/channel/Base.ts +13 -5
- package/src/channel/Contract.ts +11 -10
- package/src/channel/Spend.ts +7 -2
- package/src/channel/handlers.ts +10 -9
- package/src/channel/internal.ts +1 -1
- package/src/contract/Contract.ts +69 -79
- package/src/contract/compiler/Base.ts +94 -0
- package/src/contract/compiler/Cli.ts +134 -0
- package/src/contract/compiler/Http.ts +124 -0
- package/src/contract/compiler/HttpNode.ts +26 -0
- package/src/contract/compiler/getFileSystem.ts +42 -0
- package/src/contract/ga.ts +9 -6
- package/src/index-browser.ts +58 -0
- package/src/index.ts +4 -56
- package/src/oracle.ts +1 -1
- package/src/spend.ts +1 -1
- package/src/tx/builder/constants.ts +32 -3
- package/src/tx/builder/field-types/abi-version.ts +21 -0
- package/src/tx/builder/field-types/address.ts +23 -13
- package/src/tx/builder/field-types/array.ts +19 -0
- package/src/tx/builder/field-types/boolean.ts +9 -0
- package/src/tx/builder/field-types/coin-amount.ts +2 -1
- package/src/tx/builder/field-types/ct-version.ts +50 -0
- package/src/tx/builder/field-types/deposit.ts +1 -1
- package/src/tx/builder/field-types/encoded.ts +27 -0
- package/src/tx/builder/field-types/entry.ts +31 -0
- package/src/tx/builder/field-types/enumeration.ts +15 -4
- package/src/tx/builder/field-types/fee.ts +38 -18
- package/src/tx/builder/field-types/gas-limit.ts +12 -7
- package/src/tx/builder/field-types/index.ts +46 -17
- package/src/tx/builder/field-types/mptree.ts +242 -0
- package/src/tx/builder/field-types/name-fee.ts +1 -2
- package/src/tx/builder/field-types/name-id.ts +1 -1
- package/src/tx/builder/field-types/pointers.ts +2 -2
- package/src/tx/builder/field-types/raw.ts +9 -0
- package/src/tx/builder/field-types/short-u-int-const.ts +20 -0
- package/src/tx/builder/field-types/string.ts +11 -0
- package/src/tx/builder/field-types/u-int.ts +1 -3
- package/src/tx/builder/index.ts +63 -247
- package/src/tx/builder/schema.ts +273 -323
- package/src/tx/index.ts +37 -104
- package/src/tx/validator.ts +72 -95
- package/src/utils/bytes.ts +1 -1
- package/src/utils/errors.ts +4 -13
- package/types-legacy/ts4.2/AeSdkBase.d.ts +3 -3
- package/types-legacy/ts4.2/AeSdkMethods.d.ts +3 -4
- package/types-legacy/ts4.2/Node.d.ts +3 -3
- package/types-legacy/ts4.2/account/Base.d.ts +2 -2
- package/types-legacy/ts4.2/aens.d.ts +1 -1
- package/types-legacy/ts4.2/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
- package/types-legacy/ts4.2/chain.d.ts +9 -1
- package/types-legacy/ts4.2/channel/Base.d.ts +6 -1
- package/types-legacy/ts4.2/channel/Contract.d.ts +8 -7
- package/types-legacy/ts4.2/channel/Spend.d.ts +3 -1
- package/types-legacy/ts4.2/contract/Contract.d.ts +21 -46
- package/types-legacy/ts4.2/contract/compiler/Base.d.ts +81 -0
- package/types-legacy/ts4.2/contract/compiler/Cli.d.ts +23 -0
- package/types-legacy/ts4.2/contract/compiler/Http.d.ts +32 -0
- package/types-legacy/ts4.2/contract/compiler/HttpNode.d.ts +17 -0
- package/types-legacy/ts4.2/contract/compiler/getFileSystem.d.ts +6 -0
- package/types-legacy/ts4.2/contract/ga.d.ts +5 -4
- package/types-legacy/ts4.2/index-browser.d.ts +39 -0
- package/types-legacy/ts4.2/index.d.ts +4 -38
- package/types-legacy/ts4.2/tx/builder/constants.d.ts +28 -1
- package/types-legacy/ts4.2/tx/builder/field-types/abi-version.d.ts +10 -0
- package/types-legacy/ts4.2/tx/builder/field-types/address.d.ts +11 -12
- package/types-legacy/ts4.2/tx/builder/field-types/array.d.ts +7 -0
- package/types-legacy/ts4.2/tx/builder/field-types/boolean.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/coin-amount.d.ts +1 -1
- package/types-legacy/ts4.2/tx/builder/field-types/ct-version.d.ts +42 -0
- package/types-legacy/ts4.2/tx/builder/field-types/deposit.d.ts +1 -1
- package/types-legacy/ts4.2/tx/builder/field-types/encoded.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/entry.d.ts +11 -0
- package/types-legacy/ts4.2/tx/builder/field-types/enumeration.d.ts +5 -3
- package/types-legacy/ts4.2/tx/builder/field-types/fee.d.ts +10 -7
- package/types-legacy/ts4.2/tx/builder/field-types/gas-limit.d.ts +5 -2
- package/types-legacy/ts4.2/tx/builder/field-types/gas-price.d.ts +1 -1
- package/types-legacy/ts4.2/tx/builder/field-types/index.d.ts +72 -28
- package/types-legacy/ts4.2/tx/builder/field-types/mptree.d.ts +43 -0
- package/types-legacy/ts4.2/tx/builder/field-types/name-fee.d.ts +1 -2
- package/types-legacy/ts4.2/tx/builder/field-types/raw.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/short-u-int-const.d.ts +5 -0
- package/types-legacy/ts4.2/tx/builder/field-types/string.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/u-int.d.ts +1 -2
- package/types-legacy/ts4.2/tx/builder/index.d.ts +11 -29
- package/types-legacy/ts4.2/tx/builder/schema.d.ts +2380 -668
- package/types-legacy/ts4.2/tx/index.d.ts +5 -20
- package/types-legacy/ts4.2/tx/validator.d.ts +3 -5
- package/types-legacy/ts4.2/utils/errors.d.ts +3 -8
- package/types-legacy/ts4.2/utils/other.d.ts +1 -1
- package/types-legacy/ts4.5/AeSdkBase.d.ts +3 -3
- package/types-legacy/ts4.5/AeSdkMethods.d.ts +3 -4
- package/types-legacy/ts4.5/Node.d.ts +3 -3
- package/types-legacy/ts4.5/account/Base.d.ts +2 -2
- package/types-legacy/ts4.5/aens.d.ts +1 -1
- package/types-legacy/ts4.5/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
- package/types-legacy/ts4.5/chain.d.ts +9 -1
- package/types-legacy/ts4.5/channel/Base.d.ts +6 -1
- package/types-legacy/ts4.5/channel/Contract.d.ts +8 -7
- package/types-legacy/ts4.5/channel/Spend.d.ts +3 -1
- package/types-legacy/ts4.5/contract/Contract.d.ts +21 -46
- package/types-legacy/ts4.5/contract/compiler/Base.d.ts +81 -0
- package/types-legacy/ts4.5/contract/compiler/Cli.d.ts +23 -0
- package/types-legacy/ts4.5/contract/compiler/Http.d.ts +32 -0
- package/types-legacy/ts4.5/contract/compiler/HttpNode.d.ts +17 -0
- package/types-legacy/ts4.5/contract/compiler/getFileSystem.d.ts +6 -0
- package/types-legacy/ts4.5/contract/ga.d.ts +5 -4
- package/types-legacy/ts4.5/index-browser.d.ts +39 -0
- package/types-legacy/ts4.5/index.d.ts +4 -38
- package/types-legacy/ts4.5/tx/builder/constants.d.ts +28 -1
- package/types-legacy/ts4.5/tx/builder/field-types/abi-version.d.ts +10 -0
- package/types-legacy/ts4.5/tx/builder/field-types/address.d.ts +11 -12
- package/types-legacy/ts4.5/tx/builder/field-types/array.d.ts +7 -0
- package/types-legacy/ts4.5/tx/builder/field-types/boolean.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/coin-amount.d.ts +1 -1
- package/types-legacy/ts4.5/tx/builder/field-types/ct-version.d.ts +42 -0
- package/types-legacy/ts4.5/tx/builder/field-types/deposit.d.ts +1 -1
- package/types-legacy/ts4.5/tx/builder/field-types/encoded.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/entry.d.ts +11 -0
- package/types-legacy/ts4.5/tx/builder/field-types/enumeration.d.ts +5 -3
- package/types-legacy/ts4.5/tx/builder/field-types/fee.d.ts +10 -7
- package/types-legacy/ts4.5/tx/builder/field-types/gas-limit.d.ts +5 -2
- package/types-legacy/ts4.5/tx/builder/field-types/gas-price.d.ts +1 -1
- package/types-legacy/ts4.5/tx/builder/field-types/index.d.ts +72 -28
- package/types-legacy/ts4.5/tx/builder/field-types/mptree.d.ts +43 -0
- package/types-legacy/ts4.5/tx/builder/field-types/name-fee.d.ts +1 -2
- package/types-legacy/ts4.5/tx/builder/field-types/raw.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/short-u-int-const.d.ts +5 -0
- package/types-legacy/ts4.5/tx/builder/field-types/string.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/u-int.d.ts +1 -2
- package/types-legacy/ts4.5/tx/builder/index.d.ts +11 -29
- package/types-legacy/ts4.5/tx/builder/schema.d.ts +2380 -668
- package/types-legacy/ts4.5/tx/index.d.ts +5 -20
- package/types-legacy/ts4.5/tx/validator.d.ts +3 -5
- package/types-legacy/ts4.5/utils/errors.d.ts +3 -8
- package/types-legacy/ts4.5/utils/other.d.ts +1 -1
- package/es/contract/CompilerHttp.d.ts +0 -18
- package/es/contract/CompilerHttp.mjs.map +0 -1
- package/es/tx/builder/field-types/addresses.d.ts +0 -6
- package/es/tx/builder/field-types/addresses.mjs +0 -13
- package/es/tx/builder/field-types/addresses.mjs.map +0 -1
- package/es/utils/mptree.d.ts +0 -26
- package/es/utils/mptree.mjs +0 -143
- package/es/utils/mptree.mjs.map +0 -1
- package/src/contract/CompilerHttp.ts +0 -67
- package/src/tx/builder/field-types/addresses.ts +0 -18
- package/src/utils/mptree.ts +0 -145
- package/types-legacy/ts4.2/contract/CompilerHttp.d.ts +0 -18
- package/types-legacy/ts4.2/tx/builder/field-types/addresses.d.ts +0 -6
- package/types-legacy/ts4.2/utils/mptree.d.ts +0 -32
- package/types-legacy/ts4.5/contract/CompilerHttp.d.ts +0 -18
- package/types-legacy/ts4.5/tx/builder/field-types/addresses.d.ts +0 -6
- package/types-legacy/ts4.5/utils/mptree.d.ts +0 -32
package/es/oracle.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oracle.mjs","names":["send","mapObject","pause","oracleQueryId","unpackTx","ORACLE_TTL","QUERY_FEE","QUERY_TTL","RESPONSE_TTL","Tag","RequestTimedOutError","decode","encode","Encoding","_getPollInterval","getHeight","_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","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, getHeight } 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 ({ response, ttl } = await onNode.getOracleQueryByPubkeyAndQueryId(oracleId, queryId));\n const responseBuffer = decode(response as Encoded.OracleResponse);\n if (responseBuffer.length > 0) return responseBuffer.toString();\n await pause(interval);\n height = await getHeight({ onNode });\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 = options.onAccount.address;\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: options.onAccount.address,\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: options.onAccount.address,\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 = options.onAccount.address;\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;AANA,SASSA,IAAI;AAAA,SACJC,SAAS,EAAEC,KAAK;AAAA,SAChBC,aAAa;AAAA,SACbC,QAAQ;AAAA,SAEfC,UAAU,EAEVC,SAAS,EACTC,SAAS,EACTC,YAAY;AAAA,SAELC,GAAG;AAAA,SACHC,oBAAoB;AAAA,SAE3BC,MAAM,EAAEC,MAAM,EAAWC,QAAQ;AAAA,SAE1BC,gBAAgB,EAAEC,SAAS;AAAA,SAC3BC,QAAQ;AAMjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAc,CAC5BC,QAA+B,EAC/BC,OAAyC,QAG7B;EAAA;EAAA,IAFZ;IAAEC,QAAQ;IAAEC,MAAM;IAAE,GAAGC;EACgB,CAAC;EAExC,aAAAF,QAAQ,iDAARA,QAA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ClE,MAAM,CAACD,MAAM,CAACqF,SAAS,CAAC,EAAEnF,QAAQ,CAACsF,aAAa,CAAC,EAAE7E,OAAO,CAAC;EACtF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"oracle.mjs","names":["send","mapObject","pause","oracleQueryId","unpackTx","ORACLE_TTL","QUERY_FEE","QUERY_TTL","RESPONSE_TTL","Tag","RequestTimedOutError","decode","encode","Encoding","_getPollInterval","getHeight","_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","getQueryObject","record","decodedQuery","query","decodedResponse","respond","opt","respondToQuery","pollForResponse","postQueryToOracle","queryFee","getOracleByPubkey","senderId","onAccount","address","oracleQueryTx","OracleQueryTx","queryTtlType","type","queryTtlValue","value","responseTtlType","responseTtlValue","nonce","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, getHeight } 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 ({ response, ttl } = await onNode.getOracleQueryByPubkeyAndQueryId(oracleId, queryId));\n const responseBuffer = decode(response as Encoded.OracleResponse);\n if (responseBuffer.length > 0) return responseBuffer.toString();\n await pause(interval);\n height = await getHeight({ onNode });\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 = options.onAccount.address;\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);\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: options.onAccount.address,\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: options.onAccount.address,\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 = options.onAccount.address;\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;AANA,SASSA,IAAI;AAAA,SACJC,SAAS,EAAEC,KAAK;AAAA,SAChBC,aAAa;AAAA,SACbC,QAAQ;AAAA,SAEfC,UAAU,EAEVC,SAAS,EACTC,SAAS,EACTC,YAAY;AAAA,SAELC,GAAG;AAAA,SACHC,oBAAoB;AAAA,SAE3BC,MAAM,EAAEC,MAAM,EAAWC,QAAQ;AAAA,SAE1BC,gBAAgB,EAAEC,SAAS;AAAA,SAC3BC,QAAQ;AAMjB;AACA;AACA;AACA;AACA;AACA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9B,GAAG3C,OAAO;IACVyE,SAAS;IACTF,WAAW;IACXC;EACF,CAAC,CAAC;EACF,OAAO;IACL,IAAG,MAAM9F,IAAI,CAACgG,gBAAgB,EAAE1E,OAAO,CAAC;IACxC,IAAG,MAAMuD,eAAe,CAACjE,MAAM,CAACD,MAAM,CAACoF,SAAS,CAAC,EAAElF,QAAQ,CAACqF,aAAa,CAAC,EAAE5E,OAAO,CAAC;EACtF,CAAC;AACH"}
|
package/es/spend.mjs
CHANGED
|
@@ -73,9 +73,7 @@ export async function transferFunds(fraction, recipientIdOrName, options) {
|
|
|
73
73
|
const balance = new BigNumber(await getBalance.bind(options.onAccount)(senderId, options));
|
|
74
74
|
const desiredAmount = balance.times(fraction).integerValue(BigNumber.ROUND_HALF_UP);
|
|
75
75
|
const {
|
|
76
|
-
|
|
77
|
-
fee
|
|
78
|
-
}
|
|
76
|
+
fee
|
|
79
77
|
} = unpackTx(await _buildTx(Tag.SpendTx, {
|
|
80
78
|
...options,
|
|
81
79
|
senderId,
|
package/es/spend.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spend.mjs","names":["BigNumber","sendTransaction","getBalance","resolveName","_buildTx","buildTxHash","unpackTx","ArgumentError","Tag","send","tx","options","signed","onAccount","signTransaction","networkId","onNode","getNetworkId","innerTx","hash","rawTx","spend","amount","recipientIdOrName","SpendTx","senderId","address","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 { sendTransaction, getBalance, resolveName } 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 const signed = await options.onAccount.signTransaction(tx, {\n ...options,\n networkId: await options.onNode.getNetworkId(),\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: options.onAccount.address,\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 = options.onAccount.address;\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 {
|
|
1
|
+
{"version":3,"file":"spend.mjs","names":["BigNumber","sendTransaction","getBalance","resolveName","_buildTx","buildTxHash","unpackTx","ArgumentError","Tag","send","tx","options","signed","onAccount","signTransaction","networkId","onNode","getNetworkId","innerTx","hash","rawTx","spend","amount","recipientIdOrName","SpendTx","senderId","address","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 { sendTransaction, getBalance, resolveName } 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 const signed = await options.onAccount.signTransaction(tx, {\n ...options,\n networkId: await options.onNode.getNetworkId(),\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: options.onAccount.address,\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 = options.onAccount.address;\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 { 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: options.onAccount.address, 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,SAAS,MAAM,cAAc;AAAC,SAC5BC,eAAe,EAAEC,UAAU,EAAEC,WAAW;AAAA,SACxCC,QAAQ;AAAA,SACRC,WAAW,EAAEC,QAAQ;AAAA,SACrBC,aAAa;AAAA,SAEbC,GAAG;AAGZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,IAAI,CACxBC,EAAuB,EACvBC,OAAoB,EACK;EACzB,MAAMC,MAAM,GAAG,MAAMD,OAAO,CAACE,SAAS,CAACC,eAAe,CAACJ,EAAE,EAAE;IACzD,GAAGC,OAAO;IACVI,SAAS,EAAE,MAAMJ,OAAO,CAACK,MAAM,CAACC,YAAY;EAC9C,CAAC,CAAC;EAEF,OAAON,OAAO,CAACO,OAAO,KAAK,IAAI,GAC3B;IAAEC,IAAI,EAAEd,WAAW,CAACO,MAAM,CAAC;IAAEQ,KAAK,EAAER;EAAO,CAAC,GAC5CX,eAAe,CAACW,MAAM,EAAED,OAAO,CAAC;AACtC;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeU,KAAK,CACzBC,MAAuB,EACvBC,iBAAoD,EACpDZ,OAAqB,EACI;EACzB,OAAOF,IAAI,CACT,MAAML,QAAQ,CAACI,GAAG,CAACgB,OAAO,EAAE;IAC1B,GAAGb,OAAO;IACVc,QAAQ,EA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MAAML,QAAQ,CAACI,GAAG,CAACgB,OAAO,EAAE;IAC1B,GAAGb,OAAO;IAAEc,QAAQ;IAAEE,WAAW;IAAEL;EACrC,CAAC,CAAC,EACFX,OAAO,CACR;AACH;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAe6B,iBAAiB,CACrCC,WAAgC,EAChC9B,OAAiC,EACR;EACzB,OAAOF,IAAI,CACT,MAAML,QAAQ,CACZI,GAAG,CAACkC,WAAW,EACf;IAAE,GAAG/B,OAAO;IAAEgC,OAAO,EAAEhC,OAAO,CAACE,SAAS,CAACa,OAAO;IAAEhB,EAAE,EAAE+B;EAAY,CAAC,CACpE,EACD9B,OAAO,CACR;AACH"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
2
|
export declare const MAX_AUTH_FUN_GAS = 50000;
|
|
3
|
+
export type Int = number | string | BigNumber;
|
|
3
4
|
export type AensName = `${string}.chain`;
|
|
4
5
|
export declare const NAME_TTL = 180000;
|
|
5
6
|
export declare const NAME_MAX_TTL = 36000;
|
|
@@ -14,6 +15,31 @@ export declare const NAME_BID_MAX_LENGTH = 12;
|
|
|
14
15
|
export declare const NAME_BID_RANGES: {
|
|
15
16
|
[k: string]: BigNumber;
|
|
16
17
|
};
|
|
18
|
+
export declare enum ConsensusProtocolVersion {
|
|
19
|
+
Iris = 5
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @category transaction builder
|
|
23
|
+
* @see {@link https://github.com/aeternity/protocol/blob/0f6dee3d9d1e8e2469816798f5c7587a6c918f94/contracts/contract_vms.md#virtual-machines-on-the-%C3%A6ternity-blockchain}
|
|
24
|
+
*/
|
|
25
|
+
export declare enum VmVersion {
|
|
26
|
+
NoVm = 0,
|
|
27
|
+
Sophia = 1,
|
|
28
|
+
SophiaImprovementsMinerva = 3,
|
|
29
|
+
SophiaImprovementsFortuna = 4,
|
|
30
|
+
Fate = 5,
|
|
31
|
+
SophiaImprovementsLima = 6,
|
|
32
|
+
Fate2 = 7
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @category transaction builder
|
|
36
|
+
* @see {@link https://github.com/aeternity/protocol/blob/0f6dee3d9d1e8e2469816798f5c7587a6c918f94/contracts/contract_vms.md#virtual-machines-on-the-%C3%A6ternity-blockchain}
|
|
37
|
+
*/
|
|
38
|
+
export declare enum AbiVersion {
|
|
39
|
+
NoAbi = 0,
|
|
40
|
+
Sophia = 1,
|
|
41
|
+
Fate = 3
|
|
42
|
+
}
|
|
17
43
|
/**
|
|
18
44
|
* Enum with tag types
|
|
19
45
|
* @category transaction builder
|
|
@@ -24,10 +50,12 @@ export declare enum Tag {
|
|
|
24
50
|
Account = 10,
|
|
25
51
|
SignedTx = 11,
|
|
26
52
|
SpendTx = 12,
|
|
53
|
+
Oracle = 20,
|
|
27
54
|
OracleRegisterTx = 22,
|
|
28
55
|
OracleQueryTx = 23,
|
|
29
56
|
OracleResponseTx = 24,
|
|
30
57
|
OracleExtendTx = 25,
|
|
58
|
+
Name = 30,
|
|
31
59
|
NameClaimTx = 32,
|
|
32
60
|
NamePreclaimTx = 33,
|
|
33
61
|
NameUpdateTx = 34,
|
|
@@ -64,7 +92,6 @@ export declare enum Tag {
|
|
|
64
92
|
NameserviceMtree = 624,
|
|
65
93
|
OraclesMtree = 625,
|
|
66
94
|
AccountsMtree = 626,
|
|
67
|
-
CompilerSophia = 70,
|
|
68
95
|
GaAttachTx = 80,
|
|
69
96
|
GaMetaTx = 81,
|
|
70
97
|
PayingForTx = 82
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
2
|
import { mapObject } from "../../utils/other.mjs";
|
|
3
3
|
export const MAX_AUTH_FUN_GAS = 50000;
|
|
4
|
-
// # AENS
|
|
5
|
-
|
|
6
4
|
export const NAME_TTL = 180000;
|
|
7
5
|
// # max number of block into the future that the name is going to be available
|
|
8
6
|
// # https://github.com/aeternity/protocol/blob/epoch-v0.22.0/AENS.md#update
|
|
@@ -58,6 +56,31 @@ export const NAME_BID_RANGES = mapObject({
|
|
|
58
56
|
let [key, value] = _ref;
|
|
59
57
|
return [key, new BigNumber(value).times(NAME_FEE_MULTIPLIER)];
|
|
60
58
|
});
|
|
59
|
+
export let ConsensusProtocolVersion;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @category transaction builder
|
|
63
|
+
* @see {@link https://github.com/aeternity/protocol/blob/0f6dee3d9d1e8e2469816798f5c7587a6c918f94/contracts/contract_vms.md#virtual-machines-on-the-%C3%A6ternity-blockchain}
|
|
64
|
+
*/
|
|
65
|
+
(function (ConsensusProtocolVersion) {
|
|
66
|
+
ConsensusProtocolVersion[ConsensusProtocolVersion["Iris"] = 5] = "Iris";
|
|
67
|
+
})(ConsensusProtocolVersion || (ConsensusProtocolVersion = {}));
|
|
68
|
+
export let VmVersion;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @category transaction builder
|
|
72
|
+
* @see {@link https://github.com/aeternity/protocol/blob/0f6dee3d9d1e8e2469816798f5c7587a6c918f94/contracts/contract_vms.md#virtual-machines-on-the-%C3%A6ternity-blockchain}
|
|
73
|
+
*/
|
|
74
|
+
(function (VmVersion) {
|
|
75
|
+
VmVersion[VmVersion["NoVm"] = 0] = "NoVm";
|
|
76
|
+
VmVersion[VmVersion["Sophia"] = 1] = "Sophia";
|
|
77
|
+
VmVersion[VmVersion["SophiaImprovementsMinerva"] = 3] = "SophiaImprovementsMinerva";
|
|
78
|
+
VmVersion[VmVersion["SophiaImprovementsFortuna"] = 4] = "SophiaImprovementsFortuna";
|
|
79
|
+
VmVersion[VmVersion["Fate"] = 5] = "Fate";
|
|
80
|
+
VmVersion[VmVersion["SophiaImprovementsLima"] = 6] = "SophiaImprovementsLima";
|
|
81
|
+
VmVersion[VmVersion["Fate2"] = 7] = "Fate2";
|
|
82
|
+
})(VmVersion || (VmVersion = {}));
|
|
83
|
+
export let AbiVersion;
|
|
61
84
|
|
|
62
85
|
/**
|
|
63
86
|
* Enum with tag types
|
|
@@ -66,6 +89,11 @@ export const NAME_BID_RANGES = mapObject({
|
|
|
66
89
|
* @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_chain_objects.erl#L39-L97}
|
|
67
90
|
*/
|
|
68
91
|
// TODO: implement serialisation for commented-out tags
|
|
92
|
+
(function (AbiVersion) {
|
|
93
|
+
AbiVersion[AbiVersion["NoAbi"] = 0] = "NoAbi";
|
|
94
|
+
AbiVersion[AbiVersion["Sophia"] = 1] = "Sophia";
|
|
95
|
+
AbiVersion[AbiVersion["Fate"] = 3] = "Fate";
|
|
96
|
+
})(AbiVersion || (AbiVersion = {}));
|
|
69
97
|
export let Tag; // KeyBlock = 100,
|
|
70
98
|
// MicroBlock = 101,
|
|
71
99
|
// LightMicroBlock = 102,
|
|
@@ -74,10 +102,12 @@ export let Tag; // KeyBlock = 100,
|
|
|
74
102
|
Tag[Tag["Account"] = 10] = "Account";
|
|
75
103
|
Tag[Tag["SignedTx"] = 11] = "SignedTx";
|
|
76
104
|
Tag[Tag["SpendTx"] = 12] = "SpendTx";
|
|
105
|
+
Tag[Tag["Oracle"] = 20] = "Oracle";
|
|
77
106
|
Tag[Tag["OracleRegisterTx"] = 22] = "OracleRegisterTx";
|
|
78
107
|
Tag[Tag["OracleQueryTx"] = 23] = "OracleQueryTx";
|
|
79
108
|
Tag[Tag["OracleResponseTx"] = 24] = "OracleResponseTx";
|
|
80
109
|
Tag[Tag["OracleExtendTx"] = 25] = "OracleExtendTx";
|
|
110
|
+
Tag[Tag["Name"] = 30] = "Name";
|
|
81
111
|
Tag[Tag["NameClaimTx"] = 32] = "NameClaimTx";
|
|
82
112
|
Tag[Tag["NamePreclaimTx"] = 33] = "NamePreclaimTx";
|
|
83
113
|
Tag[Tag["NameUpdateTx"] = 34] = "NameUpdateTx";
|
|
@@ -114,7 +144,6 @@ export let Tag; // KeyBlock = 100,
|
|
|
114
144
|
Tag[Tag["NameserviceMtree"] = 624] = "NameserviceMtree";
|
|
115
145
|
Tag[Tag["OraclesMtree"] = 625] = "OraclesMtree";
|
|
116
146
|
Tag[Tag["AccountsMtree"] = 626] = "AccountsMtree";
|
|
117
|
-
Tag[Tag["CompilerSophia"] = 70] = "CompilerSophia";
|
|
118
147
|
Tag[Tag["GaAttachTx"] = 80] = "GaAttachTx";
|
|
119
148
|
Tag[Tag["GaMetaTx"] = 81] = "GaMetaTx";
|
|
120
149
|
Tag[Tag["PayingForTx"] = 82] = "PayingForTx";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","names":["BigNumber","mapObject","MAX_AUTH_FUN_GAS","NAME_TTL","NAME_MAX_TTL","NAME_MAX_CLIENT_TTL","CLIENT_TTL","MIN_GAS_PRICE","NAME_FEE_MULTIPLIER","NAME_FEE_BID_INCREMENT","NAME_BID_TIMEOUT_BLOCKS","NAME_MAX_LENGTH_FEE","NAME_BID_MAX_LENGTH","NAME_BID_RANGES","key","value","times","Tag"],"sources":["../../../src/tx/builder/constants.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport { mapObject } from '../../utils/other';\n\nexport const MAX_AUTH_FUN_GAS = 50000;\n// # AENS\nexport type AensName = `${string}.chain`;\nexport const NAME_TTL = 180000;\n// # max number of block into the future that the name is going to be available\n// # https://github.com/aeternity/protocol/blob/epoch-v0.22.0/AENS.md#update\n// # https://github.com/aeternity/protocol/blob/44a93d3aab957ca820183c3520b9daf6b0fedff4/AENS.md#aens-entry\nexport const NAME_MAX_TTL = 36000;\nexport const NAME_MAX_CLIENT_TTL = 84600;\nexport const CLIENT_TTL = NAME_MAX_CLIENT_TTL;\nexport const MIN_GAS_PRICE = 1e9;\n// # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L67\nexport const NAME_FEE_MULTIPLIER = 1e14; // 100000000000000\nexport const NAME_FEE_BID_INCREMENT = 0.05; // # the increment is in percentage\n// # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L272\nexport const NAME_BID_TIMEOUT_BLOCKS = 480; // # ~1 day\n// # this is the max length for a domain that requires a base fee to be paid\nexport const NAME_MAX_LENGTH_FEE = 31;\nexport const NAME_BID_MAX_LENGTH = 12; // # this is the max length for a domain to be part of a bid\n// # https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L290\n// # https://github.com/aeternity/protocol/blob/master/AENS.md#protocol-fees-and-protection-times\n// # bid ranges:\nexport const NAME_BID_RANGES = mapObject({\n 31: 3,\n 30: 5,\n 29: 8,\n 28: 13,\n 27: 21,\n 26: 34,\n 25: 55,\n 24: 89,\n 23: 144,\n 22: 233,\n 21: 377,\n 20: 610,\n 19: 987,\n 18: 1597,\n 17: 2584,\n 16: 4181,\n 15: 6765,\n 14: 10946,\n 13: 17711,\n 12: 28657,\n 11: 46368,\n 10: 75025,\n 9: 121393,\n 8: 196418,\n 7: 317811,\n 6: 514229,\n 5: 832040,\n 4: 1346269,\n 3: 2178309,\n 2: 3524578,\n 1: 5702887,\n}, ([key, value]) => [key, new BigNumber(value).times(NAME_FEE_MULTIPLIER)]);\n\n/**\n * Enum with tag types\n * @category transaction builder\n * @see {@link https://github.com/aeternity/protocol/blob/0f6dee3d9d1e8e2469816798f5c7587a6c918f94/serializations.md#binary-serialization}\n * @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_chain_objects.erl#L39-L97}\n */\n// TODO: implement serialisation for commented-out tags\nexport enum Tag {\n Account = 10,\n SignedTx = 11,\n SpendTx = 12,\n
|
|
1
|
+
{"version":3,"file":"constants.mjs","names":["BigNumber","mapObject","MAX_AUTH_FUN_GAS","NAME_TTL","NAME_MAX_TTL","NAME_MAX_CLIENT_TTL","CLIENT_TTL","MIN_GAS_PRICE","NAME_FEE_MULTIPLIER","NAME_FEE_BID_INCREMENT","NAME_BID_TIMEOUT_BLOCKS","NAME_MAX_LENGTH_FEE","NAME_BID_MAX_LENGTH","NAME_BID_RANGES","key","value","times","ConsensusProtocolVersion","VmVersion","AbiVersion","Tag"],"sources":["../../../src/tx/builder/constants.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport { mapObject } from '../../utils/other';\n\nexport const MAX_AUTH_FUN_GAS = 50000;\nexport type Int = number | string | BigNumber;\n// # AENS\nexport type AensName = `${string}.chain`;\nexport const NAME_TTL = 180000;\n// # max number of block into the future that the name is going to be available\n// # https://github.com/aeternity/protocol/blob/epoch-v0.22.0/AENS.md#update\n// # https://github.com/aeternity/protocol/blob/44a93d3aab957ca820183c3520b9daf6b0fedff4/AENS.md#aens-entry\nexport const NAME_MAX_TTL = 36000;\nexport const NAME_MAX_CLIENT_TTL = 84600;\nexport const CLIENT_TTL = NAME_MAX_CLIENT_TTL;\nexport const MIN_GAS_PRICE = 1e9;\n// # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L67\nexport const NAME_FEE_MULTIPLIER = 1e14; // 100000000000000\nexport const NAME_FEE_BID_INCREMENT = 0.05; // # the increment is in percentage\n// # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L272\nexport const NAME_BID_TIMEOUT_BLOCKS = 480; // # ~1 day\n// # this is the max length for a domain that requires a base fee to be paid\nexport const NAME_MAX_LENGTH_FEE = 31;\nexport const NAME_BID_MAX_LENGTH = 12; // # this is the max length for a domain to be part of a bid\n// # https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L290\n// # https://github.com/aeternity/protocol/blob/master/AENS.md#protocol-fees-and-protection-times\n// # bid ranges:\nexport const NAME_BID_RANGES = mapObject({\n 31: 3,\n 30: 5,\n 29: 8,\n 28: 13,\n 27: 21,\n 26: 34,\n 25: 55,\n 24: 89,\n 23: 144,\n 22: 233,\n 21: 377,\n 20: 610,\n 19: 987,\n 18: 1597,\n 17: 2584,\n 16: 4181,\n 15: 6765,\n 14: 10946,\n 13: 17711,\n 12: 28657,\n 11: 46368,\n 10: 75025,\n 9: 121393,\n 8: 196418,\n 7: 317811,\n 6: 514229,\n 5: 832040,\n 4: 1346269,\n 3: 2178309,\n 2: 3524578,\n 1: 5702887,\n}, ([key, value]) => [key, new BigNumber(value).times(NAME_FEE_MULTIPLIER)]);\n\nexport enum ConsensusProtocolVersion {\n Iris = 5,\n}\n\n/**\n * @category transaction builder\n * @see {@link https://github.com/aeternity/protocol/blob/0f6dee3d9d1e8e2469816798f5c7587a6c918f94/contracts/contract_vms.md#virtual-machines-on-the-%C3%A6ternity-blockchain}\n */\nexport enum VmVersion {\n NoVm = 0,\n Sophia = 1,\n SophiaImprovementsMinerva = 3,\n SophiaImprovementsFortuna = 4,\n Fate = 5,\n SophiaImprovementsLima = 6,\n Fate2 = 7,\n}\n\n/**\n * @category transaction builder\n * @see {@link https://github.com/aeternity/protocol/blob/0f6dee3d9d1e8e2469816798f5c7587a6c918f94/contracts/contract_vms.md#virtual-machines-on-the-%C3%A6ternity-blockchain}\n */\nexport enum AbiVersion {\n NoAbi = 0,\n Sophia = 1,\n Fate = 3,\n}\n\n/**\n * Enum with tag types\n * @category transaction builder\n * @see {@link https://github.com/aeternity/protocol/blob/0f6dee3d9d1e8e2469816798f5c7587a6c918f94/serializations.md#binary-serialization}\n * @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_chain_objects.erl#L39-L97}\n */\n// TODO: implement serialisation for commented-out tags\nexport enum Tag {\n Account = 10,\n SignedTx = 11,\n SpendTx = 12,\n Oracle = 20,\n // OracleQuery = 21,\n OracleRegisterTx = 22,\n OracleQueryTx = 23,\n OracleResponseTx = 24,\n OracleExtendTx = 25,\n Name = 30,\n // NameCommitment = 31,\n NameClaimTx = 32,\n NamePreclaimTx = 33,\n NameUpdateTx = 34,\n NameRevokeTx = 35,\n NameTransferTx = 36,\n // NameAuction = 37,\n Contract = 40,\n ContractCall = 41,\n ContractCreateTx = 42,\n ContractCallTx = 43,\n ChannelCreateTx = 50,\n // ChannelSetDelegatesTx = 501,\n ChannelDepositTx = 51,\n ChannelWithdrawTx = 52,\n ChannelForceProgressTx = 521,\n ChannelCloseMutualTx = 53,\n ChannelCloseSoloTx = 54,\n ChannelSlashTx = 55,\n ChannelSettleTx = 56,\n ChannelOffChainTx = 57,\n ChannelOffChainUpdateTransfer = 570,\n ChannelOffChainUpdateDeposit = 571,\n ChannelOffChainUpdateWithdraw = 572,\n ChannelOffChainUpdateCreateContract = 573,\n ChannelOffChainUpdateCallContract = 574,\n // ChannelOffChainUpdateMeta = 576,\n ChannelClientReconnectTx = 575,\n Channel = 58,\n ChannelSnapshotSoloTx = 59,\n TreesPoi = 60,\n // TreesDb = 61,\n StateTrees = 62,\n Mtree = 63,\n MtreeValue = 64,\n ContractsMtree = 621,\n CallsMtree = 622,\n ChannelsMtree = 623,\n NameserviceMtree = 624,\n OraclesMtree = 625,\n AccountsMtree = 626,\n // CompilerSophia = 70,\n GaAttachTx = 80,\n GaMetaTx = 81,\n PayingForTx = 82,\n // KeyBlock = 100,\n // MicroBlock = 101,\n // LightMicroBlock = 102,\n // Pof = 200,\n}\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,cAAc;AAAC,SAC5BC,SAAS;AAElB,OAAO,MAAMC,gBAAgB,GAAG,KAAK;AAIrC,OAAO,MAAMC,QAAQ,GAAG,MAAM;AAC9B;AACA;AACA;AACA,OAAO,MAAMC,YAAY,GAAG,KAAK;AACjC,OAAO,MAAMC,mBAAmB,GAAG,KAAK;AACxC,OAAO,MAAMC,UAAU,GAAGD,mBAAmB;AAC7C,OAAO,MAAME,aAAa,GAAG,GAAG;AACh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AG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;EAAHA,GAAG,CAAHA,GAAG;AAAA,GAAHA,GAAG,KAAHA,GAAG"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Tag, ConsensusProtocolVersion, AbiVersion } from '../constants';
|
|
3
|
+
declare const _default: {
|
|
4
|
+
serialize(value: AbiVersion | undefined, { tag, consensusProtocolVersion }: {
|
|
5
|
+
tag: Tag;
|
|
6
|
+
consensusProtocolVersion: ConsensusProtocolVersion;
|
|
7
|
+
}): Buffer;
|
|
8
|
+
deserialize(buffer: Buffer): AbiVersion;
|
|
9
|
+
};
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import _buffer from "buffer";
|
|
2
|
+
const {
|
|
3
|
+
Buffer: _Buffer
|
|
4
|
+
} = _buffer;
|
|
5
|
+
import { Tag, ConsensusProtocolVersion } from "../constants.mjs";
|
|
6
|
+
import { getProtocolDetails } from "./ct-version.mjs";
|
|
7
|
+
export default {
|
|
8
|
+
serialize(value, _ref) {
|
|
9
|
+
let {
|
|
10
|
+
tag,
|
|
11
|
+
consensusProtocolVersion = ConsensusProtocolVersion.Iris
|
|
12
|
+
} = _ref;
|
|
13
|
+
const result = value !== null && value !== void 0 ? value : getProtocolDetails(consensusProtocolVersion, Tag.ContractCallTx === tag || Tag.GaMetaTx === tag ? 'contract-call' : 'oracle-call').abiVersion;
|
|
14
|
+
return _Buffer.from([result]);
|
|
15
|
+
},
|
|
16
|
+
deserialize(buffer) {
|
|
17
|
+
return buffer[0];
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=abi-version.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abi-version.mjs","names":["Tag","ConsensusProtocolVersion","getProtocolDetails","serialize","value","tag","consensusProtocolVersion","Iris","result","ContractCallTx","GaMetaTx","abiVersion","from","deserialize","buffer"],"sources":["../../../../src/tx/builder/field-types/abi-version.ts"],"sourcesContent":["import { Tag, ConsensusProtocolVersion, AbiVersion } from '../constants';\nimport { getProtocolDetails } from './ct-version';\n\nexport default {\n serialize(\n value: AbiVersion | undefined,\n { tag, consensusProtocolVersion = ConsensusProtocolVersion.Iris }:\n { tag: Tag; consensusProtocolVersion: ConsensusProtocolVersion },\n ): Buffer {\n const result = value ?? getProtocolDetails(\n consensusProtocolVersion,\n Tag.ContractCallTx === tag || Tag.GaMetaTx === tag ? 'contract-call' : 'oracle-call',\n ).abiVersion;\n\n return Buffer.from([result]);\n },\n\n deserialize(buffer: Buffer): AbiVersion {\n return buffer[0];\n },\n};\n"],"mappings":";;;;SAASA,GAAG,EAAEC,wBAAwB;AAAA,SAC7BC,kBAAkB;AAE3B,eAAe;EACbC,SAAS,CACPC,KAA6B,QAGrB;IAAA,IAFR;MAAEC,GAAG;MAAEC,wBAAwB,GAAGL,wBAAwB,CAACM;IACI,CAAC;IAEhE,MAAMC,MAAM,GAAGJ,KAAK,aAALA,KAAK,cAALA,KAAK,GAAIF,kBAAkB,CACxCI,wBAAwB,EACxBN,GAAG,CAACS,cAAc,KAAKJ,GAAG,IAAIL,GAAG,CAACU,QAAQ,KAAKL,GAAG,GAAG,eAAe,GAAG,aAAa,CACrF,CAACM,UAAU;IAEZ,OAAO,QAAOC,IAAI,CAAC,CAACJ,MAAM,CAAC,CAAC;EAC9B,CAAC;EAEDK,WAAW,CAACC,MAAc,EAAc;IACtC,OAAOA,MAAM,CAAC,CAAC,CAAC;EAClB;AACF,CAAC"}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
2
|
+
import { Encoded } from '../../../utils/encoder';
|
|
3
3
|
/**
|
|
4
4
|
* Map of prefix to ID tag constant
|
|
5
5
|
* @see {@link https://github.com/aeternity/protocol/blob/master/serializations.md#the-id-type}
|
|
6
6
|
* @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_id.erl#L97-L102}
|
|
7
7
|
* @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_api_encoder.erl#L163-L168}
|
|
8
8
|
*/
|
|
9
|
-
declare const idTagToEncoding: readonly [Encoding.AccountAddress, Encoding.Name, Encoding.Commitment, Encoding.OracleAddress, Encoding.ContractAddress, Encoding.Channel];
|
|
9
|
+
export declare const idTagToEncoding: readonly [Encoded.Encoding.AccountAddress, Encoded.Encoding.Name, Encoded.Encoding.Commitment, Encoded.Encoding.OracleAddress, Encoded.Encoding.ContractAddress, Encoded.Encoding.Channel];
|
|
10
10
|
export type AddressEncodings = typeof idTagToEncoding[number];
|
|
11
|
-
export default function genAddressField<Encoding extends AddressEncodings>(): {
|
|
12
|
-
serialize: (value:
|
|
13
|
-
deserialize: (value: Buffer) =>
|
|
11
|
+
export default function genAddressField<Encoding extends AddressEncodings>(...encodings: Encoding[]): {
|
|
12
|
+
serialize: (value: Encoded.Generic<Encoding>) => Buffer;
|
|
13
|
+
deserialize: (value: Buffer) => Encoded.Generic<Encoding>;
|
|
14
14
|
};
|
|
15
|
-
export {};
|
|
@@ -2,7 +2,7 @@ import _buffer from "buffer";
|
|
|
2
2
|
const {
|
|
3
3
|
Buffer: _Buffer
|
|
4
4
|
} = _buffer;
|
|
5
|
-
import { PrefixNotFoundError, TagNotFoundError } from "../../../utils/errors.mjs";
|
|
5
|
+
import { ArgumentError, PrefixNotFoundError, TagNotFoundError } from "../../../utils/errors.mjs";
|
|
6
6
|
import { toBytes } from "../../../utils/bytes.mjs";
|
|
7
7
|
import { decode, encode, Encoding } from "../../../utils/encoder.mjs";
|
|
8
8
|
import { isItemOfArray } from "../../../utils/other.mjs";
|
|
@@ -12,8 +12,11 @@ import { isItemOfArray } from "../../../utils/other.mjs";
|
|
|
12
12
|
* @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_id.erl#L97-L102}
|
|
13
13
|
* @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_api_encoder.erl#L163-L168}
|
|
14
14
|
*/
|
|
15
|
-
const idTagToEncoding = [Encoding.AccountAddress, Encoding.Name, Encoding.Commitment, Encoding.OracleAddress, Encoding.ContractAddress, Encoding.Channel];
|
|
15
|
+
export const idTagToEncoding = [Encoding.AccountAddress, Encoding.Name, Encoding.Commitment, Encoding.OracleAddress, Encoding.ContractAddress, Encoding.Channel];
|
|
16
16
|
export default function genAddressField() {
|
|
17
|
+
for (var _len = arguments.length, encodings = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
18
|
+
encodings[_key] = arguments[_key];
|
|
19
|
+
}
|
|
17
20
|
return {
|
|
18
21
|
/**
|
|
19
22
|
* Utility function to create and _id type
|
|
@@ -21,9 +24,12 @@ export default function genAddressField() {
|
|
|
21
24
|
* @returns Buffer Buffer with ID tag and decoded HASh
|
|
22
25
|
*/
|
|
23
26
|
serialize(hashId) {
|
|
24
|
-
const
|
|
25
|
-
if (!isItemOfArray(
|
|
26
|
-
|
|
27
|
+
const enc = hashId.slice(0, 2);
|
|
28
|
+
if (!isItemOfArray(enc, idTagToEncoding)) throw new TagNotFoundError(enc);
|
|
29
|
+
if (!isItemOfArray(enc, encodings)) {
|
|
30
|
+
throw new ArgumentError('Address encoding', encodings.join(', '), enc);
|
|
31
|
+
}
|
|
32
|
+
const idTag = idTagToEncoding.indexOf(enc) + 1;
|
|
27
33
|
return _Buffer.from([...toBytes(idTag), ...decode(hashId)]);
|
|
28
34
|
},
|
|
29
35
|
/**
|
|
@@ -33,9 +39,12 @@ export default function genAddressField() {
|
|
|
33
39
|
*/
|
|
34
40
|
deserialize(buf) {
|
|
35
41
|
const idTag = _Buffer.from(buf).readUIntBE(0, 1);
|
|
36
|
-
const
|
|
37
|
-
if (
|
|
38
|
-
|
|
42
|
+
const enc = idTagToEncoding[idTag - 1];
|
|
43
|
+
if (enc == null) throw new PrefixNotFoundError(idTag);
|
|
44
|
+
if (!isItemOfArray(enc, encodings)) {
|
|
45
|
+
throw new ArgumentError('Address encoding', encodings.join(', '), enc);
|
|
46
|
+
}
|
|
47
|
+
return encode(buf.subarray(1), enc);
|
|
39
48
|
}
|
|
40
49
|
};
|
|
41
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.mjs","names":["PrefixNotFoundError","TagNotFoundError","toBytes","decode","encode","Encoding","isItemOfArray","idTagToEncoding","AccountAddress","Name","Commitment","OracleAddress","ContractAddress","Channel","genAddressField","serialize","hashId","
|
|
1
|
+
{"version":3,"file":"address.mjs","names":["ArgumentError","PrefixNotFoundError","TagNotFoundError","toBytes","decode","encode","Encoding","isItemOfArray","idTagToEncoding","AccountAddress","Name","Commitment","OracleAddress","ContractAddress","Channel","genAddressField","encodings","serialize","hashId","enc","slice","join","idTag","indexOf","from","deserialize","buf","readUIntBE","subarray"],"sources":["../../../../src/tx/builder/field-types/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 */\nexport const idTagToEncoding = [\n Encoding.AccountAddress,\n Encoding.Name,\n Encoding.Commitment,\n Encoding.OracleAddress,\n Encoding.ContractAddress,\n Encoding.Channel,\n] as const;\n\nexport type AddressEncodings = typeof idTagToEncoding[number];\n\nexport default function genAddressField<Encoding extends AddressEncodings>(\n ...encodings: Encoding[]\n): {\n serialize: (value: Encoded.Generic<Encoding>) => Buffer;\n deserialize: (value: Buffer) => Encoded.Generic<Encoding>;\n } {\n return {\n /**\n * Utility function to create and _id type\n * @param hashId - Encoded hash\n * @returns Buffer Buffer with ID tag and decoded HASh\n */\n serialize(hashId) {\n const enc = hashId.slice(0, 2);\n if (!isItemOfArray(enc, idTagToEncoding)) throw new TagNotFoundError(enc);\n if (!isItemOfArray(enc, encodings)) {\n throw new ArgumentError('Address encoding', encodings.join(', '), enc);\n }\n const idTag = idTagToEncoding.indexOf(enc) + 1;\n return Buffer.from([...toBytes(idTag), ...decode(hashId)]);\n },\n\n /**\n * Utility function to read and _id type\n * @param buf - Data\n * @returns Encoded hash string with prefix\n */\n deserialize(buf) {\n const idTag = Buffer.from(buf).readUIntBE(0, 1);\n const enc = idTagToEncoding[idTag - 1];\n if (enc == null) throw new PrefixNotFoundError(idTag);\n if (!isItemOfArray(enc, encodings)) {\n throw new ArgumentError('Address encoding', encodings.join(', '), enc);\n }\n return encode(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ACC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC;MAC/C,MAAMR,GAAG,GAAGX,eAAe,CAACc,KAAK,GAAG,CAAC,CAAC;MACtC,IAAIH,GAAG,IAAI,IAAI,EAAE,MAAM,IAAIlB,mBAAmB,CAACqB,KAAK,CAAC;MACrD,IAAI,CAACf,aAAa,CAACY,GAAG,EAAEH,SAAS,CAAC,EAAE;QAClC,MAAM,IAAIhB,aAAa,CAAC,kBAAkB,EAAEgB,SAAS,CAACK,IAAI,CAAC,IAAI,CAAC,EAAEF,GAAG,CAAC;MACxE;MACA,OAAOd,MAAM,CAACqB,GAAG,CAACE,QAAQ,CAAC,CAAC,CAAC,EAAET,GAAG,CAAC;IACrC;EACF,CAAC;AACH"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export default function genArrayField<Input, Output, Binary>(itemHandler: {
|
|
2
|
+
serialize: (value: Input, params: unknown) => Binary;
|
|
3
|
+
deserialize: (value: Binary, params: unknown) => Output;
|
|
4
|
+
}): {
|
|
5
|
+
serialize: (value: Input[], params: unknown) => Binary[];
|
|
6
|
+
deserialize: (value: Binary[], params: unknown) => Output[];
|
|
7
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default function genArrayField(itemHandler) {
|
|
2
|
+
return {
|
|
3
|
+
serialize(items, params) {
|
|
4
|
+
return items.map(item => itemHandler.serialize(item, params));
|
|
5
|
+
},
|
|
6
|
+
deserialize(buffers, params) {
|
|
7
|
+
return buffers.map(buffer => itemHandler.deserialize(buffer, params));
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=array.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.mjs","names":["genArrayField","itemHandler","serialize","items","params","map","item","deserialize","buffers","buffer"],"sources":["../../../../src/tx/builder/field-types/array.ts"],"sourcesContent":["export default function genArrayField<Input, Output, Binary>(\n itemHandler: {\n serialize: (value: Input, params: unknown) => Binary;\n deserialize: (value: Binary, params: unknown) => Output;\n },\n): {\n serialize: (value: Input[], params: unknown) => Binary[];\n deserialize: (value: Binary[], params: unknown) => Output[];\n } {\n return {\n serialize(items, params) {\n return items.map((item) => itemHandler.serialize(item, params));\n },\n\n deserialize(buffers, params) {\n return buffers.map((buffer) => itemHandler.deserialize(buffer, params));\n },\n };\n}\n"],"mappings":"AAAA,eAAe,SAASA,aAAa,CACnCC,WAGC,EAIC;EACF,OAAO;IACLC,SAAS,CAACC,KAAK,EAAEC,MAAM,EAAE;MACvB,OAAOD,KAAK,CAACE,GAAG,CAAEC,IAAI,IAAKL,WAAW,CAACC,SAAS,CAACI,IAAI,EAAEF,MAAM,CAAC,CAAC;IACjE,CAAC;IAEDG,WAAW,CAACC,OAAO,EAAEJ,MAAM,EAAE;MAC3B,OAAOI,OAAO,CAACH,GAAG,CAAEI,MAAM,IAAKR,WAAW,CAACM,WAAW,CAACE,MAAM,EAAEL,MAAM,CAAC,CAAC;IACzE;EACF,CAAC;AACH"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import _buffer from "buffer";
|
|
2
|
+
const {
|
|
3
|
+
Buffer: _Buffer
|
|
4
|
+
} = _buffer;
|
|
5
|
+
export default {
|
|
6
|
+
serialize(value) {
|
|
7
|
+
return _Buffer.from([value ? 1 : 0]);
|
|
8
|
+
},
|
|
9
|
+
deserialize(buffer) {
|
|
10
|
+
return buffer[0] === 1;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=boolean.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boolean.mjs","names":["serialize","value","from","deserialize","buffer"],"sources":["../../../../src/tx/builder/field-types/boolean.ts"],"sourcesContent":["export default {\n serialize(value: boolean): Buffer {\n return Buffer.from([value ? 1 : 0]);\n },\n\n deserialize(buffer: Buffer): boolean {\n return buffer[0] === 1;\n },\n};\n"],"mappings":";;;;AAAA,eAAe;EACbA,SAAS,CAACC,KAAc,EAAU;IAChC,OAAO,QAAOC,IAAI,CAAC,CAACD,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;EACrC,CAAC;EAEDE,WAAW,CAACC,MAAc,EAAW;IACnC,OAAOA,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;EACxB;AACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coin-amount.mjs","names":["uInt","formatAmount","serializeAettos","value","serialize","denomination","options"],"sources":["../../../../src/tx/builder/field-types/coin-amount.ts"],"sourcesContent":["import uInt
|
|
1
|
+
{"version":3,"file":"coin-amount.mjs","names":["uInt","formatAmount","serializeAettos","value","serialize","denomination","options"],"sources":["../../../../src/tx/builder/field-types/coin-amount.ts"],"sourcesContent":["import uInt from './u-int';\nimport { Int } from '../constants';\nimport { AE_AMOUNT_FORMATS, formatAmount } from '../../../utils/amount-formatter';\n\nexport interface Options { denomination?: AE_AMOUNT_FORMATS }\n\nexport default {\n ...uInt,\n\n serializeAettos(value: string | undefined): string {\n return value ?? '0';\n },\n\n serialize(value: Int | undefined, { denomination, ...options }: Options): Buffer {\n return uInt.serialize(\n this.serializeAettos(\n value != null ? formatAmount(value, { denomination }) : value,\n options,\n ),\n );\n },\n};\n"],"mappings":"OAAOA,IAAI;AAAA,SAEiBC,YAAY;AAIxC,eAAe;EACb,GAAGD,IAAI;EAEPE,eAAe,CAACC,KAAyB,EAAU;IACjD,OAAOA,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,GAAG;EACrB,CAAC;EAEDC,SAAS,CAACD,KAAsB,QAAiD;IAAA,IAA/C;MAAEE,YAAY;MAAE,GAAGC;IAAiB,CAAC;IACrE,OAAON,IAAI,CAACI,SAAS,CACnB,IAAI,CAACF,eAAe,CAClBC,KAAK,IAAI,IAAI,GAAGF,YAAY,CAACE,KAAK,EAAE;MAAEE;IAAa,CAAC,CAAC,GAAGF,KAAK,EAC7DG,OAAO,CACR,CACF;EACH;AACF,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ConsensusProtocolVersion, VmVersion, AbiVersion } from '../constants';
|
|
3
|
+
export declare const ProtocolToVmAbi: {
|
|
4
|
+
readonly 5: {
|
|
5
|
+
readonly 'contract-create': {
|
|
6
|
+
readonly vmVersion: readonly [VmVersion.Fate2];
|
|
7
|
+
readonly abiVersion: readonly [AbiVersion.Fate];
|
|
8
|
+
};
|
|
9
|
+
readonly 'contract-call': {
|
|
10
|
+
readonly vmVersion: readonly [];
|
|
11
|
+
readonly abiVersion: readonly [AbiVersion.Fate, AbiVersion.Sophia];
|
|
12
|
+
};
|
|
13
|
+
readonly 'oracle-call': {
|
|
14
|
+
readonly vmVersion: readonly [];
|
|
15
|
+
readonly abiVersion: readonly [AbiVersion.NoAbi, AbiVersion.Sophia];
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export interface CtVersion {
|
|
20
|
+
vmVersion: VmVersion;
|
|
21
|
+
abiVersion: AbiVersion;
|
|
22
|
+
}
|
|
23
|
+
export declare function getProtocolDetails(protocolVersion: ConsensusProtocolVersion, type: 'contract-create' | 'contract-call' | 'oracle-call'): CtVersion;
|
|
24
|
+
declare const _default: {
|
|
25
|
+
serialize(value: CtVersion | undefined, { consensusProtocolVersion }: {
|
|
26
|
+
consensusProtocolVersion: ConsensusProtocolVersion;
|
|
27
|
+
}): Buffer;
|
|
28
|
+
deserialize(buffer: Buffer): CtVersion;
|
|
29
|
+
};
|
|
30
|
+
export default _default;
|