@aeternity/aepp-sdk 12.1.3 → 13.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.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 +6580 -8859
- 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 +27 -185
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkMethods.d.ts +124 -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 +7 -12
- package/es/Node.mjs +34 -47
- 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 +111 -0
- package/es/account/Generalized.mjs.map +1 -0
- package/es/account/Ledger.d.ts +28 -0
- package/es/account/Ledger.mjs +101 -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 -65
- 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 +3 -3
- package/es/aens.mjs +42 -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.mjs +3 -7
- 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 +4 -41
- 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 +1 -1
- package/es/chain.mjs +33 -58
- package/es/chain.mjs.map +1 -1
- package/es/channel/Base.d.ts +195 -0
- package/es/channel/Base.mjs +290 -0
- package/es/channel/Base.mjs.map +1 -0
- package/es/channel/Contract.d.ts +247 -0
- package/es/channel/Contract.mjs +420 -0
- package/es/channel/Contract.mjs.map +1 -0
- package/es/channel/Spend.d.ts +217 -0
- package/es/channel/Spend.mjs +383 -0
- package/es/channel/Spend.mjs.map +1 -0
- package/es/channel/handlers.d.ts +8 -21
- package/es/channel/handlers.mjs +141 -891
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/internal.d.ts +27 -21
- package/es/channel/internal.mjs +98 -190
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/{Compiler.d.ts → CompilerHttp.d.ts} +3 -3
- package/es/contract/{Compiler.mjs → CompilerHttp.mjs} +8 -13
- package/es/contract/CompilerHttp.mjs.map +1 -0
- package/es/contract/Contract.d.ts +235 -0
- package/es/contract/Contract.mjs +534 -0
- package/es/contract/Contract.mjs.map +1 -0
- package/es/contract/ga.d.ts +7 -33
- package/es/contract/ga.mjs +20 -112
- package/es/contract/ga.mjs.map +1 -1
- package/es/index.d.ts +9 -6
- package/es/index.mjs +8 -6
- package/es/index.mjs.map +1 -1
- package/es/oracle.d.ts +5 -5
- package/es/oracle.mjs +33 -39
- package/es/oracle.mjs.map +1 -1
- package/es/spend.d.ts +3 -3
- package/es/spend.mjs +17 -20
- package/es/spend.mjs.map +1 -1
- package/es/tx/builder/constants.d.ts +2 -1
- package/es/tx/builder/constants.mjs +12 -12
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/field-types/address.d.ts +15 -0
- package/es/tx/builder/field-types/address.mjs +42 -0
- package/es/tx/builder/field-types/address.mjs.map +1 -0
- package/es/tx/builder/field-types/addresses.d.ts +6 -0
- package/es/tx/builder/field-types/addresses.mjs +13 -0
- package/es/tx/builder/field-types/addresses.mjs.map +1 -0
- package/es/tx/builder/field-types/coin-amount.d.ts +1 -2
- 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/deposit.d.ts +0 -1
- 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/enumeration.d.ts +5 -0
- package/es/tx/builder/field-types/enumeration.mjs +21 -0
- package/es/tx/builder/field-types/enumeration.mjs.map +1 -0
- package/es/tx/builder/field-types/fee.d.ts +1 -9
- package/es/tx/builder/field-types/fee.mjs +9 -25
- 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.mjs +4 -9
- 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 +23 -11
- package/es/tx/builder/field-types/index.mjs +10 -3
- package/es/tx/builder/field-types/index.mjs.map +1 -1
- package/es/tx/builder/field-types/name-fee.d.ts +0 -1
- 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 +4 -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/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/u-int.d.ts +1 -1
- 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 +1 -21
- package/es/tx/builder/index.mjs +29 -148
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +336 -176
- package/es/tx/builder/schema.mjs +71 -78
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +3 -33
- package/es/tx/index.mjs +26 -43
- package/es/tx/index.mjs.map +1 -1
- package/es/tx/validator.d.ts +2 -2
- package/es/tx/validator.mjs +86 -59
- 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 +12 -6
- package/es/utils/errors.mjs +87 -163
- 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/mptree.d.ts +1 -1
- package/es/utils/mptree.mjs +4 -26
- package/es/utils/mptree.mjs.map +1 -1
- package/es/utils/other.d.ts +3 -1
- 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 +86 -47
- package/src/AeSdk.ts +15 -11
- package/src/AeSdkAepp.ts +9 -7
- package/src/AeSdkBase.ts +28 -202
- package/src/AeSdkMethods.ts +170 -0
- package/src/AeSdkWallet.ts +16 -47
- package/src/Node.ts +11 -15
- 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 +10 -9
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +5 -4
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +3 -3
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +2 -2
- 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 +6 -3
- package/src/channel/Base.ts +327 -0
- package/src/channel/Contract.ts +487 -0
- package/src/channel/Spend.ts +403 -0
- package/src/channel/handlers.ts +154 -573
- package/src/channel/internal.ts +113 -142
- package/src/contract/{Compiler.ts → CompilerHttp.ts} +5 -5
- package/src/contract/Contract.ts +620 -0
- package/src/contract/ga.ts +18 -104
- package/src/index.ts +9 -8
- package/src/oracle.ts +7 -7
- package/src/spend.ts +5 -13
- package/src/tx/builder/constants.ts +1 -0
- package/src/tx/builder/field-types/address.ts +52 -0
- package/src/tx/builder/field-types/addresses.ts +18 -0
- package/src/tx/builder/field-types/coin-amount.ts +2 -8
- package/src/tx/builder/field-types/enumeration.ts +21 -0
- package/src/tx/builder/field-types/fee.ts +1 -3
- package/src/tx/builder/field-types/gas-limit.ts +2 -2
- package/src/tx/builder/field-types/gas-price.ts +0 -2
- package/src/tx/builder/field-types/index.ts +16 -6
- package/src/tx/builder/field-types/name-fee.ts +1 -1
- 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/u-int.ts +3 -2
- package/src/tx/builder/helpers.ts +10 -60
- package/src/tx/builder/index.ts +6 -65
- package/src/tx/builder/schema.ts +89 -100
- package/src/tx/index.ts +19 -15
- package/src/tx/validator.ts +36 -18
- package/src/typings/@aeternity__aepp-calldata/index.d.ts +20 -0
- package/src/utils/autorest.ts +16 -1
- package/src/utils/bytes.ts +5 -33
- package/src/utils/crypto.ts +23 -16
- package/src/utils/encoder.ts +0 -1
- package/src/utils/errors.ts +18 -12
- 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 +141 -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 +18 -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 +248 -0
- package/types-legacy/ts4.2/channel/Base.d.ts +194 -0
- package/types-legacy/ts4.2/channel/Contract.d.ts +247 -0
- package/types-legacy/ts4.2/channel/Spend.d.ts +217 -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/CompilerHttp.d.ts +18 -0
- package/types-legacy/ts4.2/contract/Contract.d.ts +237 -0
- package/types-legacy/ts4.2/contract/ga.d.ts +43 -0
- package/types-legacy/ts4.2/globals.d.ts +16 -0
- package/types-legacy/ts4.2/index.d.ts +39 -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 +71 -0
- package/types-legacy/ts4.2/tx/builder/field-types/address.d.ts +22 -0
- package/types-legacy/ts4.2/tx/builder/field-types/addresses.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/deposit.d.ts +14 -0
- package/types-legacy/ts4.2/tx/builder/field-types/enumeration.d.ts +5 -0
- package/types-legacy/ts4.2/tx/builder/field-types/fee.d.ts +17 -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 +12 -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 +85 -0
- package/types-legacy/ts4.2/tx/builder/field-types/name-fee.d.ts +19 -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/short-u-int.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/u-int.d.ts +8 -0
- package/types-legacy/ts4.2/tx/builder/helpers.d.ts +112 -0
- package/types-legacy/ts4.2/tx/builder/index.d.ts +68 -0
- package/types-legacy/ts4.2/tx/builder/schema.d.ts +2963 -0
- package/types-legacy/ts4.2/tx/index.d.ts +34 -0
- package/types-legacy/ts4.2/tx/validator.d.ts +20 -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 +480 -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/mptree.d.ts +32 -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 +141 -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 +18 -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 +248 -0
- package/types-legacy/ts4.5/channel/Base.d.ts +194 -0
- package/types-legacy/ts4.5/channel/Contract.d.ts +247 -0
- package/types-legacy/ts4.5/channel/Spend.d.ts +217 -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/CompilerHttp.d.ts +18 -0
- package/types-legacy/ts4.5/contract/Contract.d.ts +237 -0
- package/types-legacy/ts4.5/contract/ga.d.ts +43 -0
- package/types-legacy/ts4.5/index.d.ts +38 -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 +71 -0
- package/types-legacy/ts4.5/tx/builder/field-types/address.d.ts +22 -0
- package/types-legacy/ts4.5/tx/builder/field-types/addresses.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/deposit.d.ts +14 -0
- package/types-legacy/ts4.5/tx/builder/field-types/enumeration.d.ts +5 -0
- package/types-legacy/ts4.5/tx/builder/field-types/fee.d.ts +17 -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 +12 -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 +85 -0
- package/types-legacy/ts4.5/tx/builder/field-types/name-fee.d.ts +19 -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/short-u-int.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/u-int.d.ts +8 -0
- package/types-legacy/ts4.5/tx/builder/helpers.d.ts +112 -0
- package/types-legacy/ts4.5/tx/builder/index.d.ts +68 -0
- package/types-legacy/ts4.5/tx/builder/schema.d.ts +2963 -0
- package/types-legacy/ts4.5/tx/index.d.ts +34 -0
- package/types-legacy/ts4.5/tx/validator.d.ts +20 -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 +480 -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/mptree.d.ts +32 -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.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/src/channel/index.ts +0 -1025
- 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/channel/index.ts
DELETED
|
@@ -1,1025 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* ISC License (ISC)
|
|
3
|
-
* Copyright (c) 2018 aeternity developers
|
|
4
|
-
*
|
|
5
|
-
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
-
* purpose with or without fee is hereby granted, provided that the above
|
|
7
|
-
* copyright notice and this permission notice appear in all copies.
|
|
8
|
-
*
|
|
9
|
-
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
-
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
-
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
-
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
-
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
-
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
-
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
-
*/
|
|
17
|
-
import BigNumber from 'bignumber.js';
|
|
18
|
-
import { snakeToPascal } from '../utils/string';
|
|
19
|
-
import { buildTx, unpackTx } from '../tx/builder';
|
|
20
|
-
import { MIN_GAS_PRICE, Tag } from '../tx/builder/constants';
|
|
21
|
-
import * as handlers from './handlers';
|
|
22
|
-
import {
|
|
23
|
-
eventEmitters,
|
|
24
|
-
status as channelStatus,
|
|
25
|
-
state as channelState,
|
|
26
|
-
initialize,
|
|
27
|
-
enqueueAction,
|
|
28
|
-
send,
|
|
29
|
-
channelId,
|
|
30
|
-
call,
|
|
31
|
-
disconnect as channelDisconnect,
|
|
32
|
-
fsmId as channelFsmId,
|
|
33
|
-
SignTx,
|
|
34
|
-
ChannelOptions,
|
|
35
|
-
ChannelState,
|
|
36
|
-
} from './internal';
|
|
37
|
-
import { UnknownChannelStateError, ChannelError } from '../utils/errors';
|
|
38
|
-
import { Encoded } from '../utils/encoder';
|
|
39
|
-
import { ContractCallReturnType } from '../apis/node';
|
|
40
|
-
import { pause } from '../utils/other';
|
|
41
|
-
|
|
42
|
-
function snakeToPascalObjKeys<Type>(obj: object): Type {
|
|
43
|
-
return Object.entries(obj).reduce((result, [key, val]) => ({
|
|
44
|
-
...result,
|
|
45
|
-
[snakeToPascal(key)]: val,
|
|
46
|
-
}), {}) as Type;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
type EventCallback = (...args: any[]) => void;
|
|
50
|
-
|
|
51
|
-
interface CallContractOptions {
|
|
52
|
-
amount?: number | BigNumber;
|
|
53
|
-
callData?: Encoded.ContractBytearray;
|
|
54
|
-
abiVersion?: number;
|
|
55
|
-
contract?: Encoded.ContractAddress;
|
|
56
|
-
returnValue?: any;
|
|
57
|
-
gasUsed?: number | BigNumber;
|
|
58
|
-
gasPrice?: number | BigNumber;
|
|
59
|
-
height?: number;
|
|
60
|
-
callerNonce?: number;
|
|
61
|
-
log?: any;
|
|
62
|
-
returnType?: ContractCallReturnType;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
interface Contract {
|
|
66
|
-
abiVersion: number;
|
|
67
|
-
active: boolean;
|
|
68
|
-
deposit: number | BigNumber;
|
|
69
|
-
id: string;
|
|
70
|
-
ownerId: string;
|
|
71
|
-
referrerIds: string[];
|
|
72
|
-
vmVersion: number;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Channel
|
|
77
|
-
* @example
|
|
78
|
-
* ```js
|
|
79
|
-
* await Channel.initialize({
|
|
80
|
-
* url: 'ws://localhost:3001',
|
|
81
|
-
* role: 'initiator'
|
|
82
|
-
* initiatorId: 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',
|
|
83
|
-
* responderId: 'ak_V6an1xhec1xVaAhLuak7QoEbi6t7w5hEtYWp9bMKaJ19i6A9E',
|
|
84
|
-
* initiatorAmount: 1e18,
|
|
85
|
-
* responderAmount: 1e18,
|
|
86
|
-
* pushAmount: 0,
|
|
87
|
-
* channelReserve: 0,
|
|
88
|
-
* ttl: 1000,
|
|
89
|
-
* host: 'localhost',
|
|
90
|
-
* port: 3002,
|
|
91
|
-
* lockPeriod: 10,
|
|
92
|
-
* async sign (tag, tx) => await account.signTransaction(tx)
|
|
93
|
-
* })
|
|
94
|
-
* ```
|
|
95
|
-
*/
|
|
96
|
-
export default class Channel {
|
|
97
|
-
/**
|
|
98
|
-
* @param options - Channel params
|
|
99
|
-
* @param options.url - Channel url (for example: "ws://localhost:3001")
|
|
100
|
-
* @param options.role - Participant role ("initiator" or "responder")
|
|
101
|
-
* @param options.initiatorId - Initiator's public key
|
|
102
|
-
* @param options.responderId - Responder's public key
|
|
103
|
-
* @param options.pushAmount - Initial deposit in favour of the responder by the initiator
|
|
104
|
-
* @param options.initiatorAmount - Amount of coins the initiator has committed to
|
|
105
|
-
* the channel
|
|
106
|
-
* @param options.responderAmount - Amount of coins the responder has committed to
|
|
107
|
-
* the channel
|
|
108
|
-
* @param options.channelReserve - The minimum amount both peers need to maintain
|
|
109
|
-
* @param options.ttl - Minimum block height to include the channel_create_tx
|
|
110
|
-
* @param options.host - Host of the responder's node
|
|
111
|
-
* @param options.port - The port of the responders node
|
|
112
|
-
* @param options.lockPeriod - Amount of blocks for disputing a solo close
|
|
113
|
-
* @param options.existingChannelId - Existing channel id (required if reestablishing a
|
|
114
|
-
* channel)
|
|
115
|
-
* @param options.offchainTx - Offchain transaction (required if reestablishing
|
|
116
|
-
* a channel)
|
|
117
|
-
* @param options.timeoutIdle - The time waiting for a new event to be initiated
|
|
118
|
-
* (default: 600000)
|
|
119
|
-
* @param options.timeoutFundingCreate - The time waiting for the initiator to produce
|
|
120
|
-
* the create channel transaction after the noise session had been established (default: 120000)
|
|
121
|
-
* @param options.timeoutFundingSign - The time frame the other client has to sign an
|
|
122
|
-
* off-chain update after our client had initiated and signed it. This applies only for double
|
|
123
|
-
* signed on-chain intended updates: channel create transaction, deposit, withdrawal and etc.
|
|
124
|
-
* (default: 120000)
|
|
125
|
-
* @param options.timeoutFundingLock - The time frame the other client has to confirm an
|
|
126
|
-
* on-chain transaction reaching maturity (passing minimum depth) after the local node has
|
|
127
|
-
* detected this. This applies only for double signed on-chain intended updates: channel create
|
|
128
|
-
* transaction, deposit, withdrawal and etc. (default: 360000)
|
|
129
|
-
* @param options.timeoutSign - The time frame the client has to return a signed
|
|
130
|
-
* off-chain update or to decline it. This applies for all off-chain updates (default: 500000)
|
|
131
|
-
* @param options.timeoutAccept - The time frame the other client has to react to an
|
|
132
|
-
* event. This applies for all off-chain updates that are not meant to land on-chain, as well as
|
|
133
|
-
* some special cases: opening a noise connection, mutual closing acknowledgement and
|
|
134
|
-
* reestablishing an existing channel (default: 120000)
|
|
135
|
-
* @param options.timeoutInitialized - the time frame the responder has to accept an
|
|
136
|
-
* incoming noise session. Applicable only for initiator (default: timeout_accept's value)
|
|
137
|
-
* @param options.timeoutAwaitingOpen - The time frame the initiator has to start an
|
|
138
|
-
* outgoing noise session to the responder's node. Applicable only for responder (default:
|
|
139
|
-
* timeout_idle's value)
|
|
140
|
-
* @param options.debug=false - Log websocket communication
|
|
141
|
-
* @param options.sign - Function which verifies and signs transactions
|
|
142
|
-
*/
|
|
143
|
-
static async initialize(options: ChannelOptions): Promise<Channel> {
|
|
144
|
-
const channel = new Channel();
|
|
145
|
-
await initialize(
|
|
146
|
-
channel,
|
|
147
|
-
options.existingFsmId != null ? handlers.awaitingReconnection : handlers.awaitingConnection,
|
|
148
|
-
handlers.channelOpen,
|
|
149
|
-
options,
|
|
150
|
-
);
|
|
151
|
-
return channel;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Register event listener function
|
|
156
|
-
*
|
|
157
|
-
* Possible events:
|
|
158
|
-
*
|
|
159
|
-
* - "error"
|
|
160
|
-
* - "onChainTx"
|
|
161
|
-
* - "ownWithdrawLocked"
|
|
162
|
-
* - "withdrawLocked"
|
|
163
|
-
* - "ownDepositLocked"
|
|
164
|
-
* - "depositLocked"
|
|
165
|
-
*
|
|
166
|
-
* TODO: the event list looks outdated
|
|
167
|
-
*
|
|
168
|
-
* @param eventName - Event name
|
|
169
|
-
* @param callback - Callback function
|
|
170
|
-
*/
|
|
171
|
-
// TODO define specific callback type depending on the event name
|
|
172
|
-
on(eventName: string, callback: EventCallback): void {
|
|
173
|
-
const eventEmitter = eventEmitters.get(this);
|
|
174
|
-
if (eventEmitter == null) throw new UnknownChannelStateError();
|
|
175
|
-
eventEmitter.on(eventName, callback);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Remove event listener function
|
|
180
|
-
* @param eventName - Event name
|
|
181
|
-
* @param callback - Callback function
|
|
182
|
-
*/
|
|
183
|
-
off(eventName: string, callback: EventCallback): void {
|
|
184
|
-
const eventEmitter = eventEmitters.get(this);
|
|
185
|
-
if (eventEmitter == null) throw new UnknownChannelStateError();
|
|
186
|
-
eventEmitter.removeListener(eventName, callback);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Close the connection
|
|
191
|
-
*/
|
|
192
|
-
disconnect(): void {
|
|
193
|
-
return channelDisconnect(this);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Get current status
|
|
198
|
-
*
|
|
199
|
-
*/
|
|
200
|
-
status(): string {
|
|
201
|
-
const status = channelStatus.get(this);
|
|
202
|
-
if (status == null) throw new UnknownChannelStateError();
|
|
203
|
-
return status;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Get current state
|
|
208
|
-
*/
|
|
209
|
-
async state(): Promise<ChannelState> {
|
|
210
|
-
return snakeToPascalObjKeys(await call(this, 'channels.get.offchain_state', {}));
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Get current round
|
|
215
|
-
*
|
|
216
|
-
* If round cannot be determined (for example when channel has not been opened)
|
|
217
|
-
* it will return `null`.
|
|
218
|
-
*
|
|
219
|
-
*/
|
|
220
|
-
round(): number | null {
|
|
221
|
-
const state = channelState.get(this);
|
|
222
|
-
if (state == null) {
|
|
223
|
-
return null;
|
|
224
|
-
}
|
|
225
|
-
const { txType, tx } = unpackTx(state, Tag.SignedTx).tx.encodedTx;
|
|
226
|
-
switch (txType) {
|
|
227
|
-
case Tag.ChannelCreateTx:
|
|
228
|
-
return 1;
|
|
229
|
-
case Tag.ChannelOffChainTx:
|
|
230
|
-
case Tag.ChannelWithdrawTx:
|
|
231
|
-
case Tag.ChannelDepositTx:
|
|
232
|
-
return tx.round;
|
|
233
|
-
default:
|
|
234
|
-
return null;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Get channel id
|
|
240
|
-
*
|
|
241
|
-
*/
|
|
242
|
-
id(): string {
|
|
243
|
-
const id = channelId.get(this);
|
|
244
|
-
if (id == null) throw new ChannelError('Channel is not initialized');
|
|
245
|
-
return id;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Get channel's fsm id
|
|
250
|
-
*
|
|
251
|
-
*/
|
|
252
|
-
fsmId(): string {
|
|
253
|
-
const id = channelFsmId.get(this);
|
|
254
|
-
if (id == null) throw new ChannelError('Channel is not initialized');
|
|
255
|
-
return id;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Trigger a transfer update
|
|
260
|
-
*
|
|
261
|
-
* The transfer update is moving coins from one channel account to another.
|
|
262
|
-
* The update is a change to be applied on top of the latest state.
|
|
263
|
-
*
|
|
264
|
-
* Sender and receiver are the channel parties. Both the initiator and responder
|
|
265
|
-
* can take those roles. Any public key outside the channel is considered invalid.
|
|
266
|
-
*
|
|
267
|
-
* @param from - Sender's public address
|
|
268
|
-
* @param to - Receiver's public address
|
|
269
|
-
* @param amount - Transaction amount
|
|
270
|
-
* @param sign - Function which verifies and signs offchain transaction
|
|
271
|
-
* @param metadata - Metadata
|
|
272
|
-
|
|
273
|
-
* @example
|
|
274
|
-
* ```js
|
|
275
|
-
* channel.update(
|
|
276
|
-
* 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',
|
|
277
|
-
* 'ak_V6an1xhec1xVaAhLuak7QoEbi6t7w5hEtYWp9bMKaJ19i6A9E',
|
|
278
|
-
* 10,
|
|
279
|
-
* async (tx) => await account.signTransaction(tx)
|
|
280
|
-
* ).then(({ accepted, signedTx }) =>
|
|
281
|
-
* if (accepted) {
|
|
282
|
-
* console.log('Update has been accepted')
|
|
283
|
-
* }
|
|
284
|
-
* )
|
|
285
|
-
* ```
|
|
286
|
-
*/
|
|
287
|
-
async update(
|
|
288
|
-
from: Encoded.AccountAddress,
|
|
289
|
-
to: Encoded.AccountAddress,
|
|
290
|
-
amount: number | BigNumber,
|
|
291
|
-
sign: SignTx,
|
|
292
|
-
metadata: string[] = [],
|
|
293
|
-
): Promise<{
|
|
294
|
-
accepted: boolean;
|
|
295
|
-
signedTx?: Encoded.Transaction;
|
|
296
|
-
errorCode?: number;
|
|
297
|
-
errorMessage?: string;
|
|
298
|
-
}> {
|
|
299
|
-
return new Promise((resolve, reject) => {
|
|
300
|
-
enqueueAction(
|
|
301
|
-
this,
|
|
302
|
-
(_channel, state) => state?.handler === handlers.channelOpen,
|
|
303
|
-
(channel) => {
|
|
304
|
-
send(channel, {
|
|
305
|
-
jsonrpc: '2.0',
|
|
306
|
-
method: 'channels.update.new',
|
|
307
|
-
params: {
|
|
308
|
-
from, to, amount, meta: metadata,
|
|
309
|
-
},
|
|
310
|
-
});
|
|
311
|
-
return {
|
|
312
|
-
handler: handlers.awaitingOffChainTx,
|
|
313
|
-
state: {
|
|
314
|
-
resolve,
|
|
315
|
-
reject,
|
|
316
|
-
sign,
|
|
317
|
-
},
|
|
318
|
-
};
|
|
319
|
-
},
|
|
320
|
-
);
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* Get proof of inclusion
|
|
326
|
-
*
|
|
327
|
-
* If a certain address of an account or a contract is not found
|
|
328
|
-
* in the state tree - the response is an error.
|
|
329
|
-
*
|
|
330
|
-
* @param addresses - Addresses
|
|
331
|
-
* @param addresses.accounts - List of account addresses to include in poi
|
|
332
|
-
* @param addresses.contracts - List of contract addresses to include in poi
|
|
333
|
-
* @example
|
|
334
|
-
* ```js
|
|
335
|
-
* channel.poi({
|
|
336
|
-
* accounts: [
|
|
337
|
-
* 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',
|
|
338
|
-
* 'ak_V6an1xhec1xVaAhLuak7QoEbi6t7w5hEtYWp9bMKaJ19i6A9E'
|
|
339
|
-
* ],
|
|
340
|
-
* contracts: ['ct_2dCUAWYZdrWfACz3a2faJeKVTVrfDYxCQHCqAt5zM15f3u2UfA']
|
|
341
|
-
* }).then(poi => console.log(poi))
|
|
342
|
-
* ```
|
|
343
|
-
*/
|
|
344
|
-
async poi(
|
|
345
|
-
{ accounts, contracts }: {
|
|
346
|
-
accounts: Encoded.AccountAddress[];
|
|
347
|
-
contracts?: Encoded.ContractAddress[];
|
|
348
|
-
},
|
|
349
|
-
): Promise<Encoded.Poi> {
|
|
350
|
-
return (await call(this, 'channels.get.poi', { accounts, contracts })).poi;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* Get balances
|
|
355
|
-
*
|
|
356
|
-
* The accounts param contains a list of addresses to fetch balances of.
|
|
357
|
-
* Those can be either account balances or a contract ones, encoded as an account addresses.
|
|
358
|
-
*
|
|
359
|
-
* If a certain account address had not being found in the state tree - it is simply
|
|
360
|
-
* skipped in the response.
|
|
361
|
-
*
|
|
362
|
-
* @param accounts - List of addresses to fetch balances from
|
|
363
|
-
* @example
|
|
364
|
-
* ```js
|
|
365
|
-
* channel.balances([
|
|
366
|
-
* 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',
|
|
367
|
-
* 'ak_V6an1xhec1xVaAhLuak7QoEbi6t7w5hEtYWp9bMKaJ19i6A9E'
|
|
368
|
-
* 'ct_2dCUAWYZdrWfACz3a2faJeKVTVrfDYxCQHCqAt5zM15f3u2UfA'
|
|
369
|
-
* ]).then(balances =>
|
|
370
|
-
* console.log(balances['ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH'])
|
|
371
|
-
* )
|
|
372
|
-
* ```
|
|
373
|
-
*/
|
|
374
|
-
async balances(
|
|
375
|
-
accounts: Encoded.AccountAddress[],
|
|
376
|
-
): Promise<{ [key: Encoded.AccountAddress]: string }> {
|
|
377
|
-
return Object.fromEntries(
|
|
378
|
-
(await call(this, 'channels.get.balances', { accounts }))
|
|
379
|
-
.map((item: {
|
|
380
|
-
account: Encoded.AccountAddress;
|
|
381
|
-
balance: string;
|
|
382
|
-
}) => [item.account, item.balance]),
|
|
383
|
-
);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* Leave channel
|
|
388
|
-
*
|
|
389
|
-
* It is possible to leave a channel and then later reestablish the channel
|
|
390
|
-
* off-chain state and continue operation. When a leave method is called,
|
|
391
|
-
* the channel fsm passes it on to the peer fsm, reports the current mutually
|
|
392
|
-
* signed state and then terminates.
|
|
393
|
-
*
|
|
394
|
-
* The channel can be reestablished by instantiating another Channel instance
|
|
395
|
-
* with two extra params: existingChannelId and offchainTx (returned from leave
|
|
396
|
-
* method as channelId and signedTx respectively).
|
|
397
|
-
*
|
|
398
|
-
* @example
|
|
399
|
-
* ```js
|
|
400
|
-
* channel.leave().then(({ channelId, signedTx }) => {
|
|
401
|
-
* console.log(channelId)
|
|
402
|
-
* console.log(signedTx)
|
|
403
|
-
* })
|
|
404
|
-
* ```
|
|
405
|
-
*/
|
|
406
|
-
async leave(): Promise<{ channelId: string; signedTx: Encoded.Transaction }> {
|
|
407
|
-
return new Promise((resolve, reject) => {
|
|
408
|
-
enqueueAction(
|
|
409
|
-
this,
|
|
410
|
-
(channel, state) => state?.handler === handlers.channelOpen,
|
|
411
|
-
(channel) => {
|
|
412
|
-
send(channel, { jsonrpc: '2.0', method: 'channels.leave', params: {} });
|
|
413
|
-
return {
|
|
414
|
-
handler: handlers.awaitingLeave,
|
|
415
|
-
state: { resolve, reject },
|
|
416
|
-
};
|
|
417
|
-
},
|
|
418
|
-
);
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
/**
|
|
423
|
-
* Trigger mutual close
|
|
424
|
-
*
|
|
425
|
-
* At any moment after the channel is opened, a closing procedure can be triggered.
|
|
426
|
-
* This can be done by either of the parties. The process is similar to the off-chain updates.
|
|
427
|
-
*
|
|
428
|
-
* @param sign - Function which verifies and signs mutual close transaction
|
|
429
|
-
* @example
|
|
430
|
-
* ```js
|
|
431
|
-
* channel.shutdown(
|
|
432
|
-
* async (tx) => await account.signTransaction(tx)
|
|
433
|
-
* ).then(tx => console.log('on_chain_tx', tx))
|
|
434
|
-
* ```
|
|
435
|
-
*/
|
|
436
|
-
async shutdown(sign: Function): Promise<Encoded.Transaction> {
|
|
437
|
-
return new Promise((resolve, reject) => {
|
|
438
|
-
enqueueAction(
|
|
439
|
-
this,
|
|
440
|
-
(_channel, state) => state?.handler === handlers.channelOpen,
|
|
441
|
-
(channel) => {
|
|
442
|
-
send(channel, { jsonrpc: '2.0', method: 'channels.shutdown', params: {} });
|
|
443
|
-
return {
|
|
444
|
-
handler: handlers.awaitingShutdownTx,
|
|
445
|
-
state: {
|
|
446
|
-
sign,
|
|
447
|
-
resolve,
|
|
448
|
-
reject,
|
|
449
|
-
},
|
|
450
|
-
};
|
|
451
|
-
},
|
|
452
|
-
);
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* Withdraw coins from the channel
|
|
458
|
-
*
|
|
459
|
-
* After the channel had been opened any of the participants can initiate a withdrawal.
|
|
460
|
-
* The process closely resembles the update. The most notable difference is that the
|
|
461
|
-
* transaction has been co-signed: it is channel_withdraw_tx and after the procedure
|
|
462
|
-
* is finished - it is being posted on-chain.
|
|
463
|
-
*
|
|
464
|
-
* Any of the participants can initiate a withdrawal. The only requirements are:
|
|
465
|
-
*
|
|
466
|
-
* - Channel is already opened
|
|
467
|
-
* - No off-chain update/deposit/withdrawal is currently being performed
|
|
468
|
-
* - Channel is not being closed or in a solo closing state
|
|
469
|
-
* - The withdrawal amount must be equal to or greater than zero, and cannot exceed
|
|
470
|
-
* the available balance on the channel (minus the channel_reserve)
|
|
471
|
-
*
|
|
472
|
-
* After the other party had signed the withdraw transaction, the transaction is posted
|
|
473
|
-
* on-chain and onOnChainTx callback is called with on-chain transaction as first argument.
|
|
474
|
-
* After computing transaction hash it can be tracked on the chain: entering the mempool,
|
|
475
|
-
* block inclusion and a number of confirmations.
|
|
476
|
-
*
|
|
477
|
-
* After the minimum_depth block confirmations onOwnWithdrawLocked callback is called
|
|
478
|
-
* (without any arguments).
|
|
479
|
-
*
|
|
480
|
-
* When the other party had confirmed that the block height needed is reached
|
|
481
|
-
* onWithdrawLocked callback is called (without any arguments).
|
|
482
|
-
*
|
|
483
|
-
* @param amount - Amount of coins to withdraw
|
|
484
|
-
* @param sign - Function which verifies and signs withdraw transaction
|
|
485
|
-
* @param callbacks - Callbacks
|
|
486
|
-
* @param callbacks.onOnChainTx - Called when withdraw transaction has been posted
|
|
487
|
-
* on chain
|
|
488
|
-
* @param callbacks.onOwnWithdrawLocked
|
|
489
|
-
* @param callbacks.onWithdrawLocked
|
|
490
|
-
* @example
|
|
491
|
-
* ```js
|
|
492
|
-
* channel.withdraw(
|
|
493
|
-
* 100,
|
|
494
|
-
* async (tx) => await account.signTransaction(tx),
|
|
495
|
-
* { onOnChainTx: (tx) => console.log('on_chain_tx', tx) }
|
|
496
|
-
* ).then(({ accepted, signedTx }) => {
|
|
497
|
-
* if (accepted) {
|
|
498
|
-
* console.log('Withdrawal has been accepted')
|
|
499
|
-
* } else {
|
|
500
|
-
* console.log('Withdrawal has been rejected')
|
|
501
|
-
* }
|
|
502
|
-
* })
|
|
503
|
-
* ```
|
|
504
|
-
*/
|
|
505
|
-
async withdraw(
|
|
506
|
-
amount: number | BigNumber,
|
|
507
|
-
sign: SignTx,
|
|
508
|
-
{ onOnChainTx, onOwnWithdrawLocked, onWithdrawLocked }:
|
|
509
|
-
Pick<ChannelState, 'onOnChainTx' | 'onOwnWithdrawLocked' | 'onWithdrawLocked'> = {},
|
|
510
|
-
): Promise<{ accepted: boolean; signedTx: Encoded.Transaction }> {
|
|
511
|
-
return new Promise((resolve, reject) => {
|
|
512
|
-
enqueueAction(
|
|
513
|
-
this,
|
|
514
|
-
(_channel, state) => state?.handler === handlers.channelOpen,
|
|
515
|
-
(channel) => {
|
|
516
|
-
send(channel, { jsonrpc: '2.0', method: 'channels.withdraw', params: { amount } });
|
|
517
|
-
return {
|
|
518
|
-
handler: handlers.awaitingWithdrawTx,
|
|
519
|
-
state: {
|
|
520
|
-
sign,
|
|
521
|
-
resolve,
|
|
522
|
-
reject,
|
|
523
|
-
onOnChainTx,
|
|
524
|
-
onOwnWithdrawLocked,
|
|
525
|
-
onWithdrawLocked,
|
|
526
|
-
},
|
|
527
|
-
};
|
|
528
|
-
},
|
|
529
|
-
);
|
|
530
|
-
});
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
/**
|
|
534
|
-
* Deposit coins into the channel
|
|
535
|
-
*
|
|
536
|
-
* After the channel had been opened any of the participants can initiate a deposit.
|
|
537
|
-
* The process closely resembles the update. The most notable difference is that the
|
|
538
|
-
* transaction has been co-signed: it is channel_deposit_tx and after the procedure
|
|
539
|
-
* is finished - it is being posted on-chain.
|
|
540
|
-
*
|
|
541
|
-
* Any of the participants can initiate a deposit. The only requirements are:
|
|
542
|
-
*
|
|
543
|
-
* - Channel is already opened
|
|
544
|
-
* - No off-chain update/deposit/withdrawal is currently being performed
|
|
545
|
-
* - Channel is not being closed or in a solo closing state
|
|
546
|
-
* - The deposit amount must be equal to or greater than zero, and cannot exceed
|
|
547
|
-
* the available balance on the channel (minus the channel_reserve)
|
|
548
|
-
*
|
|
549
|
-
* After the other party had signed the deposit transaction, the transaction is posted
|
|
550
|
-
* on-chain and onOnChainTx callback is called with on-chain transaction as first argument.
|
|
551
|
-
* After computing transaction hash it can be tracked on the chain: entering the mempool,
|
|
552
|
-
* block inclusion and a number of confirmations.
|
|
553
|
-
*
|
|
554
|
-
* After the minimum_depth block confirmations onOwnDepositLocked callback is called
|
|
555
|
-
* (without any arguments).
|
|
556
|
-
*
|
|
557
|
-
* When the other party had confirmed that the block height needed is reached
|
|
558
|
-
* onDepositLocked callback is called (without any arguments).
|
|
559
|
-
*
|
|
560
|
-
* @param amount - Amount of coins to deposit
|
|
561
|
-
* @param sign - Function which verifies and signs deposit transaction
|
|
562
|
-
* @param callbacks - Callbacks
|
|
563
|
-
* @param callbacks.onOnChainTx - Called when deposit transaction has been posted
|
|
564
|
-
* on chain
|
|
565
|
-
* @param callbacks.onOwnDepositLocked
|
|
566
|
-
* @param callbacks.onDepositLocked
|
|
567
|
-
* @example
|
|
568
|
-
* ```js
|
|
569
|
-
* channel.deposit(
|
|
570
|
-
* 100,
|
|
571
|
-
* async (tx) => await account.signTransaction(tx),
|
|
572
|
-
* { onOnChainTx: (tx) => console.log('on_chain_tx', tx) }
|
|
573
|
-
* ).then(({ accepted, state }) => {
|
|
574
|
-
* if (accepted) {
|
|
575
|
-
* console.log('Deposit has been accepted')
|
|
576
|
-
* console.log('The new state is:', state)
|
|
577
|
-
* } else {
|
|
578
|
-
* console.log('Deposit has been rejected')
|
|
579
|
-
* }
|
|
580
|
-
* })
|
|
581
|
-
* ```
|
|
582
|
-
*/
|
|
583
|
-
async deposit(
|
|
584
|
-
amount: number | BigNumber,
|
|
585
|
-
sign: SignTx,
|
|
586
|
-
{ onOnChainTx, onOwnDepositLocked, onDepositLocked }:
|
|
587
|
-
Pick<ChannelState, 'onOnChainTx' | 'onOwnDepositLocked' | 'onDepositLocked'> = {},
|
|
588
|
-
): Promise<{ accepted: boolean; state: ChannelState }> {
|
|
589
|
-
return new Promise((resolve, reject) => {
|
|
590
|
-
enqueueAction(
|
|
591
|
-
this,
|
|
592
|
-
(_channel, state) => state?.handler === handlers.channelOpen,
|
|
593
|
-
(channel) => {
|
|
594
|
-
send(channel, { jsonrpc: '2.0', method: 'channels.deposit', params: { amount } });
|
|
595
|
-
return {
|
|
596
|
-
handler: handlers.awaitingDepositTx,
|
|
597
|
-
state: {
|
|
598
|
-
sign,
|
|
599
|
-
resolve,
|
|
600
|
-
reject,
|
|
601
|
-
onOnChainTx,
|
|
602
|
-
onOwnDepositLocked,
|
|
603
|
-
onDepositLocked,
|
|
604
|
-
},
|
|
605
|
-
};
|
|
606
|
-
},
|
|
607
|
-
);
|
|
608
|
-
});
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
/**
|
|
612
|
-
* Trigger create contract update
|
|
613
|
-
*
|
|
614
|
-
* The create contract update is creating a contract inside the channel's internal state tree.
|
|
615
|
-
* The update is a change to be applied on top of the latest state.
|
|
616
|
-
*
|
|
617
|
-
* That would create a contract with the poster being the owner of it. Poster commits initially
|
|
618
|
-
* a deposit amount of coins to the new contract.
|
|
619
|
-
*
|
|
620
|
-
* @param options - Options
|
|
621
|
-
* @param options.code - Api encoded compiled AEVM byte code
|
|
622
|
-
* @param options.callData - Api encoded compiled AEVM call data for the code
|
|
623
|
-
* @param options.deposit - Initial amount the owner of the contract commits to it
|
|
624
|
-
* @param options.vmVersion - Version of the Virtual Machine
|
|
625
|
-
* @param options.abiVersion - Version of the Application Binary Interface
|
|
626
|
-
* @param sign - Function which verifies and signs create contract transaction
|
|
627
|
-
* @example
|
|
628
|
-
* ```js
|
|
629
|
-
* channel.createContract({
|
|
630
|
-
* code: 'cb_HKtpipK4aCgYb17wZ...',
|
|
631
|
-
* callData: 'cb_1111111111111111...',
|
|
632
|
-
* deposit: 10,
|
|
633
|
-
* vmVersion: 3,
|
|
634
|
-
* abiVersion: 1
|
|
635
|
-
* }).then(({ accepted, signedTx, address }) => {
|
|
636
|
-
* if (accepted) {
|
|
637
|
-
* console.log('New contract has been created')
|
|
638
|
-
* console.log('Contract address:', address)
|
|
639
|
-
* } else {
|
|
640
|
-
* console.log('New contract has been rejected')
|
|
641
|
-
* }
|
|
642
|
-
* })
|
|
643
|
-
* ```
|
|
644
|
-
*/
|
|
645
|
-
async createContract(
|
|
646
|
-
{
|
|
647
|
-
code, callData, deposit, vmVersion, abiVersion,
|
|
648
|
-
}: {
|
|
649
|
-
code: Encoded.ContractBytearray;
|
|
650
|
-
callData: Encoded.ContractBytearray;
|
|
651
|
-
deposit: number | BigNumber;
|
|
652
|
-
vmVersion: number;
|
|
653
|
-
abiVersion: number;
|
|
654
|
-
},
|
|
655
|
-
sign: SignTx,
|
|
656
|
-
): Promise<{
|
|
657
|
-
accepted: boolean; signedTx: Encoded.Transaction; address: Encoded.ContractAddress;
|
|
658
|
-
}> {
|
|
659
|
-
return new Promise((resolve, reject) => {
|
|
660
|
-
enqueueAction(
|
|
661
|
-
this,
|
|
662
|
-
(_channel, state) => state?.handler === handlers.channelOpen,
|
|
663
|
-
(channel) => {
|
|
664
|
-
send(channel, {
|
|
665
|
-
jsonrpc: '2.0',
|
|
666
|
-
method: 'channels.update.new_contract',
|
|
667
|
-
params: {
|
|
668
|
-
code,
|
|
669
|
-
call_data: callData,
|
|
670
|
-
deposit,
|
|
671
|
-
vm_version: vmVersion,
|
|
672
|
-
abi_version: abiVersion,
|
|
673
|
-
},
|
|
674
|
-
});
|
|
675
|
-
return {
|
|
676
|
-
handler: handlers.awaitingNewContractTx,
|
|
677
|
-
state: {
|
|
678
|
-
sign,
|
|
679
|
-
resolve,
|
|
680
|
-
reject,
|
|
681
|
-
},
|
|
682
|
-
};
|
|
683
|
-
},
|
|
684
|
-
);
|
|
685
|
-
});
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
/**
|
|
689
|
-
* Trigger call a contract update
|
|
690
|
-
*
|
|
691
|
-
* The call contract update is calling a preexisting contract inside the channel's
|
|
692
|
-
* internal state tree. The update is a change to be applied on top of the latest state.
|
|
693
|
-
*
|
|
694
|
-
* That would call a contract with the poster being the caller of it. Poster commits
|
|
695
|
-
* an amount of coins to the contract.
|
|
696
|
-
*
|
|
697
|
-
* The call would also create a call object inside the channel state tree. It contains
|
|
698
|
-
* the result of the contract call.
|
|
699
|
-
*
|
|
700
|
-
* It is worth mentioning that the gas is not consumed, because this is an off-chain
|
|
701
|
-
* contract call. It would be consumed if it were an on-chain one. This could happen
|
|
702
|
-
* if a call with a similar computation amount is to be forced on-chain.
|
|
703
|
-
*
|
|
704
|
-
* @param options - Options
|
|
705
|
-
* @param options.amount - Amount the caller of the contract commits to it
|
|
706
|
-
* @param options.callData - ABI encoded compiled AEVM call data for the code
|
|
707
|
-
* @param options.contract - Address of the contract to call
|
|
708
|
-
* @param options.abiVersion - Version of the ABI
|
|
709
|
-
* @param sign - Function which verifies and signs contract call transaction
|
|
710
|
-
* @example
|
|
711
|
-
* ```js
|
|
712
|
-
* channel.callContract({
|
|
713
|
-
* contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',
|
|
714
|
-
* callData: 'cb_1111111111111111...',
|
|
715
|
-
* amount: 0,
|
|
716
|
-
* abiVersion: 1
|
|
717
|
-
* }).then(({ accepted, signedTx }) => {
|
|
718
|
-
* if (accepted) {
|
|
719
|
-
* console.log('Contract called succesfully')
|
|
720
|
-
* } else {
|
|
721
|
-
* console.log('Contract call has been rejected')
|
|
722
|
-
* }
|
|
723
|
-
* })
|
|
724
|
-
* ```
|
|
725
|
-
*/
|
|
726
|
-
async callContract(
|
|
727
|
-
{
|
|
728
|
-
amount, callData, contract, abiVersion,
|
|
729
|
-
}: CallContractOptions,
|
|
730
|
-
sign: SignTx,
|
|
731
|
-
): Promise<{ accepted: boolean; signedTx: Encoded.Transaction }> {
|
|
732
|
-
return new Promise((resolve, reject) => {
|
|
733
|
-
enqueueAction(
|
|
734
|
-
this,
|
|
735
|
-
(_channel, state) => state?.handler === handlers.channelOpen,
|
|
736
|
-
(channel) => {
|
|
737
|
-
send(channel, {
|
|
738
|
-
jsonrpc: '2.0',
|
|
739
|
-
method: 'channels.update.call_contract',
|
|
740
|
-
params: {
|
|
741
|
-
amount,
|
|
742
|
-
call_data: callData,
|
|
743
|
-
contract_id: contract,
|
|
744
|
-
abi_version: abiVersion,
|
|
745
|
-
},
|
|
746
|
-
});
|
|
747
|
-
return {
|
|
748
|
-
handler: handlers.awaitingCallContractUpdateTx,
|
|
749
|
-
state: { resolve, reject, sign },
|
|
750
|
-
};
|
|
751
|
-
},
|
|
752
|
-
);
|
|
753
|
-
});
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
/**
|
|
757
|
-
* Trigger a force progress contract call
|
|
758
|
-
* This call is going on-chain
|
|
759
|
-
* @param options - Options
|
|
760
|
-
* @param options.amount - Amount the caller of the contract commits to it
|
|
761
|
-
* @param options.callData - ABI encoded compiled AEVM call data for the code
|
|
762
|
-
* @param options.contract - Address of the contract to call
|
|
763
|
-
* @param options.abiVersion - Version of the ABI
|
|
764
|
-
* @param options.gasPrice=1000000000]
|
|
765
|
-
* @param options.gasLimit=1000000]
|
|
766
|
-
* @param sign - Function which verifies and signs contract force progress transaction
|
|
767
|
-
* @param callbacks - Callbacks
|
|
768
|
-
* @example
|
|
769
|
-
* ```js
|
|
770
|
-
* channel.forceProgress({
|
|
771
|
-
* contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',
|
|
772
|
-
* callData: 'cb_1111111111111111...',
|
|
773
|
-
* amount: 0,
|
|
774
|
-
* abiVersion: 1,
|
|
775
|
-
* gasPrice: 1000005554
|
|
776
|
-
* }).then(({ accepted, signedTx }) => {
|
|
777
|
-
* if (accepted) {
|
|
778
|
-
* console.log('Contract force progress call successful')
|
|
779
|
-
* } else {
|
|
780
|
-
* console.log('Contract force progress call has been rejected')
|
|
781
|
-
* }
|
|
782
|
-
* })
|
|
783
|
-
* ```
|
|
784
|
-
*/
|
|
785
|
-
async forceProgress(
|
|
786
|
-
{
|
|
787
|
-
amount, callData, contract, abiVersion, gasLimit = 1000000, gasPrice = MIN_GAS_PRICE,
|
|
788
|
-
}: {
|
|
789
|
-
amount: number;
|
|
790
|
-
callData: Encoded.ContractBytearray;
|
|
791
|
-
contract: Encoded.ContractAddress;
|
|
792
|
-
abiVersion: number;
|
|
793
|
-
gasLimit?: number;
|
|
794
|
-
gasPrice?: number;
|
|
795
|
-
},
|
|
796
|
-
sign: SignTx,
|
|
797
|
-
{ onOnChainTx }: Pick<ChannelState, 'onOnChainTx'> = {},
|
|
798
|
-
): Promise<{
|
|
799
|
-
accepted: boolean;
|
|
800
|
-
signedTx: Encoded.Transaction;
|
|
801
|
-
tx: Encoded.Transaction | Uint8Array;
|
|
802
|
-
}> {
|
|
803
|
-
return new Promise((resolve, reject) => {
|
|
804
|
-
enqueueAction(
|
|
805
|
-
this,
|
|
806
|
-
(_channel, state) => state?.handler === handlers.channelOpen,
|
|
807
|
-
(channel) => {
|
|
808
|
-
send(channel, {
|
|
809
|
-
jsonrpc: '2.0',
|
|
810
|
-
method: 'channels.force_progress',
|
|
811
|
-
params: {
|
|
812
|
-
amount,
|
|
813
|
-
call_data: callData,
|
|
814
|
-
contract_id: contract,
|
|
815
|
-
abi_version: abiVersion,
|
|
816
|
-
gas_price: gasPrice,
|
|
817
|
-
gas: gasLimit,
|
|
818
|
-
},
|
|
819
|
-
});
|
|
820
|
-
return {
|
|
821
|
-
handler: handlers.awaitingCallContractForceProgressUpdate,
|
|
822
|
-
state: {
|
|
823
|
-
resolve, reject, sign, onOnChainTx,
|
|
824
|
-
},
|
|
825
|
-
};
|
|
826
|
-
},
|
|
827
|
-
);
|
|
828
|
-
});
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
/**
|
|
832
|
-
* Call contract using dry-run
|
|
833
|
-
*
|
|
834
|
-
* In order to get the result of a potential contract call, one might need to
|
|
835
|
-
* dry-run a contract call. It takes the exact same arguments as a call would
|
|
836
|
-
* and returns the call object.
|
|
837
|
-
*
|
|
838
|
-
* The call is executed in the channel's state, but it does not impact the state
|
|
839
|
-
* whatsoever. It uses as an environment the latest channel's state and the current
|
|
840
|
-
* top of the blockchain as seen by the node.
|
|
841
|
-
*
|
|
842
|
-
* @param options - Options
|
|
843
|
-
* @param options.amount - Amount the caller of the contract commits to it
|
|
844
|
-
* @param options.callData - ABI encoded compiled AEVM call data for the code
|
|
845
|
-
* @param options.contract - Address of the contract to call
|
|
846
|
-
* @param options.abiVersion - Version of the ABI
|
|
847
|
-
* @example
|
|
848
|
-
* ```js
|
|
849
|
-
* channel.callContractStatic({
|
|
850
|
-
* contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',
|
|
851
|
-
* callData: 'cb_1111111111111111...',
|
|
852
|
-
* amount: 0,
|
|
853
|
-
* abiVersion: 1
|
|
854
|
-
* }).then(({ returnValue, gasUsed }) => {
|
|
855
|
-
* console.log('Returned value:', returnValue)
|
|
856
|
-
* console.log('Gas used:', gasUsed)
|
|
857
|
-
* })
|
|
858
|
-
* ```
|
|
859
|
-
*/
|
|
860
|
-
async callContractStatic(
|
|
861
|
-
{
|
|
862
|
-
amount, callData, contract, abiVersion,
|
|
863
|
-
}: {
|
|
864
|
-
amount: number;
|
|
865
|
-
callData: Encoded.ContractBytearray;
|
|
866
|
-
contract: Encoded.ContractAddress;
|
|
867
|
-
abiVersion: number;
|
|
868
|
-
},
|
|
869
|
-
): Promise<CallContractOptions> {
|
|
870
|
-
return snakeToPascalObjKeys(await call(this, 'channels.dry_run.call_contract', {
|
|
871
|
-
amount,
|
|
872
|
-
call_data: callData,
|
|
873
|
-
contract_id: contract,
|
|
874
|
-
abi_version: abiVersion,
|
|
875
|
-
}));
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
/**
|
|
879
|
-
* Get contract call result
|
|
880
|
-
*
|
|
881
|
-
* The combination of a caller, contract and a round of execution determines the
|
|
882
|
-
* contract call. Providing an incorrect set of those results in an error response.
|
|
883
|
-
*
|
|
884
|
-
* @param options - Options
|
|
885
|
-
* @param options.caller - Address of contract caller
|
|
886
|
-
* @param options.contract - Address of the contract
|
|
887
|
-
* @param options.round - Round when contract was called
|
|
888
|
-
* @example
|
|
889
|
-
* ```js
|
|
890
|
-
* channel.getContractCall({
|
|
891
|
-
* caller: 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',
|
|
892
|
-
* contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',
|
|
893
|
-
* round: 3
|
|
894
|
-
* }).then(({ returnType, returnValue }) => {
|
|
895
|
-
* if (returnType === 'ok') console.log(returnValue)
|
|
896
|
-
* })
|
|
897
|
-
* ```
|
|
898
|
-
*/
|
|
899
|
-
async getContractCall(
|
|
900
|
-
{ caller, contract, round }: {
|
|
901
|
-
caller: Encoded.AccountAddress;
|
|
902
|
-
contract: Encoded.ContractAddress;
|
|
903
|
-
round: number;
|
|
904
|
-
},
|
|
905
|
-
): Promise<{
|
|
906
|
-
returnType: ContractCallReturnType;
|
|
907
|
-
returnValue: string;
|
|
908
|
-
gasPrice: number | BigNumber;
|
|
909
|
-
gasUsed: number | BigNumber;
|
|
910
|
-
height: number;
|
|
911
|
-
log: string;
|
|
912
|
-
}> {
|
|
913
|
-
return snakeToPascalObjKeys(
|
|
914
|
-
await call(this, 'channels.get.contract_call', {
|
|
915
|
-
caller_id: caller,
|
|
916
|
-
contract_id: contract,
|
|
917
|
-
round,
|
|
918
|
-
}),
|
|
919
|
-
);
|
|
920
|
-
}
|
|
921
|
-
|
|
922
|
-
/**
|
|
923
|
-
* Get the latest contract state
|
|
924
|
-
*
|
|
925
|
-
* @param contract - Address of the contract
|
|
926
|
-
* @example
|
|
927
|
-
* ```js
|
|
928
|
-
* channel.getContractState(
|
|
929
|
-
* 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa'
|
|
930
|
-
* ).then(({ contract }) => {
|
|
931
|
-
* console.log('deposit:', contract.deposit)
|
|
932
|
-
* })
|
|
933
|
-
* ```
|
|
934
|
-
*/
|
|
935
|
-
async getContractState(
|
|
936
|
-
contract: Encoded.ContractAddress,
|
|
937
|
-
): Promise<{ contract: Contract; contractState: object }> {
|
|
938
|
-
const result = await call(this, 'channels.get.contract', { pubkey: contract });
|
|
939
|
-
return snakeToPascalObjKeys({
|
|
940
|
-
...result,
|
|
941
|
-
contract: snakeToPascalObjKeys(result.contract),
|
|
942
|
-
});
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
/**
|
|
946
|
-
* Clean up all locally stored contract calls
|
|
947
|
-
*
|
|
948
|
-
* Contract calls are kept locally in order for the participant to be able to look them up.
|
|
949
|
-
* They consume memory and in order for the participant to free it - one can prune all messages.
|
|
950
|
-
* This cleans up all locally stored contract calls and those will no longer be available for
|
|
951
|
-
* fetching and inspection.
|
|
952
|
-
*/
|
|
953
|
-
async cleanContractCalls(): Promise<void> {
|
|
954
|
-
return new Promise((resolve, reject) => {
|
|
955
|
-
enqueueAction(
|
|
956
|
-
this,
|
|
957
|
-
(_channel, state) => state?.handler === handlers.channelOpen,
|
|
958
|
-
(channel) => {
|
|
959
|
-
send(channel, {
|
|
960
|
-
jsonrpc: '2.0',
|
|
961
|
-
method: 'channels.clean_contract_calls',
|
|
962
|
-
params: {},
|
|
963
|
-
});
|
|
964
|
-
return {
|
|
965
|
-
handler: handlers.awaitingCallsPruned,
|
|
966
|
-
state: { resolve, reject },
|
|
967
|
-
};
|
|
968
|
-
},
|
|
969
|
-
);
|
|
970
|
-
});
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
/**
|
|
974
|
-
* Send generic message
|
|
975
|
-
*
|
|
976
|
-
* If message is an object it will be serialized into JSON string
|
|
977
|
-
* before sending.
|
|
978
|
-
*
|
|
979
|
-
* If there is ongoing update that has not yet been finished the message
|
|
980
|
-
* will be sent after that update is finalized.
|
|
981
|
-
*
|
|
982
|
-
* @param message - Message
|
|
983
|
-
* @param recipient - Address of the recipient
|
|
984
|
-
* @example
|
|
985
|
-
* ```js
|
|
986
|
-
* channel.sendMessage(
|
|
987
|
-
* 'hello world',
|
|
988
|
-
* 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH'
|
|
989
|
-
* )
|
|
990
|
-
* ```
|
|
991
|
-
*/
|
|
992
|
-
async sendMessage(
|
|
993
|
-
message: string | object,
|
|
994
|
-
recipient: Encoded.AccountAddress,
|
|
995
|
-
): Promise<void> {
|
|
996
|
-
const info = typeof message === 'object' ? JSON.stringify(message) : message;
|
|
997
|
-
if (this.status() === 'connecting') {
|
|
998
|
-
await new Promise<void>((resolve) => {
|
|
999
|
-
const onStatusChanged = (status: string): void => {
|
|
1000
|
-
if (status === 'connecting') return;
|
|
1001
|
-
resolve();
|
|
1002
|
-
this.off('statusChanged', onStatusChanged);
|
|
1003
|
-
};
|
|
1004
|
-
this.on('statusChanged', onStatusChanged);
|
|
1005
|
-
});
|
|
1006
|
-
// For some reason we can't immediately send a message when connection is
|
|
1007
|
-
// established. Thus we wait 500ms which seems to work.
|
|
1008
|
-
await pause(500);
|
|
1009
|
-
}
|
|
1010
|
-
send(this, {
|
|
1011
|
-
jsonrpc: '2.0',
|
|
1012
|
-
method: 'channels.message',
|
|
1013
|
-
params: { info, to: recipient },
|
|
1014
|
-
});
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
|
-
static async reconnect(options: ChannelOptions, txParams: any): Promise<Channel> {
|
|
1018
|
-
const { sign } = options;
|
|
1019
|
-
|
|
1020
|
-
return Channel.initialize({
|
|
1021
|
-
...options,
|
|
1022
|
-
reconnectTx: await sign('reconnect', buildTx(txParams, Tag.ChannelClientReconnectTx).tx),
|
|
1023
|
-
});
|
|
1024
|
-
}
|
|
1025
|
-
}
|