@aeternity/aepp-sdk 13.2.1 → 13.3.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/LICENSE +1 -1
- package/README.md +1 -1
- package/bin/aesophia_cli +0 -0
- package/bin/aesophia_cli_8 +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 +7288 -9464
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdk.d.ts +3 -0
- package/es/AeSdk.mjs +12 -12
- package/es/AeSdk.mjs.map +1 -1
- package/es/AeSdkAepp.d.ts +0 -1
- package/es/AeSdkAepp.mjs +12 -16
- package/es/AeSdkAepp.mjs.map +1 -1
- package/es/AeSdkBase.d.ts +61 -6
- package/es/AeSdkBase.mjs +150 -69
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkMethods.d.ts +19 -7
- package/es/AeSdkMethods.mjs +39 -38
- package/es/AeSdkMethods.mjs.map +1 -1
- package/es/AeSdkWallet.mjs +86 -55
- package/es/AeSdkWallet.mjs.map +1 -1
- package/es/Middleware.d.ts +1 -1
- package/es/Middleware.mjs +32 -28
- package/es/Middleware.mjs.map +1 -1
- package/es/MiddlewareSubscriber.mjs +5 -14
- package/es/MiddlewareSubscriber.mjs.map +1 -1
- package/es/Node.d.ts +11 -3
- package/es/Node.mjs +65 -57
- package/es/Node.mjs.map +1 -1
- package/es/account/Base.d.ts +39 -3
- package/es/account/Base.mjs +35 -1
- package/es/account/Base.mjs.map +1 -1
- package/es/account/Generalized.d.ts +2 -0
- package/es/account/Generalized.mjs +15 -6
- package/es/account/Generalized.mjs.map +1 -1
- package/es/account/Ledger.d.ts +2 -0
- package/es/account/Ledger.mjs +14 -5
- package/es/account/Ledger.mjs.map +1 -1
- package/es/account/LedgerFactory.mjs +4 -6
- package/es/account/LedgerFactory.mjs.map +1 -1
- package/es/account/Memory.d.ts +15 -4
- package/es/account/Memory.mjs +96 -31
- package/es/account/Memory.mjs.map +1 -1
- package/es/account/Rpc.d.ts +16 -5
- package/es/account/Rpc.mjs +94 -21
- package/es/account/Rpc.mjs.map +1 -1
- package/es/aens.d.ts +17 -44
- package/es/aens.mjs +32 -71
- package/es/aens.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/Browser.mjs +3 -4
- package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +3 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +7 -5
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +8 -9
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +7 -7
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/types.d.ts +14 -0
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
- package/es/aepp-wallet-communication/schema.d.ts +2 -0
- package/es/aepp-wallet-communication/schema.mjs +2 -0
- package/es/aepp-wallet-communication/schema.mjs.map +1 -1
- package/es/aepp-wallet-communication/wallet-detector.d.ts +2 -5
- package/es/aepp-wallet-communication/wallet-detector.mjs +13 -9
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
- package/es/apis/compiler/compiler.mjs.map +1 -1
- package/es/apis/compiler/models/index.d.ts +1 -0
- package/es/apis/compiler/models/index.mjs.map +1 -1
- package/es/apis/compiler/models/mappers.mjs +13 -0
- package/es/apis/compiler/models/mappers.mjs.map +1 -1
- package/es/apis/compiler/models/parameters.mjs.map +1 -1
- package/es/apis/middleware/middleware.d.ts +23 -5
- package/es/apis/middleware/middleware.mjs +114 -18
- package/es/apis/middleware/middleware.mjs.map +1 -1
- package/es/apis/middleware/models/index.d.ts +164 -15
- package/es/apis/middleware/models/index.mjs +53 -3
- package/es/apis/middleware/models/index.mjs.map +1 -1
- package/es/apis/middleware/models/mappers.d.ts +8 -1
- package/es/apis/middleware/models/mappers.mjs +376 -3
- package/es/apis/middleware/models/mappers.mjs.map +1 -1
- package/es/apis/middleware/models/parameters.d.ts +6 -3
- package/es/apis/middleware/models/parameters.mjs +38 -11
- package/es/apis/middleware/models/parameters.mjs.map +1 -1
- package/es/apis/node/models/index.d.ts +66 -2
- package/es/apis/node/models/index.mjs.map +1 -1
- package/es/apis/node/models/mappers.d.ts +5 -1
- package/es/apis/node/models/mappers.mjs +229 -7
- 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.d.ts +24 -3
- package/es/apis/node/node.mjs +135 -3
- package/es/apis/node/node.mjs.map +1 -1
- package/es/chain.d.ts +14 -44
- package/es/chain.mjs +125 -219
- package/es/chain.mjs.map +1 -1
- package/es/channel/Base.d.ts +3 -47
- package/es/channel/Base.mjs +21 -54
- package/es/channel/Base.mjs.map +1 -1
- package/es/channel/Contract.d.ts +16 -25
- package/es/channel/Contract.mjs +39 -63
- package/es/channel/Contract.mjs.map +1 -1
- package/es/channel/Spend.d.ts +0 -8
- package/es/channel/Spend.mjs +17 -29
- package/es/channel/Spend.mjs.map +1 -1
- package/es/channel/handlers.mjs +1 -1
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/internal.d.ts +104 -5
- package/es/channel/internal.mjs +26 -34
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Contract.d.ts +10 -2
- package/es/contract/Contract.mjs +83 -79
- package/es/contract/Contract.mjs.map +1 -1
- package/es/contract/compiler/Base.d.ts +14 -8
- package/es/contract/compiler/Base.mjs.map +1 -1
- package/es/contract/compiler/Cli.d.ts +12 -11
- package/es/contract/compiler/Cli.mjs +52 -25
- package/es/contract/compiler/Cli.mjs.map +1 -1
- package/es/contract/compiler/Cli8.d.ts +13 -0
- package/es/contract/compiler/Cli8.mjs +22 -0
- package/es/contract/compiler/Cli8.mjs.map +1 -0
- package/es/contract/compiler/Http.d.ts +3 -9
- package/es/contract/compiler/Http.mjs +28 -16
- package/es/contract/compiler/Http.mjs.map +1 -1
- package/es/contract/compiler/HttpNode.d.ts +2 -5
- package/es/contract/compiler/HttpNode.mjs.map +1 -1
- package/es/contract/delegation-signature.d.ts +2 -1
- package/es/contract/delegation-signature.mjs +18 -14
- package/es/contract/delegation-signature.mjs.map +1 -1
- package/es/contract/ga.d.ts +1 -2
- package/es/contract/ga.mjs +23 -25
- package/es/contract/ga.mjs.map +1 -1
- package/es/deprecated.d.ts +48 -0
- package/es/deprecated.mjs +66 -1
- package/es/deprecated.mjs.map +1 -1
- package/es/index-browser.d.ts +11 -6
- package/es/index-browser.mjs +10 -6
- package/es/index-browser.mjs.map +1 -1
- package/es/index.d.ts +1 -0
- package/es/index.mjs +1 -0
- package/es/index.mjs.map +1 -1
- package/es/oracle.d.ts +6 -37
- package/es/oracle.mjs +32 -66
- package/es/oracle.mjs.map +1 -1
- package/es/send-transaction.d.ts +53 -0
- package/es/send-transaction.mjs +109 -0
- package/es/send-transaction.mjs.map +1 -0
- package/es/spend.d.ts +4 -3
- package/es/spend.mjs +6 -1
- package/es/spend.mjs.map +1 -1
- package/es/tx/builder/common.d.ts +29 -0
- package/es/tx/builder/common.mjs +42 -0
- package/es/tx/builder/common.mjs.map +1 -0
- package/es/tx/builder/constants.d.ts +6 -5
- package/es/tx/builder/constants.mjs +7 -15
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/delegation/index.d.ts +20 -0
- package/es/tx/builder/delegation/index.mjs +24 -0
- package/es/tx/builder/delegation/index.mjs.map +1 -0
- package/es/tx/builder/delegation/schema.d.ts +130 -0
- package/es/tx/builder/delegation/schema.generated.d.ts +141 -0
- package/es/tx/builder/delegation/schema.generated.mjs +2 -0
- package/es/tx/builder/delegation/schema.generated.mjs.map +1 -0
- package/es/tx/builder/delegation/schema.mjs +54 -0
- package/es/tx/builder/delegation/schema.mjs.map +1 -0
- package/es/tx/builder/field-types/abi-version.mjs +8 -11
- package/es/tx/builder/field-types/abi-version.mjs.map +1 -1
- package/es/tx/builder/field-types/address.mjs +1 -4
- package/es/tx/builder/field-types/address.mjs.map +1 -1
- package/es/tx/builder/field-types/coin-amount.d.ts +2 -2
- package/es/tx/builder/field-types/coin-amount.mjs +6 -6
- package/es/tx/builder/field-types/coin-amount.mjs.map +1 -1
- package/es/tx/builder/field-types/ct-version.d.ts +1 -1
- package/es/tx/builder/field-types/ct-version.mjs +4 -5
- package/es/tx/builder/field-types/ct-version.mjs.map +1 -1
- package/es/tx/builder/field-types/entry.mjs +7 -13
- package/es/tx/builder/field-types/entry.mjs.map +1 -1
- package/es/tx/builder/field-types/fee.d.ts +19 -11
- package/es/tx/builder/field-types/fee.mjs +57 -39
- package/es/tx/builder/field-types/fee.mjs.map +1 -1
- package/es/tx/builder/field-types/gas-limit.mjs +13 -15
- package/es/tx/builder/field-types/gas-limit.mjs.map +1 -1
- package/es/tx/builder/field-types/gas-price.d.ts +10 -2
- package/es/tx/builder/field-types/gas-price.mjs +53 -4
- package/es/tx/builder/field-types/gas-price.mjs.map +1 -1
- package/es/tx/builder/field-types/index.d.ts +31 -29
- package/es/tx/builder/field-types/index.mjs +31 -29
- package/es/tx/builder/field-types/index.mjs.map +1 -1
- package/es/tx/builder/field-types/map.mjs +20 -31
- package/es/tx/builder/field-types/map.mjs.map +1 -1
- package/es/tx/builder/field-types/mptree.mjs +14 -29
- package/es/tx/builder/field-types/mptree.mjs.map +1 -1
- package/es/tx/builder/field-types/name-fee.d.ts +1 -1
- package/es/tx/builder/field-types/name-fee.mjs +1 -1
- package/es/tx/builder/field-types/name-fee.mjs.map +1 -1
- package/es/tx/builder/field-types/nonce.d.ts +1 -0
- package/es/tx/builder/field-types/nonce.mjs +2 -0
- package/es/tx/builder/field-types/nonce.mjs.map +1 -1
- package/es/tx/builder/field-types/pointers.mjs +4 -7
- package/es/tx/builder/field-types/pointers.mjs.map +1 -1
- package/es/tx/builder/field-types/pointers2.d.ts +23 -0
- package/es/tx/builder/field-types/pointers2.mjs +65 -0
- package/es/tx/builder/field-types/pointers2.mjs.map +1 -0
- package/es/tx/builder/field-types/query-fee.d.ts +19 -0
- package/es/tx/builder/field-types/query-fee.mjs +20 -0
- package/es/tx/builder/field-types/query-fee.mjs.map +1 -0
- package/es/tx/builder/field-types/ttl.d.ts +9 -1
- package/es/tx/builder/field-types/ttl.mjs +19 -8
- package/es/tx/builder/field-types/ttl.mjs.map +1 -1
- package/es/tx/builder/field-types/with-default.d.ts +7 -0
- package/es/tx/builder/field-types/with-default.mjs +9 -0
- package/es/tx/builder/field-types/with-default.mjs.map +1 -0
- package/es/tx/builder/field-types/with-formatting.d.ts +7 -0
- package/es/tx/builder/field-types/with-formatting.mjs +9 -0
- package/es/tx/builder/field-types/with-formatting.mjs.map +1 -0
- package/es/tx/builder/field-types/wrapped.mjs +6 -8
- package/es/tx/builder/field-types/wrapped.mjs.map +1 -1
- package/es/tx/builder/helpers.d.ts +2 -2
- package/es/tx/builder/helpers.mjs +12 -21
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +17 -10
- package/es/tx/builder/index.mjs +39 -65
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +478 -257
- package/es/tx/builder/schema.generated.d.ts +39 -3
- package/es/tx/builder/schema.generated.mjs.map +1 -1
- package/es/tx/builder/schema.mjs +48 -36
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/execution-cost.d.ts +6 -5
- package/es/tx/execution-cost.mjs +16 -17
- package/es/tx/execution-cost.mjs.map +1 -1
- package/es/tx/transaction-signer.mjs +1 -4
- package/es/tx/transaction-signer.mjs.map +1 -1
- package/es/tx/validator.mjs +61 -42
- package/es/tx/validator.mjs.map +1 -1
- package/es/utils/amount-formatter.mjs +15 -22
- package/es/utils/amount-formatter.mjs.map +1 -1
- package/es/utils/autorest.d.ts +2 -3
- package/es/utils/autorest.mjs +41 -25
- package/es/utils/autorest.mjs.map +1 -1
- package/es/utils/bytes.mjs +1 -2
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.d.ts +9 -5
- package/es/utils/crypto.mjs +18 -14
- package/es/utils/crypto.mjs.map +1 -1
- package/es/utils/errors.d.ts +6 -0
- package/es/utils/errors.mjs +12 -6
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.d.ts +2 -0
- package/es/utils/hd-wallet.mjs +6 -5
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/json-big.mjs +2 -10
- package/es/utils/json-big.mjs.map +1 -1
- package/es/utils/jwt.d.ts +53 -0
- package/es/utils/jwt.mjs +120 -0
- package/es/utils/jwt.mjs.map +1 -0
- package/es/utils/keystore.d.ts +6 -2
- package/es/utils/keystore.mjs +8 -16
- package/es/utils/keystore.mjs.map +1 -1
- package/es/utils/typed-data.d.ts +0 -2
- package/es/utils/typed-data.mjs +8 -23
- package/es/utils/typed-data.mjs.map +1 -1
- package/es/utils/wrap-proxy.d.ts +2 -0
- package/es/utils/wrap-proxy.mjs +15 -0
- package/es/utils/wrap-proxy.mjs.map +1 -0
- package/package.json +57 -51
- package/src/AeSdk.ts +3 -0
- package/src/AeSdkAepp.ts +0 -1
- package/src/AeSdkBase.ts +97 -10
- package/src/AeSdkMethods.ts +37 -33
- package/src/AeSdkWallet.ts +22 -3
- package/src/Middleware.ts +17 -9
- package/src/MiddlewareSubscriber.ts +1 -1
- package/src/Node.ts +51 -21
- package/src/account/Base.ts +62 -3
- package/src/account/Generalized.ts +10 -0
- package/src/account/Ledger.ts +10 -0
- package/src/account/Memory.ts +83 -9
- package/src/account/Rpc.ts +69 -6
- package/src/aens.ts +35 -56
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +3 -0
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +2 -2
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +4 -2
- package/src/aepp-wallet-communication/rpc/types.ts +14 -1
- package/src/aepp-wallet-communication/schema.ts +2 -0
- package/src/aepp-wallet-communication/wallet-detector.ts +10 -10
- package/src/apis/compiler/compiler.ts +93 -93
- package/src/apis/compiler/models/index.ts +1 -0
- package/src/apis/compiler/models/mappers.ts +178 -165
- package/src/apis/compiler/models/parameters.ts +18 -18
- package/src/apis/middleware/middleware.ts +462 -341
- package/src/apis/middleware/models/index.ts +258 -56
- package/src/apis/middleware/models/mappers.ts +2357 -1919
- package/src/apis/middleware/models/parameters.ts +172 -142
- package/src/apis/node/models/index.ts +79 -2
- package/src/apis/node/models/mappers.ts +1529 -1302
- package/src/apis/node/models/parameters.ts +51 -51
- package/src/apis/node/node.ts +420 -275
- package/src/chain.ts +42 -128
- package/src/channel/Base.ts +14 -47
- package/src/channel/Contract.ts +18 -26
- package/src/channel/Spend.ts +0 -8
- package/src/channel/internal.ts +115 -13
- package/src/contract/Contract.ts +36 -12
- package/src/contract/compiler/Base.ts +15 -8
- package/src/contract/compiler/Cli.ts +44 -23
- package/src/contract/compiler/Cli8.ts +17 -0
- package/src/contract/compiler/Http.ts +24 -14
- package/src/contract/compiler/HttpNode.ts +2 -2
- package/src/contract/delegation-signature.ts +11 -5
- package/src/contract/ga.ts +4 -3
- package/src/deprecated.ts +55 -1
- package/src/index-browser.ts +18 -11
- package/src/index.ts +1 -0
- package/src/oracle.ts +11 -54
- package/src/send-transaction.ts +136 -0
- package/src/spend.ts +25 -11
- package/src/tx/builder/common.ts +74 -0
- package/src/tx/builder/constants.ts +7 -9
- package/src/tx/builder/delegation/index.ts +28 -0
- package/src/tx/builder/delegation/schema.generated.ts +143 -0
- package/src/tx/builder/delegation/schema.ts +61 -0
- package/src/tx/builder/field-types/coin-amount.ts +3 -2
- package/src/tx/builder/field-types/ct-version.ts +1 -1
- package/src/tx/builder/field-types/entry.ts +1 -4
- package/src/tx/builder/field-types/fee.ts +72 -44
- package/src/tx/builder/field-types/gas-limit.ts +4 -4
- package/src/tx/builder/field-types/gas-price.ts +59 -3
- package/src/tx/builder/field-types/index.ts +31 -59
- package/src/tx/builder/field-types/name-fee.ts +1 -1
- package/src/tx/builder/field-types/nonce.ts +7 -1
- package/src/tx/builder/field-types/pointers2.ts +62 -0
- package/src/tx/builder/field-types/query-fee.ts +25 -0
- package/src/tx/builder/field-types/ttl.ts +13 -3
- package/src/tx/builder/field-types/with-default.ts +18 -0
- package/src/tx/builder/field-types/with-formatting.ts +18 -0
- package/src/tx/builder/helpers.ts +2 -2
- package/src/tx/builder/index.ts +42 -59
- package/src/tx/builder/schema.generated.ts +39 -3
- package/src/tx/builder/schema.ts +55 -29
- package/src/tx/execution-cost.ts +6 -5
- package/src/tx/validator.ts +31 -5
- package/src/utils/autorest.ts +37 -28
- package/src/utils/crypto.ts +24 -14
- package/src/utils/errors.ts +10 -0
- package/src/utils/hd-wallet.ts +2 -0
- package/src/utils/jwt.ts +126 -0
- package/src/utils/keystore.ts +6 -2
- package/src/utils/typed-data.ts +4 -30
- package/src/utils/wrap-proxy.ts +24 -0
- package/types-legacy/ts4.2/AeSdk.d.ts +3 -0
- package/types-legacy/ts4.2/AeSdkAepp.d.ts +0 -1
- package/types-legacy/ts4.2/AeSdkBase.d.ts +61 -6
- package/types-legacy/ts4.2/AeSdkMethods.d.ts +19 -7
- package/types-legacy/ts4.2/Middleware.d.ts +1 -1
- package/types-legacy/ts4.2/Node.d.ts +15 -2
- package/types-legacy/ts4.2/account/Base.d.ts +39 -3
- package/types-legacy/ts4.2/account/Generalized.d.ts +2 -0
- package/types-legacy/ts4.2/account/Ledger.d.ts +2 -0
- package/types-legacy/ts4.2/account/Memory.d.ts +15 -4
- package/types-legacy/ts4.2/account/Rpc.d.ts +16 -5
- package/types-legacy/ts4.2/aens.d.ts +17 -44
- package/types-legacy/ts4.2/aepp-wallet-communication/connection/BrowserRuntime.d.ts +3 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/rpc/types.d.ts +14 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/schema.d.ts +2 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/wallet-detector.d.ts +2 -5
- package/types-legacy/ts4.2/apis/compiler/models/index.d.ts +1 -0
- package/types-legacy/ts4.2/apis/middleware/middleware.d.ts +23 -5
- package/types-legacy/ts4.2/apis/middleware/models/index.d.ts +164 -15
- package/types-legacy/ts4.2/apis/middleware/models/mappers.d.ts +8 -1
- package/types-legacy/ts4.2/apis/middleware/models/parameters.d.ts +6 -3
- package/types-legacy/ts4.2/apis/node/models/index.d.ts +66 -2
- package/types-legacy/ts4.2/apis/node/models/mappers.d.ts +5 -1
- package/types-legacy/ts4.2/apis/node/models/parameters.d.ts +2 -2
- package/types-legacy/ts4.2/apis/node/node.d.ts +24 -3
- package/types-legacy/ts4.2/chain.d.ts +14 -44
- package/types-legacy/ts4.2/channel/Base.d.ts +3 -47
- package/types-legacy/ts4.2/channel/Contract.d.ts +16 -25
- package/types-legacy/ts4.2/channel/Spend.d.ts +0 -8
- package/types-legacy/ts4.2/channel/internal.d.ts +104 -5
- package/types-legacy/ts4.2/contract/Contract.d.ts +10 -2
- package/types-legacy/ts4.2/contract/compiler/Base.d.ts +14 -8
- package/types-legacy/ts4.2/contract/compiler/Cli.d.ts +12 -11
- package/types-legacy/ts4.2/contract/compiler/Cli8.d.ts +13 -0
- package/types-legacy/ts4.2/contract/compiler/Http.d.ts +3 -9
- package/types-legacy/ts4.2/contract/compiler/HttpNode.d.ts +2 -5
- package/types-legacy/ts4.2/contract/delegation-signature.d.ts +2 -1
- package/types-legacy/ts4.2/contract/ga.d.ts +1 -2
- package/types-legacy/ts4.2/deprecated.d.ts +48 -0
- package/types-legacy/ts4.2/index-browser.d.ts +11 -6
- package/types-legacy/ts4.2/index.d.ts +1 -0
- package/types-legacy/ts4.2/oracle.d.ts +6 -37
- package/types-legacy/ts4.2/send-transaction.d.ts +53 -0
- package/types-legacy/ts4.2/spend.d.ts +4 -3
- package/types-legacy/ts4.2/tx/builder/common.d.ts +32 -0
- package/types-legacy/ts4.2/tx/builder/constants.d.ts +6 -5
- package/types-legacy/ts4.2/tx/builder/delegation/index.d.ts +20 -0
- package/types-legacy/ts4.2/tx/builder/delegation/schema.d.ts +136 -0
- package/types-legacy/ts4.2/tx/builder/delegation/schema.generated.d.ts +141 -0
- package/types-legacy/ts4.2/tx/builder/field-types/coin-amount.d.ts +2 -2
- package/types-legacy/ts4.2/tx/builder/field-types/ct-version.d.ts +1 -1
- package/types-legacy/ts4.2/tx/builder/field-types/fee.d.ts +19 -11
- package/types-legacy/ts4.2/tx/builder/field-types/gas-price.d.ts +10 -2
- package/types-legacy/ts4.2/tx/builder/field-types/index.d.ts +31 -29
- package/types-legacy/ts4.2/tx/builder/field-types/name-fee.d.ts +1 -1
- package/types-legacy/ts4.2/tx/builder/field-types/nonce.d.ts +1 -0
- package/types-legacy/ts4.2/tx/builder/field-types/pointers2.d.ts +26 -0
- package/types-legacy/ts4.2/tx/builder/field-types/query-fee.d.ts +19 -0
- package/types-legacy/ts4.2/tx/builder/field-types/ttl.d.ts +9 -1
- package/types-legacy/ts4.2/tx/builder/field-types/with-default.d.ts +7 -0
- package/types-legacy/ts4.2/tx/builder/field-types/with-formatting.d.ts +7 -0
- package/types-legacy/ts4.2/tx/builder/helpers.d.ts +2 -2
- package/types-legacy/ts4.2/tx/builder/index.d.ts +17 -10
- package/types-legacy/ts4.2/tx/builder/schema.d.ts +482 -257
- package/types-legacy/ts4.2/tx/builder/schema.generated.d.ts +39 -3
- package/types-legacy/ts4.2/tx/execution-cost.d.ts +6 -5
- package/types-legacy/ts4.2/utils/autorest.d.ts +2 -3
- package/types-legacy/ts4.2/utils/crypto.d.ts +9 -5
- package/types-legacy/ts4.2/utils/errors.d.ts +6 -0
- package/types-legacy/ts4.2/utils/hd-wallet.d.ts +2 -0
- package/types-legacy/ts4.2/utils/jwt.d.ts +53 -0
- package/types-legacy/ts4.2/utils/keystore.d.ts +6 -2
- package/types-legacy/ts4.2/utils/typed-data.d.ts +0 -2
- package/types-legacy/ts4.2/utils/wrap-proxy.d.ts +2 -0
- package/types-legacy/ts4.5/AeSdk.d.ts +3 -0
- package/types-legacy/ts4.5/AeSdkAepp.d.ts +0 -1
- package/types-legacy/ts4.5/AeSdkBase.d.ts +61 -6
- package/types-legacy/ts4.5/AeSdkMethods.d.ts +19 -7
- package/types-legacy/ts4.5/Middleware.d.ts +1 -1
- package/types-legacy/ts4.5/Node.d.ts +15 -2
- package/types-legacy/ts4.5/account/Base.d.ts +39 -3
- package/types-legacy/ts4.5/account/Generalized.d.ts +2 -0
- package/types-legacy/ts4.5/account/Ledger.d.ts +2 -0
- package/types-legacy/ts4.5/account/Memory.d.ts +15 -4
- package/types-legacy/ts4.5/account/Rpc.d.ts +16 -5
- package/types-legacy/ts4.5/aens.d.ts +17 -44
- package/types-legacy/ts4.5/aepp-wallet-communication/connection/BrowserRuntime.d.ts +3 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/rpc/types.d.ts +14 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/schema.d.ts +2 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/wallet-detector.d.ts +2 -5
- package/types-legacy/ts4.5/apis/compiler/models/index.d.ts +1 -0
- package/types-legacy/ts4.5/apis/middleware/middleware.d.ts +23 -5
- package/types-legacy/ts4.5/apis/middleware/models/index.d.ts +164 -15
- package/types-legacy/ts4.5/apis/middleware/models/mappers.d.ts +8 -1
- package/types-legacy/ts4.5/apis/middleware/models/parameters.d.ts +6 -3
- package/types-legacy/ts4.5/apis/node/models/index.d.ts +66 -2
- package/types-legacy/ts4.5/apis/node/models/mappers.d.ts +5 -1
- package/types-legacy/ts4.5/apis/node/models/parameters.d.ts +2 -2
- package/types-legacy/ts4.5/apis/node/node.d.ts +24 -3
- package/types-legacy/ts4.5/chain.d.ts +14 -44
- package/types-legacy/ts4.5/channel/Base.d.ts +3 -47
- package/types-legacy/ts4.5/channel/Contract.d.ts +16 -25
- package/types-legacy/ts4.5/channel/Spend.d.ts +0 -8
- package/types-legacy/ts4.5/channel/internal.d.ts +104 -5
- package/types-legacy/ts4.5/contract/Contract.d.ts +10 -2
- package/types-legacy/ts4.5/contract/compiler/Base.d.ts +14 -8
- package/types-legacy/ts4.5/contract/compiler/Cli.d.ts +12 -11
- package/types-legacy/ts4.5/contract/compiler/Cli8.d.ts +13 -0
- package/types-legacy/ts4.5/contract/compiler/Http.d.ts +3 -9
- package/types-legacy/ts4.5/contract/compiler/HttpNode.d.ts +2 -5
- package/types-legacy/ts4.5/contract/delegation-signature.d.ts +2 -1
- package/types-legacy/ts4.5/contract/ga.d.ts +1 -2
- package/types-legacy/ts4.5/deprecated.d.ts +48 -0
- package/types-legacy/ts4.5/index-browser.d.ts +11 -6
- package/types-legacy/ts4.5/index.d.ts +1 -0
- package/types-legacy/ts4.5/oracle.d.ts +6 -37
- package/types-legacy/ts4.5/send-transaction.d.ts +53 -0
- package/types-legacy/ts4.5/spend.d.ts +4 -3
- package/types-legacy/ts4.5/tx/builder/common.d.ts +32 -0
- package/types-legacy/ts4.5/tx/builder/constants.d.ts +6 -5
- package/types-legacy/ts4.5/tx/builder/delegation/index.d.ts +20 -0
- package/types-legacy/ts4.5/tx/builder/delegation/schema.d.ts +136 -0
- package/types-legacy/ts4.5/tx/builder/delegation/schema.generated.d.ts +141 -0
- package/types-legacy/ts4.5/tx/builder/field-types/coin-amount.d.ts +2 -2
- package/types-legacy/ts4.5/tx/builder/field-types/ct-version.d.ts +1 -1
- package/types-legacy/ts4.5/tx/builder/field-types/fee.d.ts +19 -11
- package/types-legacy/ts4.5/tx/builder/field-types/gas-price.d.ts +10 -2
- package/types-legacy/ts4.5/tx/builder/field-types/index.d.ts +31 -29
- package/types-legacy/ts4.5/tx/builder/field-types/name-fee.d.ts +1 -1
- package/types-legacy/ts4.5/tx/builder/field-types/nonce.d.ts +1 -0
- package/types-legacy/ts4.5/tx/builder/field-types/pointers2.d.ts +26 -0
- package/types-legacy/ts4.5/tx/builder/field-types/query-fee.d.ts +19 -0
- package/types-legacy/ts4.5/tx/builder/field-types/ttl.d.ts +9 -1
- package/types-legacy/ts4.5/tx/builder/field-types/with-default.d.ts +7 -0
- package/types-legacy/ts4.5/tx/builder/field-types/with-formatting.d.ts +7 -0
- package/types-legacy/ts4.5/tx/builder/helpers.d.ts +2 -2
- package/types-legacy/ts4.5/tx/builder/index.d.ts +17 -10
- package/types-legacy/ts4.5/tx/builder/schema.d.ts +482 -257
- package/types-legacy/ts4.5/tx/builder/schema.generated.d.ts +39 -3
- package/types-legacy/ts4.5/tx/execution-cost.d.ts +6 -5
- package/types-legacy/ts4.5/utils/autorest.d.ts +2 -3
- package/types-legacy/ts4.5/utils/crypto.d.ts +9 -5
- package/types-legacy/ts4.5/utils/errors.d.ts +6 -0
- package/types-legacy/ts4.5/utils/hd-wallet.d.ts +2 -0
- package/types-legacy/ts4.5/utils/jwt.d.ts +53 -0
- package/types-legacy/ts4.5/utils/keystore.d.ts +6 -2
- package/types-legacy/ts4.5/utils/typed-data.d.ts +0 -2
- package/types-legacy/ts4.5/utils/wrap-proxy.d.ts +2 -0
- package/es/tx/builder/field-types/deposit.d.ts +0 -15
- package/es/tx/builder/field-types/deposit.mjs +0 -18
- package/es/tx/builder/field-types/deposit.mjs.map +0 -1
- package/src/tx/builder/field-types/deposit.ts +0 -23
- package/types-legacy/ts4.2/tx/builder/field-types/deposit.d.ts +0 -15
- package/types-legacy/ts4.5/tx/builder/field-types/deposit.d.ts +0 -15
package/es/channel/Base.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ import { TxUnpacked } from '../tx/builder/schema.generated';
|
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
30
|
export default class Channel {
|
|
31
|
+
#private;
|
|
31
32
|
_eventEmitter: EventEmitter;
|
|
32
33
|
_pingTimeoutId: NodeJS.Timeout;
|
|
33
34
|
_nextRpcMessageId: number;
|
|
@@ -43,55 +44,10 @@ export default class Channel {
|
|
|
43
44
|
_state: Encoded.Transaction | '';
|
|
44
45
|
_options: ChannelOptions;
|
|
45
46
|
_channelId?: Encoded.Channel;
|
|
47
|
+
protected constructor();
|
|
48
|
+
_debug(...args: any[]): void;
|
|
46
49
|
/**
|
|
47
50
|
* @param options - Channel params
|
|
48
|
-
* @param options.url - Channel url (for example: "ws://localhost:3001")
|
|
49
|
-
* @param options.role - Participant role ("initiator" or "responder")
|
|
50
|
-
* @param options.initiatorId - Initiator's public key
|
|
51
|
-
* @param options.responderId - Responder's public key
|
|
52
|
-
* @param options.pushAmount - Initial deposit in favour of the responder by the initiator
|
|
53
|
-
* @param options.initiatorAmount - Amount of coins the initiator has committed to
|
|
54
|
-
* the channel
|
|
55
|
-
* @param options.responderAmount - Amount of coins the responder has committed to
|
|
56
|
-
* the channel
|
|
57
|
-
* @param options.channelReserve - The minimum amount both peers need to maintain
|
|
58
|
-
* @param options.ttl - Minimum block height to include the channel_create_tx
|
|
59
|
-
* @param options.host - Host of the responder's node
|
|
60
|
-
* @param options.port - The port of the responders node
|
|
61
|
-
* @param options.lockPeriod - Amount of blocks for disputing a solo close
|
|
62
|
-
* @param options.minimumDepthStrategy - How to calculate minimum depth (default: txfee)
|
|
63
|
-
* @param options.minimumDepth - The minimum amount of blocks to be mined
|
|
64
|
-
* @param options.fee - The fee to be used for the channel open transaction
|
|
65
|
-
* @param options.gasPrice - Used for the fee computation of the channel open transaction
|
|
66
|
-
* @param options.existingChannelId - Existing channel id (required if reestablishing a
|
|
67
|
-
* channel)
|
|
68
|
-
* @param options.offchainTx - Offchain transaction (required if reestablishing
|
|
69
|
-
* a channel)
|
|
70
|
-
* @param options.timeoutIdle - The time waiting for a new event to be initiated
|
|
71
|
-
* (default: 600000)
|
|
72
|
-
* @param options.timeoutFundingCreate - The time waiting for the initiator to produce
|
|
73
|
-
* the create channel transaction after the noise session had been established (default: 120000)
|
|
74
|
-
* @param options.timeoutFundingSign - The time frame the other client has to sign an
|
|
75
|
-
* off-chain update after our client had initiated and signed it. This applies only for double
|
|
76
|
-
* signed on-chain intended updates: channel create transaction, deposit, withdrawal and etc.
|
|
77
|
-
* (default: 120000)
|
|
78
|
-
* @param options.timeoutFundingLock - The time frame the other client has to confirm an
|
|
79
|
-
* on-chain transaction reaching maturity (passing minimum depth) after the local node has
|
|
80
|
-
* detected this. This applies only for double signed on-chain intended updates: channel create
|
|
81
|
-
* transaction, deposit, withdrawal and etc. (default: 360000)
|
|
82
|
-
* @param options.timeoutSign - The time frame the client has to return a signed
|
|
83
|
-
* off-chain update or to decline it. This applies for all off-chain updates (default: 500000)
|
|
84
|
-
* @param options.timeoutAccept - The time frame the other client has to react to an
|
|
85
|
-
* event. This applies for all off-chain updates that are not meant to land on-chain, as well as
|
|
86
|
-
* some special cases: opening a noise connection, mutual closing acknowledgement and
|
|
87
|
-
* reestablishing an existing channel (default: 120000)
|
|
88
|
-
* @param options.timeoutInitialized - the time frame the responder has to accept an
|
|
89
|
-
* incoming noise session. Applicable only for initiator (default: timeout_accept's value)
|
|
90
|
-
* @param options.timeoutAwaitingOpen - The time frame the initiator has to start an
|
|
91
|
-
* outgoing noise session to the responder's node. Applicable only for responder (default:
|
|
92
|
-
* timeout_idle's value)
|
|
93
|
-
* @param options.debug=false - Log websocket communication
|
|
94
|
-
* @param options.sign - Function which verifies and signs transactions
|
|
95
51
|
*/
|
|
96
52
|
static initialize(options: ChannelOptions): Promise<Channel>;
|
|
97
53
|
static _initialize<T extends Channel>(channel: T, options: ChannelOptions): Promise<T>;
|
package/es/channel/Base.mjs
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
|
|
2
|
+
import _classPrivateFieldGet from "@babel/runtime-corejs3/helpers/classPrivateFieldGet";
|
|
3
|
+
import _classPrivateFieldSet from "@babel/runtime-corejs3/helpers/classPrivateFieldSet";
|
|
4
|
+
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
5
|
+
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
2
6
|
import EventEmitter from 'events';
|
|
3
7
|
import { snakeToPascal } from "../utils/string.mjs";
|
|
4
8
|
import { buildTx, unpackTx } from "../tx/builder/index.mjs";
|
|
@@ -7,14 +11,12 @@ import * as handlers from "./handlers.mjs";
|
|
|
7
11
|
import { initialize, enqueueAction, notify, call, disconnect as channelDisconnect } from "./internal.mjs";
|
|
8
12
|
import { ChannelError } from "../utils/errors.mjs";
|
|
9
13
|
function snakeToPascalObjKeys(obj) {
|
|
10
|
-
return Object.entries(obj).reduce((result,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
[snakeToPascal(key)]: val
|
|
15
|
-
};
|
|
16
|
-
}, {});
|
|
14
|
+
return Object.entries(obj).reduce((result, [key, val]) => ({
|
|
15
|
+
...result,
|
|
16
|
+
[snakeToPascal(key)]: val
|
|
17
|
+
}), {});
|
|
17
18
|
}
|
|
19
|
+
let channelCounter = 0;
|
|
18
20
|
|
|
19
21
|
/**
|
|
20
22
|
* Channel
|
|
@@ -37,6 +39,7 @@ function snakeToPascalObjKeys(obj) {
|
|
|
37
39
|
* })
|
|
38
40
|
* ```
|
|
39
41
|
*/
|
|
42
|
+
var _debugId = /*#__PURE__*/new WeakMap();
|
|
40
43
|
export default class Channel {
|
|
41
44
|
constructor() {
|
|
42
45
|
_defineProperty(this, "_eventEmitter", new EventEmitter());
|
|
@@ -48,56 +51,20 @@ export default class Channel {
|
|
|
48
51
|
_defineProperty(this, "_isActionQueueLocked", false);
|
|
49
52
|
_defineProperty(this, "_status", 'disconnected');
|
|
50
53
|
_defineProperty(this, "_state", '');
|
|
54
|
+
_classPrivateFieldInitSpec(this, _debugId, {
|
|
55
|
+
writable: true,
|
|
56
|
+
value: void 0
|
|
57
|
+
});
|
|
58
|
+
channelCounter += 1;
|
|
59
|
+
_classPrivateFieldSet(this, _debugId, channelCounter);
|
|
51
60
|
}
|
|
61
|
+
_debug(...args) {
|
|
62
|
+
if (this._options.debug !== true) return;
|
|
63
|
+
console.debug(`Channel #${_classPrivateFieldGet(this, _debugId)}`, ...args);
|
|
64
|
+
}
|
|
65
|
+
|
|
52
66
|
/**
|
|
53
67
|
* @param options - Channel params
|
|
54
|
-
* @param options.url - Channel url (for example: "ws://localhost:3001")
|
|
55
|
-
* @param options.role - Participant role ("initiator" or "responder")
|
|
56
|
-
* @param options.initiatorId - Initiator's public key
|
|
57
|
-
* @param options.responderId - Responder's public key
|
|
58
|
-
* @param options.pushAmount - Initial deposit in favour of the responder by the initiator
|
|
59
|
-
* @param options.initiatorAmount - Amount of coins the initiator has committed to
|
|
60
|
-
* the channel
|
|
61
|
-
* @param options.responderAmount - Amount of coins the responder has committed to
|
|
62
|
-
* the channel
|
|
63
|
-
* @param options.channelReserve - The minimum amount both peers need to maintain
|
|
64
|
-
* @param options.ttl - Minimum block height to include the channel_create_tx
|
|
65
|
-
* @param options.host - Host of the responder's node
|
|
66
|
-
* @param options.port - The port of the responders node
|
|
67
|
-
* @param options.lockPeriod - Amount of blocks for disputing a solo close
|
|
68
|
-
* @param options.minimumDepthStrategy - How to calculate minimum depth (default: txfee)
|
|
69
|
-
* @param options.minimumDepth - The minimum amount of blocks to be mined
|
|
70
|
-
* @param options.fee - The fee to be used for the channel open transaction
|
|
71
|
-
* @param options.gasPrice - Used for the fee computation of the channel open transaction
|
|
72
|
-
* @param options.existingChannelId - Existing channel id (required if reestablishing a
|
|
73
|
-
* channel)
|
|
74
|
-
* @param options.offchainTx - Offchain transaction (required if reestablishing
|
|
75
|
-
* a channel)
|
|
76
|
-
* @param options.timeoutIdle - The time waiting for a new event to be initiated
|
|
77
|
-
* (default: 600000)
|
|
78
|
-
* @param options.timeoutFundingCreate - The time waiting for the initiator to produce
|
|
79
|
-
* the create channel transaction after the noise session had been established (default: 120000)
|
|
80
|
-
* @param options.timeoutFundingSign - The time frame the other client has to sign an
|
|
81
|
-
* off-chain update after our client had initiated and signed it. This applies only for double
|
|
82
|
-
* signed on-chain intended updates: channel create transaction, deposit, withdrawal and etc.
|
|
83
|
-
* (default: 120000)
|
|
84
|
-
* @param options.timeoutFundingLock - The time frame the other client has to confirm an
|
|
85
|
-
* on-chain transaction reaching maturity (passing minimum depth) after the local node has
|
|
86
|
-
* detected this. This applies only for double signed on-chain intended updates: channel create
|
|
87
|
-
* transaction, deposit, withdrawal and etc. (default: 360000)
|
|
88
|
-
* @param options.timeoutSign - The time frame the client has to return a signed
|
|
89
|
-
* off-chain update or to decline it. This applies for all off-chain updates (default: 500000)
|
|
90
|
-
* @param options.timeoutAccept - The time frame the other client has to react to an
|
|
91
|
-
* event. This applies for all off-chain updates that are not meant to land on-chain, as well as
|
|
92
|
-
* some special cases: opening a noise connection, mutual closing acknowledgement and
|
|
93
|
-
* reestablishing an existing channel (default: 120000)
|
|
94
|
-
* @param options.timeoutInitialized - the time frame the responder has to accept an
|
|
95
|
-
* incoming noise session. Applicable only for initiator (default: timeout_accept's value)
|
|
96
|
-
* @param options.timeoutAwaitingOpen - The time frame the initiator has to start an
|
|
97
|
-
* outgoing noise session to the responder's node. Applicable only for responder (default:
|
|
98
|
-
* timeout_idle's value)
|
|
99
|
-
* @param options.debug=false - Log websocket communication
|
|
100
|
-
* @param options.sign - Function which verifies and signs transactions
|
|
101
68
|
*/
|
|
102
69
|
static async initialize(options) {
|
|
103
70
|
return Channel._initialize(new Channel(), options);
|
package/es/channel/Base.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Base.mjs","names":["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,OAAOA,YAAY,MAAM,QAAQ;AAAC,SAEzBC,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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;EACE,MAAME,KAAKA,CAAA,EAA6E;IACtF,OAAO,IAAI,CAAC1D,aAAa,CAAC,MAAM;MAC9BC,MAAM,CAAC,IAAI,EAAE,gBAAgB,CAAC;MAC9B,OAAO;QAAEwD,OAAO,EAAE3D,QAAQ,CAAC6D;MAAc,CAAC;IAC5C,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE,MAAMC,QAAQA,CAACC,IAAY,EAAgC;IACzD,OAAO,IAAI,CAAC7D,aAAa,CAAC,MAAM;MAC9BC,MAAM,CAAC,IAAI,EAAE,mBAAmB,CAAC;MACjC,OAAO;QACLwD,OAAO,EAAE3D,QAAQ,CAACgE,kBAAkB;QACpC5B,KAAK,EAAE;UAAE2B;QAAK;MAChB,CAAC;IACH,CAAC,CAAC;EACJ;EAEA,aAAaE,SAASA,CAAC5C,OAAuB,EAAE6C,QAAa,EAAoB;IAC/E,MAAM;MAAEH;IAAK,CAAC,GAAG1C,OAAO;IAExB,OAAOJ,OAAO,CAAChB,UAAU,CAAC;MACxB,GAAGoB,OAAO;MACV8C,WAAW,EAAE,MAAMJ,IAAI,CACrB,WAAW,EACXlE,OAAO,CAAC;QAAE,GAAGqE,QAAQ;QAAEjB,GAAG,EAAElD,GAAG,CAACqE;MAAyB,CAAC,CAC5D;IACF,CAAC,CAAC;EACJ;AACF"}
|
|
1
|
+
{"version":3,"file":"Base.mjs","names":["EventEmitter","snakeToPascal","buildTx","unpackTx","Tag","handlers","initialize","enqueueAction","notify","call","disconnect","channelDisconnect","ChannelError","snakeToPascalObjKeys","obj","Object","entries","reduce","result","key","val","channelCounter","_debugId","WeakMap","Channel","constructor","_defineProperty","Map","_classPrivateFieldInitSpec","writable","value","_classPrivateFieldSet","_debug","args","_options","debug","console","_classPrivateFieldGet","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\nlet channelCounter = 0;\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 readonly #debugId: number;\n\n _channelId?: Encoded.Channel;\n\n protected constructor() {\n channelCounter += 1;\n this.#debugId = channelCounter;\n }\n\n _debug(...args: any[]): void {\n if (this._options.debug !== true) return;\n console.debug(`Channel #${this.#debugId}`, ...args);\n }\n\n /**\n * @param options - Channel params\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,OAAOA,YAAY,MAAM,QAAQ;AAAC,SAEzBC,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,EAAE,CAACC,GAAG,EAAEC,GAAG,CAAC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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE,MAAME,KAAKA,CAAA,EAA6E;IACtF,OAAO,IAAI,CAACtE,aAAa,CAAC,MAAM;MAC9BC,MAAM,CAAC,IAAI,EAAE,gBAAgB,CAAC;MAC9B,OAAO;QAAEoE,OAAO,EAAEvE,QAAQ,CAACyE;MAAc,CAAC;IAC5C,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE,MAAMC,QAAQA,CAACC,IAAY,EAAgC;IACzD,OAAO,IAAI,CAACzE,aAAa,CAAC,MAAM;MAC9BC,MAAM,CAAC,IAAI,EAAE,mBAAmB,CAAC;MACjC,OAAO;QACLoE,OAAO,EAAEvE,QAAQ,CAAC4E,kBAAkB;QACpC5B,KAAK,EAAE;UAAE2B;QAAK;MAChB,CAAC;IACH,CAAC,CAAC;EACJ;EAEA,aAAaE,SAASA,CAAC5C,OAAuB,EAAE6C,QAAa,EAAoB;IAC/E,MAAM;MAAEH;IAAK,CAAC,GAAG1C,OAAO;IAExB,OAAOd,OAAO,CAAClB,UAAU,CAAC;MACxB,GAAGgC,OAAO;MACV8C,WAAW,EAAE,MAAMJ,IAAI,CACrB,WAAW,EACX9E,OAAO,CAAC;QAAE,GAAGiF,QAAQ;QAAEjB,GAAG,EAAE9D,GAAG,CAACiF;MAAyB,CAAC,CAC5D;IACF,CAAC,CAAC;EACJ;AACF"}
|
package/es/channel/Contract.d.ts
CHANGED
|
@@ -6,10 +6,24 @@ import { ContractCallReturnType } from '../apis/node';
|
|
|
6
6
|
import { ContractCallObject } from '../contract/Contract';
|
|
7
7
|
import ChannelSpend from './Spend';
|
|
8
8
|
interface CallContractOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Amount the caller of the contract commits to it
|
|
11
|
+
*/
|
|
9
12
|
amount?: number | BigNumber;
|
|
13
|
+
/**
|
|
14
|
+
* ABI encoded compiled AEVM call data for the code
|
|
15
|
+
*/
|
|
10
16
|
callData?: Encoded.ContractBytearray;
|
|
17
|
+
/**
|
|
18
|
+
* Version of the ABI
|
|
19
|
+
*/
|
|
11
20
|
abiVersion?: AbiVersion;
|
|
21
|
+
/**
|
|
22
|
+
* Address of the contract to call
|
|
23
|
+
*/
|
|
12
24
|
contract?: Encoded.ContractAddress;
|
|
25
|
+
}
|
|
26
|
+
interface CallContractResult extends CallContractOptions {
|
|
13
27
|
returnValue?: any;
|
|
14
28
|
gasUsed?: number | BigNumber;
|
|
15
29
|
gasPrice?: number | BigNumber;
|
|
@@ -91,10 +105,6 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
91
105
|
* if a call with a similar computation amount is to be forced on-chain.
|
|
92
106
|
*
|
|
93
107
|
* @param options - Options
|
|
94
|
-
* @param options.amount - Amount the caller of the contract commits to it
|
|
95
|
-
* @param options.callData - ABI encoded compiled AEVM call data for the code
|
|
96
|
-
* @param options.contract - Address of the contract to call
|
|
97
|
-
* @param options.abiVersion - Version of the ABI
|
|
98
108
|
* @param sign - Function which verifies and signs contract call transaction
|
|
99
109
|
* @example
|
|
100
110
|
* ```js
|
|
@@ -120,12 +130,6 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
120
130
|
* Trigger a force progress contract call
|
|
121
131
|
* This call is going on-chain
|
|
122
132
|
* @param options - Options
|
|
123
|
-
* @param options.amount - Amount the caller of the contract commits to it
|
|
124
|
-
* @param options.callData - ABI encoded compiled AEVM call data for the code
|
|
125
|
-
* @param options.contract - Address of the contract to call
|
|
126
|
-
* @param options.abiVersion - Version of the ABI
|
|
127
|
-
* @param options.gasPrice=1000000000]
|
|
128
|
-
* @param options.gasLimit=1000000]
|
|
129
133
|
* @param sign - Function which verifies and signs contract force progress transaction
|
|
130
134
|
* @param callbacks - Callbacks
|
|
131
135
|
* @example
|
|
@@ -145,11 +149,7 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
145
149
|
* })
|
|
146
150
|
* ```
|
|
147
151
|
*/
|
|
148
|
-
forceProgress({ amount, callData, contract, abiVersion, gasLimit, gasPrice, }: {
|
|
149
|
-
amount: number;
|
|
150
|
-
callData: Encoded.ContractBytearray;
|
|
151
|
-
contract: Encoded.ContractAddress;
|
|
152
|
-
abiVersion: AbiVersion;
|
|
152
|
+
forceProgress({ amount, callData, contract, abiVersion, gasLimit, gasPrice, }: CallContractOptions & {
|
|
153
153
|
gasLimit?: number;
|
|
154
154
|
gasPrice?: number;
|
|
155
155
|
}, sign: SignTx, { onOnChainTx }?: Pick<ChannelState, 'onOnChainTx'>): Promise<{
|
|
@@ -169,10 +169,6 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
169
169
|
* top of the blockchain as seen by the node.
|
|
170
170
|
*
|
|
171
171
|
* @param options - Options
|
|
172
|
-
* @param options.amount - Amount the caller of the contract commits to it
|
|
173
|
-
* @param options.callData - ABI encoded compiled AEVM call data for the code
|
|
174
|
-
* @param options.contract - Address of the contract to call
|
|
175
|
-
* @param options.abiVersion - Version of the ABI
|
|
176
172
|
* @example
|
|
177
173
|
* ```js
|
|
178
174
|
* channel.callContractStatic({
|
|
@@ -186,12 +182,7 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
186
182
|
* })
|
|
187
183
|
* ```
|
|
188
184
|
*/
|
|
189
|
-
callContractStatic({ amount, callData, contract, abiVersion, }:
|
|
190
|
-
amount: number;
|
|
191
|
-
callData: Encoded.ContractBytearray;
|
|
192
|
-
contract: Encoded.ContractAddress;
|
|
193
|
-
abiVersion: AbiVersion;
|
|
194
|
-
}): Promise<CallContractOptions>;
|
|
185
|
+
callContractStatic({ amount, callData, contract, abiVersion, }: CallContractOptions): Promise<CallContractResult>;
|
|
195
186
|
/**
|
|
196
187
|
* Get contract call result
|
|
197
188
|
*
|
package/es/channel/Contract.mjs
CHANGED
|
@@ -8,13 +8,10 @@ import { ChannelError, UnexpectedChannelMessageError } from "../utils/errors.mjs
|
|
|
8
8
|
import { unpackTx } from "../tx/builder/index.mjs";
|
|
9
9
|
import { encodeContractAddress } from "../utils/crypto.mjs";
|
|
10
10
|
function snakeToPascalObjKeys(obj) {
|
|
11
|
-
return Object.entries(obj).reduce((result,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
[snakeToPascal(key)]: val
|
|
16
|
-
};
|
|
17
|
-
}, {});
|
|
11
|
+
return Object.entries(obj).reduce((result, [key, val]) => ({
|
|
12
|
+
...result,
|
|
13
|
+
[snakeToPascal(key)]: val
|
|
14
|
+
}), {});
|
|
18
15
|
}
|
|
19
16
|
export default class ChannelContract extends ChannelSpend {
|
|
20
17
|
static async initialize(options) {
|
|
@@ -55,14 +52,13 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
55
52
|
* })
|
|
56
53
|
* ```
|
|
57
54
|
*/
|
|
58
|
-
async createContract(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
} = _ref2;
|
|
55
|
+
async createContract({
|
|
56
|
+
code,
|
|
57
|
+
callData,
|
|
58
|
+
deposit,
|
|
59
|
+
vmVersion,
|
|
60
|
+
abiVersion
|
|
61
|
+
}, sign) {
|
|
66
62
|
return this.enqueueAction(() => {
|
|
67
63
|
notify(this, 'channels.update.new_contract', {
|
|
68
64
|
code,
|
|
@@ -124,10 +120,6 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
124
120
|
* if a call with a similar computation amount is to be forced on-chain.
|
|
125
121
|
*
|
|
126
122
|
* @param options - Options
|
|
127
|
-
* @param options.amount - Amount the caller of the contract commits to it
|
|
128
|
-
* @param options.callData - ABI encoded compiled AEVM call data for the code
|
|
129
|
-
* @param options.contract - Address of the contract to call
|
|
130
|
-
* @param options.abiVersion - Version of the ABI
|
|
131
123
|
* @param sign - Function which verifies and signs contract call transaction
|
|
132
124
|
* @example
|
|
133
125
|
* ```js
|
|
@@ -145,13 +137,12 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
145
137
|
* })
|
|
146
138
|
* ```
|
|
147
139
|
*/
|
|
148
|
-
async callContract(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
} = _ref3;
|
|
140
|
+
async callContract({
|
|
141
|
+
amount,
|
|
142
|
+
callData,
|
|
143
|
+
contract,
|
|
144
|
+
abiVersion
|
|
145
|
+
}, sign) {
|
|
155
146
|
return this.enqueueAction(() => {
|
|
156
147
|
notify(this, 'channels.update.call_contract', {
|
|
157
148
|
amount,
|
|
@@ -192,12 +183,6 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
192
183
|
* Trigger a force progress contract call
|
|
193
184
|
* This call is going on-chain
|
|
194
185
|
* @param options - Options
|
|
195
|
-
* @param options.amount - Amount the caller of the contract commits to it
|
|
196
|
-
* @param options.callData - ABI encoded compiled AEVM call data for the code
|
|
197
|
-
* @param options.contract - Address of the contract to call
|
|
198
|
-
* @param options.abiVersion - Version of the ABI
|
|
199
|
-
* @param options.gasPrice=1000000000]
|
|
200
|
-
* @param options.gasLimit=1000000]
|
|
201
186
|
* @param sign - Function which verifies and signs contract force progress transaction
|
|
202
187
|
* @param callbacks - Callbacks
|
|
203
188
|
* @example
|
|
@@ -217,18 +202,16 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
217
202
|
* })
|
|
218
203
|
* ```
|
|
219
204
|
*/
|
|
220
|
-
async forceProgress(
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
onOnChainTx
|
|
231
|
-
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
205
|
+
async forceProgress({
|
|
206
|
+
amount,
|
|
207
|
+
callData,
|
|
208
|
+
contract,
|
|
209
|
+
abiVersion,
|
|
210
|
+
gasLimit = 1000000,
|
|
211
|
+
gasPrice = MIN_GAS_PRICE
|
|
212
|
+
}, sign, {
|
|
213
|
+
onOnChainTx
|
|
214
|
+
} = {}) {
|
|
232
215
|
return this.enqueueAction(() => {
|
|
233
216
|
notify(this, 'channels.force_progress', {
|
|
234
217
|
amount,
|
|
@@ -250,7 +233,7 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
250
233
|
handler: (_2, message2, state2) => {
|
|
251
234
|
if (message2.method === 'channels.on_chain_tx') {
|
|
252
235
|
var _state2$onOnChainTx;
|
|
253
|
-
(_state2$onOnChainTx = state2.onOnChainTx) === null || _state2$onOnChainTx === void 0
|
|
236
|
+
(_state2$onOnChainTx = state2.onOnChainTx) === null || _state2$onOnChainTx === void 0 || _state2$onOnChainTx.call(state2, message2.params.data.tx);
|
|
254
237
|
emit(this, 'onChainTx', message2.params.data.tx, {
|
|
255
238
|
info: message2.params.data.info,
|
|
256
239
|
type: message2.params.data.type
|
|
@@ -261,7 +244,6 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
261
244
|
});
|
|
262
245
|
// TODO: shouldn't be unexpected message in this case
|
|
263
246
|
}
|
|
264
|
-
|
|
265
247
|
return handleUnexpectedMessage(this, message2, state2);
|
|
266
248
|
},
|
|
267
249
|
state
|
|
@@ -287,10 +269,6 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
287
269
|
* top of the blockchain as seen by the node.
|
|
288
270
|
*
|
|
289
271
|
* @param options - Options
|
|
290
|
-
* @param options.amount - Amount the caller of the contract commits to it
|
|
291
|
-
* @param options.callData - ABI encoded compiled AEVM call data for the code
|
|
292
|
-
* @param options.contract - Address of the contract to call
|
|
293
|
-
* @param options.abiVersion - Version of the ABI
|
|
294
272
|
* @example
|
|
295
273
|
* ```js
|
|
296
274
|
* channel.callContractStatic({
|
|
@@ -304,13 +282,12 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
304
282
|
* })
|
|
305
283
|
* ```
|
|
306
284
|
*/
|
|
307
|
-
async callContractStatic(
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
} = _ref5;
|
|
285
|
+
async callContractStatic({
|
|
286
|
+
amount,
|
|
287
|
+
callData,
|
|
288
|
+
contract,
|
|
289
|
+
abiVersion
|
|
290
|
+
}) {
|
|
314
291
|
return snakeToPascalObjKeys(await call(this, 'channels.dry_run.call_contract', {
|
|
315
292
|
amount,
|
|
316
293
|
call_data: callData,
|
|
@@ -340,12 +317,11 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
340
317
|
* })
|
|
341
318
|
* ```
|
|
342
319
|
*/
|
|
343
|
-
async getContractCall(
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
} = _ref6;
|
|
320
|
+
async getContractCall({
|
|
321
|
+
caller,
|
|
322
|
+
contract,
|
|
323
|
+
round
|
|
324
|
+
}) {
|
|
349
325
|
return snakeToPascalObjKeys(await call(this, 'channels.get.contract_call', {
|
|
350
326
|
caller_id: caller,
|
|
351
327
|
contract_id: contract,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Contract.mjs","names":["snakeToPascal","MIN_GAS_PRICE","Tag","signAndNotify","awaitingCompletion","channelClosed","channelOpen","handleUnexpectedMessage","notify","call","changeState","emit","Channel","ChannelSpend","ChannelError","UnexpectedChannelMessageError","unpackTx","encodeContractAddress","snakeToPascalObjKeys","obj","Object","entries","reduce","result","_ref","key","val","ChannelContract","initialize","options","_initialize","createContract","_ref2","sign","code","callData","deposit","vmVersion","abiVersion","enqueueAction","call_data","vm_version","abi_version","handler","_","message","state","method","params","data","tx","_2","message2","state2","SignedTx","encodedTx","tag","ChannelOffChainTx","addressKey","_options","role","owner","address","round","resolve","accepted","signedTx","callContract","_ref3","amount","contract","contract_id","updates","forceProgress","_ref4","gasLimit","gasPrice","onOnChainTx","arguments","length","undefined","gas_price","gas","_state2$onOnChainTx","info","type","callContractStatic","_ref5","getContractCall","_ref6","caller","caller_id","getContractState","pubkey","cleanContractCalls","reject"],"sources":["../../src/channel/Contract.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport { snakeToPascal } from '../utils/string';\nimport {\n MIN_GAS_PRICE, Tag, AbiVersion, VmVersion,\n} from '../tx/builder/constants';\nimport {\n signAndNotify,\n awaitingCompletion,\n channelClosed,\n channelOpen,\n handleUnexpectedMessage,\n} from './handlers';\nimport {\n notify, call, SignTx, ChannelState, ChannelOptions, ChannelMessage, ChannelFsm, changeState, emit,\n} from './internal';\nimport { Encoded } from '../utils/encoder';\nimport { ContractCallReturnType } from '../apis/node';\nimport { ContractCallObject } from '../contract/Contract';\nimport Channel from './Base';\nimport ChannelSpend from './Spend';\nimport { ChannelError, UnexpectedChannelMessageError } from '../utils/errors';\nimport { unpackTx } from '../tx/builder';\nimport { encodeContractAddress } from '../utils/crypto';\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\ninterface CallContractOptions {\n amount?: number | BigNumber;\n callData?: Encoded.ContractBytearray;\n abiVersion?: AbiVersion;\n contract?: Encoded.ContractAddress;\n returnValue?: any;\n gasUsed?: number | BigNumber;\n gasPrice?: number | BigNumber;\n height?: number;\n callerNonce?: number;\n log?: any;\n returnType?: ContractCallReturnType;\n}\n\ninterface Contract {\n abiVersion: AbiVersion;\n active: boolean;\n deposit: number | BigNumber;\n id: string;\n ownerId: string;\n referrerIds: string[];\n vmVersion: VmVersion;\n}\n\nexport default class ChannelContract extends ChannelSpend {\n static override async initialize(options: ChannelOptions): Promise<ChannelContract> {\n return Channel._initialize(new ChannelContract(), options);\n }\n\n /**\n * Trigger create contract update\n *\n * The create contract update is creating a contract inside the channel's internal state tree.\n * The update is a change to be applied on top of the latest state.\n *\n * That would create a contract with the poster being the owner of it. Poster commits initially\n * a deposit amount of coins to the new contract.\n *\n * @param options - Options\n * @param options.code - Api encoded compiled AEVM byte code\n * @param options.callData - Api encoded compiled AEVM call data for the code\n * @param options.deposit - Initial amount the owner of the contract commits to it\n * @param options.vmVersion - Version of the Virtual Machine\n * @param options.abiVersion - Version of the Application Binary Interface\n * @param sign - Function which verifies and signs create contract transaction\n * @example\n * ```js\n * channel.createContract({\n * code: 'cb_HKtpipK4aCgYb17wZ...',\n * callData: 'cb_1111111111111111...',\n * deposit: 10,\n * vmVersion: 3,\n * abiVersion: 1\n * }).then(({ accepted, signedTx, address }) => {\n * if (accepted) {\n * console.log('New contract has been created')\n * console.log('Contract address:', address)\n * } else {\n * console.log('New contract has been rejected')\n * }\n * })\n * ```\n */\n async createContract(\n {\n code, callData, deposit, vmVersion, abiVersion,\n }: {\n code: Encoded.ContractBytearray;\n callData: Encoded.ContractBytearray;\n deposit: number | BigNumber;\n vmVersion: VmVersion;\n abiVersion: AbiVersion;\n },\n sign: SignTx,\n ): Promise<{\n accepted: boolean; signedTx: Encoded.Transaction; address: Encoded.ContractAddress;\n }> {\n return this.enqueueAction(() => {\n notify(this, 'channels.update.new_contract', {\n code,\n call_data: callData,\n deposit,\n vm_version: vmVersion,\n abi_version: abiVersion,\n });\n return {\n handler: async (\n _: Channel,\n message: ChannelMessage,\n state: ChannelState,\n ): Promise<ChannelFsm> => {\n if (message.method !== 'channels.sign.update') {\n return handleUnexpectedMessage(this, message, state);\n }\n await signAndNotify(\n this,\n 'channels.update',\n message.params.data,\n async (tx) => state.sign(tx),\n );\n return {\n handler: (\n _2: Channel,\n message2: ChannelMessage,\n state2: ChannelState,\n ): ChannelFsm => (\n awaitingCompletion(this, message2, state2, () => {\n const params = unpackTx(message2.params.data.state, Tag.SignedTx).encodedTx;\n if (params.tag !== Tag.ChannelOffChainTx) {\n throw new ChannelError(`Tag should be ${Tag[Tag.ChannelOffChainTx]}, got ${Tag[params.tag]} instead`);\n }\n const addressKey = this._options.role === 'initiator'\n ? 'initiatorId' : 'responderId';\n const owner = this._options[addressKey];\n changeState(this, message2.params.data.state);\n const address = encodeContractAddress(owner, params.round);\n emit(this, 'newContract', address);\n state2.resolve({ accepted: true, address, signedTx: message2.params.data.state });\n return { handler: channelOpen };\n })\n ),\n state,\n };\n },\n state: { sign },\n };\n });\n }\n\n /**\n * Trigger call a contract update\n *\n * The call contract update is calling a preexisting contract inside the channel's\n * internal state tree. The update is a change to be applied on top of the latest state.\n *\n * That would call a contract with the poster being the caller of it. Poster commits\n * an amount of coins to the contract.\n *\n * The call would also create a call object inside the channel state tree. It contains\n * the result of the contract call.\n *\n * It is worth mentioning that the gas is not consumed, because this is an off-chain\n * contract call. It would be consumed if it were an on-chain one. This could happen\n * if a call with a similar computation amount is to be forced on-chain.\n *\n * @param options - Options\n * @param options.amount - Amount the caller of the contract commits to it\n * @param options.callData - ABI encoded compiled AEVM call data for the code\n * @param options.contract - Address of the contract to call\n * @param options.abiVersion - Version of the ABI\n * @param sign - Function which verifies and signs contract call transaction\n * @example\n * ```js\n * channel.callContract({\n * contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',\n * callData: 'cb_1111111111111111...',\n * amount: 0,\n * abiVersion: 1\n * }).then(({ accepted, signedTx }) => {\n * if (accepted) {\n * console.log('Contract called succesfully')\n * } else {\n * console.log('Contract call has been rejected')\n * }\n * })\n * ```\n */\n async callContract(\n {\n amount, callData, contract, abiVersion,\n }: CallContractOptions,\n sign: SignTx,\n ): Promise<{ accepted: boolean; signedTx: Encoded.Transaction }> {\n return this.enqueueAction(() => {\n notify(this, 'channels.update.call_contract', {\n amount,\n call_data: callData,\n contract_id: contract,\n abi_version: abiVersion,\n });\n return {\n handler: async (\n _: Channel,\n message: ChannelMessage,\n state: ChannelState,\n ): Promise<ChannelFsm> => {\n if (message.method !== 'channels.sign.update') {\n return handleUnexpectedMessage(this, message, state);\n }\n await signAndNotify(\n this,\n 'channels.update',\n message.params.data,\n async (tx) => state.sign(tx, { updates: message.params.data.updates }),\n );\n return {\n handler: (\n _2: Channel,\n message2: ChannelMessage,\n state2: ChannelState,\n ): ChannelFsm => (\n awaitingCompletion(this, message2, state2, () => {\n changeState(this, message2.params.data.state);\n state2.resolve({ accepted: true, signedTx: message2.params.data.state });\n return { handler: channelOpen };\n })\n ),\n state,\n };\n },\n state: { sign },\n };\n });\n }\n\n /**\n * Trigger a force progress contract call\n * This call is going on-chain\n * @param options - Options\n * @param options.amount - Amount the caller of the contract commits to it\n * @param options.callData - ABI encoded compiled AEVM call data for the code\n * @param options.contract - Address of the contract to call\n * @param options.abiVersion - Version of the ABI\n * @param options.gasPrice=1000000000]\n * @param options.gasLimit=1000000]\n * @param sign - Function which verifies and signs contract force progress transaction\n * @param callbacks - Callbacks\n * @example\n * ```js\n * channel.forceProgress({\n * contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',\n * callData: 'cb_1111111111111111...',\n * amount: 0,\n * abiVersion: 1,\n * gasPrice: 1000005554\n * }).then(({ accepted, signedTx }) => {\n * if (accepted) {\n * console.log('Contract force progress call successful')\n * } else {\n * console.log('Contract force progress call has been rejected')\n * }\n * })\n * ```\n */\n async forceProgress(\n {\n amount, callData, contract, abiVersion, gasLimit = 1000000, gasPrice = MIN_GAS_PRICE,\n }: {\n amount: number;\n callData: Encoded.ContractBytearray;\n contract: Encoded.ContractAddress;\n abiVersion: AbiVersion;\n gasLimit?: number;\n gasPrice?: number;\n },\n sign: SignTx,\n { onOnChainTx }: Pick<ChannelState, 'onOnChainTx'> = {},\n ): Promise<{\n accepted: boolean;\n signedTx: Encoded.Transaction;\n tx: Encoded.Transaction | Uint8Array;\n }> {\n return this.enqueueAction(() => {\n notify(this, 'channels.force_progress', {\n amount,\n call_data: callData,\n contract_id: contract,\n abi_version: abiVersion,\n gas_price: gasPrice,\n gas: gasLimit,\n });\n return {\n handler: async (\n _: Channel,\n message: ChannelMessage,\n state: ChannelState,\n ): Promise<ChannelFsm> => {\n if (message.method !== 'channels.sign.force_progress_tx') {\n return handleUnexpectedMessage(this, message, state);\n }\n await signAndNotify(\n this,\n 'channels.force_progress_sign',\n message.params.data,\n async (tx) => state.sign(tx, { updates: message.params.data.updates }),\n );\n return {\n handler: (\n _2: Channel,\n message2: ChannelMessage,\n state2: ChannelState,\n ): ChannelFsm => {\n if (message2.method === 'channels.on_chain_tx') {\n state2.onOnChainTx?.(message2.params.data.tx);\n emit(this, 'onChainTx', message2.params.data.tx, {\n info: message2.params.data.info,\n type: message2.params.data.type,\n });\n state2.resolve({ accepted: true, tx: message2.params.data.tx });\n // TODO: shouldn't be unexpected message in this case\n }\n return handleUnexpectedMessage(this, message2, state2);\n },\n state,\n };\n },\n state: { sign, onOnChainTx },\n };\n });\n }\n\n /**\n * Call contract using dry-run\n *\n * In order to get the result of a potential contract call, one might need to\n * dry-run a contract call. It takes the exact same arguments as a call would\n * and returns the call object.\n *\n * The call is executed in the channel's state, but it does not impact the state\n * whatsoever. It uses as an environment the latest channel's state and the current\n * top of the blockchain as seen by the node.\n *\n * @param options - Options\n * @param options.amount - Amount the caller of the contract commits to it\n * @param options.callData - ABI encoded compiled AEVM call data for the code\n * @param options.contract - Address of the contract to call\n * @param options.abiVersion - Version of the ABI\n * @example\n * ```js\n * channel.callContractStatic({\n * contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',\n * callData: 'cb_1111111111111111...',\n * amount: 0,\n * abiVersion: 1\n * }).then(({ returnValue, gasUsed }) => {\n * console.log('Returned value:', returnValue)\n * console.log('Gas used:', gasUsed)\n * })\n * ```\n */\n async callContractStatic(\n {\n amount, callData, contract, abiVersion,\n }: {\n amount: number;\n callData: Encoded.ContractBytearray;\n contract: Encoded.ContractAddress;\n abiVersion: AbiVersion;\n },\n ): Promise<CallContractOptions> {\n return snakeToPascalObjKeys(await call(this, 'channels.dry_run.call_contract', {\n amount,\n call_data: callData,\n contract_id: contract,\n abi_version: abiVersion,\n }));\n }\n\n /**\n * Get contract call result\n *\n * The combination of a caller, contract and a round of execution determines the\n * contract call. Providing an incorrect set of those results in an error response.\n *\n * @param options - Options\n * @param options.caller - Address of contract caller\n * @param options.contract - Address of the contract\n * @param options.round - Round when contract was called\n * @example\n * ```js\n * channel.getContractCall({\n * caller: 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',\n * contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',\n * round: 3\n * }).then(({ returnType, returnValue }) => {\n * if (returnType === 'ok') console.log(returnValue)\n * })\n * ```\n */\n async getContractCall(\n { caller, contract, round }: {\n caller: Encoded.AccountAddress;\n contract: Encoded.ContractAddress;\n round: number;\n },\n ): Promise<ContractCallObject> {\n return snakeToPascalObjKeys(\n await call(this, 'channels.get.contract_call', {\n caller_id: caller,\n contract_id: contract,\n round,\n }),\n );\n }\n\n /**\n * Get the latest contract state\n *\n * @param contract - Address of the contract\n * @example\n * ```js\n * channel.getContractState(\n * 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa'\n * ).then(({ contract }) => {\n * console.log('deposit:', contract.deposit)\n * })\n * ```\n */\n async getContractState(\n contract: Encoded.ContractAddress,\n ): Promise<{ contract: Contract; contractState: object }> {\n const result = await call(this, 'channels.get.contract', { pubkey: contract });\n return snakeToPascalObjKeys({\n ...result,\n contract: snakeToPascalObjKeys(result.contract),\n });\n }\n\n /**\n * Clean up all locally stored contract calls\n *\n * Contract calls are kept locally in order for the participant to be able to look them up.\n * They consume memory and in order for the participant to free it - one can prune all messages.\n * This cleans up all locally stored contract calls and those will no longer be available for\n * fetching and inspection.\n */\n async cleanContractCalls(): Promise<void> {\n return this.enqueueAction(() => {\n notify(this, 'channels.clean_contract_calls');\n return {\n handler(_: Channel, message: ChannelMessage, state: ChannelState): ChannelFsm {\n if (message.method === 'channels.calls_pruned.reply') {\n state.resolve();\n return { handler: channelOpen };\n }\n state.reject(new UnexpectedChannelMessageError('Unexpected message received'));\n return { handler: channelClosed };\n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;AACA;AACA;EACE,MAAM6B,gBAAgBA,CACpBtB,QAAiC,EACuB;IACxD,MAAM/C,MAAM,GAAG,MAAMd,IAAI,CAAC,IAAI,EAAE,uBAAuB,EAAE;MAAEoF,MAAM,EAAEvB;IAAS,CAAC,CAAC;IAC9E,OAAOpD,oBAAoB,CAAC;MAC1B,GAAGK,MAAM;MACT+C,QAAQ,EAAEpD,oBAAoB,CAACK,MAAM,CAAC+C,QAAQ;IAChD,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE,MAAMwB,kBAAkBA,CAAA,EAAkB;IACxC,OAAO,IAAI,CAACvD,aAAa,CAAC,MAAM;MAC9B/B,MAAM,CAAC,IAAI,EAAE,+BAA+B,CAAC;MAC7C,OAAO;QACLmC,OAAOA,CAACC,CAAU,EAAEC,OAAuB,EAAEC,KAAmB,EAAc;UAC5E,IAAID,OAAO,CAACE,MAAM,KAAK,6BAA6B,EAAE;YACpDD,KAAK,CAACkB,OAAO,CAAC,CAAC;YACf,OAAO;cAAErB,OAAO,EAAErC;YAAY,CAAC;UACjC;UACAwC,KAAK,CAACiD,MAAM,CAAC,IAAIhF,6BAA6B,CAAC,6BAA6B,CAAC,CAAC;UAC9E,OAAO;YAAE4B,OAAO,EAAEtC;UAAc,CAAC;QACnC;MACF,CAAC;IACH,CAAC,CAAC;EACJ;AACF"}
|
|
1
|
+
{"version":3,"file":"Contract.mjs","names":["snakeToPascal","MIN_GAS_PRICE","Tag","signAndNotify","awaitingCompletion","channelClosed","channelOpen","handleUnexpectedMessage","notify","call","changeState","emit","Channel","ChannelSpend","ChannelError","UnexpectedChannelMessageError","unpackTx","encodeContractAddress","snakeToPascalObjKeys","obj","Object","entries","reduce","result","key","val","ChannelContract","initialize","options","_initialize","createContract","code","callData","deposit","vmVersion","abiVersion","sign","enqueueAction","call_data","vm_version","abi_version","handler","_","message","state","method","params","data","tx","_2","message2","state2","SignedTx","encodedTx","tag","ChannelOffChainTx","addressKey","_options","role","owner","address","round","resolve","accepted","signedTx","callContract","amount","contract","contract_id","updates","forceProgress","gasLimit","gasPrice","onOnChainTx","gas_price","gas","_state2$onOnChainTx","info","type","callContractStatic","getContractCall","caller","caller_id","getContractState","pubkey","cleanContractCalls","reject"],"sources":["../../src/channel/Contract.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport { snakeToPascal } from '../utils/string';\nimport {\n MIN_GAS_PRICE, Tag, AbiVersion, VmVersion,\n} from '../tx/builder/constants';\nimport {\n signAndNotify,\n awaitingCompletion,\n channelClosed,\n channelOpen,\n handleUnexpectedMessage,\n} from './handlers';\nimport {\n notify, call, SignTx, ChannelState, ChannelOptions, ChannelMessage, ChannelFsm, changeState, emit,\n} from './internal';\nimport { Encoded } from '../utils/encoder';\nimport { ContractCallReturnType } from '../apis/node';\nimport { ContractCallObject } from '../contract/Contract';\nimport Channel from './Base';\nimport ChannelSpend from './Spend';\nimport { ChannelError, UnexpectedChannelMessageError } from '../utils/errors';\nimport { unpackTx } from '../tx/builder';\nimport { encodeContractAddress } from '../utils/crypto';\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\ninterface CallContractOptions {\n /**\n * Amount the caller of the contract commits to it\n */\n amount?: number | BigNumber;\n /**\n * ABI encoded compiled AEVM call data for the code\n */\n callData?: Encoded.ContractBytearray;\n /**\n * Version of the ABI\n */\n abiVersion?: AbiVersion;\n /**\n * Address of the contract to call\n */\n contract?: Encoded.ContractAddress;\n}\n\ninterface CallContractResult extends CallContractOptions {\n returnValue?: any;\n gasUsed?: number | BigNumber;\n gasPrice?: number | BigNumber;\n height?: number;\n callerNonce?: number;\n log?: any;\n returnType?: ContractCallReturnType;\n}\n\ninterface Contract {\n abiVersion: AbiVersion;\n active: boolean;\n deposit: number | BigNumber;\n id: string;\n ownerId: string;\n referrerIds: string[];\n vmVersion: VmVersion;\n}\n\nexport default class ChannelContract extends ChannelSpend {\n static override async initialize(options: ChannelOptions): Promise<ChannelContract> {\n return Channel._initialize(new ChannelContract(), options);\n }\n\n /**\n * Trigger create contract update\n *\n * The create contract update is creating a contract inside the channel's internal state tree.\n * The update is a change to be applied on top of the latest state.\n *\n * That would create a contract with the poster being the owner of it. Poster commits initially\n * a deposit amount of coins to the new contract.\n *\n * @param options - Options\n * @param options.code - Api encoded compiled AEVM byte code\n * @param options.callData - Api encoded compiled AEVM call data for the code\n * @param options.deposit - Initial amount the owner of the contract commits to it\n * @param options.vmVersion - Version of the Virtual Machine\n * @param options.abiVersion - Version of the Application Binary Interface\n * @param sign - Function which verifies and signs create contract transaction\n * @example\n * ```js\n * channel.createContract({\n * code: 'cb_HKtpipK4aCgYb17wZ...',\n * callData: 'cb_1111111111111111...',\n * deposit: 10,\n * vmVersion: 3,\n * abiVersion: 1\n * }).then(({ accepted, signedTx, address }) => {\n * if (accepted) {\n * console.log('New contract has been created')\n * console.log('Contract address:', address)\n * } else {\n * console.log('New contract has been rejected')\n * }\n * })\n * ```\n */\n async createContract(\n {\n code, callData, deposit, vmVersion, abiVersion,\n }: {\n code: Encoded.ContractBytearray;\n callData: Encoded.ContractBytearray;\n deposit: number | BigNumber;\n vmVersion: VmVersion;\n abiVersion: AbiVersion;\n },\n sign: SignTx,\n ): Promise<{\n accepted: boolean; signedTx: Encoded.Transaction; address: Encoded.ContractAddress;\n }> {\n return this.enqueueAction(() => {\n notify(this, 'channels.update.new_contract', {\n code,\n call_data: callData,\n deposit,\n vm_version: vmVersion,\n abi_version: abiVersion,\n });\n return {\n handler: async (\n _: Channel,\n message: ChannelMessage,\n state: ChannelState,\n ): Promise<ChannelFsm> => {\n if (message.method !== 'channels.sign.update') {\n return handleUnexpectedMessage(this, message, state);\n }\n await signAndNotify(\n this,\n 'channels.update',\n message.params.data,\n async (tx) => state.sign(tx),\n );\n return {\n handler: (\n _2: Channel,\n message2: ChannelMessage,\n state2: ChannelState,\n ): ChannelFsm => (\n awaitingCompletion(this, message2, state2, () => {\n const params = unpackTx(message2.params.data.state, Tag.SignedTx).encodedTx;\n if (params.tag !== Tag.ChannelOffChainTx) {\n throw new ChannelError(`Tag should be ${Tag[Tag.ChannelOffChainTx]}, got ${Tag[params.tag]} instead`);\n }\n const addressKey = this._options.role === 'initiator'\n ? 'initiatorId' : 'responderId';\n const owner = this._options[addressKey];\n changeState(this, message2.params.data.state);\n const address = encodeContractAddress(owner, params.round);\n emit(this, 'newContract', address);\n state2.resolve({ accepted: true, address, signedTx: message2.params.data.state });\n return { handler: channelOpen };\n })\n ),\n state,\n };\n },\n state: { sign },\n };\n });\n }\n\n /**\n * Trigger call a contract update\n *\n * The call contract update is calling a preexisting contract inside the channel's\n * internal state tree. The update is a change to be applied on top of the latest state.\n *\n * That would call a contract with the poster being the caller of it. Poster commits\n * an amount of coins to the contract.\n *\n * The call would also create a call object inside the channel state tree. It contains\n * the result of the contract call.\n *\n * It is worth mentioning that the gas is not consumed, because this is an off-chain\n * contract call. It would be consumed if it were an on-chain one. This could happen\n * if a call with a similar computation amount is to be forced on-chain.\n *\n * @param options - Options\n * @param sign - Function which verifies and signs contract call transaction\n * @example\n * ```js\n * channel.callContract({\n * contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',\n * callData: 'cb_1111111111111111...',\n * amount: 0,\n * abiVersion: 1\n * }).then(({ accepted, signedTx }) => {\n * if (accepted) {\n * console.log('Contract called succesfully')\n * } else {\n * console.log('Contract call has been rejected')\n * }\n * })\n * ```\n */\n async callContract(\n {\n amount, callData, contract, abiVersion,\n }: CallContractOptions,\n sign: SignTx,\n ): Promise<{ accepted: boolean; signedTx: Encoded.Transaction }> {\n return this.enqueueAction(() => {\n notify(this, 'channels.update.call_contract', {\n amount,\n call_data: callData,\n contract_id: contract,\n abi_version: abiVersion,\n });\n return {\n handler: async (\n _: Channel,\n message: ChannelMessage,\n state: ChannelState,\n ): Promise<ChannelFsm> => {\n if (message.method !== 'channels.sign.update') {\n return handleUnexpectedMessage(this, message, state);\n }\n await signAndNotify(\n this,\n 'channels.update',\n message.params.data,\n async (tx) => state.sign(tx, { updates: message.params.data.updates }),\n );\n return {\n handler: (\n _2: Channel,\n message2: ChannelMessage,\n state2: ChannelState,\n ): ChannelFsm => (\n awaitingCompletion(this, message2, state2, () => {\n changeState(this, message2.params.data.state);\n state2.resolve({ accepted: true, signedTx: message2.params.data.state });\n return { handler: channelOpen };\n })\n ),\n state,\n };\n },\n state: { sign },\n };\n });\n }\n\n /**\n * Trigger a force progress contract call\n * This call is going on-chain\n * @param options - Options\n * @param sign - Function which verifies and signs contract force progress transaction\n * @param callbacks - Callbacks\n * @example\n * ```js\n * channel.forceProgress({\n * contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',\n * callData: 'cb_1111111111111111...',\n * amount: 0,\n * abiVersion: 1,\n * gasPrice: 1000005554\n * }).then(({ accepted, signedTx }) => {\n * if (accepted) {\n * console.log('Contract force progress call successful')\n * } else {\n * console.log('Contract force progress call has been rejected')\n * }\n * })\n * ```\n */\n async forceProgress(\n {\n amount, callData, contract, abiVersion, gasLimit = 1000000, gasPrice = MIN_GAS_PRICE,\n }: CallContractOptions & {\n gasLimit?: number;\n gasPrice?: number;\n },\n sign: SignTx,\n { onOnChainTx }: Pick<ChannelState, 'onOnChainTx'> = {},\n ): Promise<{\n accepted: boolean;\n signedTx: Encoded.Transaction;\n tx: Encoded.Transaction | Uint8Array;\n }> {\n return this.enqueueAction(() => {\n notify(this, 'channels.force_progress', {\n amount,\n call_data: callData,\n contract_id: contract,\n abi_version: abiVersion,\n gas_price: gasPrice,\n gas: gasLimit,\n });\n return {\n handler: async (\n _: Channel,\n message: ChannelMessage,\n state: ChannelState,\n ): Promise<ChannelFsm> => {\n if (message.method !== 'channels.sign.force_progress_tx') {\n return handleUnexpectedMessage(this, message, state);\n }\n await signAndNotify(\n this,\n 'channels.force_progress_sign',\n message.params.data,\n async (tx) => state.sign(tx, { updates: message.params.data.updates }),\n );\n return {\n handler: (\n _2: Channel,\n message2: ChannelMessage,\n state2: ChannelState,\n ): ChannelFsm => {\n if (message2.method === 'channels.on_chain_tx') {\n state2.onOnChainTx?.(message2.params.data.tx);\n emit(this, 'onChainTx', message2.params.data.tx, {\n info: message2.params.data.info,\n type: message2.params.data.type,\n });\n state2.resolve({ accepted: true, tx: message2.params.data.tx });\n // TODO: shouldn't be unexpected message in this case\n }\n return handleUnexpectedMessage(this, message2, state2);\n },\n state,\n };\n },\n state: { sign, onOnChainTx },\n };\n });\n }\n\n /**\n * Call contract using dry-run\n *\n * In order to get the result of a potential contract call, one might need to\n * dry-run a contract call. It takes the exact same arguments as a call would\n * and returns the call object.\n *\n * The call is executed in the channel's state, but it does not impact the state\n * whatsoever. It uses as an environment the latest channel's state and the current\n * top of the blockchain as seen by the node.\n *\n * @param options - Options\n * @example\n * ```js\n * channel.callContractStatic({\n * contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',\n * callData: 'cb_1111111111111111...',\n * amount: 0,\n * abiVersion: 1\n * }).then(({ returnValue, gasUsed }) => {\n * console.log('Returned value:', returnValue)\n * console.log('Gas used:', gasUsed)\n * })\n * ```\n */\n async callContractStatic(\n {\n amount, callData, contract, abiVersion,\n }: CallContractOptions,\n ): Promise<CallContractResult> {\n return snakeToPascalObjKeys(await call(this, 'channels.dry_run.call_contract', {\n amount,\n call_data: callData,\n contract_id: contract,\n abi_version: abiVersion,\n }));\n }\n\n /**\n * Get contract call result\n *\n * The combination of a caller, contract and a round of execution determines the\n * contract call. Providing an incorrect set of those results in an error response.\n *\n * @param options - Options\n * @param options.caller - Address of contract caller\n * @param options.contract - Address of the contract\n * @param options.round - Round when contract was called\n * @example\n * ```js\n * channel.getContractCall({\n * caller: 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',\n * contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',\n * round: 3\n * }).then(({ returnType, returnValue }) => {\n * if (returnType === 'ok') console.log(returnValue)\n * })\n * ```\n */\n async getContractCall(\n { caller, contract, round }: {\n caller: Encoded.AccountAddress;\n contract: Encoded.ContractAddress;\n round: number;\n },\n ): Promise<ContractCallObject> {\n return snakeToPascalObjKeys(\n await call(this, 'channels.get.contract_call', {\n caller_id: caller,\n contract_id: contract,\n round,\n }),\n );\n }\n\n /**\n * Get the latest contract state\n *\n * @param contract - Address of the contract\n * @example\n * ```js\n * channel.getContractState(\n * 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa'\n * ).then(({ contract }) => {\n * console.log('deposit:', contract.deposit)\n * })\n * ```\n */\n async getContractState(\n contract: Encoded.ContractAddress,\n ): Promise<{ contract: Contract; contractState: object }> {\n const result = await call(this, 'channels.get.contract', { pubkey: contract });\n return snakeToPascalObjKeys({\n ...result,\n contract: snakeToPascalObjKeys(result.contract),\n });\n }\n\n /**\n * Clean up all locally stored contract calls\n *\n * Contract calls are kept locally in order for the participant to be able to look them up.\n * They consume memory and in order for the participant to free it - one can prune all messages.\n * This cleans up all locally stored contract calls and those will no longer be available for\n * fetching and inspection.\n */\n async cleanContractCalls(): Promise<void> {\n return this.enqueueAction(() => {\n notify(this, 'channels.clean_contract_calls');\n return {\n handler(_: Channel, message: ChannelMessage, state: ChannelState): ChannelFsm {\n if (message.method === 'channels.calls_pruned.reply') {\n state.resolve();\n return { handler: channelOpen };\n }\n state.reject(new UnexpectedChannelMessageError('Unexpected message received'));\n return { handler: channelClosed };\n },\n };\n });\n }\n}\n"],"mappings":"SACSA,aAAa;AAAA,SAEpBC,aAAa,EAAEC,GAAG;AAAA,SAGlBC,aAAa,EACbC,kBAAkB,EAClBC,aAAa,EACbC,WAAW,EACXC,uBAAuB;AAAA,SAGvBC,MAAM,EAAEC,IAAI,E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