@aeternity/aepp-sdk 12.1.3 → 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 +12031 -11231
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdk.d.ts +7 -3
- package/es/AeSdk.mjs +17 -22
- package/es/AeSdk.mjs.map +1 -1
- package/es/AeSdkAepp.d.ts +6 -5
- package/es/AeSdkAepp.mjs +7 -30
- package/es/AeSdkAepp.mjs.map +1 -1
- package/es/AeSdkBase.d.ts +18 -140
- package/es/AeSdkBase.mjs +30 -184
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkMethods.d.ts +123 -0
- package/es/AeSdkMethods.mjs +122 -0
- package/es/AeSdkMethods.mjs.map +1 -0
- package/es/AeSdkWallet.d.ts +7 -21
- package/es/AeSdkWallet.mjs +38 -86
- package/es/AeSdkWallet.mjs.map +1 -1
- package/es/Node.d.ts +11 -15
- package/es/Node.mjs +35 -48
- package/es/Node.mjs.map +1 -1
- package/es/account/Base.d.ts +24 -40
- package/es/account/Base.mjs +1 -101
- package/es/account/Base.mjs.map +1 -1
- package/es/account/Generalized.d.ts +16 -0
- package/es/account/Generalized.mjs +113 -0
- package/es/account/Generalized.mjs.map +1 -0
- package/es/account/Ledger.d.ts +28 -0
- package/es/account/Ledger.mjs +102 -0
- package/es/account/Ledger.mjs.map +1 -0
- package/es/account/LedgerFactory.d.ts +39 -0
- package/es/account/LedgerFactory.mjs +81 -0
- package/es/account/LedgerFactory.mjs.map +1 -0
- package/es/account/Memory.d.ts +13 -17
- package/es/account/Memory.mjs +43 -64
- package/es/account/Memory.mjs.map +1 -1
- package/es/account/Rpc.d.ts +6 -8
- package/es/account/Rpc.mjs +14 -32
- package/es/account/Rpc.mjs.map +1 -1
- package/es/aens.d.ts +4 -4
- package/es/aens.mjs +46 -41
- package/es/aens.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/Browser.mjs +9 -13
- 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 +22 -11
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +1 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +0 -31
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +3 -3
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +5 -42
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/types.d.ts +7 -1
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
- package/es/aepp-wallet-communication/schema.mjs +14 -68
- package/es/aepp-wallet-communication/schema.mjs.map +1 -1
- package/es/aepp-wallet-communication/wallet-detector.mjs +0 -3
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
- package/es/apis/compiler/compiler.d.ts +23 -29
- package/es/apis/compiler/compiler.mjs +128 -189
- package/es/apis/compiler/compiler.mjs.map +1 -1
- package/es/apis/compiler/index.mjs.map +1 -1
- package/es/apis/compiler/models/index.d.ts +82 -135
- package/es/apis/compiler/models/index.mjs +1 -47
- package/es/apis/compiler/models/index.mjs.map +1 -1
- package/es/apis/compiler/models/mappers.d.ts +8 -8
- package/es/apis/compiler/models/mappers.mjs +165 -183
- package/es/apis/compiler/models/mappers.mjs.map +1 -1
- package/es/apis/compiler/models/parameters.d.ts +0 -1
- package/es/apis/compiler/models/parameters.mjs +5 -9
- package/es/apis/compiler/models/parameters.mjs.map +1 -1
- package/es/apis/node/index.mjs.map +1 -1
- package/es/apis/node/models/index.d.ts +48 -48
- package/es/apis/node/models/mappers.mjs +12 -6
- package/es/apis/node/models/mappers.mjs.map +1 -1
- package/es/apis/node/models/parameters.mjs.map +1 -1
- package/es/apis/node/node.mjs +43 -84
- package/es/apis/node/node.mjs.map +1 -1
- package/es/chain.d.ts +10 -2
- package/es/chain.mjs +37 -59
- package/es/chain.mjs.map +1 -1
- package/es/channel/Base.d.ts +200 -0
- package/es/channel/Base.mjs +293 -0
- package/es/channel/Base.mjs.map +1 -0
- package/es/channel/Contract.d.ts +248 -0
- package/es/channel/Contract.mjs +420 -0
- package/es/channel/Contract.mjs.map +1 -0
- package/es/channel/Spend.d.ts +219 -0
- package/es/channel/Spend.mjs +385 -0
- package/es/channel/Spend.mjs.map +1 -0
- package/es/channel/handlers.d.ts +8 -21
- package/es/channel/handlers.mjs +151 -899
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/internal.d.ts +27 -21
- package/es/channel/internal.mjs +101 -191
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Contract.d.ts +210 -0
- package/es/contract/Contract.mjs +551 -0
- package/es/contract/Contract.mjs.map +1 -0
- 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/compiler/Http.mjs +118 -0
- 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 +9 -34
- package/es/contract/ga.mjs +29 -112
- 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 -35
- package/es/index.mjs +4 -51
- package/es/index.mjs.map +1 -1
- package/es/oracle.d.ts +5 -5
- package/es/oracle.mjs +34 -40
- package/es/oracle.mjs.map +1 -1
- package/es/spend.d.ts +3 -3
- package/es/spend.mjs +18 -23
- package/es/spend.mjs.map +1 -1
- package/es/tx/builder/constants.d.ts +30 -2
- package/es/tx/builder/constants.mjs +43 -14
- 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 +14 -0
- package/es/tx/builder/field-types/address.mjs +51 -0
- package/es/tx/builder/field-types/address.mjs.map +1 -0
- 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 +2 -3
- package/es/tx/builder/field-types/coin-amount.mjs +4 -12
- 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 -2
- package/es/tx/builder/field-types/deposit.mjs +2 -4
- 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 +7 -0
- package/es/tx/builder/field-types/enumeration.mjs +30 -0
- package/es/tx/builder/field-types/enumeration.mjs.map +1 -0
- package/es/tx/builder/field-types/fee.d.ts +10 -15
- package/es/tx/builder/field-types/fee.mjs +31 -43
- package/es/tx/builder/field-types/fee.mjs.map +1 -1
- package/es/tx/builder/field-types/field.mjs +0 -2
- package/es/tx/builder/field-types/field.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 +12 -14
- package/es/tx/builder/field-types/gas-limit.mjs.map +1 -1
- package/es/tx/builder/field-types/gas-price.d.ts +1 -2
- package/es/tx/builder/field-types/gas-price.mjs +3 -7
- package/es/tx/builder/field-types/gas-price.mjs.map +1 -1
- package/es/tx/builder/field-types/index.d.ts +80 -30
- package/es/tx/builder/field-types/index.mjs +34 -9
- 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 -3
- package/es/tx/builder/field-types/name-fee.mjs +3 -5
- package/es/tx/builder/field-types/name-fee.mjs.map +1 -1
- package/es/tx/builder/field-types/name-id.d.ts +1 -4
- package/es/tx/builder/field-types/name-id.mjs +5 -10
- package/es/tx/builder/field-types/name-id.mjs.map +1 -1
- package/es/tx/builder/field-types/name.mjs +0 -2
- package/es/tx/builder/field-types/name.mjs.map +1 -1
- package/es/tx/builder/field-types/pointers.d.ts +23 -0
- package/es/tx/builder/field-types/pointers.mjs +36 -0
- package/es/tx/builder/field-types/pointers.mjs.map +1 -0
- 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/short-u-int.mjs +0 -2
- package/es/tx/builder/field-types/short-u-int.mjs.map +1 -1
- 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 +3 -4
- package/es/tx/builder/field-types/u-int.mjs.map +1 -1
- package/es/tx/builder/helpers.d.ts +2 -32
- package/es/tx/builder/helpers.mjs +19 -71
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +11 -49
- package/es/tx/builder/index.mjs +57 -337
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +2367 -667
- package/es/tx/builder/schema.mjs +70 -145
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +4 -49
- package/es/tx/index.mjs +38 -112
- package/es/tx/index.mjs.map +1 -1
- package/es/tx/validator.d.ts +4 -6
- package/es/tx/validator.mjs +104 -90
- package/es/tx/validator.mjs.map +1 -1
- package/es/typings/{@aeternity__argon2-browser → @aeternity__aepp-calldata}/index.d.mjs +0 -0
- package/es/typings/@aeternity__aepp-calldata/index.d.mjs.map +1 -0
- package/es/utils/amount-formatter.mjs +4 -10
- package/es/utils/amount-formatter.mjs.map +1 -1
- package/es/utils/autorest.d.ts +1 -0
- package/es/utils/autorest.mjs +17 -19
- package/es/utils/autorest.mjs.map +1 -1
- package/es/utils/bignumber.mjs +4 -7
- package/es/utils/bignumber.mjs.map +1 -1
- package/es/utils/bytes.d.ts +0 -17
- package/es/utils/bytes.mjs +6 -35
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.d.ts +15 -8
- package/es/utils/crypto.mjs +40 -40
- package/es/utils/crypto.mjs.map +1 -1
- package/es/utils/encoder-types.d.ts +28 -28
- package/es/utils/encoder-types.mjs +0 -1
- package/es/utils/encoder-types.mjs.map +1 -1
- package/es/utils/encoder.d.ts +0 -1
- package/es/utils/encoder.mjs +7 -15
- package/es/utils/encoder.mjs.map +1 -1
- package/es/utils/errors.d.ts +15 -14
- package/es/utils/errors.mjs +86 -172
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.d.ts +27 -19
- package/es/utils/hd-wallet.mjs +42 -26
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/json-big.mjs +0 -8
- package/es/utils/json-big.mjs.map +1 -1
- package/es/utils/keystore.d.ts +2 -0
- package/es/utils/keystore.mjs +37 -36
- package/es/utils/keystore.mjs.map +1 -1
- package/es/utils/other.d.ts +4 -2
- package/es/utils/other.mjs +11 -7
- package/es/utils/other.mjs.map +1 -1
- package/es/utils/semver-satisfies.mjs +0 -3
- package/es/utils/semver-satisfies.mjs.map +1 -1
- package/es/utils/string.d.ts +0 -12
- package/es/utils/string.mjs +1 -21
- package/es/utils/string.mjs.map +1 -1
- package/package.json +98 -51
- package/src/AeSdk.ts +15 -11
- package/src/AeSdkAepp.ts +9 -7
- package/src/AeSdkBase.ts +31 -202
- package/src/AeSdkMethods.ts +169 -0
- package/src/AeSdkWallet.ts +16 -47
- package/src/Node.ts +17 -18
- package/src/account/Base.ts +29 -75
- package/src/account/Generalized.ts +98 -0
- package/src/account/Ledger.ts +131 -0
- package/src/account/LedgerFactory.ts +86 -0
- package/src/account/Memory.ts +46 -60
- package/src/account/Rpc.ts +17 -26
- package/src/aens.ts +13 -11
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +21 -9
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +3 -3
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +4 -4
- package/src/aepp-wallet-communication/rpc/types.ts +11 -1
- package/src/aepp-wallet-communication/schema.ts +18 -18
- package/src/apis/compiler/code-model-v4.yaml +681 -888
- package/src/apis/compiler/compiler.ts +113 -154
- package/src/apis/compiler/models/index.ts +80 -140
- package/src/apis/compiler/models/mappers.ts +165 -183
- package/src/apis/compiler/models/parameters.ts +6 -12
- package/src/chain.ts +11 -6
- package/src/channel/Base.ts +335 -0
- package/src/channel/Contract.ts +488 -0
- package/src/channel/Spend.ts +408 -0
- package/src/channel/handlers.ts +164 -582
- package/src/channel/internal.ts +114 -143
- package/src/contract/Contract.ts +610 -0
- 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 +23 -106
- package/src/index-browser.ts +58 -0
- package/src/index.ts +4 -55
- package/src/oracle.ts +8 -8
- package/src/spend.ts +6 -14
- package/src/tx/builder/constants.ts +33 -3
- package/src/tx/builder/field-types/abi-version.ts +21 -0
- package/src/tx/builder/field-types/address.ts +62 -0
- 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 +4 -9
- 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 +32 -0
- package/src/tx/builder/field-types/fee.ts +39 -21
- package/src/tx/builder/field-types/gas-limit.ts +13 -8
- package/src/tx/builder/field-types/gas-price.ts +0 -2
- package/src/tx/builder/field-types/index.ts +54 -15
- package/src/tx/builder/field-types/mptree.ts +242 -0
- package/src/tx/builder/field-types/name-fee.ts +2 -3
- package/src/tx/builder/field-types/name-id.ts +7 -10
- package/src/tx/builder/field-types/pointers.ts +41 -0
- 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 +4 -5
- package/src/tx/builder/helpers.ts +10 -60
- package/src/tx/builder/index.ts +65 -308
- package/src/tx/builder/schema.ts +280 -341
- package/src/tx/index.ts +40 -103
- package/src/tx/validator.ts +91 -96
- package/src/typings/@aeternity__aepp-calldata/index.d.ts +20 -0
- package/src/utils/autorest.ts +16 -1
- package/src/utils/bytes.ts +6 -34
- package/src/utils/crypto.ts +23 -16
- package/src/utils/encoder.ts +0 -1
- package/src/utils/errors.ts +22 -25
- package/src/utils/hd-wallet.ts +30 -9
- package/src/utils/keystore.ts +24 -21
- package/src/utils/other.ts +16 -1
- package/src/utils/string.ts +0 -20
- package/types-legacy/ts4.2/AeSdk.d.ts +41 -0
- package/types-legacy/ts4.2/AeSdkAepp.d.ts +71 -0
- package/types-legacy/ts4.2/AeSdkBase.d.ts +91 -0
- package/types-legacy/ts4.2/AeSdkMethods.d.ts +140 -0
- package/types-legacy/ts4.2/AeSdkWallet.d.ts +90 -0
- package/types-legacy/ts4.2/Node.d.ts +78 -0
- package/types-legacy/ts4.2/account/Base.d.ts +52 -0
- package/types-legacy/ts4.2/account/Generalized.d.ts +16 -0
- package/types-legacy/ts4.2/account/Ledger.d.ts +28 -0
- package/types-legacy/ts4.2/account/LedgerFactory.d.ts +39 -0
- package/types-legacy/ts4.2/account/Memory.d.ts +22 -0
- package/types-legacy/ts4.2/account/Rpc.d.ts +25 -0
- package/types-legacy/ts4.2/aens.d.ts +222 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/connection/Browser.d.ts +33 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/connection/BrowserRuntime.d.ts +19 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +36 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/connection-proxy.d.ts +11 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/rpc/RpcClient.d.ts +34 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/rpc/types.d.ts +83 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/schema.d.ts +133 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/wallet-detector.d.ts +25 -0
- package/types-legacy/ts4.2/apis/compiler/compiler.d.ts +86 -0
- package/types-legacy/ts4.2/apis/compiler/index.d.ts +2 -0
- package/types-legacy/ts4.2/apis/compiler/models/index.d.ts +195 -0
- package/types-legacy/ts4.2/apis/compiler/models/mappers.d.ts +23 -0
- package/types-legacy/ts4.2/apis/compiler/models/parameters.d.ts +12 -0
- package/types-legacy/ts4.2/apis/node/index.d.ts +2 -0
- package/types-legacy/ts4.2/apis/node/models/index.d.ts +1065 -0
- package/types-legacy/ts4.2/apis/node/models/mappers.d.ts +95 -0
- package/types-legacy/ts4.2/apis/node/models/parameters.d.ts +17 -0
- package/types-legacy/ts4.2/apis/node/node.d.ts +215 -0
- package/types-legacy/ts4.2/chain.d.ts +256 -0
- package/types-legacy/ts4.2/channel/Base.d.ts +199 -0
- package/types-legacy/ts4.2/channel/Contract.d.ts +248 -0
- package/types-legacy/ts4.2/channel/Spend.d.ts +219 -0
- package/types-legacy/ts4.2/channel/handlers.d.ts +21 -0
- package/types-legacy/ts4.2/channel/internal.d.ts +107 -0
- package/types-legacy/ts4.2/contract/Contract.d.ts +212 -0
- 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 +44 -0
- package/types-legacy/ts4.2/globals.d.ts +16 -0
- package/types-legacy/ts4.2/index-browser.d.ts +39 -0
- package/types-legacy/ts4.2/index.d.ts +5 -0
- package/types-legacy/ts4.2/oracle.d.ts +161 -0
- package/types-legacy/ts4.2/spend.d.ts +62 -0
- package/types-legacy/ts4.2/tx/builder/constants.d.ts +98 -0
- 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 +21 -0
- 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 +12 -0
- 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 +14 -0
- 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 +7 -0
- package/types-legacy/ts4.2/tx/builder/field-types/fee.d.ts +20 -0
- package/types-legacy/ts4.2/tx/builder/field-types/field.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/gas-limit.d.ts +15 -0
- package/types-legacy/ts4.2/tx/builder/field-types/gas-price.d.ts +7 -0
- package/types-legacy/ts4.2/tx/builder/field-types/index.d.ts +129 -0
- 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 +18 -0
- package/types-legacy/ts4.2/tx/builder/field-types/name-id.d.ts +11 -0
- package/types-legacy/ts4.2/tx/builder/field-types/name.d.ts +13 -0
- package/types-legacy/ts4.2/tx/builder/field-types/pointers.d.ts +26 -0
- 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/short-u-int.d.ts +6 -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 +7 -0
- package/types-legacy/ts4.2/tx/builder/helpers.d.ts +112 -0
- package/types-legacy/ts4.2/tx/builder/index.d.ts +50 -0
- package/types-legacy/ts4.2/tx/builder/schema.d.ts +4675 -0
- package/types-legacy/ts4.2/tx/index.d.ts +19 -0
- package/types-legacy/ts4.2/tx/validator.d.ts +18 -0
- package/types-legacy/ts4.2/utils/amount-formatter.d.ts +42 -0
- package/types-legacy/ts4.2/utils/autorest.d.ts +7 -0
- package/types-legacy/ts4.2/utils/bignumber.d.ts +13 -0
- package/types-legacy/ts4.2/utils/bytes.d.ts +9 -0
- package/types-legacy/ts4.2/utils/crypto.d.ts +95 -0
- package/types-legacy/ts4.2/utils/encoder-types.d.ts +61 -0
- package/types-legacy/ts4.2/utils/encoder.d.ts +24 -0
- package/types-legacy/ts4.2/utils/errors.d.ts +475 -0
- package/types-legacy/ts4.2/utils/hd-wallet.d.ts +65 -0
- package/types-legacy/ts4.2/utils/json-big.d.ts +5 -0
- package/types-legacy/ts4.2/utils/keystore.d.ts +53 -0
- package/types-legacy/ts4.2/utils/other.d.ts +31 -0
- package/types-legacy/ts4.2/utils/semver-satisfies.d.ts +1 -0
- package/types-legacy/ts4.2/utils/string.d.ts +12 -0
- package/types-legacy/ts4.5/AeSdk.d.ts +41 -0
- package/types-legacy/ts4.5/AeSdkAepp.d.ts +71 -0
- package/types-legacy/ts4.5/AeSdkBase.d.ts +91 -0
- package/types-legacy/ts4.5/AeSdkMethods.d.ts +140 -0
- package/types-legacy/ts4.5/AeSdkWallet.d.ts +90 -0
- package/types-legacy/ts4.5/Node.d.ts +78 -0
- package/types-legacy/ts4.5/account/Base.d.ts +52 -0
- package/types-legacy/ts4.5/account/Generalized.d.ts +16 -0
- package/types-legacy/ts4.5/account/Ledger.d.ts +28 -0
- package/types-legacy/ts4.5/account/LedgerFactory.d.ts +39 -0
- package/types-legacy/ts4.5/account/Memory.d.ts +22 -0
- package/types-legacy/ts4.5/account/Rpc.d.ts +25 -0
- package/types-legacy/ts4.5/aens.d.ts +222 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/connection/Browser.d.ts +33 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/connection/BrowserRuntime.d.ts +19 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +36 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/connection-proxy.d.ts +11 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/rpc/RpcClient.d.ts +34 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/rpc/types.d.ts +83 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/schema.d.ts +133 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/wallet-detector.d.ts +25 -0
- package/types-legacy/ts4.5/apis/compiler/compiler.d.ts +86 -0
- package/types-legacy/ts4.5/apis/compiler/index.d.ts +2 -0
- package/types-legacy/ts4.5/apis/compiler/models/index.d.ts +195 -0
- package/types-legacy/ts4.5/apis/compiler/models/mappers.d.ts +23 -0
- package/types-legacy/ts4.5/apis/compiler/models/parameters.d.ts +12 -0
- package/types-legacy/ts4.5/apis/node/index.d.ts +2 -0
- package/types-legacy/ts4.5/apis/node/models/index.d.ts +1065 -0
- package/types-legacy/ts4.5/apis/node/models/mappers.d.ts +95 -0
- package/types-legacy/ts4.5/apis/node/models/parameters.d.ts +17 -0
- package/types-legacy/ts4.5/apis/node/node.d.ts +215 -0
- package/types-legacy/ts4.5/chain.d.ts +256 -0
- package/types-legacy/ts4.5/channel/Base.d.ts +199 -0
- package/types-legacy/ts4.5/channel/Contract.d.ts +248 -0
- package/types-legacy/ts4.5/channel/Spend.d.ts +219 -0
- package/types-legacy/ts4.5/channel/handlers.d.ts +21 -0
- package/types-legacy/ts4.5/channel/internal.d.ts +107 -0
- package/types-legacy/ts4.5/contract/Contract.d.ts +212 -0
- 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 +44 -0
- package/types-legacy/ts4.5/index-browser.d.ts +39 -0
- package/types-legacy/ts4.5/index.d.ts +4 -0
- package/types-legacy/ts4.5/oracle.d.ts +161 -0
- package/types-legacy/ts4.5/spend.d.ts +62 -0
- package/types-legacy/ts4.5/tx/builder/constants.d.ts +98 -0
- 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 +21 -0
- 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 +12 -0
- 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 +14 -0
- 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 +7 -0
- package/types-legacy/ts4.5/tx/builder/field-types/fee.d.ts +20 -0
- package/types-legacy/ts4.5/tx/builder/field-types/field.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/gas-limit.d.ts +15 -0
- package/types-legacy/ts4.5/tx/builder/field-types/gas-price.d.ts +7 -0
- package/types-legacy/ts4.5/tx/builder/field-types/index.d.ts +129 -0
- 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 +18 -0
- package/types-legacy/ts4.5/tx/builder/field-types/name-id.d.ts +11 -0
- package/types-legacy/ts4.5/tx/builder/field-types/name.d.ts +13 -0
- package/types-legacy/ts4.5/tx/builder/field-types/pointers.d.ts +26 -0
- 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/short-u-int.d.ts +6 -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 +7 -0
- package/types-legacy/ts4.5/tx/builder/helpers.d.ts +112 -0
- package/types-legacy/ts4.5/tx/builder/index.d.ts +50 -0
- package/types-legacy/ts4.5/tx/builder/schema.d.ts +4675 -0
- package/types-legacy/ts4.5/tx/index.d.ts +19 -0
- package/types-legacy/ts4.5/tx/validator.d.ts +18 -0
- package/types-legacy/ts4.5/utils/amount-formatter.d.ts +42 -0
- package/types-legacy/ts4.5/utils/autorest.d.ts +7 -0
- package/types-legacy/ts4.5/utils/bignumber.d.ts +13 -0
- package/types-legacy/ts4.5/utils/bytes.d.ts +9 -0
- package/types-legacy/ts4.5/utils/crypto.d.ts +95 -0
- package/types-legacy/ts4.5/utils/encoder-types.d.ts +61 -0
- package/types-legacy/ts4.5/utils/encoder.d.ts +24 -0
- package/types-legacy/ts4.5/utils/errors.d.ts +475 -0
- package/types-legacy/ts4.5/utils/hd-wallet.d.ts +65 -0
- package/types-legacy/ts4.5/utils/json-big.d.ts +5 -0
- package/types-legacy/ts4.5/utils/keystore.d.ts +53 -0
- package/types-legacy/ts4.5/utils/other.d.ts +31 -0
- package/types-legacy/ts4.5/utils/semver-satisfies.d.ts +1 -0
- package/types-legacy/ts4.5/utils/string.d.ts +12 -0
- package/es/channel/index.d.ts +0 -625
- package/es/channel/index.mjs +0 -975
- package/es/channel/index.mjs.map +0 -1
- package/es/contract/Compiler.d.ts +0 -18
- package/es/contract/Compiler.mjs +0 -68
- package/es/contract/Compiler.mjs.map +0 -1
- package/es/contract/aci.d.ts +0 -127
- package/es/contract/aci.mjs +0 -508
- package/es/contract/aci.mjs.map +0 -1
- package/es/contract/methods.d.ts +0 -71
- package/es/contract/methods.mjs +0 -104
- package/es/contract/methods.mjs.map +0 -1
- package/es/deprecated/index.d.ts +0 -143
- package/es/deprecated/index.mjs +0 -162
- package/es/deprecated/index.mjs.map +0 -1
- package/es/deprecated/methods.d.ts +0 -18
- package/es/deprecated/methods.mjs +0 -26
- package/es/deprecated/methods.mjs.map +0 -1
- package/es/tx/builder/address.d.ts +0 -25
- package/es/tx/builder/address.mjs +0 -45
- package/es/tx/builder/address.mjs.map +0 -1
- package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +0 -1
- package/es/utils/mptree.d.ts +0 -26
- package/es/utils/mptree.mjs +0 -165
- package/es/utils/mptree.mjs.map +0 -1
- package/src/channel/index.ts +0 -1025
- package/src/contract/Compiler.ts +0 -67
- package/src/contract/aci.ts +0 -537
- package/src/contract/methods.ts +0 -123
- package/src/deprecated/index.ts +0 -172
- package/src/deprecated/methods.ts +0 -25
- package/src/tx/builder/address.ts +0 -50
- package/src/typings/@aeternity__argon2-browser/index.d.ts +0 -3
- package/src/utils/mptree.ts +0 -145
package/es/oracle.mjs
CHANGED
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
15
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
17
|
/**
|
|
19
18
|
* Oracle methods - routines to interact with the æternity oracle system
|
|
20
19
|
*
|
|
@@ -30,9 +29,8 @@ import { ORACLE_TTL, QUERY_FEE, QUERY_TTL, RESPONSE_TTL } from "./tx/builder/sch
|
|
|
30
29
|
import { Tag } from "./tx/builder/constants.mjs";
|
|
31
30
|
import { RequestTimedOutError } from "./utils/errors.mjs";
|
|
32
31
|
import { decode, encode, Encoding } from "./utils/encoder.mjs";
|
|
33
|
-
import { _getPollInterval } from "./chain.mjs";
|
|
32
|
+
import { _getPollInterval, getHeight } from "./chain.mjs";
|
|
34
33
|
import { _buildTx } from "./tx/index.mjs";
|
|
35
|
-
|
|
36
34
|
/**
|
|
37
35
|
* Poll for oracle queries
|
|
38
36
|
* @category oracle
|
|
@@ -45,7 +43,6 @@ import { _buildTx } from "./tx/index.mjs";
|
|
|
45
43
|
*/
|
|
46
44
|
export function pollForQueries(oracleId, onQuery, _ref) {
|
|
47
45
|
var _interval;
|
|
48
|
-
|
|
49
46
|
let {
|
|
50
47
|
interval,
|
|
51
48
|
onNode,
|
|
@@ -53,10 +50,8 @@ export function pollForQueries(oracleId, onQuery, _ref) {
|
|
|
53
50
|
} = _ref;
|
|
54
51
|
(_interval = interval) !== null && _interval !== void 0 ? _interval : interval = _getPollInterval('microblock', options);
|
|
55
52
|
const knownQueryIds = new Set();
|
|
56
|
-
|
|
57
53
|
const checkNewQueries = async () => {
|
|
58
54
|
var _await$onNode$getOrac;
|
|
59
|
-
|
|
60
55
|
const queries = ((_await$onNode$getOrac = (await onNode.getOracleQueriesByPubkey(oracleId)).oracleQueries) !== null && _await$onNode$getOrac !== void 0 ? _await$onNode$getOrac : []).filter(_ref2 => {
|
|
61
56
|
let {
|
|
62
57
|
id
|
|
@@ -71,9 +66,9 @@ export function pollForQueries(oracleId, onQuery, _ref) {
|
|
|
71
66
|
});
|
|
72
67
|
if (queries.length > 0) onQuery(queries);
|
|
73
68
|
};
|
|
69
|
+
let stopped = false;
|
|
74
70
|
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
77
72
|
(async () => {
|
|
78
73
|
while (!stopped) {
|
|
79
74
|
// eslint-disable-line no-unmodified-loop-condition
|
|
@@ -82,11 +77,11 @@ export function pollForQueries(oracleId, onQuery, _ref) {
|
|
|
82
77
|
await pause(interval);
|
|
83
78
|
}
|
|
84
79
|
})();
|
|
85
|
-
|
|
86
80
|
return () => {
|
|
87
81
|
stopped = true;
|
|
88
82
|
};
|
|
89
83
|
}
|
|
84
|
+
|
|
90
85
|
/**
|
|
91
86
|
* Poll for oracle query response
|
|
92
87
|
* @category oracle
|
|
@@ -97,10 +92,8 @@ export function pollForQueries(oracleId, onQuery, _ref) {
|
|
|
97
92
|
* @param options.onNode - Node to use
|
|
98
93
|
* @returns OracleQuery object
|
|
99
94
|
*/
|
|
100
|
-
|
|
101
95
|
export async function pollForQueryResponse(oracleId, queryId, _ref4) {
|
|
102
96
|
var _interval2;
|
|
103
|
-
|
|
104
97
|
let {
|
|
105
98
|
interval,
|
|
106
99
|
onNode,
|
|
@@ -110,20 +103,21 @@ export async function pollForQueryResponse(oracleId, queryId, _ref4) {
|
|
|
110
103
|
let height;
|
|
111
104
|
let ttl;
|
|
112
105
|
let response;
|
|
113
|
-
|
|
114
106
|
do {
|
|
115
|
-
if (height != null) await pause(interval);
|
|
116
107
|
({
|
|
117
108
|
response,
|
|
118
109
|
ttl
|
|
119
110
|
} = await onNode.getOracleQueryByPubkeyAndQueryId(oracleId, queryId));
|
|
120
111
|
const responseBuffer = decode(response);
|
|
121
112
|
if (responseBuffer.length > 0) return responseBuffer.toString();
|
|
122
|
-
|
|
113
|
+
await pause(interval);
|
|
114
|
+
height = await getHeight({
|
|
115
|
+
onNode
|
|
116
|
+
});
|
|
123
117
|
} while (ttl >= height);
|
|
124
|
-
|
|
125
118
|
throw new RequestTimedOutError(height);
|
|
126
119
|
}
|
|
120
|
+
|
|
127
121
|
/**
|
|
128
122
|
* Constructor for OracleQuery Object (helper object for using OracleQuery)
|
|
129
123
|
* @category oracle
|
|
@@ -132,22 +126,24 @@ export async function pollForQueryResponse(oracleId, queryId, _ref4) {
|
|
|
132
126
|
* @param options - Options
|
|
133
127
|
* @returns OracleQuery object
|
|
134
128
|
*/
|
|
135
|
-
|
|
136
129
|
export async function getQueryObject(oracleId, queryId, options) {
|
|
137
130
|
const record = await options.onNode.getOracleQueryByPubkeyAndQueryId(oracleId, queryId);
|
|
138
|
-
return {
|
|
131
|
+
return {
|
|
132
|
+
...record,
|
|
139
133
|
decodedQuery: decode(record.query).toString(),
|
|
140
134
|
decodedResponse: decode(record.response).toString(),
|
|
141
|
-
respond: async (response, opt) =>
|
|
142
|
-
|
|
135
|
+
respond: async (response, opt) =>
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
137
|
+
respondToQuery(oracleId, queryId, response, {
|
|
138
|
+
...options,
|
|
143
139
|
...opt
|
|
144
140
|
}),
|
|
145
|
-
pollForResponse: async opt => pollForQueryResponse(oracleId, queryId, {
|
|
141
|
+
pollForResponse: async opt => pollForQueryResponse(oracleId, queryId, {
|
|
142
|
+
...options,
|
|
146
143
|
...opt
|
|
147
144
|
})
|
|
148
145
|
};
|
|
149
146
|
}
|
|
150
|
-
|
|
151
147
|
/**
|
|
152
148
|
* Post query to oracle
|
|
153
149
|
* @category oracle
|
|
@@ -163,9 +159,8 @@ export async function getQueryObject(oracleId, queryId, options) {
|
|
|
163
159
|
*/
|
|
164
160
|
export async function postQueryToOracle(oracleId, query, options) {
|
|
165
161
|
var _options$queryFee;
|
|
166
|
-
|
|
167
162
|
(_options$queryFee = options.queryFee) !== null && _options$queryFee !== void 0 ? _options$queryFee : options.queryFee = (await options.onNode.getOracleByPubkey(oracleId)).queryFee.toString();
|
|
168
|
-
const senderId =
|
|
163
|
+
const senderId = options.onAccount.address;
|
|
169
164
|
const oracleQueryTx = await _buildTx(Tag.OracleQueryTx, {
|
|
170
165
|
queryTtlType: QUERY_TTL.type,
|
|
171
166
|
queryTtlValue: QUERY_TTL.value,
|
|
@@ -178,13 +173,13 @@ export async function postQueryToOracle(oracleId, query, options) {
|
|
|
178
173
|
});
|
|
179
174
|
const {
|
|
180
175
|
nonce
|
|
181
|
-
} = unpackTx(oracleQueryTx, Tag.OracleQueryTx)
|
|
176
|
+
} = unpackTx(oracleQueryTx, Tag.OracleQueryTx);
|
|
182
177
|
const queryId = oracleQueryId(senderId, nonce, oracleId);
|
|
183
|
-
return {
|
|
178
|
+
return {
|
|
179
|
+
...(await send(oracleQueryTx, options)),
|
|
184
180
|
...(await getQueryObject(oracleId, queryId, options))
|
|
185
181
|
};
|
|
186
182
|
}
|
|
187
|
-
|
|
188
183
|
/**
|
|
189
184
|
* Extend oracle ttl
|
|
190
185
|
* @category oracle
|
|
@@ -201,15 +196,15 @@ export async function extendOracleTtl(oracleId, options) {
|
|
|
201
196
|
oracleTtlType: ORACLE_TTL.type,
|
|
202
197
|
oracleTtlValue: ORACLE_TTL.value,
|
|
203
198
|
...options,
|
|
204
|
-
callerId:
|
|
199
|
+
callerId: options.onAccount.address,
|
|
205
200
|
oracleId
|
|
206
201
|
});
|
|
207
|
-
return {
|
|
202
|
+
return {
|
|
203
|
+
...(await send(oracleExtendTx, options)),
|
|
208
204
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
209
205
|
...(await getOracleObject(oracleId, options))
|
|
210
206
|
};
|
|
211
207
|
}
|
|
212
|
-
|
|
213
208
|
/**
|
|
214
209
|
* Extend oracle ttl
|
|
215
210
|
* @category oracle
|
|
@@ -227,17 +222,17 @@ export async function respondToQuery(oracleId, queryId, response, options) {
|
|
|
227
222
|
responseTtlType: RESPONSE_TTL.type,
|
|
228
223
|
responseTtlValue: RESPONSE_TTL.value,
|
|
229
224
|
...options,
|
|
230
|
-
callerId:
|
|
225
|
+
callerId: options.onAccount.address,
|
|
231
226
|
oracleId,
|
|
232
227
|
queryId,
|
|
233
228
|
response
|
|
234
229
|
});
|
|
235
|
-
return {
|
|
230
|
+
return {
|
|
231
|
+
...(await send(oracleRespondTx, options)),
|
|
236
232
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
237
233
|
...(await getOracleObject(oracleId, options))
|
|
238
234
|
};
|
|
239
235
|
}
|
|
240
|
-
|
|
241
236
|
/**
|
|
242
237
|
* Constructor for Oracle Object (helper object for using Oracle)
|
|
243
238
|
* @category oracle
|
|
@@ -246,7 +241,8 @@ export async function respondToQuery(oracleId, queryId, response, options) {
|
|
|
246
241
|
* @returns Oracle object
|
|
247
242
|
*/
|
|
248
243
|
export async function getOracleObject(oracleId, options) {
|
|
249
|
-
return {
|
|
244
|
+
return {
|
|
245
|
+
...(await options.onNode.getOracleByPubkey(oracleId)),
|
|
250
246
|
queries: (await options.onNode.getOracleQueriesByPubkey(oracleId)).oracleQueries,
|
|
251
247
|
...mapObject({
|
|
252
248
|
pollQueries: pollForQueries,
|
|
@@ -260,21 +256,18 @@ export async function getOracleObject(oracleId, options) {
|
|
|
260
256
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
261
257
|
args[_key] = arguments[_key];
|
|
262
258
|
}
|
|
263
|
-
|
|
264
259
|
const lastArg = args[args.length - 1];
|
|
265
|
-
|
|
266
260
|
if (lastArg != null && typeof lastArg === 'object' && lastArg.constructor === Object) {
|
|
267
|
-
Object.assign(lastArg, {
|
|
261
|
+
Object.assign(lastArg, {
|
|
262
|
+
...options,
|
|
268
263
|
...lastArg
|
|
269
264
|
});
|
|
270
265
|
} else args.push(options);
|
|
271
|
-
|
|
272
266
|
return handler(oracleId, ...args);
|
|
273
267
|
}];
|
|
274
268
|
})
|
|
275
269
|
};
|
|
276
270
|
}
|
|
277
|
-
|
|
278
271
|
/**
|
|
279
272
|
* Register oracle
|
|
280
273
|
* @category oracle
|
|
@@ -289,7 +282,7 @@ export async function getOracleObject(oracleId, options) {
|
|
|
289
282
|
* @returns Oracle object
|
|
290
283
|
*/
|
|
291
284
|
export async function registerOracle(queryFormat, responseFormat, options) {
|
|
292
|
-
const accountId =
|
|
285
|
+
const accountId = options.onAccount.address;
|
|
293
286
|
const oracleRegisterTx = await _buildTx(Tag.OracleRegisterTx, {
|
|
294
287
|
queryFee: QUERY_FEE,
|
|
295
288
|
oracleTtlValue: ORACLE_TTL.value,
|
|
@@ -299,7 +292,8 @@ export async function registerOracle(queryFormat, responseFormat, options) {
|
|
|
299
292
|
queryFormat,
|
|
300
293
|
responseFormat
|
|
301
294
|
});
|
|
302
|
-
return {
|
|
295
|
+
return {
|
|
296
|
+
...(await send(oracleRegisterTx, options)),
|
|
303
297
|
...(await getOracleObject(encode(decode(accountId), Encoding.OracleAddress), options))
|
|
304
298
|
};
|
|
305
299
|
}
|
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","_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,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,EAGL1E,OAHK,EAIoF;EACzF,MAAM2E,SAAS,GAAG,MAAM3E,OAAO,CAACuC,SAAR,CAAkBC,OAAlB,CAA0BxC,OAA1B,CAAxB;EACA,MAAM4E,gBAAgB,GAAG,MAAMlF,QAAQ,CAACN,GAAG,CAACyF,gBAAL,EAAuB;IAC5DzC,QAAQ,EAAEnD,SADkD;IAE5DsE,cAAc,EAAEvE,UAAU,CAAC8D,KAFiC;IAG5DQ,aAAa,EAAEtE,UAAU,CAAC4D,IAHkC;IAI5D,GAAG5C,OAJyD;IAK5D2E,SAL4D;IAM5DF,WAN4D;IAO5DC;EAP4D,CAAvB,CAAvC;EASA,OAAO,EACL,IAAG,MAAM/F,IAAI,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"}
|
|
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;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,QAAQ,GAAKN,gBAAgB,CAAC,YAAY,EAAEQ,OAAO,CAAC;EACpD,MAAMC,aAAa,GAAG,IAAIC,GAAG,EAAE;EAC/B,MAAMC,eAAe,GAAG,YAA2B;IAAA;IACjD,MAAMC,OAAO,GAAG,0BAAC,CAAC,MAAML,MAAM,CAACM,wBAAwB,CAACT,QAAQ,CAAC,EAAEU,aAAa,yEAAI,EAAE,EACnFC,MAAM,CAAC;MAAA,IAAC;QAAEC;MAAG,CAAC;MAAA,OAAK,CAACP,aAAa,CAACQ,GAAG,CAACD,EAAE,CAAC;IAAA,EAAC;IAC7CJ,OAAO,CAACM,OAAO,CAAC;MAAA,IAAC;QAAEF;MAAG,CAAC;MAAA,OAAKP,aAAa,CAACU,GAAG,CAACH,EAAE,CAAC;IAAA,EAAC;IAClD,IAAIJ,OAAO,CAACQ,MAAM,GAAG,C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rE,OAAO,CAAC;QACzB,OAAO+D,OAAO,CAACnE,QAAQ,EAAE,GAAGoE,IAAI,CAAC;MACnC,CAAC,CACF;IAAA;EAEL,CAAC;AACH;AAaA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeM,cAAc,CAClCC,WAAmB,EACnBC,cAAsB,EACtBxE,OAA8B,EAC2D;EACzF,MAAMyE,SAAS,GAAGzE,OAAO,CAACsC,SAAS,CAACC,OAAO;EAC3C,MAAMmC,gBAAgB,GAAG,MAAMhF,QAAQ,CAACP,GAAG,CAACwF,gBAAgB,EAAE;IAC5DxC,QAAQ,EAAEnD,SAAS;IACnBqE,cAAc,EAAEtE,UAAU,CAAC8D,KAAK;IAChCO,aAAa,EAAErE,UAAU,CAAC4D,IAAI;IAC9B,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.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ import AccountBase from './account/Base';
|
|
|
13
13
|
* @returns Transaction
|
|
14
14
|
*/
|
|
15
15
|
export declare function send(tx: Encoded.Transaction, options: SendOptions): Promise<SendReturnType>;
|
|
16
|
-
|
|
16
|
+
type SendOptionsType = Parameters<AccountBase['signTransaction']>[1] & Parameters<typeof sendTransaction>[1] & {
|
|
17
17
|
onAccount: AccountBase;
|
|
18
18
|
};
|
|
19
19
|
export interface SendOptions extends SendOptionsType {
|
|
@@ -29,7 +29,7 @@ interface SendReturnType extends Awaited<ReturnType<typeof sendTransaction>> {
|
|
|
29
29
|
* @returns Transaction
|
|
30
30
|
*/
|
|
31
31
|
export declare function spend(amount: number | string, recipientIdOrName: Encoded.AccountAddress | AensName, options: SpendOptions): ReturnType<typeof send>;
|
|
32
|
-
|
|
32
|
+
type SpendOptionsType = BuildTxOptions<Tag.SpendTx, 'senderId' | 'recipientId' | 'amount'> & Parameters<typeof resolveName>[2] & {
|
|
33
33
|
onAccount: AccountBase;
|
|
34
34
|
} & SendOptions;
|
|
35
35
|
interface SpendOptions extends SpendOptionsType {
|
|
@@ -43,7 +43,7 @@ interface SpendOptions extends SpendOptionsType {
|
|
|
43
43
|
* @returns Transaction
|
|
44
44
|
*/
|
|
45
45
|
export declare function transferFunds(fraction: number | string, recipientIdOrName: AensName | Encoded.AccountAddress, options: TransferFundsOptions): ReturnType<typeof send>;
|
|
46
|
-
|
|
46
|
+
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 {
|
package/es/spend.mjs
CHANGED
|
@@ -15,12 +15,11 @@
|
|
|
15
15
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
*/
|
|
17
17
|
import BigNumber from 'bignumber.js';
|
|
18
|
-
import { sendTransaction,
|
|
18
|
+
import { sendTransaction, getBalance, resolveName } from "./chain.mjs";
|
|
19
19
|
import { _buildTx } from "./tx/index.mjs";
|
|
20
20
|
import { buildTxHash, unpackTx } from "./tx/builder/index.mjs";
|
|
21
21
|
import { ArgumentError } from "./utils/errors.mjs";
|
|
22
22
|
import { Tag } from "./tx/builder/constants.mjs";
|
|
23
|
-
|
|
24
23
|
/**
|
|
25
24
|
* Sign and post a transaction to the chain
|
|
26
25
|
* @category chain
|
|
@@ -31,18 +30,15 @@ import { Tag } from "./tx/builder/constants.mjs";
|
|
|
31
30
|
* @returns Transaction
|
|
32
31
|
*/
|
|
33
32
|
export async function send(tx, options) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
authFun,
|
|
38
|
-
networkId: (await options.onNode.getStatus()).networkId
|
|
33
|
+
const signed = await options.onAccount.signTransaction(tx, {
|
|
34
|
+
...options,
|
|
35
|
+
networkId: await options.onNode.getNetworkId()
|
|
39
36
|
});
|
|
40
37
|
return options.innerTx === true ? {
|
|
41
38
|
hash: buildTxHash(signed),
|
|
42
39
|
rawTx: signed
|
|
43
40
|
} : sendTransaction(signed, options);
|
|
44
41
|
}
|
|
45
|
-
|
|
46
42
|
/**
|
|
47
43
|
* Send coins to another account
|
|
48
44
|
* @category chain
|
|
@@ -52,14 +48,14 @@ export async function send(tx, options) {
|
|
|
52
48
|
* @returns Transaction
|
|
53
49
|
*/
|
|
54
50
|
export async function spend(amount, recipientIdOrName, options) {
|
|
55
|
-
return send(await _buildTx(Tag.SpendTx, {
|
|
56
|
-
|
|
51
|
+
return send(await _buildTx(Tag.SpendTx, {
|
|
52
|
+
...options,
|
|
53
|
+
senderId: options.onAccount.address,
|
|
57
54
|
recipientId: await resolveName(recipientIdOrName, 'account_pubkey', options),
|
|
58
55
|
amount
|
|
59
56
|
}), options);
|
|
60
57
|
}
|
|
61
58
|
// TODO: Rename to spendFraction
|
|
62
|
-
|
|
63
59
|
/**
|
|
64
60
|
* Send a fraction of coin balance to another account
|
|
65
61
|
* @category chain
|
|
@@ -72,29 +68,27 @@ export async function transferFunds(fraction, recipientIdOrName, options) {
|
|
|
72
68
|
if (fraction < 0 || fraction > 1) {
|
|
73
69
|
throw new ArgumentError('fraction', 'a number between 0 and 1', fraction);
|
|
74
70
|
}
|
|
75
|
-
|
|
76
71
|
const recipientId = await resolveName(recipientIdOrName, 'account_pubkey', options);
|
|
77
|
-
const senderId =
|
|
72
|
+
const senderId = options.onAccount.address;
|
|
78
73
|
const balance = new BigNumber(await getBalance.bind(options.onAccount)(senderId, options));
|
|
79
74
|
const desiredAmount = balance.times(fraction).integerValue(BigNumber.ROUND_HALF_UP);
|
|
80
75
|
const {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
} = unpackTx(await _buildTx(Tag.SpendTx, { ...options,
|
|
76
|
+
fee
|
|
77
|
+
} = unpackTx(await _buildTx(Tag.SpendTx, {
|
|
78
|
+
...options,
|
|
85
79
|
senderId,
|
|
86
80
|
recipientId,
|
|
87
81
|
amount: desiredAmount
|
|
88
|
-
}), Tag.SpendTx);
|
|
89
|
-
|
|
82
|
+
}), Tag.SpendTx);
|
|
83
|
+
// Reducing of the amount may reduce transaction fee, so this is not completely accurate
|
|
90
84
|
const amount = desiredAmount.plus(fee).gt(balance) ? balance.minus(fee) : desiredAmount;
|
|
91
|
-
return send(await _buildTx(Tag.SpendTx, {
|
|
85
|
+
return send(await _buildTx(Tag.SpendTx, {
|
|
86
|
+
...options,
|
|
92
87
|
senderId,
|
|
93
88
|
recipientId,
|
|
94
89
|
amount
|
|
95
90
|
}), options);
|
|
96
91
|
}
|
|
97
|
-
|
|
98
92
|
/**
|
|
99
93
|
* Submit transaction of another account paying for it (fee and gas)
|
|
100
94
|
* @category chain
|
|
@@ -103,8 +97,9 @@ export async function transferFunds(fraction, recipientIdOrName, options) {
|
|
|
103
97
|
* @returns Object Transaction
|
|
104
98
|
*/
|
|
105
99
|
export async function payForTransaction(transaction, options) {
|
|
106
|
-
return send(await _buildTx(Tag.PayingForTx, {
|
|
107
|
-
|
|
100
|
+
return send(await _buildTx(Tag.PayingForTx, {
|
|
101
|
+
...options,
|
|
102
|
+
payerId: options.onAccount.address,
|
|
108
103
|
tx: transaction
|
|
109
104
|
}), options);
|
|
110
105
|
}
|
package/es/spend.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spend.mjs","names":["BigNumber","sendTransaction","
|
|
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,C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AI,CAAC,GAAG9B,QAAQ,CACtB,MAAMF,QAAQ,CAACI,GAAG,CAACgB,OAAO,EAAE;IAC1B,GAAGb,OAAO;IAAEc,QAAQ;IAAEE,WAAW;IAAEL,MAAM,EAAEU;EAC7C,CAAC,CAAC,EACFxB,GAAG,CAACgB,OAAO,CACZ;EACD;EACA,MAAMF,MAAM,GAAGU,aAAa,CAACK,IAAI,CAACD,GAAG,CAAC,CAACE,EAAE,CAACR,OAAO,CAAC,GAAGA,OAAO,CAACS,KAAK,CAACH,GAAG,CAAC,GAAGJ,aAAa;EACvF,OAAOvB,IAAI,CACT,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,7 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
|
-
export declare
|
|
2
|
+
export declare const MAX_AUTH_FUN_GAS = 50000;
|
|
3
|
+
export type Int = number | string | BigNumber;
|
|
4
|
+
export type AensName = `${string}.chain`;
|
|
3
5
|
export declare const NAME_TTL = 180000;
|
|
4
6
|
export declare const NAME_MAX_TTL = 36000;
|
|
5
7
|
export declare const NAME_MAX_CLIENT_TTL = 84600;
|
|
@@ -13,6 +15,31 @@ export declare const NAME_BID_MAX_LENGTH = 12;
|
|
|
13
15
|
export declare const NAME_BID_RANGES: {
|
|
14
16
|
[k: string]: BigNumber;
|
|
15
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
|
+
}
|
|
16
43
|
/**
|
|
17
44
|
* Enum with tag types
|
|
18
45
|
* @category transaction builder
|
|
@@ -23,10 +50,12 @@ export declare enum Tag {
|
|
|
23
50
|
Account = 10,
|
|
24
51
|
SignedTx = 11,
|
|
25
52
|
SpendTx = 12,
|
|
53
|
+
Oracle = 20,
|
|
26
54
|
OracleRegisterTx = 22,
|
|
27
55
|
OracleQueryTx = 23,
|
|
28
56
|
OracleResponseTx = 24,
|
|
29
57
|
OracleExtendTx = 25,
|
|
58
|
+
Name = 30,
|
|
30
59
|
NameClaimTx = 32,
|
|
31
60
|
NamePreclaimTx = 33,
|
|
32
61
|
NameUpdateTx = 34,
|
|
@@ -63,7 +92,6 @@ export declare enum Tag {
|
|
|
63
92
|
NameserviceMtree = 624,
|
|
64
93
|
OraclesMtree = 625,
|
|
65
94
|
AccountsMtree = 626,
|
|
66
|
-
CompilerSophia = 70,
|
|
67
95
|
GaAttachTx = 80,
|
|
68
96
|
GaMetaTx = 81,
|
|
69
97
|
PayingForTx = 82
|