@aeternity/aepp-sdk 13.0.0-alpha.0 → 13.0.0-beta.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/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 +5595 -2249
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdk.mjs.map +1 -1
- package/es/AeSdkAepp.mjs.map +1 -1
- package/es/AeSdkBase.d.ts +3 -3
- package/es/AeSdkBase.mjs +4 -0
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkMethods.d.ts +12 -14
- package/es/AeSdkMethods.mjs +6 -8
- package/es/AeSdkMethods.mjs.map +1 -1
- package/es/AeSdkWallet.mjs +1 -1
- package/es/AeSdkWallet.mjs.map +1 -1
- package/es/Node.d.ts +9 -4
- package/es/Node.mjs +12 -6
- package/es/Node.mjs.map +1 -1
- package/es/account/Base.d.ts +13 -8
- package/es/account/Base.mjs +0 -17
- package/es/account/Base.mjs.map +1 -1
- package/es/account/Generalized.mjs +14 -25
- package/es/account/Generalized.mjs.map +1 -1
- package/es/account/Ledger.mjs +2 -1
- package/es/account/Ledger.mjs.map +1 -1
- package/es/account/LedgerFactory.mjs.map +1 -1
- package/es/account/Memory.d.ts +2 -1
- package/es/account/Memory.mjs +11 -22
- package/es/account/Memory.mjs.map +1 -1
- package/es/account/Rpc.mjs.map +1 -1
- package/es/aens.d.ts +12 -14
- package/es/aens.mjs +22 -32
- package/es/aens.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/Browser.mjs +0 -16
- 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 +19 -20
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +0 -16
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection-proxy.mjs +0 -17
- package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +5 -6
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/types.d.ts +6 -2
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
- package/es/aepp-wallet-communication/schema.mjs.map +1 -1
- package/es/aepp-wallet-communication/wallet-detector.mjs +0 -16
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
- package/es/apis/compiler/compiler.d.ts +1 -1
- package/es/apis/compiler/compiler.mjs +4 -20
- package/es/apis/compiler/compiler.mjs.map +1 -1
- package/es/apis/compiler/models/index.d.ts +3 -2
- package/es/apis/compiler/models/index.mjs.map +1 -1
- package/es/apis/compiler/models/mappers.d.ts +1 -1
- package/es/apis/compiler/models/mappers.mjs +19 -2
- package/es/apis/compiler/models/mappers.mjs.map +1 -1
- package/es/apis/node/models/index.d.ts +15 -15
- package/es/apis/node/models/index.mjs.map +1 -1
- package/es/apis/node/models/mappers.d.ts +1 -1
- package/es/apis/node/models/mappers.mjs +2 -1
- package/es/apis/node/models/mappers.mjs.map +1 -1
- package/es/apis/node/models/parameters.d.ts +2 -2
- package/es/apis/node/models/parameters.mjs +2 -2
- package/es/apis/node/models/parameters.mjs.map +1 -1
- package/es/apis/node/node.mjs +3 -19
- package/es/apis/node/node.mjs.map +1 -1
- package/es/chain.d.ts +17 -9
- package/es/chain.mjs +23 -23
- package/es/chain.mjs.map +1 -1
- package/es/channel/Base.d.ts +27 -9
- package/es/channel/Base.mjs +27 -27
- package/es/channel/Base.mjs.map +1 -1
- package/es/channel/Contract.d.ts +8 -7
- package/es/channel/Contract.mjs +8 -21
- package/es/channel/Contract.mjs.map +1 -1
- package/es/channel/Spend.d.ts +5 -1
- package/es/channel/Spend.mjs +4 -18
- package/es/channel/Spend.mjs.map +1 -1
- package/es/channel/handlers.mjs +16 -26
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/internal.d.ts +19 -2
- package/es/channel/internal.mjs +22 -20
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Contract.d.ts +43 -123
- package/es/contract/Contract.mjs +230 -250
- package/es/contract/Contract.mjs.map +1 -1
- package/es/contract/compiler/Base.d.ts +74 -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 +149 -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 +94 -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/delegation-signature.d.ts +43 -0
- package/es/contract/delegation-signature.mjs +45 -0
- package/es/contract/delegation-signature.mjs.map +1 -0
- package/es/contract/ga.d.ts +27 -10
- package/es/contract/ga.mjs +63 -29
- package/es/contract/ga.mjs.map +1 -1
- package/es/index-browser.d.ts +40 -0
- package/es/index-browser.mjs +41 -0
- package/es/index-browser.mjs.map +1 -0
- package/es/index.d.ts +4 -38
- package/es/index.mjs +4 -53
- package/es/index.mjs.map +1 -1
- package/es/oracle.d.ts +12 -17
- package/es/oracle.mjs +29 -49
- package/es/oracle.mjs.map +1 -1
- package/es/spend.d.ts +19 -27
- package/es/spend.mjs +21 -46
- package/es/spend.mjs.map +1 -1
- package/es/tx/builder/SchemaTypes.d.ts +37 -0
- package/es/tx/builder/SchemaTypes.mjs +2 -0
- package/es/tx/builder/SchemaTypes.mjs.map +1 -0
- package/es/tx/builder/constants.d.ts +31 -2
- package/es/tx/builder/constants.mjs +34 -3
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/field-types/abi-version.d.ts +19 -0
- package/es/tx/builder/field-types/abi-version.mjs +40 -0
- package/es/tx/builder/field-types/abi-version.mjs.map +1 -0
- package/es/tx/builder/field-types/address.d.ts +5 -6
- package/es/tx/builder/field-types/address.mjs +17 -8
- package/es/tx/builder/field-types/address.mjs.map +1 -1
- package/es/tx/builder/field-types/array.d.ts +7 -0
- package/es/tx/builder/field-types/array.mjs +11 -0
- package/es/tx/builder/field-types/array.mjs.map +1 -0
- package/es/tx/builder/field-types/boolean.d.ts +6 -0
- package/es/tx/builder/field-types/boolean.mjs +13 -0
- package/es/tx/builder/field-types/boolean.mjs.map +1 -0
- package/es/tx/builder/field-types/coin-amount.d.ts +4 -5
- package/es/tx/builder/field-types/coin-amount.mjs +4 -5
- package/es/tx/builder/field-types/coin-amount.mjs.map +1 -1
- package/es/tx/builder/field-types/ct-version.d.ts +49 -0
- package/es/tx/builder/field-types/ct-version.mjs +76 -0
- package/es/tx/builder/field-types/ct-version.mjs.map +1 -0
- package/es/tx/builder/field-types/deposit.d.ts +3 -2
- package/es/tx/builder/field-types/deposit.mjs +3 -2
- 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 +34 -0
- package/es/tx/builder/field-types/entry.mjs.map +1 -0
- package/es/tx/builder/field-types/enumeration.d.ts +5 -3
- package/es/tx/builder/field-types/enumeration.mjs +11 -2
- package/es/tx/builder/field-types/enumeration.mjs.map +1 -1
- package/es/tx/builder/field-types/fee.d.ts +12 -7
- package/es/tx/builder/field-types/fee.mjs +28 -20
- package/es/tx/builder/field-types/fee.mjs.map +1 -1
- package/es/tx/builder/field-types/field.mjs.map +1 -1
- package/es/tx/builder/field-types/gas-limit.d.ts +7 -3
- package/es/tx/builder/field-types/gas-limit.mjs +13 -8
- package/es/tx/builder/field-types/gas-limit.mjs.map +1 -1
- package/es/tx/builder/field-types/gas-price.d.ts +3 -1
- package/es/tx/builder/field-types/gas-price.mjs.map +1 -1
- package/es/tx/builder/field-types/index.d.ts +107 -30
- package/es/tx/builder/field-types/index.mjs +38 -12
- package/es/tx/builder/field-types/index.mjs.map +1 -1
- package/es/tx/builder/field-types/map.d.ts +13 -0
- package/es/tx/builder/field-types/map.mjs +49 -0
- package/es/tx/builder/field-types/map.mjs.map +1 -0
- package/es/tx/builder/field-types/mptree.d.ts +42 -0
- package/es/tx/builder/field-types/mptree.mjs +266 -0
- package/es/tx/builder/field-types/mptree.mjs.map +1 -0
- package/es/tx/builder/field-types/name-fee.d.ts +2 -3
- package/es/tx/builder/field-types/name-fee.mjs +2 -2
- package/es/tx/builder/field-types/name-fee.mjs.map +1 -1
- package/es/tx/builder/field-types/name-id.mjs +2 -1
- package/es/tx/builder/field-types/name-id.mjs.map +1 -1
- package/es/tx/builder/field-types/name.mjs.map +1 -1
- package/es/tx/builder/field-types/nonce.d.ts +14 -0
- package/es/tx/builder/field-types/nonce.mjs +29 -0
- package/es/tx/builder/field-types/nonce.mjs.map +1 -0
- package/es/tx/builder/field-types/pointers.mjs +2 -2
- package/es/tx/builder/field-types/pointers.mjs.map +1 -1
- package/es/tx/builder/field-types/raw.d.ts +6 -0
- package/es/tx/builder/field-types/raw.mjs +13 -0
- package/es/tx/builder/field-types/raw.mjs.map +1 -0
- package/es/tx/builder/field-types/short-u-int-const.d.ts +7 -0
- package/es/tx/builder/field-types/short-u-int-const.mjs +20 -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.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/ttl.d.ts +11 -0
- package/es/tx/builder/field-types/ttl.mjs +21 -0
- package/es/tx/builder/field-types/ttl.mjs.map +1 -0
- package/es/tx/builder/field-types/u-int.d.ts +1 -2
- package/es/tx/builder/field-types/u-int.mjs.map +1 -1
- package/es/tx/builder/field-types/wrapped.d.ts +14 -0
- package/es/tx/builder/field-types/wrapped.mjs +22 -0
- package/es/tx/builder/field-types/wrapped.mjs.map +1 -0
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +18 -36
- package/es/tx/builder/index.mjs +65 -236
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +2734 -1324
- package/es/tx/builder/schema.generated.d.ts +2011 -0
- package/es/tx/builder/schema.generated.mjs +2 -0
- package/es/tx/builder/schema.generated.mjs.map +1 -0
- package/es/tx/builder/schema.mjs +459 -223
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/execution-cost.d.ts +35 -0
- package/es/tx/execution-cost.mjs +123 -0
- package/es/tx/execution-cost.mjs.map +1 -0
- package/es/tx/transaction-signer.d.ts +6 -0
- package/es/tx/transaction-signer.mjs +27 -0
- package/es/tx/transaction-signer.mjs.map +1 -0
- package/es/tx/validator.d.ts +3 -5
- package/es/tx/validator.mjs +91 -153
- package/es/tx/validator.mjs.map +1 -1
- package/es/utils/amount-formatter.mjs +0 -16
- package/es/utils/amount-formatter.mjs.map +1 -1
- package/es/utils/autorest.d.ts +3 -2
- package/es/utils/autorest.mjs +43 -11
- package/es/utils/autorest.mjs.map +1 -1
- package/es/utils/bytes.mjs +1 -17
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.mjs +0 -16
- package/es/utils/crypto.mjs.map +1 -1
- package/es/utils/encoder.mjs.map +1 -1
- package/es/utils/errors.d.ts +16 -38
- package/es/utils/errors.mjs +3 -43
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/json-big.mjs.map +1 -1
- package/es/utils/keystore.mjs.map +1 -1
- package/es/utils/other.mjs.map +1 -1
- package/es/utils/semver-satisfies.mjs.map +1 -1
- package/es/utils/string.mjs +0 -17
- package/es/utils/string.mjs.map +1 -1
- package/package.json +52 -40
- package/src/AeSdkBase.ts +6 -3
- package/src/AeSdkMethods.ts +12 -18
- package/src/AeSdkWallet.ts +1 -1
- package/src/Node.ts +23 -9
- package/src/account/Base.ts +13 -24
- package/src/account/Generalized.ts +9 -24
- package/src/account/Ledger.ts +1 -1
- package/src/account/Memory.ts +15 -22
- package/src/aens.ts +34 -49
- package/src/aepp-wallet-communication/connection/Browser.ts +0 -17
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +18 -24
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +0 -17
- package/src/aepp-wallet-communication/connection-proxy.ts +0 -17
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +2 -2
- package/src/aepp-wallet-communication/rpc/types.ts +6 -2
- package/src/aepp-wallet-communication/wallet-detector.ts +0 -17
- package/src/apis/compiler/compiler.ts +3 -27
- package/src/apis/compiler/models/index.ts +3 -2
- package/src/apis/compiler/models/mappers.ts +15 -2
- package/src/apis/node/models/index.ts +16 -15
- package/src/apis/node/models/mappers.ts +2 -1
- package/src/apis/node/models/parameters.ts +2 -2
- package/src/apis/node/node.ts +3 -27
- package/src/chain.ts +33 -30
- package/src/channel/Base.ts +39 -31
- package/src/channel/Contract.ts +18 -32
- package/src/channel/Spend.ts +8 -18
- package/src/channel/handlers.ts +14 -26
- package/src/channel/internal.ts +41 -23
- package/src/contract/Contract.ts +188 -228
- package/src/contract/compiler/Base.ts +87 -0
- package/src/contract/compiler/Cli.ts +128 -0
- package/src/contract/compiler/Http.ts +105 -0
- package/src/contract/compiler/HttpNode.ts +26 -0
- package/src/contract/compiler/getFileSystem.ts +42 -0
- package/src/contract/delegation-signature.ts +56 -0
- package/src/contract/ga.ts +61 -37
- package/src/index-browser.ts +50 -0
- package/src/index.ts +4 -56
- package/src/oracle.ts +47 -57
- package/src/spend.ts +34 -68
- package/src/tx/builder/SchemaTypes.ts +79 -0
- package/src/tx/builder/constants.ts +34 -3
- package/src/tx/builder/field-types/abi-version.ts +44 -0
- package/src/tx/builder/field-types/address.ts +23 -13
- package/src/tx/builder/field-types/array.ts +19 -0
- package/src/tx/builder/field-types/boolean.ts +9 -0
- package/src/tx/builder/field-types/coin-amount.ts +8 -5
- package/src/tx/builder/field-types/ct-version.ts +83 -0
- package/src/tx/builder/field-types/deposit.ts +4 -2
- package/src/tx/builder/field-types/encoded.ts +27 -0
- package/src/tx/builder/field-types/entry.ts +36 -0
- package/src/tx/builder/field-types/enumeration.ts +15 -4
- package/src/tx/builder/field-types/fee.ts +41 -19
- package/src/tx/builder/field-types/gas-limit.ts +13 -8
- package/src/tx/builder/field-types/index.ts +60 -17
- package/src/tx/builder/field-types/map.ts +45 -0
- package/src/tx/builder/field-types/mptree.ts +243 -0
- package/src/tx/builder/field-types/name-fee.ts +3 -3
- package/src/tx/builder/field-types/name-id.ts +1 -1
- package/src/tx/builder/field-types/nonce.ts +40 -0
- package/src/tx/builder/field-types/pointers.ts +2 -2
- package/src/tx/builder/field-types/raw.ts +9 -0
- package/src/tx/builder/field-types/short-u-int-const.ts +30 -0
- package/src/tx/builder/field-types/string.ts +11 -0
- package/src/tx/builder/field-types/ttl.ts +24 -0
- package/src/tx/builder/field-types/u-int.ts +1 -3
- package/src/tx/builder/field-types/wrapped.ts +32 -0
- package/src/tx/builder/index.ts +82 -280
- package/src/tx/builder/schema.generated.ts +2013 -0
- package/src/tx/builder/schema.ts +536 -666
- package/src/tx/execution-cost.ts +146 -0
- package/src/tx/transaction-signer.ts +27 -0
- package/src/tx/validator.ts +100 -154
- package/src/utils/amount-formatter.ts +0 -16
- package/src/utils/autorest.ts +52 -11
- package/src/utils/bytes.ts +1 -17
- package/src/utils/crypto.ts +0 -16
- package/src/utils/errors.ts +18 -56
- package/src/utils/string.ts +0 -17
- package/types-legacy/ts4.2/AeSdkBase.d.ts +3 -3
- package/types-legacy/ts4.2/AeSdkMethods.d.ts +12 -14
- package/types-legacy/ts4.2/Node.d.ts +8 -4
- package/types-legacy/ts4.2/account/Base.d.ts +13 -8
- package/types-legacy/ts4.2/account/Memory.d.ts +2 -1
- package/types-legacy/ts4.2/aens.d.ts +12 -14
- package/types-legacy/ts4.2/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/rpc/types.d.ts +6 -2
- package/types-legacy/ts4.2/apis/compiler/compiler.d.ts +1 -1
- package/types-legacy/ts4.2/apis/compiler/models/index.d.ts +3 -2
- package/types-legacy/ts4.2/apis/compiler/models/mappers.d.ts +1 -1
- package/types-legacy/ts4.2/apis/node/models/index.d.ts +15 -15
- package/types-legacy/ts4.2/apis/node/models/mappers.d.ts +1 -1
- package/types-legacy/ts4.2/apis/node/models/parameters.d.ts +2 -2
- package/types-legacy/ts4.2/chain.d.ts +17 -9
- package/types-legacy/ts4.2/channel/Base.d.ts +27 -9
- package/types-legacy/ts4.2/channel/Contract.d.ts +8 -7
- package/types-legacy/ts4.2/channel/Spend.d.ts +5 -1
- package/types-legacy/ts4.2/channel/internal.d.ts +22 -2
- package/types-legacy/ts4.2/contract/Contract.d.ts +42 -122
- package/types-legacy/ts4.2/contract/compiler/Base.d.ts +74 -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/delegation-signature.d.ts +43 -0
- package/types-legacy/ts4.2/contract/ga.d.ts +27 -10
- package/types-legacy/ts4.2/index-browser.d.ts +40 -0
- package/types-legacy/ts4.2/index.d.ts +4 -38
- package/types-legacy/ts4.2/oracle.d.ts +12 -17
- package/types-legacy/ts4.2/spend.d.ts +19 -27
- package/types-legacy/ts4.2/tx/builder/SchemaTypes.d.ts +37 -0
- package/types-legacy/ts4.2/tx/builder/constants.d.ts +31 -2
- package/types-legacy/ts4.2/tx/builder/field-types/abi-version.d.ts +19 -0
- package/types-legacy/ts4.2/tx/builder/field-types/address.d.ts +11 -12
- package/types-legacy/ts4.2/tx/builder/field-types/array.d.ts +7 -0
- package/types-legacy/ts4.2/tx/builder/field-types/boolean.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/coin-amount.d.ts +4 -5
- package/types-legacy/ts4.2/tx/builder/field-types/ct-version.d.ts +72 -0
- package/types-legacy/ts4.2/tx/builder/field-types/deposit.d.ts +3 -2
- package/types-legacy/ts4.2/tx/builder/field-types/encoded.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/entry.d.ts +11 -0
- package/types-legacy/ts4.2/tx/builder/field-types/enumeration.d.ts +5 -3
- package/types-legacy/ts4.2/tx/builder/field-types/fee.d.ts +12 -7
- package/types-legacy/ts4.2/tx/builder/field-types/gas-limit.d.ts +7 -3
- package/types-legacy/ts4.2/tx/builder/field-types/gas-price.d.ts +3 -1
- package/types-legacy/ts4.2/tx/builder/field-types/index.d.ts +113 -30
- package/types-legacy/ts4.2/tx/builder/field-types/map.d.ts +13 -0
- package/types-legacy/ts4.2/tx/builder/field-types/mptree.d.ts +48 -0
- package/types-legacy/ts4.2/tx/builder/field-types/name-fee.d.ts +2 -3
- package/types-legacy/ts4.2/tx/builder/field-types/nonce.d.ts +14 -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 +7 -0
- package/types-legacy/ts4.2/tx/builder/field-types/string.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/ttl.d.ts +11 -0
- package/types-legacy/ts4.2/tx/builder/field-types/u-int.d.ts +1 -2
- package/types-legacy/ts4.2/tx/builder/field-types/wrapped.d.ts +14 -0
- package/types-legacy/ts4.2/tx/builder/index.d.ts +21 -36
- package/types-legacy/ts4.2/tx/builder/schema.d.ts +2971 -2926
- package/types-legacy/ts4.2/tx/builder/schema.generated.d.ts +2011 -0
- package/types-legacy/ts4.2/tx/execution-cost.d.ts +35 -0
- package/types-legacy/ts4.2/tx/transaction-signer.d.ts +6 -0
- package/types-legacy/ts4.2/tx/validator.d.ts +3 -5
- package/types-legacy/ts4.2/utils/autorest.d.ts +3 -2
- package/types-legacy/ts4.2/utils/errors.d.ts +16 -38
- package/types-legacy/ts4.5/AeSdkBase.d.ts +3 -3
- package/types-legacy/ts4.5/AeSdkMethods.d.ts +12 -14
- package/types-legacy/ts4.5/Node.d.ts +8 -4
- package/types-legacy/ts4.5/account/Base.d.ts +13 -8
- package/types-legacy/ts4.5/account/Memory.d.ts +2 -1
- package/types-legacy/ts4.5/aens.d.ts +12 -14
- package/types-legacy/ts4.5/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/rpc/types.d.ts +6 -2
- package/types-legacy/ts4.5/apis/compiler/compiler.d.ts +1 -1
- package/types-legacy/ts4.5/apis/compiler/models/index.d.ts +3 -2
- package/types-legacy/ts4.5/apis/compiler/models/mappers.d.ts +1 -1
- package/types-legacy/ts4.5/apis/node/models/index.d.ts +15 -15
- package/types-legacy/ts4.5/apis/node/models/mappers.d.ts +1 -1
- package/types-legacy/ts4.5/apis/node/models/parameters.d.ts +2 -2
- package/types-legacy/ts4.5/chain.d.ts +17 -9
- package/types-legacy/ts4.5/channel/Base.d.ts +27 -9
- package/types-legacy/ts4.5/channel/Contract.d.ts +8 -7
- package/types-legacy/ts4.5/channel/Spend.d.ts +5 -1
- package/types-legacy/ts4.5/channel/internal.d.ts +22 -2
- package/types-legacy/ts4.5/contract/Contract.d.ts +42 -122
- package/types-legacy/ts4.5/contract/compiler/Base.d.ts +74 -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/delegation-signature.d.ts +43 -0
- package/types-legacy/ts4.5/contract/ga.d.ts +27 -10
- package/types-legacy/ts4.5/index-browser.d.ts +40 -0
- package/types-legacy/ts4.5/index.d.ts +4 -38
- package/types-legacy/ts4.5/oracle.d.ts +12 -17
- package/types-legacy/ts4.5/spend.d.ts +19 -27
- package/types-legacy/ts4.5/tx/builder/SchemaTypes.d.ts +37 -0
- package/types-legacy/ts4.5/tx/builder/constants.d.ts +31 -2
- package/types-legacy/ts4.5/tx/builder/field-types/abi-version.d.ts +19 -0
- package/types-legacy/ts4.5/tx/builder/field-types/address.d.ts +11 -12
- package/types-legacy/ts4.5/tx/builder/field-types/array.d.ts +7 -0
- package/types-legacy/ts4.5/tx/builder/field-types/boolean.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/coin-amount.d.ts +4 -5
- package/types-legacy/ts4.5/tx/builder/field-types/ct-version.d.ts +72 -0
- package/types-legacy/ts4.5/tx/builder/field-types/deposit.d.ts +3 -2
- package/types-legacy/ts4.5/tx/builder/field-types/encoded.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/entry.d.ts +11 -0
- package/types-legacy/ts4.5/tx/builder/field-types/enumeration.d.ts +5 -3
- package/types-legacy/ts4.5/tx/builder/field-types/fee.d.ts +12 -7
- package/types-legacy/ts4.5/tx/builder/field-types/gas-limit.d.ts +7 -3
- package/types-legacy/ts4.5/tx/builder/field-types/gas-price.d.ts +3 -1
- package/types-legacy/ts4.5/tx/builder/field-types/index.d.ts +113 -30
- package/types-legacy/ts4.5/tx/builder/field-types/map.d.ts +13 -0
- package/types-legacy/ts4.5/tx/builder/field-types/mptree.d.ts +48 -0
- package/types-legacy/ts4.5/tx/builder/field-types/name-fee.d.ts +2 -3
- package/types-legacy/ts4.5/tx/builder/field-types/nonce.d.ts +14 -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 +7 -0
- package/types-legacy/ts4.5/tx/builder/field-types/string.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/ttl.d.ts +11 -0
- package/types-legacy/ts4.5/tx/builder/field-types/u-int.d.ts +1 -2
- package/types-legacy/ts4.5/tx/builder/field-types/wrapped.d.ts +14 -0
- package/types-legacy/ts4.5/tx/builder/index.d.ts +21 -36
- package/types-legacy/ts4.5/tx/builder/schema.d.ts +2971 -2926
- package/types-legacy/ts4.5/tx/builder/schema.generated.d.ts +2011 -0
- package/types-legacy/ts4.5/tx/execution-cost.d.ts +35 -0
- package/types-legacy/ts4.5/tx/transaction-signer.d.ts +6 -0
- package/types-legacy/ts4.5/tx/validator.d.ts +3 -5
- package/types-legacy/ts4.5/utils/autorest.d.ts +3 -2
- package/types-legacy/ts4.5/utils/errors.d.ts +16 -38
- package/es/contract/CompilerHttp.d.ts +0 -18
- package/es/contract/CompilerHttp.mjs +0 -63
- package/es/contract/CompilerHttp.mjs.map +0 -1
- package/es/tx/builder/field-types/addresses.d.ts +0 -6
- package/es/tx/builder/field-types/addresses.mjs +0 -13
- package/es/tx/builder/field-types/addresses.mjs.map +0 -1
- package/es/tx/index.d.ts +0 -34
- package/es/tx/index.mjs +0 -172
- package/es/tx/index.mjs.map +0 -1
- package/es/utils/mptree.d.ts +0 -26
- package/es/utils/mptree.mjs +0 -143
- package/es/utils/mptree.mjs.map +0 -1
- package/src/apis/compiler/code-model-v4.yaml +0 -2442
- package/src/apis/node/code-model-v4.yaml +0 -10080
- package/src/contract/CompilerHttp.ts +0 -67
- package/src/tx/builder/field-types/addresses.ts +0 -18
- package/src/tx/index.ts +0 -196
- package/src/utils/mptree.ts +0 -145
- package/types-legacy/ts4.2/contract/CompilerHttp.d.ts +0 -18
- package/types-legacy/ts4.2/tx/builder/field-types/addresses.d.ts +0 -6
- package/types-legacy/ts4.2/tx/index.d.ts +0 -34
- package/types-legacy/ts4.2/utils/mptree.d.ts +0 -32
- package/types-legacy/ts4.5/contract/CompilerHttp.d.ts +0 -18
- package/types-legacy/ts4.5/tx/builder/field-types/addresses.d.ts +0 -6
- package/types-legacy/ts4.5/tx/index.d.ts +0 -34
- package/types-legacy/ts4.5/utils/mptree.d.ts +0 -32
package/es/chain.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chain.mjs","names":["AE_AMOUNT_FORMATS","formatAmount","verifyTransaction","isAccountNotFoundError","pause","isNameValid","produceNameId","DRY_RUN_ACCOUNT","AensPointerContextError","DryRunError","InvalidAensNameError","TransactionError","TxTimedOutError","TxNotInChainError","InternalError","decode","_getPollInterval","type","_expectedMineRate","_microBlockCycle","_maxPollInterval","base","block","microblock","Math","min","InvalidTxError","constructor","message","validation","transaction","name","getHeight","onNode","getCurrentKeyBlockHeight","height","poll","th","blocks","interval","options","max","tx","getTransactionByHash","blockHeight","awaitHeight","currentHeight","waitForTxConfirm","txHash","confirm","newBlockHeight","sendTransaction","onAccount","verify","waitMined","length","map","v","join","__queue","address","error","postTransaction","requestOptions","customHeaders","pollResult","txData","hash","rawTx","c","undefined","confirmationHeight","Object","assign","verifyTx","getAccount","getAccountByPubkeyAndHeight","getAccountByPubkeyAndHash","getAccountByPubkey","getBalance","format","AETTOS","balance","catch","targetDenomination","getCurrentGeneration","getGeneration","hashOrHeight","getGenerationByHeight","getGenerationByHash","getMicroBlockTransactions","getMicroBlockTransactionsByHash","transactions","getKeyBlock","getKeyBlockByHeight","getKeyBlockByHash","getMicroBlockHeader","getMicroBlockHeaderByHash","txDryRunRequests","Map","txDryRunHandler","key","rs","get","delete","dryRunRes","protectedDryRunTxs","top","txEvents","txs","req","accounts","Array","from","Set","accountAddress","pubKey","amount","forEach","reject","results","idx","result","reason","resultPayload","resolve","txDryRun","combine","requests","set","Promise","push","timeout","setTimeout","getContractByteCode","contractId","getContractCode","getContract","getName","getNameEntryByName","resolveName","nameOrId","resolveByNode","pointer","pointers","find","p","id"],"sources":["../src/chain.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 { AE_AMOUNT_FORMATS, formatAmount } from './utils/amount-formatter';\nimport verifyTransaction, { ValidatorResult } from './tx/validator';\nimport { isAccountNotFoundError, pause } from './utils/other';\nimport { isNameValid, produceNameId } from './tx/builder/helpers';\nimport { DRY_RUN_ACCOUNT } from './tx/builder/schema';\nimport { AensName } from './tx/builder/constants';\nimport {\n AensPointerContextError, DryRunError, InvalidAensNameError, TransactionError,\n TxTimedOutError, TxNotInChainError, InternalError,\n} from './utils/errors';\nimport Node, { TransformNodeType } from './Node';\nimport {\n Account as AccountNode, ByteCode, ContractObject, DryRunResult, DryRunResults,\n Generation, KeyBlock, MicroBlockHeader, NameEntry, SignedTx,\n} from './apis/node';\nimport { decode, Encoded, Encoding } from './utils/encoder';\nimport AccountBase from './account/Base';\n\n/**\n * @category chain\n */\nexport function _getPollInterval(\n type: 'block' | 'microblock',\n { _expectedMineRate = 180000, _microBlockCycle = 3000, _maxPollInterval = 5000 }:\n { _expectedMineRate?: number; _microBlockCycle?: number; _maxPollInterval?: number },\n): number {\n const base = {\n block: _expectedMineRate,\n microblock: _microBlockCycle,\n }[type];\n return Math.min(base / 3, _maxPollInterval);\n}\n\n/**\n * @category exception\n */\nexport class InvalidTxError extends TransactionError {\n validation: ValidatorResult[];\n\n transaction: Encoded.Transaction;\n\n constructor(\n message: string,\n validation: ValidatorResult[],\n transaction: Encoded.Transaction,\n ) {\n super(message);\n this.name = 'InvalidTxError';\n this.validation = validation;\n this.transaction = transaction;\n }\n}\n\n/**\n * Obtain current height of the chain\n * @category chain\n * @returns Current chain height\n */\nexport async function getHeight({ onNode }: { onNode: Node }): Promise<number> {\n return (await onNode.getCurrentKeyBlockHeight()).height;\n}\n\n/**\n * Wait for a transaction to be mined\n * @category chain\n * @param th - The hash of transaction to poll\n * @param options - Options\n * @param options.interval - Interval (in ms) at which to poll the chain\n * @param options.blocks - Number of blocks mined after which to fail\n * @param options.onNode - Node to use\n * @returns The transaction as it was mined\n */\nexport async function poll(\n th: Encoded.TxHash,\n {\n blocks = 10, interval, onNode, ...options\n }:\n { blocks?: number; interval?: number; onNode: Node } & Parameters<typeof _getPollInterval>[1],\n): Promise<TransformNodeType<SignedTx>> {\n interval ??= _getPollInterval('microblock', options);\n const max = await getHeight({ onNode }) + blocks;\n do {\n const tx = await onNode.getTransactionByHash(th);\n if (tx.blockHeight !== -1) return tx;\n await pause(interval);\n } while (await getHeight({ onNode }) < max);\n throw new TxTimedOutError(blocks, th);\n}\n\n/**\n * Wait for the chain to reach a specific height\n * @category chain\n * @param height - Height to wait for\n * @param options - Options\n * @param options.interval - Interval (in ms) at which to poll the chain\n * @param options.onNode - Node to use\n * @returns Current chain height\n */\nexport async function awaitHeight(\n height: number,\n { interval, onNode, ...options }:\n { interval?: number; onNode: Node } & Parameters<typeof _getPollInterval>[1],\n): Promise<number> {\n interval ??= _getPollInterval('block', options);\n let currentHeight;\n do {\n if (currentHeight != null) await pause(interval);\n currentHeight = (await onNode.getCurrentKeyBlockHeight()).height;\n } while (currentHeight < height);\n return currentHeight;\n}\n\n/**\n * Wait for transaction confirmation\n * @category chain\n * @param txHash - Transaction hash\n * @param options - Options\n * @param options.confirm - Number of micro blocks to wait for transaction confirmation\n * @param options.onNode - Node to use\n * @returns Current Height\n */\nexport async function waitForTxConfirm(\n txHash: Encoded.TxHash,\n { confirm = 3, onNode, ...options }:\n { confirm?: number; onNode: Node } & Parameters<typeof awaitHeight>[1],\n): Promise<number> {\n const { blockHeight } = await onNode.getTransactionByHash(txHash);\n const height = await awaitHeight(blockHeight + confirm, { onNode, ...options });\n const { blockHeight: newBlockHeight } = await onNode.getTransactionByHash(txHash);\n switch (newBlockHeight) {\n case -1:\n throw new TxNotInChainError(txHash);\n case blockHeight:\n return height;\n default:\n return waitForTxConfirm(txHash, { onNode, confirm, ...options });\n }\n}\n\n/**\n * Submit a signed transaction for mining\n * @category chain\n * @param tx - Transaction to submit\n * @param options - Options\n * @param options.onNode - Node to use\n * @param options.onAccount - Account to use\n * @param options.verify - Verify transaction before sending\n * @param options.waitMined - Ensure that transaction get into block\n * @param options.confirm - Number of micro blocks that should be mined after tx get included\n * @returns Transaction details\n */\nexport async function sendTransaction(\n tx: Encoded.Transaction,\n {\n onNode, onAccount, verify = true, waitMined = true, confirm, ...options\n }:\n SendTransactionOptions,\n): Promise<SendTransactionReturnType> {\n if (verify) {\n const validation = await verifyTransaction(tx, onNode);\n if (validation.length > 0) {\n const message = `Transaction verification errors: ${\n validation.map((v: { message: string }) => v.message).join(', ')}`;\n throw new InvalidTxError(message, validation, tx);\n }\n }\n\n try {\n let __queue;\n try {\n __queue = onAccount != null ? `tx-${onAccount.address}` : null;\n } catch (error) {\n __queue = null;\n }\n const { txHash } = await onNode.postTransaction(\n { tx },\n __queue != null ? { requestOptions: { customHeaders: { __queue } } } : {},\n );\n\n if (waitMined) {\n const pollResult = await poll(txHash, { onNode, ...options });\n const txData = {\n ...pollResult,\n hash: pollResult.hash as Encoded.TxHash,\n rawTx: tx,\n };\n // wait for transaction confirmation\n if (confirm != null && (confirm === true || confirm > 0)) {\n const c = typeof confirm === 'boolean' ? undefined : confirm;\n return {\n ...txData,\n confirmationHeight: await waitForTxConfirm(txHash, { onNode, confirm: c, ...options }),\n };\n }\n return txData;\n }\n return { hash: txHash, rawTx: tx };\n } catch (error) {\n throw Object.assign(error, {\n rawTx: tx,\n verifyTx: async () => verifyTransaction(tx, onNode),\n });\n }\n}\n\ntype SendTransactionOptionsType = {\n onNode: Node;\n onAccount?: AccountBase;\n verify?: boolean;\n waitMined?: boolean;\n confirm?: boolean | number;\n} & Parameters<typeof poll>[1] & Omit<Parameters<typeof waitForTxConfirm>[1], 'confirm'>;\ninterface SendTransactionOptions extends SendTransactionOptionsType {}\ninterface SendTransactionReturnType extends Partial<TransformNodeType<SignedTx>> {\n hash: Encoded.TxHash;\n rawTx: Encoded.Transaction;\n confirmationHeight?: number;\n}\n\n/**\n * Get account by account public key\n * @category chain\n * @param address - Account address (public key)\n * @param options - Options\n * @param options.height - Get account on specific block by block height\n * @param options.hash - Get account on specific block by micro block hash or key block hash\n * @param options.onNode - Node to use\n */\nexport async function getAccount(\n address: Encoded.AccountAddress | Encoded.ContractAddress,\n { height, hash, onNode }:\n { height?: number; hash?: Encoded.KeyBlockHash | Encoded.MicroBlockHash; onNode: Node },\n): Promise<TransformNodeType<AccountNode>> {\n if (height != null) return onNode.getAccountByPubkeyAndHeight(address, height);\n if (hash != null) return onNode.getAccountByPubkeyAndHash(address, hash);\n return onNode.getAccountByPubkey(address);\n}\n\n/**\n * Request the balance of specified account\n * @category chain\n * @param address - The public account address to obtain the balance for\n * @param options - Options\n * @param options.format\n * @param options.height - The chain height at which to obtain the balance for\n * (default: top of chain)\n * @param options.hash - The block hash on which to obtain the balance for (default: top of chain)\n */\nexport async function getBalance(\n address: Encoded.AccountAddress | Encoded.ContractAddress,\n { format = AE_AMOUNT_FORMATS.AETTOS, ...options }:\n { format?: AE_AMOUNT_FORMATS } & Parameters<typeof getAccount>[1],\n): Promise<string> {\n const { balance } = await getAccount(address, options).catch((error) => {\n if (!isAccountNotFoundError(error)) throw error;\n return { balance: 0n };\n });\n\n return formatAmount(balance, { targetDenomination: format });\n}\n\n/**\n * Obtain current generation\n * @category chain\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Current Generation\n */\nexport async function getCurrentGeneration(\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<Generation>> {\n return onNode.getCurrentGeneration();\n}\n\n/**\n * Get generation by hash or height\n * @category chain\n * @param hashOrHeight - Generation hash or height\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Generation\n */\nexport async function getGeneration(\n hashOrHeight: Encoded.KeyBlockHash | number,\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<Generation>> {\n if (typeof hashOrHeight === 'number') return onNode.getGenerationByHeight(hashOrHeight);\n return onNode.getGenerationByHash(hashOrHeight);\n}\n\n/**\n * Get micro block transactions\n * @category chain\n * @param hash - Micro block hash\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Transactions\n */\nexport async function getMicroBlockTransactions(\n hash: Encoded.MicroBlockHash,\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<SignedTx[]>> {\n return (await onNode.getMicroBlockTransactionsByHash(hash)).transactions;\n}\n\n/**\n * Get key block\n * @category chain\n * @param hashOrHeight - Key block hash or height\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Key Block\n */\nexport async function getKeyBlock(\n hashOrHeight: Encoded.KeyBlockHash | number,\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<KeyBlock>> {\n if (typeof hashOrHeight === 'number') return onNode.getKeyBlockByHeight(hashOrHeight);\n return onNode.getKeyBlockByHash(hashOrHeight);\n}\n\n/**\n * Get micro block header\n * @category chain\n * @param hash - Micro block hash\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Micro block header\n */\nexport async function getMicroBlockHeader(\n hash: Encoded.MicroBlockHash,\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<MicroBlockHeader>> {\n return onNode.getMicroBlockHeaderByHash(hash);\n}\n\ninterface TxDryRunArguments {\n tx: Encoded.Transaction;\n accountAddress: Encoded.AccountAddress;\n top?: number;\n txEvents?: any;\n resolve: Function;\n reject: Function;\n}\nconst txDryRunRequests: Map<string, TxDryRunArguments[] & { timeout?: NodeJS.Timeout }> = new Map();\n\nasync function txDryRunHandler(key: string, onNode: Node): Promise<void> {\n const rs = txDryRunRequests.get(key);\n txDryRunRequests.delete(key);\n if (rs == null) throw new InternalError('Can\\'t get dry-run request');\n\n let dryRunRes;\n try {\n dryRunRes = await onNode.protectedDryRunTxs({\n top: rs[0].top,\n txEvents: rs[0].txEvents,\n txs: rs.map((req) => ({ tx: req.tx })),\n accounts: Array.from(new Set(rs.map((req) => req.accountAddress)))\n .map((pubKey) => ({ pubKey, amount: DRY_RUN_ACCOUNT.amount })),\n });\n } catch (error) {\n rs.forEach(({ reject }) => reject(error));\n return;\n }\n\n const { results, txEvents } = dryRunRes;\n results.forEach(({ result, reason, ...resultPayload }, idx) => {\n const {\n resolve, reject, tx, accountAddress,\n } = rs[idx];\n if (result === 'ok') resolve({ ...resultPayload, txEvents });\n else reject(Object.assign(new DryRunError(reason as string), { tx, accountAddress }));\n });\n}\n\n/**\n * Transaction dry-run\n * @category chain\n * @param tx - transaction to execute\n * @param accountAddress - address that will be used to execute transaction\n * @param options - Options\n * @param options.top - hash of block on which to make dry-run\n * @param options.txEvents - collect and return on-chain tx events that would result from the call\n * @param options.combine - Enables combining of similar requests to a single dry-run call\n * @param options.onNode - Node to use\n */\nexport async function txDryRun(\n tx: Encoded.Transaction,\n accountAddress: Encoded.AccountAddress,\n {\n top, txEvents, combine, onNode,\n }:\n { top?: number; txEvents?: boolean; combine?: boolean; onNode: Node },\n): Promise<{\n txEvents?: TransformNodeType<DryRunResults['txEvents']>;\n } & TransformNodeType<DryRunResult>> {\n const key = combine === true ? [top, txEvents].join() : 'immediate';\n const requests = txDryRunRequests.get(key) ?? [];\n txDryRunRequests.set(key, requests);\n return new Promise((resolve, reject) => {\n requests.push({\n tx, accountAddress, top, txEvents, resolve, reject,\n });\n if (combine !== true) {\n void txDryRunHandler(key, onNode);\n return;\n }\n requests.timeout ??= setTimeout(() => { void txDryRunHandler(key, onNode); });\n });\n}\n\n/**\n * Get contract byte code\n * @category contract\n * @param contractId - Contract address\n * @param options - Options\n * @param options.onNode - Node to use\n */\nexport async function getContractByteCode(\n contractId: Encoded.ContractAddress,\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<ByteCode>> {\n return onNode.getContractCode(contractId);\n}\n\n/**\n * Get contract entry\n * @category contract\n * @param contractId - Contract address\n * @param options - Options\n * @param options.onNode - Node to use\n */\nexport async function getContract(\n contractId: Encoded.ContractAddress,\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<ContractObject>> {\n return onNode.getContract(contractId);\n}\n\n/**\n * Get name entry\n * @category AENS\n * @param name - AENS name\n * @param options - Options\n * @param options.onNode - Node to use\n */\nexport async function getName(\n name: AensName,\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<NameEntry>> {\n return onNode.getNameEntryByName(name);\n}\n\n/**\n * Resolve AENS name and return name hash\n * @category AENS\n * @param nameOrId - AENS name or address\n * @param key - in AENS pointers record\n * @param options - Options\n * @param options.verify - To ensure that name exist and have a corresponding pointer\n * // TODO: avoid that to don't trust to current api gateway\n * @param options.resolveByNode - Enables pointer resolving using node\n * @param options.onNode - Node to use\n * @returns Address or AENS name hash\n */\nexport async function resolveName <\n Type extends Encoding.AccountAddress | Encoding.ContractAddress,\n>(\n nameOrId: AensName | Encoded.Generic<Type>,\n key: string,\n { verify = true, resolveByNode = false, onNode }:\n { verify?: boolean; resolveByNode?: boolean; onNode: Node },\n): Promise<Encoded.Generic<Type | Encoding.Name>> {\n if (isNameValid(nameOrId)) {\n if (verify || resolveByNode) {\n const name = await onNode.getNameEntryByName(nameOrId);\n const pointer = name.pointers.find((p) => p.key === key);\n if (pointer == null) throw new AensPointerContextError(nameOrId, key);\n if (resolveByNode) return pointer.id as Encoded.Generic<Type>;\n }\n return produceNameId(nameOrId);\n }\n try {\n decode(nameOrId);\n return nameOrId;\n } catch (error) {\n throw new InvalidAensNameError(`Invalid name or address: ${nameOrId}`);\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAfA,SAgBSA,iBAAiB,EAAEC,YAAY;AAAA,OACjCC,iBAAiB;AAAA,SACfC,sBAAsB,EAAEC,KAAK;AAAA,SAC7BC,WAAW,EAAEC,aAAa;AAAA,SAC1BC,eAAe;AAAA,SAGtBC,uBAAuB,EAAEC,WAAW,EAAEC,oBAAoB,EAAEC,gBAAgB,EAC5EC,eAAe,EAAEC,iBAAiB,EAAEC,aAAa;AAAA,SAO1CC,MAAM;AAGf;AACA;AACA;AACA,OAAO,SAASC,gBAAgB,CAC9BC,IAA4B,QAGpB;EAAA,IAFR;IAAEC,iBAAiB,GAAG,MAAM;IAAEC,gBAAgB,GAAG,IAAI;IAAEC,gBAAgB,GAAG;EACS,CAAC;EAEpF,MAAMC,IAAI,GAAG;IACXC,KAAK,EAAEJ,iBAAiB;IACxBK,UAAU,EAAEJ;EACd,CAAC,CAACF,IAAI,CAAC;EACP,OAAOO,IAAI,CAACC,GAAG,CAACJ,IAAI,GAAG,CAAC,EAAED,gBAAgB,CAAC;AAC7C;;AAEA;AACA;AACA;AACA,OAAO,MAAMM,cAAc,SAASf,gBAAgB,CAAC;EAKnDgB,WAAW,CACTC,OAAe,EACfC,UAA6B,EAC7BC,WAAgC,EAChC;IACA,KAAK,CAACF,OAAO,CAAC;I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,OAAOC,OAAO,CAACI,EAAE;IACtC;IACA,OAAO7I,aAAa,CAACuI,QAAQ,CAAC;EAChC;EACA,IAAI;IACF9H,MAAM,CAAC8H,QAAQ,CAAC;IAChB,OAAOA,QAAQ;EACjB,CAAC,CAAC,OAAOhF,KAAK,EAAE;IACd,MAAM,IAAInD,oBAAoB,CAAE,4BAA2BmI,QAAS,EAAC,CAAC;EACxE;AACF"}
|
|
1
|
+
{"version":3,"file":"chain.mjs","names":["AE_AMOUNT_FORMATS","formatAmount","verifyTransaction","isAccountNotFoundError","pause","isNameValid","produceNameId","DRY_RUN_ACCOUNT","AensPointerContextError","DryRunError","InvalidAensNameError","TransactionError","TxTimedOutError","TxNotInChainError","InternalError","decode","encode","Encoding","buildTxHash","_getPollInterval","type","_ref","_expectedMineRate","_microBlockCycle","_maxPollInterval","base","block","microblock","Math","min","InvalidTxError","constructor","message","validation","transaction","name","getHeight","_ref2","onNode","getCurrentKeyBlockHeight","height","poll","th","_ref3","_interval","blocks","interval","options","max","tx","getTransactionByHash","blockHeight","awaitHeight","_ref4","_interval2","currentHeight","waitForTxConfirm","txHash","_ref5","confirm","newBlockHeight","sendTransaction","txUnsigned","_ref6","onAccount","verify","waitMined","innerTx","signTransaction","networkId","getNetworkId","hash","rawTx","length","map","v","join","__queue","address","error","postTransaction","requestOptions","customHeaders","pollResult","txData","c","undefined","confirmationHeight","Object","assign","verifyTx","getAccount","_ref7","getAccountByPubkeyAndHeight","getAccountByPubkeyAndHash","getAccountByPubkey","getBalance","_ref8","format","AETTOS","addr","startsWith","AccountAddress","balance","catch","targetDenomination","getCurrentGeneration","_ref9","getGeneration","hashOrHeight","_ref10","getGenerationByHeight","getGenerationByHash","getMicroBlockTransactions","_ref11","getMicroBlockTransactionsByHash","transactions","getKeyBlock","_ref12","getKeyBlockByHeight","getKeyBlockByHash","getMicroBlockHeader","_ref13","getMicroBlockHeaderByHash","txDryRunRequests","Map","txDryRunHandler","key","rs","get","delete","dryRunRes","top","protectedDryRunTxs","txEvents","txs","req","accounts","Array","from","Set","accountAddress","pubKey","amount","forEach","_ref14","reject","results","_ref15","idx","result","reason","resultPayload","resolve","txDryRun","_ref16","_txDryRunRequests$get","combine","requests","set","Promise","_requests$timeout","push","timeout","setTimeout","getContractByteCode","contractId","_ref17","getContractCode","getContract","_ref18","getName","_ref19","getNameEntryByName","resolveName","nameOrId","_ref20","resolveByNode","pointer","pointers","find","p","id"],"sources":["../src/chain.ts"],"sourcesContent":["import { AE_AMOUNT_FORMATS, formatAmount } from './utils/amount-formatter';\nimport verifyTransaction, { ValidatorResult } from './tx/validator';\nimport { isAccountNotFoundError, pause } from './utils/other';\nimport { isNameValid, produceNameId } from './tx/builder/helpers';\nimport { DRY_RUN_ACCOUNT } from './tx/builder/schema';\nimport { AensName } from './tx/builder/constants';\nimport {\n AensPointerContextError, DryRunError, InvalidAensNameError, TransactionError,\n TxTimedOutError, TxNotInChainError, InternalError,\n} from './utils/errors';\nimport Node, { TransformNodeType } from './Node';\nimport {\n Account as AccountNode, ByteCode, ContractObject, DryRunResult, DryRunResults,\n Generation, KeyBlock, MicroBlockHeader, NameEntry, SignedTx,\n} from './apis/node';\nimport {\n decode, encode, Encoded, Encoding,\n} from './utils/encoder';\nimport AccountBase from './account/Base';\nimport { buildTxHash } from './tx/builder';\n\n/**\n * @category chain\n */\nexport function _getPollInterval(\n type: 'block' | 'microblock',\n { _expectedMineRate = 180000, _microBlockCycle = 3000, _maxPollInterval = 5000 }:\n { _expectedMineRate?: number; _microBlockCycle?: number; _maxPollInterval?: number },\n): number {\n const base = {\n block: _expectedMineRate,\n microblock: _microBlockCycle,\n }[type];\n return Math.min(base / 3, _maxPollInterval);\n}\n\n/**\n * @category exception\n */\nexport class InvalidTxError extends TransactionError {\n validation: ValidatorResult[];\n\n transaction: Encoded.Transaction;\n\n constructor(\n message: string,\n validation: ValidatorResult[],\n transaction: Encoded.Transaction,\n ) {\n super(message);\n this.name = 'InvalidTxError';\n this.validation = validation;\n this.transaction = transaction;\n }\n}\n\n/**\n * Obtain current height of the chain\n * @category chain\n * @returns Current chain height\n */\nexport async function getHeight({ onNode }: { onNode: Node }): Promise<number> {\n return (await onNode.getCurrentKeyBlockHeight()).height;\n}\n\n/**\n * Wait for a transaction to be mined\n * @category chain\n * @param th - The hash of transaction to poll\n * @param options - Options\n * @param options.interval - Interval (in ms) at which to poll the chain\n * @param options.blocks - Number of blocks mined after which to fail\n * @param options.onNode - Node to use\n * @returns The transaction as it was mined\n */\nexport async function poll(\n th: Encoded.TxHash,\n {\n blocks = 10, interval, onNode, ...options\n }:\n { blocks?: number; interval?: number; onNode: Node } & Parameters<typeof _getPollInterval>[1],\n): Promise<TransformNodeType<SignedTx>> {\n interval ??= _getPollInterval('microblock', options);\n const max = await getHeight({ onNode }) + blocks;\n do {\n const tx = await onNode.getTransactionByHash(th);\n if (tx.blockHeight !== -1) return tx;\n await pause(interval);\n } while (await getHeight({ onNode }) < max);\n throw new TxTimedOutError(blocks, th);\n}\n\n/**\n * Wait for the chain to reach a specific height\n * @category chain\n * @param height - Height to wait for\n * @param options - Options\n * @param options.interval - Interval (in ms) at which to poll the chain\n * @param options.onNode - Node to use\n * @returns Current chain height\n */\nexport async function awaitHeight(\n height: number,\n { interval, onNode, ...options }:\n { interval?: number; onNode: Node } & Parameters<typeof _getPollInterval>[1],\n): Promise<number> {\n interval ??= _getPollInterval('block', options);\n let currentHeight;\n do {\n if (currentHeight != null) await pause(interval);\n currentHeight = (await onNode.getCurrentKeyBlockHeight()).height;\n } while (currentHeight < height);\n return currentHeight;\n}\n\n/**\n * Wait for transaction confirmation\n * @category chain\n * @param txHash - Transaction hash\n * @param options - Options\n * @param options.confirm - Number of micro blocks to wait for transaction confirmation\n * @param options.onNode - Node to use\n * @returns Current Height\n */\nexport async function waitForTxConfirm(\n txHash: Encoded.TxHash,\n { confirm = 3, onNode, ...options }:\n { confirm?: number; onNode: Node } & Parameters<typeof awaitHeight>[1],\n): Promise<number> {\n const { blockHeight } = await onNode.getTransactionByHash(txHash);\n const height = await awaitHeight(blockHeight + confirm, { onNode, ...options });\n const { blockHeight: newBlockHeight } = await onNode.getTransactionByHash(txHash);\n switch (newBlockHeight) {\n case -1:\n throw new TxNotInChainError(txHash);\n case blockHeight:\n return height;\n default:\n return waitForTxConfirm(txHash, { onNode, confirm, ...options });\n }\n}\n\n/**\n * Signs and submits transaction for mining\n * @category chain\n * @param txUnsigned - Transaction to sign and submit\n * @param options - Options\n * @param options.onNode - Node to use\n * @param options.onAccount - Account to use\n * @param options.verify - Verify transaction before broadcast, throw error if not\n * @param options.waitMined - Ensure that transaction get into block\n * @param options.confirm - Number of micro blocks that should be mined after tx get included\n * @returns Transaction details\n */\nexport async function sendTransaction(\n txUnsigned: Encoded.Transaction,\n {\n onNode, onAccount, verify = true, waitMined = true, confirm, innerTx, ...options\n }:\n SendTransactionOptions,\n): Promise<SendTransactionReturnType> {\n const tx = await onAccount.signTransaction(txUnsigned, {\n ...options,\n onNode,\n innerTx,\n networkId: await onNode.getNetworkId(),\n });\n\n if (innerTx === true) return { hash: buildTxHash(tx), rawTx: tx };\n\n if (verify) {\n const validation = await verifyTransaction(tx, onNode);\n if (validation.length > 0) {\n const message = `Transaction verification errors: ${\n validation.map((v: { message: string }) => v.message).join(', ')}`;\n throw new InvalidTxError(message, validation, tx);\n }\n }\n\n try {\n let __queue;\n try {\n __queue = onAccount != null ? `tx-${onAccount.address}` : null;\n } catch (error) {\n __queue = null;\n }\n const { txHash } = await onNode.postTransaction(\n { tx },\n __queue != null ? { requestOptions: { customHeaders: { __queue } } } : {},\n );\n\n if (waitMined) {\n const pollResult = await poll(txHash, { onNode, ...options });\n const txData = {\n ...pollResult,\n hash: pollResult.hash as Encoded.TxHash,\n rawTx: tx,\n };\n // wait for transaction confirmation\n if (confirm != null && (confirm === true || confirm > 0)) {\n const c = typeof confirm === 'boolean' ? undefined : confirm;\n return {\n ...txData,\n confirmationHeight: await waitForTxConfirm(txHash, { onNode, confirm: c, ...options }),\n };\n }\n return txData;\n }\n return { hash: txHash, rawTx: tx };\n } catch (error) {\n throw Object.assign(error, {\n rawTx: tx,\n verifyTx: async () => verifyTransaction(tx, onNode),\n });\n }\n}\n\ntype SendTransactionOptionsType = {\n onNode: Node;\n onAccount: AccountBase;\n verify?: boolean;\n waitMined?: boolean;\n confirm?: boolean | number;\n} & Parameters<typeof poll>[1] & Omit<Parameters<typeof waitForTxConfirm>[1], 'confirm'>\n& Parameters<AccountBase['signTransaction']>[1];\nexport interface SendTransactionOptions extends SendTransactionOptionsType {}\ninterface SendTransactionReturnType extends Partial<TransformNodeType<SignedTx>> {\n hash: Encoded.TxHash;\n rawTx: Encoded.Transaction;\n confirmationHeight?: number;\n}\n\n/**\n * Get account by account public key\n * @category chain\n * @param address - Account address (public key)\n * @param options - Options\n * @param options.height - Get account on specific block by block height\n * @param options.hash - Get account on specific block by micro block hash or key block hash\n * @param options.onNode - Node to use\n */\nexport async function getAccount(\n address: Encoded.AccountAddress | Encoded.ContractAddress,\n { height, hash, onNode }:\n { height?: number; hash?: Encoded.KeyBlockHash | Encoded.MicroBlockHash; onNode: Node },\n): Promise<TransformNodeType<AccountNode>> {\n if (height != null) return onNode.getAccountByPubkeyAndHeight(address, height);\n if (hash != null) return onNode.getAccountByPubkeyAndHash(address, hash);\n return onNode.getAccountByPubkey(address);\n}\n\n/**\n * Request the balance of specified account\n * @category chain\n * @param address - The public account address to obtain the balance for\n * @param options - Options\n * @param options.format\n * @param options.height - The chain height at which to obtain the balance for\n * (default: top of chain)\n * @param options.hash - The block hash on which to obtain the balance for (default: top of chain)\n */\nexport async function getBalance(\n address: Encoded.AccountAddress | Encoded.ContractAddress | Encoded.OracleAddress,\n { format = AE_AMOUNT_FORMATS.AETTOS, ...options }:\n { format?: AE_AMOUNT_FORMATS } & Parameters<typeof getAccount>[1],\n): Promise<string> {\n const addr = address.startsWith('ok_')\n ? encode(decode(address), Encoding.AccountAddress)\n : address as Encoded.AccountAddress | Encoded.ContractAddress;\n\n const { balance } = await getAccount(addr, options).catch((error) => {\n if (!isAccountNotFoundError(error)) throw error;\n return { balance: 0n };\n });\n\n return formatAmount(balance, { targetDenomination: format });\n}\n\n/**\n * Obtain current generation\n * @category chain\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Current Generation\n */\nexport async function getCurrentGeneration(\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<Generation>> {\n return onNode.getCurrentGeneration();\n}\n\n/**\n * Get generation by hash or height\n * @category chain\n * @param hashOrHeight - Generation hash or height\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Generation\n */\nexport async function getGeneration(\n hashOrHeight: Encoded.KeyBlockHash | number,\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<Generation>> {\n if (typeof hashOrHeight === 'number') return onNode.getGenerationByHeight(hashOrHeight);\n return onNode.getGenerationByHash(hashOrHeight);\n}\n\n/**\n * Get micro block transactions\n * @category chain\n * @param hash - Micro block hash\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Transactions\n */\nexport async function getMicroBlockTransactions(\n hash: Encoded.MicroBlockHash,\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<SignedTx[]>> {\n return (await onNode.getMicroBlockTransactionsByHash(hash)).transactions;\n}\n\n/**\n * Get key block\n * @category chain\n * @param hashOrHeight - Key block hash or height\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Key Block\n */\nexport async function getKeyBlock(\n hashOrHeight: Encoded.KeyBlockHash | number,\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<KeyBlock>> {\n if (typeof hashOrHeight === 'number') return onNode.getKeyBlockByHeight(hashOrHeight);\n return onNode.getKeyBlockByHash(hashOrHeight);\n}\n\n/**\n * Get micro block header\n * @category chain\n * @param hash - Micro block hash\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Micro block header\n */\nexport async function getMicroBlockHeader(\n hash: Encoded.MicroBlockHash,\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<MicroBlockHeader>> {\n return onNode.getMicroBlockHeaderByHash(hash);\n}\n\ninterface TxDryRunArguments {\n tx: Encoded.Transaction;\n accountAddress: Encoded.AccountAddress;\n top?: number | Encoded.KeyBlockHash | Encoded.MicroBlockHash;\n txEvents?: any;\n resolve: Function;\n reject: Function;\n}\nconst txDryRunRequests: Map<string, TxDryRunArguments[] & { timeout?: NodeJS.Timeout }> = new Map();\n\nasync function txDryRunHandler(key: string, onNode: Node): Promise<void> {\n const rs = txDryRunRequests.get(key);\n txDryRunRequests.delete(key);\n if (rs == null) throw new InternalError('Can\\'t get dry-run request');\n\n let dryRunRes;\n try {\n const top = typeof rs[0].top === 'number'\n ? (await getKeyBlock(rs[0].top, { onNode })).hash : rs[0].top;\n dryRunRes = await onNode.protectedDryRunTxs({\n top,\n txEvents: rs[0].txEvents,\n txs: rs.map((req) => ({ tx: req.tx })),\n accounts: Array.from(new Set(rs.map((req) => req.accountAddress)))\n .map((pubKey) => ({ pubKey, amount: DRY_RUN_ACCOUNT.amount })),\n });\n } catch (error) {\n rs.forEach(({ reject }) => reject(error));\n return;\n }\n\n const { results, txEvents } = dryRunRes;\n results.forEach(({ result, reason, ...resultPayload }, idx) => {\n const {\n resolve, reject, tx, accountAddress,\n } = rs[idx];\n if (result === 'ok') resolve({ ...resultPayload, txEvents });\n else reject(Object.assign(new DryRunError(reason as string), { tx, accountAddress }));\n });\n}\n\n/**\n * Transaction dry-run\n * @category chain\n * @param tx - transaction to execute\n * @param accountAddress - address that will be used to execute transaction\n * @param options - Options\n * @param options.top - hash of block on which to make dry-run\n * @param options.txEvents - collect and return on-chain tx events that would result from the call\n * @param options.combine - Enables combining of similar requests to a single dry-run call\n * @param options.onNode - Node to use\n */\nexport async function txDryRun(\n tx: Encoded.Transaction,\n accountAddress: Encoded.AccountAddress,\n {\n top, txEvents, combine, onNode,\n }:\n { top?: TxDryRunArguments['top']; txEvents?: boolean; combine?: boolean; onNode: Node },\n): Promise<{\n txEvents?: TransformNodeType<DryRunResults['txEvents']>;\n } & TransformNodeType<DryRunResult>> {\n const key = combine === true ? [top, txEvents].join() : 'immediate';\n const requests = txDryRunRequests.get(key) ?? [];\n txDryRunRequests.set(key, requests);\n return new Promise((resolve, reject) => {\n requests.push({\n tx, accountAddress, top, txEvents, resolve, reject,\n });\n if (combine !== true) {\n void txDryRunHandler(key, onNode);\n return;\n }\n requests.timeout ??= setTimeout(() => { void txDryRunHandler(key, onNode); });\n });\n}\n\n/**\n * Get contract byte code\n * @category contract\n * @param contractId - Contract address\n * @param options - Options\n * @param options.onNode - Node to use\n */\nexport async function getContractByteCode(\n contractId: Encoded.ContractAddress,\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<ByteCode>> {\n return onNode.getContractCode(contractId);\n}\n\n/**\n * Get contract entry\n * @category contract\n * @param contractId - Contract address\n * @param options - Options\n * @param options.onNode - Node to use\n */\nexport async function getContract(\n contractId: Encoded.ContractAddress,\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<ContractObject>> {\n return onNode.getContract(contractId);\n}\n\n/**\n * Get name entry\n * @category AENS\n * @param name - AENS name\n * @param options - Options\n * @param options.onNode - Node to use\n */\nexport async function getName(\n name: AensName,\n { onNode }: { onNode: Node },\n): Promise<TransformNodeType<NameEntry>> {\n return onNode.getNameEntryByName(name);\n}\n\n/**\n * Resolve AENS name and return name hash\n * @category AENS\n * @param nameOrId - AENS name or address\n * @param key - in AENS pointers record\n * @param options - Options\n * @param options.verify - To ensure that name exist and have a corresponding pointer\n * // TODO: avoid that to don't trust to current api gateway\n * @param options.resolveByNode - Enables pointer resolving using node\n * @param options.onNode - Node to use\n * @returns Address or AENS name hash\n */\nexport async function resolveName <\n Type extends Encoding.AccountAddress | Encoding.ContractAddress,\n>(\n nameOrId: AensName | Encoded.Generic<Type>,\n key: string,\n { verify = true, resolveByNode = false, onNode }:\n { verify?: boolean; resolveByNode?: boolean; onNode: Node },\n): Promise<Encoded.Generic<Type | Encoding.Name>> {\n if (isNameValid(nameOrId)) {\n if (verify || resolveByNode) {\n const name = await onNode.getNameEntryByName(nameOrId);\n const pointer = name.pointers.find((p) => p.key === key);\n if (pointer == null) throw new AensPointerContextError(nameOrId, key);\n if (resolveByNode) return pointer.id as Encoded.Generic<Type>;\n }\n return produceNameId(nameOrId);\n }\n try {\n decode(nameOrId);\n return nameOrId;\n } catch (error) {\n throw new InvalidAensNameError(`Invalid name or address: ${nameOrId}`);\n }\n}\n"],"mappings":"SAASA,iBAAiB,EAAEC,YAAY;AAAA,OACjCC,iBAAiB;AAAA,SACfC,sBAAsB,EAAEC,KAAK;AAAA,SAC7BC,WAAW,EAAEC,aAAa;AAAA,SAC1BC,eAAe;AAAA,SAGtBC,uBAAuB,EAAEC,WAAW,EAAEC,oBAAoB,EAAEC,gBAAgB,EAC5EC,eAAe,EAAEC,iBAAiB,EAAEC,aAAa;AAAA,SAQjDC,MAAM,EAAEC,MAAM,EAAWC,QAAQ;AAAA,SAG1BC,WAAW;AAEpB;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAC9BC,IAA4B,EAAAC,IAAA,EAGpB;EAAA,IAFR;IAAEC,iBAAiB,GAAG,MAAM;IAAEC,gBAAgB,GAAG,IAAI;IAAEC,gBAAgB,GAAG;EACS,CAAC,GAAAH,IAAA;EAEpF,MAAMI,IAAI,GAAG;IACXC,KAAK,EAAEJ,iBAAiB;IACxBK,UAAU,EAAEJ;EACd,CAAC,CAACH,IAAI,CAAC;EACP,OAAOQ,IAAI,CAACC,GAAG,CAACJ,IAAI,GAAG,CAAC,EAAED,gBAAgB,CAAC;AAC7C;;AAEA;AACA;AACA;AACA,OAAO,MAAMM,cAAc,SAASnB,gBAAgB,CAAC;EAKnDoB,WAAWA,CACTC,OAAe,EACfC,UAA6B,EAC7BC,WAAgC,EAChC;IACA,KAAK,CAACF,OAAO,CAAC;IACd,IAAI,CAACG,IAAI,GAAG,gBAAgB;IAC5B,IAAI,CAACF,UAAU,GAAGA,UAAU;IAC5B,IAAI,CAACC,WAAW,GAAGA,WAAW;EAChC;AACF;;A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AAI,IAAI,EAAE,MAAM,IAAI1K,uBAAuB,CAACuK,QAAQ,EAAEhD,GAAG,CAAC;MACrE,IAAIkD,aAAa,EAAE,OAAOC,OAAO,CAACI,EAAE;IACtC;IACA,OAAOhL,aAAa,CAACyK,QAAQ,CAAC;EAChC;EACA,IAAI;IACFhK,MAAM,CAACgK,QAAQ,CAAC;IAChB,OAAOA,QAAQ;EACjB,CAAC,CAAC,OAAOhG,KAAK,EAAE;IACd,MAAM,IAAIrE,oBAAoB,CAAE,4BAA2BqK,QAAS,EAAC,CAAC;EACxE;AACF"}
|
package/es/channel/Base.d.ts
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
4
|
import { w3cwebsocket as W3CWebSocket } from 'websocket';
|
|
5
|
-
import {
|
|
5
|
+
import { Tag } from '../tx/builder/constants';
|
|
6
|
+
import { SignTx, ChannelOptions, ChannelState, ChannelHandler, ChannelAction, ChannelStatus, ChannelFsm, ChannelMessage, ChannelEvents } from './internal';
|
|
6
7
|
import { Encoded } from '../utils/encoder';
|
|
7
|
-
|
|
8
|
+
import { TxUnpacked } from '../tx/builder/schema.generated';
|
|
8
9
|
/**
|
|
9
10
|
* Channel
|
|
10
11
|
* @example
|
|
@@ -32,14 +33,14 @@ export default class Channel {
|
|
|
32
33
|
_nextRpcMessageId: number;
|
|
33
34
|
_rpcCallbacks: Map<number, (message: object) => void>;
|
|
34
35
|
_fsmId?: Encoded.Bytearray;
|
|
35
|
-
_messageQueue:
|
|
36
|
+
_messageQueue: ChannelMessage[];
|
|
36
37
|
_isMessageQueueLocked: boolean;
|
|
37
38
|
_actionQueue: ChannelAction[];
|
|
38
39
|
_isActionQueueLocked: boolean;
|
|
39
40
|
_status: ChannelStatus;
|
|
40
41
|
_fsm: ChannelFsm;
|
|
41
42
|
_websocket: W3CWebSocket;
|
|
42
|
-
_state
|
|
43
|
+
_state: Encoded.Transaction | '';
|
|
43
44
|
_options: ChannelOptions;
|
|
44
45
|
_channelId?: Encoded.Channel;
|
|
45
46
|
/**
|
|
@@ -100,24 +101,29 @@ export default class Channel {
|
|
|
100
101
|
* Possible events:
|
|
101
102
|
*
|
|
102
103
|
* - "error"
|
|
104
|
+
* - "stateChanged"
|
|
105
|
+
* - "statusChanged"
|
|
106
|
+
* - "message"
|
|
107
|
+
* - "peerDisconnected"
|
|
103
108
|
* - "onChainTx"
|
|
104
109
|
* - "ownWithdrawLocked"
|
|
105
110
|
* - "withdrawLocked"
|
|
106
111
|
* - "ownDepositLocked"
|
|
107
112
|
* - "depositLocked"
|
|
113
|
+
* - "channelReestablished"
|
|
114
|
+
* - "newContract"
|
|
108
115
|
*
|
|
109
|
-
* TODO: the event list looks outdated
|
|
110
116
|
*
|
|
111
117
|
* @param eventName - Event name
|
|
112
118
|
* @param callback - Callback function
|
|
113
119
|
*/
|
|
114
|
-
on(eventName:
|
|
120
|
+
on<E extends keyof ChannelEvents>(eventName: E, callback: ChannelEvents[E]): void;
|
|
115
121
|
/**
|
|
116
122
|
* Remove event listener function
|
|
117
123
|
* @param eventName - Event name
|
|
118
124
|
* @param callback - Callback function
|
|
119
125
|
*/
|
|
120
|
-
off(eventName:
|
|
126
|
+
off<E extends keyof ChannelEvents>(eventName: E, callback: ChannelEvents[E]): void;
|
|
121
127
|
/**
|
|
122
128
|
* Close the connection
|
|
123
129
|
*/
|
|
@@ -129,7 +135,20 @@ export default class Channel {
|
|
|
129
135
|
/**
|
|
130
136
|
* Get current state
|
|
131
137
|
*/
|
|
132
|
-
state(): Promise<
|
|
138
|
+
state(): Promise<{
|
|
139
|
+
calls: TxUnpacked & {
|
|
140
|
+
tag: Tag.CallsMtree;
|
|
141
|
+
};
|
|
142
|
+
halfSignedTx?: TxUnpacked & {
|
|
143
|
+
tag: Tag.SignedTx;
|
|
144
|
+
};
|
|
145
|
+
signedTx?: TxUnpacked & {
|
|
146
|
+
tag: Tag.SignedTx;
|
|
147
|
+
};
|
|
148
|
+
trees: TxUnpacked & {
|
|
149
|
+
tag: Tag.StateTrees;
|
|
150
|
+
};
|
|
151
|
+
}>;
|
|
133
152
|
/**
|
|
134
153
|
* Get current round
|
|
135
154
|
*
|
|
@@ -192,4 +211,3 @@ export default class Channel {
|
|
|
192
211
|
shutdown(sign: SignTx): Promise<Encoded.Transaction>;
|
|
193
212
|
static reconnect(options: ChannelOptions, txParams: any): Promise<Channel>;
|
|
194
213
|
}
|
|
195
|
-
export {};
|
package/es/channel/Base.mjs
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
|
|
2
|
-
/*
|
|
3
|
-
* ISC License (ISC)
|
|
4
|
-
* Copyright (c) 2022 aeternity developers
|
|
5
|
-
*
|
|
6
|
-
* Permission to use, copy, modify, and/or distribute this software for any
|
|
7
|
-
* purpose with or without fee is hereby granted, provided that the above
|
|
8
|
-
* copyright notice and this permission notice appear in all copies.
|
|
9
|
-
*
|
|
10
|
-
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
11
|
-
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
12
|
-
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
13
|
-
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
14
|
-
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
15
|
-
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
16
|
-
* PERFORMANCE OF THIS SOFTWARE.
|
|
17
|
-
*/
|
|
18
2
|
import _events from 'events';
|
|
19
3
|
const {
|
|
20
4
|
EventEmitter
|
|
@@ -34,6 +18,7 @@ function snakeToPascalObjKeys(obj) {
|
|
|
34
18
|
};
|
|
35
19
|
}, {});
|
|
36
20
|
}
|
|
21
|
+
|
|
37
22
|
/**
|
|
38
23
|
* Channel
|
|
39
24
|
* @example
|
|
@@ -65,6 +50,7 @@ export default class Channel {
|
|
|
65
50
|
_defineProperty(this, "_actionQueue", []);
|
|
66
51
|
_defineProperty(this, "_isActionQueueLocked", false);
|
|
67
52
|
_defineProperty(this, "_status", 'disconnected');
|
|
53
|
+
_defineProperty(this, "_state", '');
|
|
68
54
|
}
|
|
69
55
|
/**
|
|
70
56
|
* @param options - Channel params
|
|
@@ -130,18 +116,22 @@ export default class Channel {
|
|
|
130
116
|
* Possible events:
|
|
131
117
|
*
|
|
132
118
|
* - "error"
|
|
119
|
+
* - "stateChanged"
|
|
120
|
+
* - "statusChanged"
|
|
121
|
+
* - "message"
|
|
122
|
+
* - "peerDisconnected"
|
|
133
123
|
* - "onChainTx"
|
|
134
124
|
* - "ownWithdrawLocked"
|
|
135
125
|
* - "withdrawLocked"
|
|
136
126
|
* - "ownDepositLocked"
|
|
137
127
|
* - "depositLocked"
|
|
128
|
+
* - "channelReestablished"
|
|
129
|
+
* - "newContract"
|
|
138
130
|
*
|
|
139
|
-
* TODO: the event list looks outdated
|
|
140
131
|
*
|
|
141
132
|
* @param eventName - Event name
|
|
142
133
|
* @param callback - Callback function
|
|
143
134
|
*/
|
|
144
|
-
// TODO define specific callback type depending on the event name
|
|
145
135
|
on(eventName, callback) {
|
|
146
136
|
this._eventEmitter.on(eventName, callback);
|
|
147
137
|
}
|
|
@@ -173,7 +163,17 @@ export default class Channel {
|
|
|
173
163
|
* Get current state
|
|
174
164
|
*/
|
|
175
165
|
async state() {
|
|
176
|
-
|
|
166
|
+
const res = snakeToPascalObjKeys(await call(this, 'channels.get.offchain_state', {}));
|
|
167
|
+
return {
|
|
168
|
+
calls: unpackTx(res.calls, Tag.CallsMtree),
|
|
169
|
+
...(res.halfSignedTx !== '' && {
|
|
170
|
+
halfSignedTx: unpackTx(res.halfSignedTx, Tag.SignedTx)
|
|
171
|
+
}),
|
|
172
|
+
...(res.signedTx !== '' && {
|
|
173
|
+
signedTx: unpackTx(res.signedTx, Tag.SignedTx)
|
|
174
|
+
}),
|
|
175
|
+
trees: unpackTx(res.trees, Tag.StateTrees)
|
|
176
|
+
};
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
/**
|
|
@@ -183,20 +183,17 @@ export default class Channel {
|
|
|
183
183
|
* it will return `null`.
|
|
184
184
|
*/
|
|
185
185
|
round() {
|
|
186
|
-
if (this._state
|
|
186
|
+
if (this._state === '') {
|
|
187
187
|
return null;
|
|
188
188
|
}
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
tx
|
|
192
|
-
} = unpackTx(this._state, Tag.SignedTx).tx.encodedTx;
|
|
193
|
-
switch (txType) {
|
|
189
|
+
const params = unpackTx(this._state, Tag.SignedTx).encodedTx;
|
|
190
|
+
switch (params.tag) {
|
|
194
191
|
case Tag.ChannelCreateTx:
|
|
195
192
|
return 1;
|
|
196
193
|
case Tag.ChannelOffChainTx:
|
|
197
194
|
case Tag.ChannelWithdrawTx:
|
|
198
195
|
case Tag.ChannelDepositTx:
|
|
199
|
-
return
|
|
196
|
+
return params.round;
|
|
200
197
|
default:
|
|
201
198
|
return null;
|
|
202
199
|
}
|
|
@@ -283,7 +280,10 @@ export default class Channel {
|
|
|
283
280
|
} = options;
|
|
284
281
|
return Channel.initialize({
|
|
285
282
|
...options,
|
|
286
|
-
reconnectTx: await sign('reconnect', buildTx(
|
|
283
|
+
reconnectTx: await sign('reconnect', buildTx({
|
|
284
|
+
...txParams,
|
|
285
|
+
tag: Tag.ChannelClientReconnectTx
|
|
286
|
+
}))
|
|
287
287
|
});
|
|
288
288
|
}
|
|
289
289
|
}
|
package/es/channel/Base.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Base.mjs","names":["snakeToPascal","buildTx","unpackTx","Tag","handlers","initialize","enqueueAction","notify","call","disconnect","channelDisconnect","ChannelError","snakeToPascalObjKeys","obj","Object","entries","reduce","result","key","val","Channel","EventEmitter","Map","options","_initialize","channel","existingFsmId","awaitingReconnection","awaitingConnection","channelOpen","on","eventName","callback","_eventEmitter","off","removeListener","status","_status","state","round","_state","txType","tx","SignedTx","encodedTx","ChannelCreateTx","ChannelOffChainTx","ChannelWithdrawTx","ChannelDepositTx","id","_channelId","fsmId","_fsmId","action","handler","leave","awaitingLeave","shutdown","sign","awaitingShutdownTx","reconnect","txParams","reconnectTx","ChannelClientReconnectTx"],"sources":["../../src/channel/Base.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 { EventEmitter } from 'events';\nimport { w3cwebsocket as W3CWebSocket } from 'websocket';\nimport { snakeToPascal } from '../utils/string';\nimport { buildTx, unpackTx } from '../tx/builder';\nimport { Tag } from '../tx/builder/constants';\nimport * as handlers from './handlers';\nimport {\n initialize,\n enqueueAction,\n notify,\n call,\n disconnect as channelDisconnect,\n SignTx,\n ChannelOptions,\n ChannelState,\n ChannelHandler,\n ChannelAction,\n ChannelStatus,\n ChannelFsm,\n} from './internal';\nimport { ChannelError } from '../utils/errors';\nimport { Encoded } from '../utils/encoder';\n\nfunction snakeToPascalObjKeys<Type>(obj: object): Type {\n return Object.entries(obj).reduce((result, [key, val]) => ({\n ...result,\n [snakeToPascal(key)]: val,\n }), {}) as Type;\n}\n\ntype EventCallback = (...args: any[]) => void;\n\n/**\n * Channel\n * @example\n * ```js\n * await Channel.initialize({\n * url: 'ws://localhost:3001',\n * role: 'initiator'\n * initiatorId: 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',\n * responderId: 'ak_V6an1xhec1xVaAhLuak7QoEbi6t7w5hEtYWp9bMKaJ19i6A9E',\n * initiatorAmount: 1e18,\n * responderAmount: 1e18,\n * pushAmount: 0,\n * channelReserve: 0,\n * ttl: 1000,\n * host: 'localhost',\n * port: 3002,\n * lockPeriod: 10,\n * async sign (tag, tx) => await account.signTransaction(tx)\n * })\n * ```\n */\nexport default class Channel {\n _eventEmitter = new EventEmitter();\n\n _pingTimeoutId: NodeJS.Timeout;\n\n _nextRpcMessageId = 0;\n\n _rpcCallbacks = new Map<number, (message: object) => void>();\n\n _fsmId?: Encoded.Bytearray;\n\n _messageQueue: object[] = [];\n\n _isMessageQueueLocked = false;\n\n _actionQueue: ChannelAction[] = [];\n\n _isActionQueueLocked = false;\n\n _status: ChannelStatus = 'disconnected';\n\n _fsm: ChannelFsm;\n\n _websocket: W3CWebSocket;\n\n _state?: Encoded.Transaction;\n\n _options: ChannelOptions;\n\n _channelId?: Encoded.Channel;\n\n /**\n * @param options - Channel params\n * @param options.url - Channel url (for example: \"ws://localhost:3001\")\n * @param options.role - Participant role (\"initiator\" or \"responder\")\n * @param options.initiatorId - Initiator's public key\n * @param options.responderId - Responder's public key\n * @param options.pushAmount - Initial deposit in favour of the responder by the initiator\n * @param options.initiatorAmount - Amount of coins the initiator has committed to\n * the channel\n * @param options.responderAmount - Amount of coins the responder has committed to\n * the channel\n * @param options.channelReserve - The minimum amount both peers need to maintain\n * @param options.ttl - Minimum block height to include the channel_create_tx\n * @param options.host - Host of the responder's node\n * @param options.port - The port of the responders node\n * @param options.lockPeriod - Amount of blocks for disputing a solo close\n * @param options.minimumDepthStrategy - How to calculate minimum depth (default: txfee)\n * @param options.minimumDepth - The minimum amount of blocks to be mined\n * @param options.fee - The fee to be used for the channel open transaction\n * @param options.gasPrice - Used for the fee computation of the channel open transaction\n * @param options.existingChannelId - Existing channel id (required if reestablishing a\n * channel)\n * @param options.offchainTx - Offchain transaction (required if reestablishing\n * a channel)\n * @param options.timeoutIdle - The time waiting for a new event to be initiated\n * (default: 600000)\n * @param options.timeoutFundingCreate - The time waiting for the initiator to produce\n * the create channel transaction after the noise session had been established (default: 120000)\n * @param options.timeoutFundingSign - The time frame the other client has to sign an\n * off-chain update after our client had initiated and signed it. This applies only for double\n * signed on-chain intended updates: channel create transaction, deposit, withdrawal and etc.\n * (default: 120000)\n * @param options.timeoutFundingLock - The time frame the other client has to confirm an\n * on-chain transaction reaching maturity (passing minimum depth) after the local node has\n * detected this. This applies only for double signed on-chain intended updates: channel create\n * transaction, deposit, withdrawal and etc. (default: 360000)\n * @param options.timeoutSign - The time frame the client has to return a signed\n * off-chain update or to decline it. This applies for all off-chain updates (default: 500000)\n * @param options.timeoutAccept - The time frame the other client has to react to an\n * event. This applies for all off-chain updates that are not meant to land on-chain, as well as\n * some special cases: opening a noise connection, mutual closing acknowledgement and\n * reestablishing an existing channel (default: 120000)\n * @param options.timeoutInitialized - the time frame the responder has to accept an\n * incoming noise session. Applicable only for initiator (default: timeout_accept's value)\n * @param options.timeoutAwaitingOpen - The time frame the initiator has to start an\n * outgoing noise session to the responder's node. Applicable only for responder (default:\n * timeout_idle's value)\n * @param options.debug=false - Log websocket communication\n * @param options.sign - Function which verifies and signs transactions\n */\n static async initialize(options: ChannelOptions): Promise<Channel> {\n return Channel._initialize(new Channel(), options);\n }\n\n static async _initialize<T extends Channel>(channel: T, options: ChannelOptions): Promise<T> {\n await initialize(\n channel,\n options.existingFsmId != null ? handlers.awaitingReconnection : handlers.awaitingConnection,\n handlers.channelOpen,\n options,\n );\n return channel;\n }\n\n /**\n * Register event listener function\n *\n * Possible events:\n *\n * - \"error\"\n * - \"onChainTx\"\n * - \"ownWithdrawLocked\"\n * - \"withdrawLocked\"\n * - \"ownDepositLocked\"\n * - \"depositLocked\"\n *\n * TODO: the event list looks outdated\n *\n * @param eventName - Event name\n * @param callback - Callback function\n */\n // TODO define specific callback type depending on the event name\n on(eventName: string, callback: EventCallback): void {\n this._eventEmitter.on(eventName, callback);\n }\n\n /**\n * Remove event listener function\n * @param eventName - Event name\n * @param callback - Callback function\n */\n off(eventName: string, callback: EventCallback): void {\n this._eventEmitter.removeListener(eventName, callback);\n }\n\n /**\n * Close the connection\n */\n disconnect(): void {\n return channelDisconnect(this);\n }\n\n /**\n * Get current status\n */\n status(): ChannelStatus {\n return this._status;\n }\n\n /**\n * Get current state\n */\n async state(): Promise<ChannelState> {\n return snakeToPascalObjKeys(await call(this, 'channels.get.offchain_state', {}));\n }\n\n /**\n * Get current round\n *\n * If round cannot be determined (for example when channel has not been opened)\n * it will return `null`.\n */\n round(): number | null {\n if (this._state == null) {\n return null;\n }\n const { txType, tx } = unpackTx(this._state, Tag.SignedTx).tx.encodedTx;\n switch (txType) {\n case Tag.ChannelCreateTx:\n return 1;\n case Tag.ChannelOffChainTx:\n case Tag.ChannelWithdrawTx:\n case Tag.ChannelDepositTx:\n return tx.round;\n default:\n return null;\n }\n }\n\n /**\n * Get channel id\n *\n */\n id(): Encoded.Channel {\n if (this._channelId == null) throw new ChannelError('Channel is not initialized');\n return this._channelId;\n }\n\n /**\n * Get channel's fsm id\n *\n */\n fsmId(): Encoded.Bytearray {\n if (this._fsmId == null) throw new ChannelError('Channel is not initialized');\n return this._fsmId;\n }\n\n protected async enqueueAction(\n action: () => { handler: ChannelHandler; state?: Partial<ChannelState> },\n ): Promise<any> {\n return enqueueAction(\n this,\n (channel, state) => state?.handler === handlers.channelOpen,\n action,\n );\n }\n\n /**\n * Leave channel\n *\n * It is possible to leave a channel and then later reestablish the channel\n * off-chain state and continue operation. When a leave method is called,\n * the channel fsm passes it on to the peer fsm, reports the current mutually\n * signed state and then terminates.\n *\n * The channel can be reestablished by instantiating another Channel instance\n * with two extra params: existingChannelId and offchainTx (returned from leave\n * method as channelId and signedTx respectively).\n *\n * @example\n * ```js\n * channel.leave().then(({ channelId, signedTx }) => {\n * console.log(channelId)\n * console.log(signedTx)\n * })\n * ```\n */\n async leave(): Promise<{ channelId: Encoded.Bytearray; signedTx: Encoded.Transaction }> {\n return this.enqueueAction(() => {\n notify(this, 'channels.leave');\n return { handler: handlers.awaitingLeave };\n });\n }\n\n /**\n * Trigger mutual close\n *\n * At any moment after the channel is opened, a closing procedure can be triggered.\n * This can be done by either of the parties. The process is similar to the off-chain updates.\n *\n * @param sign - Function which verifies and signs mutual close transaction\n * @example\n * ```js\n * channel.shutdown(\n * async (tx) => await account.signTransaction(tx)\n * ).then(tx => console.log('on_chain_tx', tx))\n * ```\n */\n async shutdown(sign: SignTx): Promise<Encoded.Transaction> {\n return this.enqueueAction(() => {\n notify(this, 'channels.shutdown');\n return {\n handler: handlers.awaitingShutdownTx,\n state: { sign },\n };\n });\n }\n\n static async reconnect(options: ChannelOptions, txParams: any): Promise<Channel> {\n const { sign } = options;\n\n return Channel.initialize({\n ...options,\n reconnectTx: await sign('reconnect', buildTx(txParams, Tag.ChannelClientReconnectTx).tx),\n });\n }\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oBAA6B,QAAQ;AAAC;EAAA;AAAA;AAAA,SAE7BA,aAAa;AAAA,SACbC,OAAO,EAAEC,QAAQ;AAAA,SACjBC,GAAG;AAAA,OACL,KAAKC,QAAQ;AAAA,SAElBC,UAAU,EACVC,aAAa,EACbC,MAAM,EACNC,IAAI,EACJC,UAAU,IAAIC,iBAAiB;AAAA,SASxBC,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AC,GAAGnC,OAAO;IAExB,OAAOH,OAAO,CAACf,UAAU,CAAC;MACxB,GAAGkB,OAAO;MACVuC,WAAW,EAAE,MAAMJ,IAAI,CAAC,WAAW,EAAEzD,OAAO,CAAC4D,QAAQ,EAAE1D,GAAG,CAAC4D,wBAAwB,CAAC,CAACrB,EAAE;IACzF,CAAC,CAAC;EACJ;AACF"}
|
|
1
|
+
{"version":3,"file":"Base.mjs","names":["_events","EventEmitter","snakeToPascal","buildTx","unpackTx","Tag","handlers","initialize","enqueueAction","notify","call","disconnect","channelDisconnect","ChannelError","snakeToPascalObjKeys","obj","Object","entries","reduce","result","_ref","key","val","Channel","constructor","_defineProperty","Map","options","_initialize","channel","existingFsmId","awaitingReconnection","awaitingConnection","channelOpen","on","eventName","callback","_eventEmitter","off","removeListener","status","_status","state","res","calls","CallsMtree","halfSignedTx","SignedTx","signedTx","trees","StateTrees","round","_state","params","encodedTx","tag","ChannelCreateTx","ChannelOffChainTx","ChannelWithdrawTx","ChannelDepositTx","id","_channelId","fsmId","_fsmId","action","handler","leave","awaitingLeave","shutdown","sign","awaitingShutdownTx","reconnect","txParams","reconnectTx","ChannelClientReconnectTx"],"sources":["../../src/channel/Base.ts"],"sourcesContent":["import { EventEmitter } from 'events';\nimport { w3cwebsocket as W3CWebSocket } from 'websocket';\nimport { snakeToPascal } from '../utils/string';\nimport { buildTx, unpackTx } from '../tx/builder';\nimport { Tag } from '../tx/builder/constants';\nimport * as handlers from './handlers';\nimport {\n initialize,\n enqueueAction,\n notify,\n call,\n disconnect as channelDisconnect,\n SignTx,\n ChannelOptions,\n ChannelState,\n ChannelHandler,\n ChannelAction,\n ChannelStatus,\n ChannelFsm,\n ChannelMessage,\n ChannelEvents,\n} from './internal';\nimport { ChannelError } from '../utils/errors';\nimport { Encoded } from '../utils/encoder';\nimport { TxUnpacked } from '../tx/builder/schema.generated';\n\nfunction snakeToPascalObjKeys<Type>(obj: object): Type {\n return Object.entries(obj).reduce((result, [key, val]) => ({\n ...result,\n [snakeToPascal(key)]: val,\n }), {}) as Type;\n}\n\n/**\n * Channel\n * @example\n * ```js\n * await Channel.initialize({\n * url: 'ws://localhost:3001',\n * role: 'initiator'\n * initiatorId: 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',\n * responderId: 'ak_V6an1xhec1xVaAhLuak7QoEbi6t7w5hEtYWp9bMKaJ19i6A9E',\n * initiatorAmount: 1e18,\n * responderAmount: 1e18,\n * pushAmount: 0,\n * channelReserve: 0,\n * ttl: 1000,\n * host: 'localhost',\n * port: 3002,\n * lockPeriod: 10,\n * async sign (tag, tx) => await account.signTransaction(tx)\n * })\n * ```\n */\nexport default class Channel {\n _eventEmitter = new EventEmitter();\n\n _pingTimeoutId: NodeJS.Timeout;\n\n _nextRpcMessageId = 0;\n\n _rpcCallbacks = new Map<number, (message: object) => void>();\n\n _fsmId?: Encoded.Bytearray;\n\n _messageQueue: ChannelMessage[] = [];\n\n _isMessageQueueLocked = false;\n\n _actionQueue: ChannelAction[] = [];\n\n _isActionQueueLocked = false;\n\n _status: ChannelStatus = 'disconnected';\n\n _fsm: ChannelFsm;\n\n _websocket: W3CWebSocket;\n\n _state: Encoded.Transaction | '' = '';\n\n _options: ChannelOptions;\n\n _channelId?: Encoded.Channel;\n\n /**\n * @param options - Channel params\n * @param options.url - Channel url (for example: \"ws://localhost:3001\")\n * @param options.role - Participant role (\"initiator\" or \"responder\")\n * @param options.initiatorId - Initiator's public key\n * @param options.responderId - Responder's public key\n * @param options.pushAmount - Initial deposit in favour of the responder by the initiator\n * @param options.initiatorAmount - Amount of coins the initiator has committed to\n * the channel\n * @param options.responderAmount - Amount of coins the responder has committed to\n * the channel\n * @param options.channelReserve - The minimum amount both peers need to maintain\n * @param options.ttl - Minimum block height to include the channel_create_tx\n * @param options.host - Host of the responder's node\n * @param options.port - The port of the responders node\n * @param options.lockPeriod - Amount of blocks for disputing a solo close\n * @param options.minimumDepthStrategy - How to calculate minimum depth (default: txfee)\n * @param options.minimumDepth - The minimum amount of blocks to be mined\n * @param options.fee - The fee to be used for the channel open transaction\n * @param options.gasPrice - Used for the fee computation of the channel open transaction\n * @param options.existingChannelId - Existing channel id (required if reestablishing a\n * channel)\n * @param options.offchainTx - Offchain transaction (required if reestablishing\n * a channel)\n * @param options.timeoutIdle - The time waiting for a new event to be initiated\n * (default: 600000)\n * @param options.timeoutFundingCreate - The time waiting for the initiator to produce\n * the create channel transaction after the noise session had been established (default: 120000)\n * @param options.timeoutFundingSign - The time frame the other client has to sign an\n * off-chain update after our client had initiated and signed it. This applies only for double\n * signed on-chain intended updates: channel create transaction, deposit, withdrawal and etc.\n * (default: 120000)\n * @param options.timeoutFundingLock - The time frame the other client has to confirm an\n * on-chain transaction reaching maturity (passing minimum depth) after the local node has\n * detected this. This applies only for double signed on-chain intended updates: channel create\n * transaction, deposit, withdrawal and etc. (default: 360000)\n * @param options.timeoutSign - The time frame the client has to return a signed\n * off-chain update or to decline it. This applies for all off-chain updates (default: 500000)\n * @param options.timeoutAccept - The time frame the other client has to react to an\n * event. This applies for all off-chain updates that are not meant to land on-chain, as well as\n * some special cases: opening a noise connection, mutual closing acknowledgement and\n * reestablishing an existing channel (default: 120000)\n * @param options.timeoutInitialized - the time frame the responder has to accept an\n * incoming noise session. Applicable only for initiator (default: timeout_accept's value)\n * @param options.timeoutAwaitingOpen - The time frame the initiator has to start an\n * outgoing noise session to the responder's node. Applicable only for responder (default:\n * timeout_idle's value)\n * @param options.debug=false - Log websocket communication\n * @param options.sign - Function which verifies and signs transactions\n */\n static async initialize(options: ChannelOptions): Promise<Channel> {\n return Channel._initialize(new Channel(), options);\n }\n\n static async _initialize<T extends Channel>(channel: T, options: ChannelOptions): Promise<T> {\n await initialize(\n channel,\n options.existingFsmId != null ? handlers.awaitingReconnection : handlers.awaitingConnection,\n handlers.channelOpen,\n options,\n );\n return channel;\n }\n\n /**\n * Register event listener function\n *\n * Possible events:\n *\n * - \"error\"\n * - \"stateChanged\"\n * - \"statusChanged\"\n * - \"message\"\n * - \"peerDisconnected\"\n * - \"onChainTx\"\n * - \"ownWithdrawLocked\"\n * - \"withdrawLocked\"\n * - \"ownDepositLocked\"\n * - \"depositLocked\"\n * - \"channelReestablished\"\n * - \"newContract\"\n *\n *\n * @param eventName - Event name\n * @param callback - Callback function\n */\n on<E extends keyof ChannelEvents>(eventName: E, callback: ChannelEvents[E]): void {\n this._eventEmitter.on(eventName, callback);\n }\n\n /**\n * Remove event listener function\n * @param eventName - Event name\n * @param callback - Callback function\n */\n off<E extends keyof ChannelEvents>(eventName: E, callback: ChannelEvents[E]): void {\n this._eventEmitter.removeListener(eventName, callback);\n }\n\n /**\n * Close the connection\n */\n disconnect(): void {\n return channelDisconnect(this);\n }\n\n /**\n * Get current status\n */\n status(): ChannelStatus {\n return this._status;\n }\n\n /**\n * Get current state\n */\n async state(): Promise<{\n calls: TxUnpacked & { tag: Tag.CallsMtree };\n halfSignedTx?: TxUnpacked & { tag: Tag.SignedTx };\n signedTx?: TxUnpacked & { tag: Tag.SignedTx };\n trees: TxUnpacked & { tag: Tag.StateTrees };\n }> {\n const res = snakeToPascalObjKeys<{\n calls: Encoded.CallStateTree;\n halfSignedTx: Encoded.Transaction | '';\n signedTx: Encoded.Transaction | '';\n trees: Encoded.StateTrees;\n }>(await call(this, 'channels.get.offchain_state', {}));\n return {\n calls: unpackTx(res.calls, Tag.CallsMtree),\n ...res.halfSignedTx !== '' && { halfSignedTx: unpackTx(res.halfSignedTx, Tag.SignedTx) },\n ...res.signedTx !== '' && { signedTx: unpackTx(res.signedTx, Tag.SignedTx) },\n trees: unpackTx(res.trees, Tag.StateTrees),\n };\n }\n\n /**\n * Get current round\n *\n * If round cannot be determined (for example when channel has not been opened)\n * it will return `null`.\n */\n round(): number | null {\n if (this._state === '') {\n return null;\n }\n const params = unpackTx(this._state, Tag.SignedTx).encodedTx;\n switch (params.tag) {\n case Tag.ChannelCreateTx:\n return 1;\n case Tag.ChannelOffChainTx:\n case Tag.ChannelWithdrawTx:\n case Tag.ChannelDepositTx:\n return params.round;\n default:\n return null;\n }\n }\n\n /**\n * Get channel id\n *\n */\n id(): Encoded.Channel {\n if (this._channelId == null) throw new ChannelError('Channel is not initialized');\n return this._channelId;\n }\n\n /**\n * Get channel's fsm id\n *\n */\n fsmId(): Encoded.Bytearray {\n if (this._fsmId == null) throw new ChannelError('Channel is not initialized');\n return this._fsmId;\n }\n\n protected async enqueueAction(\n action: () => { handler: ChannelHandler; state?: Partial<ChannelState> },\n ): Promise<any> {\n return enqueueAction(\n this,\n (channel, state) => state?.handler === handlers.channelOpen,\n action,\n );\n }\n\n /**\n * Leave channel\n *\n * It is possible to leave a channel and then later reestablish the channel\n * off-chain state and continue operation. When a leave method is called,\n * the channel fsm passes it on to the peer fsm, reports the current mutually\n * signed state and then terminates.\n *\n * The channel can be reestablished by instantiating another Channel instance\n * with two extra params: existingChannelId and offchainTx (returned from leave\n * method as channelId and signedTx respectively).\n *\n * @example\n * ```js\n * channel.leave().then(({ channelId, signedTx }) => {\n * console.log(channelId)\n * console.log(signedTx)\n * })\n * ```\n */\n async leave(): Promise<{ channelId: Encoded.Bytearray; signedTx: Encoded.Transaction }> {\n return this.enqueueAction(() => {\n notify(this, 'channels.leave');\n return { handler: handlers.awaitingLeave };\n });\n }\n\n /**\n * Trigger mutual close\n *\n * At any moment after the channel is opened, a closing procedure can be triggered.\n * This can be done by either of the parties. The process is similar to the off-chain updates.\n *\n * @param sign - Function which verifies and signs mutual close transaction\n * @example\n * ```js\n * channel.shutdown(\n * async (tx) => await account.signTransaction(tx)\n * ).then(tx => console.log('on_chain_tx', tx))\n * ```\n */\n async shutdown(sign: SignTx): Promise<Encoded.Transaction> {\n return this.enqueueAction(() => {\n notify(this, 'channels.shutdown');\n return {\n handler: handlers.awaitingShutdownTx,\n state: { sign },\n };\n });\n }\n\n static async reconnect(options: ChannelOptions, txParams: any): Promise<Channel> {\n const { sign } = options;\n\n return Channel.initialize({\n ...options,\n reconnectTx: await sign(\n 'reconnect',\n buildTx({ ...txParams, tag: Tag.ChannelClientReconnectTx }),\n ),\n });\n }\n}\n"],"mappings":";AAAA,OAAAA,OAAA,MAA6B,QAAQ;AAAC;EAAAC;AAAA,IAAAD,OAAA;AAAA,SAE7BE,aAAa;AAAA,SACbC,OAAO,EAAEC,QAAQ;AAAA,SACjBC,GAAG;AAAA,OACL,KAAKC,QAAQ;AAAA,SAElBC,UAAU,EACVC,aAAa,EACbC,MAAM,EACNC,IAAI,EACJC,UAAU,IAAIC,iBAAiB;AAAA,SAWxBC,YAAY;AAIrB,SAASC,oBAAoBA,CAAOC,GAAW,EAAQ;EACrD,OAAOC,MAAM,CAACC,OAAO,CAACF,GAAG,CAAC,CAACG,MAAM,CAAC,CAACC,MAAM,EAAAC,IAAA;IAAA,IAAE,CAACC,GAAG,EAAEC,GAAG,CAAC,GAAAF,IAAA;IAAA,OAAM;MACzD,GAAGD,MAAM;MACT,CAACjB,aAAa,CAACmB,GAAG,CAAC,GAAGC;IACxB,CAAC;EAAA,CAAC,EAAE,CAAC,CAAC,CAAC;AACT;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,MAAMC,OAAO,CAAC;EAAAC,YAAA;IAAAC,eAAA,wBACX,IAAIxB,YAAY,EAAE;IAAAwB,eAAA,4BAId,CAAC;IAAAA,eAAA,wBAEL,IAAIC,GAAG,EAAqC;IAAAD,eAAA,wBAI1B,EAAE;IAAAA,eAAA,gCAEZ,KAAK;IAAAA,eAAA,uBAEG,EAAE;IAAAA,eAAA,+BAEX,KAAK;IAAAA,eAAA,kBAEH,cAAc;IAAAA,eAAA,iBAMJ,EAAE;EAAA;EAMrC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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CAACqE;MAAyB,CAAC,CAAC;IAE/D,CAAC,CAAC;EACJ;AACF"}
|
package/es/channel/Contract.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
|
+
import { AbiVersion, VmVersion } from '../tx/builder/constants';
|
|
2
3
|
import { SignTx, ChannelState, ChannelOptions } from './internal';
|
|
3
4
|
import { Encoded } from '../utils/encoder';
|
|
4
5
|
import { ContractCallReturnType } from '../apis/node';
|
|
@@ -7,7 +8,7 @@ import ChannelSpend from './Spend';
|
|
|
7
8
|
interface CallContractOptions {
|
|
8
9
|
amount?: number | BigNumber;
|
|
9
10
|
callData?: Encoded.ContractBytearray;
|
|
10
|
-
abiVersion?:
|
|
11
|
+
abiVersion?: AbiVersion;
|
|
11
12
|
contract?: Encoded.ContractAddress;
|
|
12
13
|
returnValue?: any;
|
|
13
14
|
gasUsed?: number | BigNumber;
|
|
@@ -18,13 +19,13 @@ interface CallContractOptions {
|
|
|
18
19
|
returnType?: ContractCallReturnType;
|
|
19
20
|
}
|
|
20
21
|
interface Contract {
|
|
21
|
-
abiVersion:
|
|
22
|
+
abiVersion: AbiVersion;
|
|
22
23
|
active: boolean;
|
|
23
24
|
deposit: number | BigNumber;
|
|
24
25
|
id: string;
|
|
25
26
|
ownerId: string;
|
|
26
27
|
referrerIds: string[];
|
|
27
|
-
vmVersion:
|
|
28
|
+
vmVersion: VmVersion;
|
|
28
29
|
}
|
|
29
30
|
export default class ChannelContract extends ChannelSpend {
|
|
30
31
|
static initialize(options: ChannelOptions): Promise<ChannelContract>;
|
|
@@ -66,8 +67,8 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
66
67
|
code: Encoded.ContractBytearray;
|
|
67
68
|
callData: Encoded.ContractBytearray;
|
|
68
69
|
deposit: number | BigNumber;
|
|
69
|
-
vmVersion:
|
|
70
|
-
abiVersion:
|
|
70
|
+
vmVersion: VmVersion;
|
|
71
|
+
abiVersion: AbiVersion;
|
|
71
72
|
}, sign: SignTx): Promise<{
|
|
72
73
|
accepted: boolean;
|
|
73
74
|
signedTx: Encoded.Transaction;
|
|
@@ -148,7 +149,7 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
148
149
|
amount: number;
|
|
149
150
|
callData: Encoded.ContractBytearray;
|
|
150
151
|
contract: Encoded.ContractAddress;
|
|
151
|
-
abiVersion:
|
|
152
|
+
abiVersion: AbiVersion;
|
|
152
153
|
gasLimit?: number;
|
|
153
154
|
gasPrice?: number;
|
|
154
155
|
}, sign: SignTx, { onOnChainTx }?: Pick<ChannelState, 'onOnChainTx'>): Promise<{
|
|
@@ -189,7 +190,7 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
189
190
|
amount: number;
|
|
190
191
|
callData: Encoded.ContractBytearray;
|
|
191
192
|
contract: Encoded.ContractAddress;
|
|
192
|
-
abiVersion:
|
|
193
|
+
abiVersion: AbiVersion;
|
|
193
194
|
}): Promise<CallContractOptions>;
|
|
194
195
|
/**
|
|
195
196
|
* Get contract call result
|
package/es/channel/Contract.mjs
CHANGED
|
@@ -1,26 +1,10 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* ISC License (ISC)
|
|
3
|
-
* Copyright (c) 2022 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
1
|
import { snakeToPascal } from "../utils/string.mjs";
|
|
18
2
|
import { MIN_GAS_PRICE, Tag } from "../tx/builder/constants.mjs";
|
|
19
3
|
import { signAndNotify, awaitingCompletion, channelClosed, channelOpen, handleUnexpectedMessage } from "./handlers.mjs";
|
|
20
4
|
import { notify, call, changeState, emit } from "./internal.mjs";
|
|
21
5
|
import Channel from "./Base.mjs";
|
|
22
6
|
import ChannelSpend from "./Spend.mjs";
|
|
23
|
-
import { UnexpectedChannelMessageError } from "../utils/errors.mjs";
|
|
7
|
+
import { ChannelError, UnexpectedChannelMessageError } from "../utils/errors.mjs";
|
|
24
8
|
import { unpackTx } from "../tx/builder/index.mjs";
|
|
25
9
|
import { encodeContractAddress } from "../utils/crypto.mjs";
|
|
26
10
|
function snakeToPascalObjKeys(obj) {
|
|
@@ -95,15 +79,18 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
95
79
|
await signAndNotify(this, 'channels.update', message.params.data, async tx => state.sign(tx));
|
|
96
80
|
return {
|
|
97
81
|
handler: (_2, message2, state2) => awaitingCompletion(this, message2, state2, () => {
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
82
|
+
const params = unpackTx(message2.params.data.state, Tag.SignedTx).encodedTx;
|
|
83
|
+
if (params.tag !== Tag.ChannelOffChainTx) {
|
|
84
|
+
throw new ChannelError(`Tag should be ${Tag[Tag.ChannelOffChainTx]}, got ${Tag[params.tag]} instead`);
|
|
85
|
+
}
|
|
101
86
|
const addressKey = this._options.role === 'initiator' ? 'initiatorId' : 'responderId';
|
|
102
87
|
const owner = this._options[addressKey];
|
|
103
88
|
changeState(this, message2.params.data.state);
|
|
89
|
+
const address = encodeContractAddress(owner, params.round);
|
|
90
|
+
emit(this, 'newContract', address);
|
|
104
91
|
state2.resolve({
|
|
105
92
|
accepted: true,
|
|
106
|
-
address
|
|
93
|
+
address,
|
|
107
94
|
signedTx: message2.params.data.state
|
|
108
95
|
});
|
|
109
96
|
return {
|