@aeternity/aepp-sdk 11.0.1 → 12.0.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/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +12 -19
- 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 +1 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdk.d.ts +37 -0
- package/es/AeSdk.mjs +81 -0
- package/es/AeSdk.mjs.map +1 -0
- package/es/AeSdkAepp.d.ts +69 -0
- package/es/AeSdkAepp.mjs +175 -0
- package/es/AeSdkAepp.mjs.map +1 -0
- package/es/AeSdkBase.d.ts +212 -0
- package/es/AeSdkBase.mjs +310 -0
- package/es/AeSdkBase.mjs.map +1 -0
- package/es/AeSdkWallet.d.ts +103 -0
- package/es/AeSdkWallet.mjs +322 -0
- package/es/AeSdkWallet.mjs.map +1 -0
- package/es/Node.d.ts +44 -0
- package/es/Node.mjs +141 -0
- package/es/Node.mjs.map +1 -0
- package/es/account/Base.d.ts +65 -0
- package/es/account/Base.mjs +123 -0
- package/es/account/Base.mjs.map +1 -0
- package/es/account/Memory.d.ts +25 -0
- package/es/account/Memory.mjs +81 -0
- package/es/account/Memory.mjs.map +1 -0
- package/es/account/Rpc.d.ts +27 -0
- package/es/account/Rpc.mjs +79 -0
- package/es/account/Rpc.mjs.map +1 -0
- package/es/aens.d.ts +209 -0
- package/es/aens.mjs +332 -0
- package/es/aens.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection/Browser.d.ts +32 -0
- package/es/aepp-wallet-communication/connection/Browser.mjs +70 -0
- package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +17 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +57 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +35 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +142 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection-proxy.d.ts +10 -0
- package/{src/utils/crypto-ts.ts → es/aepp-wallet-communication/connection-proxy.mjs} +15 -11
- package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +33 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +169 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -0
- package/es/aepp-wallet-communication/rpc/types.d.ts +77 -0
- package/es/aepp-wallet-communication/rpc/types.mjs +3 -0
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -0
- package/es/aepp-wallet-communication/schema.d.ts +90 -46
- package/es/aepp-wallet-communication/schema.mjs +214 -0
- package/es/aepp-wallet-communication/schema.mjs.map +1 -0
- package/es/aepp-wallet-communication/wallet-detector.d.ts +24 -0
- package/es/aepp-wallet-communication/wallet-detector.mjs +63 -0
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
- package/es/apis/compiler/compiler.d.ts +92 -0
- package/es/apis/compiler/compiler.mjs +576 -0
- package/es/apis/compiler/compiler.mjs.map +1 -0
- package/es/apis/compiler/index.d.ts +2 -0
- package/es/apis/compiler/index.mjs +3 -0
- package/es/apis/compiler/index.mjs.map +1 -0
- package/es/apis/compiler/models/index.d.ts +248 -0
- package/es/apis/compiler/models/index.mjs +48 -0
- package/es/apis/compiler/models/index.mjs.map +1 -0
- package/es/apis/compiler/models/mappers.d.ts +23 -0
- package/es/apis/compiler/models/mappers.mjs +585 -0
- package/es/apis/compiler/models/mappers.mjs.map +1 -0
- package/es/apis/compiler/models/parameters.d.ts +13 -0
- package/es/apis/compiler/models/parameters.mjs +71 -0
- package/es/apis/compiler/models/parameters.mjs.map +1 -0
- package/es/apis/node/index.d.ts +2 -0
- package/es/apis/node/index.mjs +3 -0
- package/es/apis/node/index.mjs.map +1 -0
- package/es/apis/node/models/index.d.ts +1061 -0
- package/es/apis/node/models/index.mjs +2 -0
- package/es/apis/node/models/index.mjs.map +1 -0
- package/es/apis/node/models/mappers.d.ts +95 -0
- package/es/apis/node/models/mappers.mjs +4164 -0
- package/es/apis/node/models/mappers.mjs.map +1 -0
- package/es/apis/node/models/parameters.d.ts +17 -0
- package/es/apis/node/models/parameters.mjs +165 -0
- package/es/apis/node/models/parameters.mjs.map +1 -0
- package/es/apis/node/node.d.ts +215 -0
- package/es/apis/node/node.mjs +1165 -0
- package/es/apis/node/node.mjs.map +1 -0
- package/es/chain.d.ts +220 -0
- package/es/chain.mjs +524 -0
- package/es/chain.mjs.map +1 -0
- package/es/channel/handlers.d.ts +34 -0
- package/es/channel/handlers.mjs +147 -112
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/index.d.ts +634 -0
- package/es/channel/index.mjs +898 -900
- package/es/channel/index.mjs.map +1 -1
- package/es/channel/internal.d.ts +100 -0
- package/es/channel/internal.mjs +97 -51
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Compiler.d.ts +17 -0
- package/es/contract/Compiler.mjs +67 -0
- package/es/contract/Compiler.mjs.map +1 -0
- package/es/contract/aci.d.ts +125 -0
- package/es/contract/aci.mjs +199 -180
- package/es/contract/aci.mjs.map +1 -1
- package/es/contract/ga.d.ts +68 -0
- package/es/contract/ga.mjs +190 -0
- package/es/contract/ga.mjs.map +1 -0
- package/es/contract/methods.d.ts +68 -0
- package/es/contract/methods.mjs +101 -0
- package/es/contract/methods.mjs.map +1 -0
- package/es/index.d.ts +32 -0
- package/es/index.mjs +32 -40
- package/es/index.mjs.map +1 -1
- package/es/oracle.d.ts +154 -0
- package/es/oracle.mjs +288 -0
- package/es/oracle.mjs.map +1 -0
- package/es/spend.d.ts +61 -0
- package/es/spend.mjs +122 -0
- package/es/spend.mjs.map +1 -0
- package/es/tx/builder/constants.d.ts +41 -0
- package/es/tx/builder/constants.mjs +11 -19
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/field-types.d.ts +62 -0
- package/es/tx/builder/field-types.mjs +62 -10
- package/es/tx/builder/field-types.mjs.map +1 -1
- package/es/tx/builder/helpers.d.ts +131 -0
- package/es/tx/builder/helpers.mjs +71 -169
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +75 -0
- package/es/tx/builder/index.mjs +141 -323
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +350 -0
- package/es/tx/builder/schema.mjs +173 -510
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +63 -0
- package/es/tx/index.mjs +171 -265
- package/es/tx/index.mjs.map +1 -1
- package/es/tx/min-fee.d.ts +20 -0
- package/es/tx/min-fee.mjs +148 -0
- package/es/tx/min-fee.mjs.map +1 -0
- package/es/tx/validator.d.ts +19 -0
- package/es/tx/validator.mjs +64 -71
- package/es/tx/validator.mjs.map +1 -1
- package/es/typings/@aeternity__argon2-browser/index.d.mjs +2 -0
- package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -0
- package/es/typings/@aeternity__uuid/index.d.mjs +2 -0
- package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -0
- package/es/typings/bip32-path/index.d.mjs +2 -0
- package/es/typings/bip32-path/index.d.mjs.map +1 -0
- package/es/typings/blakejs/index.d.mjs.map +1 -1
- package/es/typings/tweetnacl-auth/index.d.mjs +2 -0
- package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -0
- package/es/utils/amount-formatter.d.ts +42 -0
- package/es/utils/amount-formatter.mjs +28 -41
- package/es/utils/amount-formatter.mjs.map +1 -1
- package/es/utils/autorest.d.ts +6 -0
- package/es/utils/autorest.mjs +97 -0
- package/es/utils/autorest.mjs.map +1 -0
- package/es/utils/bignumber.d.ts +13 -0
- package/es/utils/bignumber.mjs +10 -8
- package/es/utils/bignumber.mjs.map +1 -1
- package/es/{bytes.d.ts → utils/bytes.d.ts} +10 -13
- package/es/utils/bytes.mjs +10 -14
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.d.ts +103 -0
- package/es/utils/crypto.mjs +60 -68
- package/es/utils/crypto.mjs.map +1 -1
- package/es/utils/encoder.d.ts +26 -0
- package/es/utils/encoder.mjs +47 -51
- package/es/utils/encoder.mjs.map +1 -1
- package/es/{errors.d.ts → utils/errors.d.ts} +254 -57
- package/es/utils/errors.mjs +318 -125
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.d.ts +34 -0
- package/es/utils/hd-wallet.mjs +27 -16
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/json-big.d.ts +5 -0
- package/es/utils/json-big.mjs +10 -14
- package/es/utils/json-big.mjs.map +1 -1
- package/es/utils/keystore.d.ts +51 -0
- package/es/utils/keystore.mjs +98 -193
- package/es/utils/keystore.mjs.map +1 -1
- package/es/{mptree.d.ts → utils/mptree.d.ts} +5 -8
- package/es/utils/mptree.mjs +13 -14
- package/es/utils/mptree.mjs.map +1 -1
- package/es/utils/other.d.ts +14 -0
- package/es/utils/other.mjs +21 -36
- package/es/utils/other.mjs.map +1 -1
- package/es/{semver-satisfies.d.ts → utils/semver-satisfies.d.ts} +0 -0
- package/es/utils/semver-satisfies.mjs.map +1 -1
- package/es/utils/string.d.ts +24 -0
- package/es/utils/string.mjs +8 -10
- package/es/utils/string.mjs.map +1 -1
- package/package.json +49 -39
- package/src/AeSdk.ts +65 -0
- package/src/AeSdkAepp.ts +167 -0
- package/src/AeSdkBase.ts +320 -0
- package/src/AeSdkWallet.ts +332 -0
- package/src/Node.ts +167 -0
- package/src/account/Base.ts +114 -0
- package/src/account/Memory.ts +83 -0
- package/src/account/Rpc.ts +67 -0
- package/src/aens.ts +391 -0
- package/src/aepp-wallet-communication/connection/Browser.ts +68 -0
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +58 -0
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +111 -0
- package/{es/utils/crypto-ts.mjs → src/aepp-wallet-communication/connection-proxy.ts} +16 -17
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +137 -0
- package/src/aepp-wallet-communication/rpc/types.ts +66 -0
- package/src/aepp-wallet-communication/schema.ts +181 -0
- package/src/aepp-wallet-communication/wallet-detector.ts +71 -0
- package/src/apis/compiler/code-model-v4.yaml +2649 -0
- package/src/apis/compiler/compiler.ts +585 -0
- package/src/apis/compiler/index.ts +2 -0
- package/src/apis/compiler/models/index.ts +301 -0
- package/src/apis/compiler/models/mappers.ts +583 -0
- package/src/apis/compiler/models/parameters.ts +93 -0
- package/src/apis/node/code-model-v4.yaml +10046 -0
- package/src/apis/node/index.ts +2 -0
- package/src/apis/node/models/index.ts +1253 -0
- package/src/apis/node/models/mappers.ts +4278 -0
- package/src/apis/node/models/parameters.ts +188 -0
- package/src/apis/node/node.ts +1299 -0
- package/src/chain.ts +444 -0
- package/src/channel/{handlers.js → handlers.ts} +220 -128
- package/src/channel/index.ts +991 -0
- package/src/channel/internal.ts +345 -0
- package/src/contract/Compiler.ts +66 -0
- package/src/contract/aci.ts +529 -0
- package/src/contract/ga.ts +178 -0
- package/src/contract/methods.ts +118 -0
- package/src/index.ts +51 -0
- package/src/oracle.ts +342 -0
- package/src/spend.ts +152 -0
- package/src/tx/builder/{constants.js → constants.ts} +12 -16
- package/src/tx/builder/field-types.ts +111 -0
- package/src/tx/builder/helpers.ts +253 -0
- package/src/tx/builder/index.ts +394 -0
- package/src/tx/builder/schema.ts +771 -0
- package/src/tx/index.ts +199 -0
- package/src/tx/min-fee.ts +136 -0
- package/src/tx/validator.ts +226 -0
- package/src/typings/@aeternity__argon2-browser/index.d.ts +3 -0
- package/src/typings/@aeternity__uuid/index.d.ts +3 -0
- package/src/typings/bip32-path/index.d.ts +33 -0
- package/src/typings/tweetnacl-auth/index.d.ts +14 -0
- package/src/utils/amount-formatter.ts +29 -42
- package/src/utils/autorest.ts +90 -0
- package/src/utils/bignumber.ts +9 -11
- package/src/utils/bytes.ts +12 -14
- package/src/utils/crypto.ts +217 -0
- package/src/utils/encoder.ts +52 -55
- package/src/utils/errors.ts +268 -134
- package/src/utils/hd-wallet.ts +134 -0
- package/src/utils/json-big.ts +26 -0
- package/src/utils/keystore.ts +179 -0
- package/src/utils/mptree.ts +14 -14
- package/src/utils/other.ts +28 -43
- package/src/utils/string.ts +8 -10
- package/es/account/base.mjs +0 -179
- package/es/account/base.mjs.map +0 -1
- package/es/account/memory.mjs +0 -99
- package/es/account/memory.mjs.map +0 -1
- package/es/account/multiple.mjs +0 -179
- package/es/account/multiple.mjs.map +0 -1
- package/es/ae/aens.mjs +0 -404
- package/es/ae/aens.mjs.map +0 -1
- package/es/ae/aepp.mjs +0 -45
- package/es/ae/aepp.mjs.map +0 -1
- package/es/ae/contract.mjs +0 -159
- package/es/ae/contract.mjs.map +0 -1
- package/es/ae/index.mjs +0 -207
- package/es/ae/index.mjs.map +0 -1
- package/es/ae/oracle.mjs +0 -339
- package/es/ae/oracle.mjs.map +0 -1
- package/es/ae/universal.mjs +0 -45
- package/es/ae/universal.mjs.map +0 -1
- package/es/ae/wallet.mjs +0 -50
- package/es/ae/wallet.mjs.map +0 -1
- package/es/amount-formatter.d.ts +0 -58
- package/es/bignumber.d.ts +0 -18
- package/es/chain/index.mjs +0 -272
- package/es/chain/index.mjs.map +0 -1
- package/es/chain/node.mjs +0 -442
- package/es/chain/node.mjs.map +0 -1
- package/es/contract/compiler.mjs +0 -115
- package/es/contract/compiler.mjs.map +0 -1
- package/es/contract/ga/helpers.mjs +0 -30
- package/es/contract/ga/helpers.mjs.map +0 -1
- package/es/contract/ga/index.mjs +0 -178
- package/es/contract/ga/index.mjs.map +0 -1
- package/es/crypto-ts.d.ts +0 -9
- package/es/encoder.d.ts +0 -26
- package/es/node-pool/index.mjs +0 -188
- package/es/node-pool/index.mjs.map +0 -1
- package/es/node.mjs +0 -133
- package/es/node.mjs.map +0 -1
- package/es/other.d.ts +0 -31
- package/es/string.d.ts +0 -26
- package/es/tx/tx-object.mjs +0 -283
- package/es/tx/tx-object.mjs.map +0 -1
- package/es/tx/tx.mjs +0 -938
- package/es/tx/tx.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs +0 -132
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +0 -183
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/index.mjs +0 -87
- package/es/utils/aepp-wallet-communication/connection/index.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.mjs +0 -98
- package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/helpers.mjs +0 -92
- package/es/utils/aepp-wallet-communication/helpers.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +0 -375
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +0 -275
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +0 -541
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/schema.mjs +0 -102
- package/es/utils/aepp-wallet-communication/schema.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs +0 -110
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +0 -1
- package/es/utils/async-init.mjs +0 -64
- package/es/utils/async-init.mjs.map +0 -1
- package/es/utils/crypto-ts.mjs.map +0 -1
- package/es/utils/swagger.mjs +0 -164
- package/es/utils/swagger.mjs.map +0 -1
- package/src/account/base.js +0 -153
- package/src/account/memory.js +0 -83
- package/src/account/multiple.js +0 -162
- package/src/ae/aens.js +0 -361
- package/src/ae/aepp.js +0 -45
- package/src/ae/contract.js +0 -148
- package/src/ae/index.js +0 -168
- package/src/ae/oracle.js +0 -311
- package/src/ae/universal.js +0 -47
- package/src/ae/wallet.js +0 -50
- package/src/chain/index.js +0 -269
- package/src/chain/node.js +0 -320
- package/src/channel/index.js +0 -903
- package/src/channel/internal.js +0 -236
- package/src/contract/aci.js +0 -376
- package/src/contract/compiler.js +0 -100
- package/src/contract/ga/helpers.js +0 -19
- package/src/contract/ga/index.js +0 -150
- package/src/index.js +0 -89
- package/src/node-pool/index.js +0 -172
- package/src/node.js +0 -116
- package/src/tx/builder/field-types.js +0 -61
- package/src/tx/builder/helpers.js +0 -334
- package/src/tx/builder/index.js +0 -465
- package/src/tx/builder/schema.js +0 -1100
- package/src/tx/index.js +0 -301
- package/src/tx/tx-object.js +0 -187
- package/src/tx/tx.js +0 -631
- package/src/tx/validator.js +0 -181
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -119
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -165
- package/src/utils/aepp-wallet-communication/connection/index.js +0 -85
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +0 -86
- package/src/utils/aepp-wallet-communication/helpers.js +0 -60
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -294
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -232
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -401
- package/src/utils/aepp-wallet-communication/schema.ts +0 -80
- package/src/utils/aepp-wallet-communication/wallet-detector.js +0 -92
- package/src/utils/async-init.js +0 -45
- package/src/utils/crypto.js +0 -219
- package/src/utils/hd-wallet.js +0 -100
- package/src/utils/json-big.js +0 -26
- package/src/utils/keystore.js +0 -219
- package/src/utils/swagger.js +0 -156
package/es/chain.mjs
ADDED
|
@@ -0,0 +1,524 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ISC License (ISC)
|
|
3
|
+
* Copyright (c) 2022 aeternity developers
|
|
4
|
+
*
|
|
5
|
+
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
* purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
* copyright notice and this permission notice appear in all copies.
|
|
8
|
+
*
|
|
9
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
*/
|
|
17
|
+
import { AE_AMOUNT_FORMATS, formatAmount } from "./utils/amount-formatter.mjs";
|
|
18
|
+
import verifyTransaction from "./tx/validator.mjs";
|
|
19
|
+
import { pause } from "./utils/other.mjs";
|
|
20
|
+
import { isNameValid, produceNameId, decode } from "./tx/builder/helpers.mjs";
|
|
21
|
+
import { DRY_RUN_ACCOUNT } from "./tx/builder/schema.mjs";
|
|
22
|
+
import { AensPointerContextError, DryRunError, InvalidAensNameError, InvalidTxError, RequestTimedOutError, TxTimedOutError, TxNotInChainError, InternalError } from "./utils/errors.mjs";
|
|
23
|
+
export function _getPollInterval(type, _ref) {
|
|
24
|
+
let {
|
|
25
|
+
_expectedMineRate = 180000,
|
|
26
|
+
_microBlockCycle = 3000,
|
|
27
|
+
_maxPollInterval = 5000
|
|
28
|
+
} = _ref;
|
|
29
|
+
const base = {
|
|
30
|
+
block: _expectedMineRate,
|
|
31
|
+
microblock: _microBlockCycle
|
|
32
|
+
}[type];
|
|
33
|
+
return Math.min(base / 3, _maxPollInterval);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Submit a signed transaction for mining
|
|
37
|
+
* @param tx - Transaction to submit
|
|
38
|
+
* @param options - Options
|
|
39
|
+
* @param options.onNode - Node to use
|
|
40
|
+
* @param options.onAccount - Account to use
|
|
41
|
+
* @param options.verify - Verify transaction before sending
|
|
42
|
+
* @param options.waitMined - Ensure that transaction get into block
|
|
43
|
+
* @param options.confirm - Number of micro blocks that should be mined after tx get included
|
|
44
|
+
* @returns Transaction details
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
export async function sendTransaction(tx, _ref2) {
|
|
48
|
+
let {
|
|
49
|
+
onNode,
|
|
50
|
+
onAccount,
|
|
51
|
+
verify = true,
|
|
52
|
+
waitMined = true,
|
|
53
|
+
confirm,
|
|
54
|
+
...options
|
|
55
|
+
} = _ref2;
|
|
56
|
+
|
|
57
|
+
if (verify) {
|
|
58
|
+
const validation = await verifyTransaction(tx, onNode);
|
|
59
|
+
|
|
60
|
+
if (validation.length > 0) {
|
|
61
|
+
const message = 'Transaction verification errors: ' + validation.map(v => v.message).join(', ');
|
|
62
|
+
throw new InvalidTxError(message, validation, tx);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
var _await$onAccount$addr;
|
|
68
|
+
|
|
69
|
+
const {
|
|
70
|
+
txHash
|
|
71
|
+
} = await onNode.postTransaction({
|
|
72
|
+
tx
|
|
73
|
+
}, {
|
|
74
|
+
requestOptions: {
|
|
75
|
+
customHeaders: {
|
|
76
|
+
__queue: `tx-${(_await$onAccount$addr = await (onAccount === null || onAccount === void 0 ? void 0 : onAccount.address(options).catch(() => ''))) !== null && _await$onAccount$addr !== void 0 ? _await$onAccount$addr : ''}`
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
if (waitMined) {
|
|
82
|
+
const pollResult = await poll(txHash, {
|
|
83
|
+
onNode,
|
|
84
|
+
...options
|
|
85
|
+
});
|
|
86
|
+
const txData = { ...pollResult,
|
|
87
|
+
hash: pollResult.hash,
|
|
88
|
+
rawTx: tx
|
|
89
|
+
}; // wait for transaction confirmation
|
|
90
|
+
|
|
91
|
+
if (confirm != null && (confirm === true || confirm > 0)) {
|
|
92
|
+
const c = typeof confirm === 'boolean' ? undefined : confirm;
|
|
93
|
+
return { ...txData,
|
|
94
|
+
confirmationHeight: await waitForTxConfirm(txHash, {
|
|
95
|
+
onNode,
|
|
96
|
+
confirm: c,
|
|
97
|
+
...options
|
|
98
|
+
})
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return txData;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
hash: txHash,
|
|
107
|
+
rawTx: tx
|
|
108
|
+
};
|
|
109
|
+
} catch (error) {
|
|
110
|
+
throw Object.assign(error, {
|
|
111
|
+
rawTx: tx,
|
|
112
|
+
verifyTx: async () => await verifyTransaction(tx, onNode)
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Wait for transaction confirmation
|
|
119
|
+
* @param txHash - Transaction hash
|
|
120
|
+
* @param options - Options
|
|
121
|
+
* @param options.confirm - Number of micro blocks to wait for transaction confirmation
|
|
122
|
+
* @param options.onNode - Node to use
|
|
123
|
+
* @returns Current Height
|
|
124
|
+
*/
|
|
125
|
+
export async function waitForTxConfirm(txHash, _ref3) {
|
|
126
|
+
let {
|
|
127
|
+
confirm = 3,
|
|
128
|
+
onNode,
|
|
129
|
+
...options
|
|
130
|
+
} = _ref3;
|
|
131
|
+
const {
|
|
132
|
+
blockHeight
|
|
133
|
+
} = await onNode.getTransactionByHash(txHash);
|
|
134
|
+
const height = await awaitHeight(blockHeight + confirm, {
|
|
135
|
+
onNode,
|
|
136
|
+
...options
|
|
137
|
+
});
|
|
138
|
+
const {
|
|
139
|
+
blockHeight: newBlockHeight
|
|
140
|
+
} = await onNode.getTransactionByHash(txHash);
|
|
141
|
+
|
|
142
|
+
switch (newBlockHeight) {
|
|
143
|
+
case -1:
|
|
144
|
+
throw new TxNotInChainError(txHash);
|
|
145
|
+
|
|
146
|
+
case blockHeight:
|
|
147
|
+
return height;
|
|
148
|
+
|
|
149
|
+
default:
|
|
150
|
+
return await waitForTxConfirm(txHash, {
|
|
151
|
+
onNode,
|
|
152
|
+
confirm,
|
|
153
|
+
...options
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Get account by account public key
|
|
159
|
+
* @param address - Account address (public key)
|
|
160
|
+
* @param options - Options
|
|
161
|
+
* @param options.height - Get account on specific block by block height
|
|
162
|
+
* @param options.hash - Get account on specific block by micro block hash or key block hash
|
|
163
|
+
* @param options.onNode - Node to use
|
|
164
|
+
*/
|
|
165
|
+
|
|
166
|
+
export async function getAccount(address, _ref4) {
|
|
167
|
+
let {
|
|
168
|
+
height,
|
|
169
|
+
hash,
|
|
170
|
+
onNode
|
|
171
|
+
} = _ref4;
|
|
172
|
+
if (height != null) return await onNode.getAccountByPubkeyAndHeight(address, height);
|
|
173
|
+
if (hash != null) return await onNode.getAccountByPubkeyAndHash(address, hash);
|
|
174
|
+
return await onNode.getAccountByPubkey(address);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Request the balance of specified account
|
|
178
|
+
* @param address - The public account address to obtain the balance for
|
|
179
|
+
* @param options - Options
|
|
180
|
+
* @param options.format
|
|
181
|
+
* @param options.height - The chain height at which to obtain the balance for
|
|
182
|
+
* (default: top of chain)
|
|
183
|
+
* @param options.hash - The block hash on which to obtain the balance for (default: top of chain)
|
|
184
|
+
*/
|
|
185
|
+
|
|
186
|
+
export async function getBalance(address, _ref5) {
|
|
187
|
+
let {
|
|
188
|
+
format = AE_AMOUNT_FORMATS.AETTOS,
|
|
189
|
+
...options
|
|
190
|
+
} = _ref5;
|
|
191
|
+
const {
|
|
192
|
+
balance
|
|
193
|
+
} = await getAccount(address, options).catch(() => ({
|
|
194
|
+
balance: 0n
|
|
195
|
+
}));
|
|
196
|
+
return formatAmount(balance, {
|
|
197
|
+
targetDenomination: format
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Obtain current height of the chain
|
|
202
|
+
* @returns Current chain height
|
|
203
|
+
*/
|
|
204
|
+
|
|
205
|
+
export async function height(_ref6) {
|
|
206
|
+
let {
|
|
207
|
+
onNode
|
|
208
|
+
} = _ref6;
|
|
209
|
+
return (await onNode.getCurrentKeyBlockHeight()).height;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Wait for the chain to reach a specific height
|
|
213
|
+
* @param height - Height to wait for
|
|
214
|
+
* @param options - Options
|
|
215
|
+
* @param options.interval - Interval (in ms) at which to poll the chain
|
|
216
|
+
* @param options.attempts - Number of polling attempts after which to fail
|
|
217
|
+
* @param options.onNode - Node to use
|
|
218
|
+
* @returns Current chain height
|
|
219
|
+
*/
|
|
220
|
+
|
|
221
|
+
export async function awaitHeight(height, _ref7) {
|
|
222
|
+
var _interval;
|
|
223
|
+
|
|
224
|
+
let {
|
|
225
|
+
interval,
|
|
226
|
+
attempts = 20,
|
|
227
|
+
onNode,
|
|
228
|
+
...options
|
|
229
|
+
} = _ref7;
|
|
230
|
+
(_interval = interval) !== null && _interval !== void 0 ? _interval : interval = _getPollInterval('block', options);
|
|
231
|
+
let currentHeight;
|
|
232
|
+
|
|
233
|
+
for (let i = 0; i < attempts; i++) {
|
|
234
|
+
if (i !== 0) await pause(interval);
|
|
235
|
+
currentHeight = (await onNode.getCurrentKeyBlockHeight()).height;
|
|
236
|
+
if (currentHeight >= height) return currentHeight;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
throw new RequestTimedOutError((attempts - 1) * interval, currentHeight, height);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Wait for a transaction to be mined
|
|
243
|
+
* @param th - The hash of transaction to poll
|
|
244
|
+
* @param options - Options
|
|
245
|
+
* @param options.interval - Interval (in ms) at which to poll the chain
|
|
246
|
+
* @param options.blocks - Number of blocks mined after which to fail
|
|
247
|
+
* @param options.onNode - Node to use
|
|
248
|
+
* @returns The transaction as it was mined
|
|
249
|
+
*/
|
|
250
|
+
|
|
251
|
+
export async function poll(th, _ref8) {
|
|
252
|
+
var _interval2;
|
|
253
|
+
|
|
254
|
+
let {
|
|
255
|
+
blocks = 10,
|
|
256
|
+
interval,
|
|
257
|
+
onNode,
|
|
258
|
+
...options
|
|
259
|
+
} = _ref8;
|
|
260
|
+
(_interval2 = interval) !== null && _interval2 !== void 0 ? _interval2 : interval = _getPollInterval('microblock', options);
|
|
261
|
+
const max = (await height({
|
|
262
|
+
onNode
|
|
263
|
+
})) + blocks;
|
|
264
|
+
|
|
265
|
+
do {
|
|
266
|
+
const tx = await onNode.getTransactionByHash(th);
|
|
267
|
+
if (tx.blockHeight !== -1) return tx;
|
|
268
|
+
await pause(interval);
|
|
269
|
+
} while ((await height({
|
|
270
|
+
onNode
|
|
271
|
+
})) < max);
|
|
272
|
+
|
|
273
|
+
throw new TxTimedOutError(blocks, th);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Obtain current generation
|
|
277
|
+
* @param options - Options
|
|
278
|
+
* @param options.onNode - Node to use
|
|
279
|
+
* @returns Current Generation
|
|
280
|
+
*/
|
|
281
|
+
|
|
282
|
+
export async function getCurrentGeneration(_ref9) {
|
|
283
|
+
let {
|
|
284
|
+
onNode
|
|
285
|
+
} = _ref9;
|
|
286
|
+
return await onNode.getCurrentGeneration();
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Get generation by hash or height
|
|
290
|
+
* @param hashOrHeight - Generation hash or height
|
|
291
|
+
* @param options - Options
|
|
292
|
+
* @param options.onNode - Node to use
|
|
293
|
+
* @returns Generation
|
|
294
|
+
*/
|
|
295
|
+
|
|
296
|
+
export async function getGeneration(hashOrHeight, _ref10) {
|
|
297
|
+
let {
|
|
298
|
+
onNode
|
|
299
|
+
} = _ref10;
|
|
300
|
+
if (typeof hashOrHeight === 'number') return await onNode.getGenerationByHeight(hashOrHeight);
|
|
301
|
+
return await onNode.getGenerationByHash(hashOrHeight);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Get micro block transactions
|
|
305
|
+
* @param hash - Micro block hash
|
|
306
|
+
* @param options - Options
|
|
307
|
+
* @param options.onNode - Node to use
|
|
308
|
+
* @returns Transactions
|
|
309
|
+
*/
|
|
310
|
+
|
|
311
|
+
export async function getMicroBlockTransactions(hash, _ref11) {
|
|
312
|
+
let {
|
|
313
|
+
onNode
|
|
314
|
+
} = _ref11;
|
|
315
|
+
return (await onNode.getMicroBlockTransactionsByHash(hash)).transactions;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Get key block
|
|
319
|
+
* @param hashOrHeight - Key block hash or height
|
|
320
|
+
* @param options - Options
|
|
321
|
+
* @param options.onNode - Node to use
|
|
322
|
+
* @returns Key Block
|
|
323
|
+
*/
|
|
324
|
+
|
|
325
|
+
export async function getKeyBlock(hashOrHeight, _ref12) {
|
|
326
|
+
let {
|
|
327
|
+
onNode
|
|
328
|
+
} = _ref12;
|
|
329
|
+
if (typeof hashOrHeight === 'number') return await onNode.getKeyBlockByHeight(hashOrHeight);
|
|
330
|
+
return await onNode.getKeyBlockByHash(hashOrHeight);
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Get micro block header
|
|
334
|
+
* @param hash - Micro block hash
|
|
335
|
+
* @param options - Options
|
|
336
|
+
* @param options.onNode - Node to use
|
|
337
|
+
* @returns Micro block header
|
|
338
|
+
*/
|
|
339
|
+
|
|
340
|
+
export async function getMicroBlockHeader(hash, _ref13) {
|
|
341
|
+
let {
|
|
342
|
+
onNode
|
|
343
|
+
} = _ref13;
|
|
344
|
+
return await onNode.getMicroBlockHeaderByHash(hash);
|
|
345
|
+
}
|
|
346
|
+
const txDryRunRequests = new Map();
|
|
347
|
+
|
|
348
|
+
async function txDryRunHandler(key, onNode) {
|
|
349
|
+
const rs = txDryRunRequests.get(key);
|
|
350
|
+
txDryRunRequests.delete(key);
|
|
351
|
+
if (rs == null) throw new InternalError('Can\'t get dry-run request');
|
|
352
|
+
let dryRunRes;
|
|
353
|
+
|
|
354
|
+
try {
|
|
355
|
+
dryRunRes = await onNode.protectedDryRunTxs({
|
|
356
|
+
top: rs[0].top,
|
|
357
|
+
txEvents: rs[0].txEvents,
|
|
358
|
+
txs: rs.map(req => ({
|
|
359
|
+
tx: req.tx
|
|
360
|
+
})),
|
|
361
|
+
accounts: Array.from(new Set(rs.map(req => req.accountAddress))).map(pubKey => ({
|
|
362
|
+
pubKey,
|
|
363
|
+
amount: DRY_RUN_ACCOUNT.amount
|
|
364
|
+
}))
|
|
365
|
+
});
|
|
366
|
+
} catch (error) {
|
|
367
|
+
rs.forEach(_ref14 => {
|
|
368
|
+
let {
|
|
369
|
+
reject
|
|
370
|
+
} = _ref14;
|
|
371
|
+
return reject(error);
|
|
372
|
+
});
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const {
|
|
377
|
+
results,
|
|
378
|
+
txEvents
|
|
379
|
+
} = dryRunRes;
|
|
380
|
+
results.forEach((_ref15, idx) => {
|
|
381
|
+
let {
|
|
382
|
+
result,
|
|
383
|
+
reason,
|
|
384
|
+
...resultPayload
|
|
385
|
+
} = _ref15;
|
|
386
|
+
const {
|
|
387
|
+
resolve,
|
|
388
|
+
reject,
|
|
389
|
+
tx,
|
|
390
|
+
accountAddress
|
|
391
|
+
} = rs[idx];
|
|
392
|
+
if (result === 'ok') return resolve({ ...resultPayload,
|
|
393
|
+
txEvents
|
|
394
|
+
});
|
|
395
|
+
reject(Object.assign(new DryRunError(reason), {
|
|
396
|
+
tx,
|
|
397
|
+
accountAddress
|
|
398
|
+
}));
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Transaction dry-run
|
|
403
|
+
* @param tx - transaction to execute
|
|
404
|
+
* @param accountAddress - address that will be used to execute transaction
|
|
405
|
+
* @param options - Options
|
|
406
|
+
* @param options.top - hash of block on which to make dry-run
|
|
407
|
+
* @param options.txEvents - collect and return on-chain tx events that would result from the call
|
|
408
|
+
* @param options.combine - Enables combining of similar requests to a single dry-run call
|
|
409
|
+
* @param options.onNode - Node to use
|
|
410
|
+
*/
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
export async function txDryRun(tx, accountAddress, _ref16) {
|
|
414
|
+
var _txDryRunRequests$get;
|
|
415
|
+
|
|
416
|
+
let {
|
|
417
|
+
top,
|
|
418
|
+
txEvents,
|
|
419
|
+
combine,
|
|
420
|
+
onNode
|
|
421
|
+
} = _ref16;
|
|
422
|
+
const key = combine === true ? [top, txEvents].join() : 'immediate';
|
|
423
|
+
const requests = (_txDryRunRequests$get = txDryRunRequests.get(key)) !== null && _txDryRunRequests$get !== void 0 ? _txDryRunRequests$get : [];
|
|
424
|
+
txDryRunRequests.set(key, requests);
|
|
425
|
+
return await new Promise((resolve, reject) => {
|
|
426
|
+
var _requests$timeout;
|
|
427
|
+
|
|
428
|
+
requests.push({
|
|
429
|
+
tx,
|
|
430
|
+
accountAddress,
|
|
431
|
+
top,
|
|
432
|
+
txEvents,
|
|
433
|
+
resolve,
|
|
434
|
+
reject
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
if (combine !== true) {
|
|
438
|
+
void txDryRunHandler(key, onNode);
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
(_requests$timeout = requests.timeout) !== null && _requests$timeout !== void 0 ? _requests$timeout : requests.timeout = setTimeout(() => {
|
|
443
|
+
void txDryRunHandler(key, onNode);
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Get contract byte code
|
|
449
|
+
* @param contractId - Contract address
|
|
450
|
+
* @param options - Options
|
|
451
|
+
* @param options.onNode - Node to use
|
|
452
|
+
*/
|
|
453
|
+
|
|
454
|
+
export async function getContractByteCode(contractId, _ref17) {
|
|
455
|
+
let {
|
|
456
|
+
onNode
|
|
457
|
+
} = _ref17;
|
|
458
|
+
return await onNode.getContractCode(contractId);
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Get contract entry
|
|
462
|
+
* @param contractId - Contract address
|
|
463
|
+
* @param options - Options
|
|
464
|
+
* @param options.onNode - Node to use
|
|
465
|
+
*/
|
|
466
|
+
|
|
467
|
+
export async function getContract(contractId, _ref18) {
|
|
468
|
+
let {
|
|
469
|
+
onNode
|
|
470
|
+
} = _ref18;
|
|
471
|
+
return await onNode.getContract(contractId);
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Get name entry
|
|
475
|
+
* @param name - AENS name
|
|
476
|
+
* @param options - Options
|
|
477
|
+
* @param options.onNode - Node to use
|
|
478
|
+
*/
|
|
479
|
+
|
|
480
|
+
export async function getName(name, _ref19) {
|
|
481
|
+
let {
|
|
482
|
+
onNode
|
|
483
|
+
} = _ref19;
|
|
484
|
+
return await onNode.getNameEntryByName(name);
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Resolve AENS name and return name hash
|
|
488
|
+
* @param nameOrId - AENS name or address
|
|
489
|
+
* @param key - in AENS pointers record
|
|
490
|
+
* @param options - Options
|
|
491
|
+
* @param options.verify - To ensure that name exist and have a corresponding pointer
|
|
492
|
+
* // TODO: avoid that to don't trust to current api gateway
|
|
493
|
+
* @param options.resolveByNode - Enables pointer resolving using node
|
|
494
|
+
* @param options.onNode - Node to use
|
|
495
|
+
* @returns Address or AENS name hash
|
|
496
|
+
*/
|
|
497
|
+
|
|
498
|
+
export async function resolveName(nameOrId, key, _ref20) {
|
|
499
|
+
let {
|
|
500
|
+
verify = true,
|
|
501
|
+
resolveByNode = false,
|
|
502
|
+
onNode
|
|
503
|
+
} = _ref20;
|
|
504
|
+
|
|
505
|
+
try {
|
|
506
|
+
const id = nameOrId;
|
|
507
|
+
decode(id);
|
|
508
|
+
return id;
|
|
509
|
+
} catch (error) {}
|
|
510
|
+
|
|
511
|
+
if (isNameValid(nameOrId)) {
|
|
512
|
+
if (verify || resolveByNode) {
|
|
513
|
+
const name = await onNode.getNameEntryByName(nameOrId);
|
|
514
|
+
const pointer = name.pointers.find(pointer => pointer.key === key);
|
|
515
|
+
if (pointer == null) throw new AensPointerContextError(nameOrId, key);
|
|
516
|
+
if (resolveByNode) return pointer.id;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
return produceNameId(nameOrId);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
throw new InvalidAensNameError(`Invalid name or address: ${nameOrId}`);
|
|
523
|
+
}
|
|
524
|
+
//# sourceMappingURL=chain.mjs.map
|
package/es/chain.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.mjs","names":["AE_AMOUNT_FORMATS","formatAmount","verifyTransaction","pause","isNameValid","produceNameId","decode","DRY_RUN_ACCOUNT","AensPointerContextError","DryRunError","InvalidAensNameError","InvalidTxError","RequestTimedOutError","TxTimedOutError","TxNotInChainError","InternalError","_getPollInterval","type","_expectedMineRate","_microBlockCycle","_maxPollInterval","base","block","microblock","Math","min","sendTransaction","tx","onNode","onAccount","verify","waitMined","confirm","options","validation","length","message","map","v","join","txHash","postTransaction","requestOptions","customHeaders","__queue","address","catch","pollResult","poll","txData","hash","rawTx","c","undefined","confirmationHeight","waitForTxConfirm","error","Object","assign","verifyTx","blockHeight","getTransactionByHash","height","awaitHeight","newBlockHeight","getAccount","getAccountByPubkeyAndHeight","getAccountByPubkeyAndHash","getAccountByPubkey","getBalance","format","AETTOS","balance","targetDenomination","getCurrentKeyBlockHeight","interval","attempts","currentHeight","i","th","blocks","max","getCurrentGeneration","getGeneration","hashOrHeight","getGenerationByHeight","getGenerationByHash","getMicroBlockTransactions","getMicroBlockTransactionsByHash","transactions","getKeyBlock","getKeyBlockByHeight","getKeyBlockByHash","getMicroBlockHeader","getMicroBlockHeaderByHash","txDryRunRequests","Map","txDryRunHandler","key","rs","get","delete","dryRunRes","protectedDryRunTxs","top","txEvents","txs","req","accounts","Array","from","Set","accountAddress","pubKey","amount","forEach","reject","results","idx","result","reason","resultPayload","resolve","txDryRun","combine","requests","set","Promise","push","timeout","setTimeout","getContractByteCode","contractId","getContractCode","getContract","getName","name","getNameEntryByName","resolveName","nameOrId","resolveByNode","id","pointer","pointers","find"],"sources":["../src/chain.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2022 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\nimport { AE_AMOUNT_FORMATS, formatAmount } from './utils/amount-formatter'\nimport verifyTransaction from './tx/validator'\nimport { pause } from './utils/other'\nimport { isNameValid, produceNameId, decode } from './tx/builder/helpers'\nimport { DRY_RUN_ACCOUNT, AensName } from './tx/builder/schema'\nimport {\n AensPointerContextError, DryRunError, InvalidAensNameError, InvalidTxError,\n RequestTimedOutError, TxTimedOutError, TxNotInChainError, InternalError\n} from './utils/errors'\nimport Node, { TransformNodeType } from './Node'\nimport {\n Account as AccountNode, ByteCode, ContractObject, DryRunResult, DryRunResults,\n Generation, KeyBlock, MicroBlockHeader, NameEntry, SignedTx\n} from './apis/node'\nimport { EncodedData } from './utils/encoder'\nimport AccountBase from './account/Base'\n\nexport function _getPollInterval (\n type: 'block' | 'microblock',\n { _expectedMineRate = 180000, _microBlockCycle = 3000, _maxPollInterval = 5000 }:\n { _expectedMineRate?: number, _microBlockCycle?: number, _maxPollInterval?: number }\n): number {\n const base = {\n block: _expectedMineRate,\n microblock: _microBlockCycle\n }[type]\n return Math.min(base / 3, _maxPollInterval)\n}\n\n/**\n * Submit a signed transaction for mining\n * @param tx - Transaction to submit\n * @param options - Options\n * @param options.onNode - Node to use\n * @param options.onAccount - Account to use\n * @param options.verify - Verify transaction before sending\n * @param options.waitMined - Ensure that transaction get into block\n * @param options.confirm - Number of micro blocks that should be mined after tx get included\n * @returns Transaction details\n */\nexport async function sendTransaction (\n tx: EncodedData<'tx'>,\n { onNode, onAccount, verify = true, waitMined = true, confirm, ...options }:\n SendTransactionOptions\n): Promise<SendTransactionReturnType> {\n if (verify) {\n const validation = await verifyTransaction(tx, onNode)\n if (validation.length > 0) {\n const message = 'Transaction verification errors: ' +\n validation.map((v: { message: string }) => v.message).join(', ')\n throw new InvalidTxError(message, validation, tx)\n }\n }\n\n try {\n const { txHash } = await onNode.postTransaction({ tx }, {\n requestOptions: {\n customHeaders: {\n __queue: `tx-${await onAccount?.address(options).catch(() => '') ?? ''}`\n }\n }\n })\n\n if (waitMined) {\n const pollResult = await poll(txHash, { onNode, ...options })\n const txData = {\n ...pollResult,\n hash: pollResult.hash as EncodedData<'th'>,\n rawTx: tx\n }\n // wait for transaction confirmation\n if (confirm != null && (confirm === true || confirm > 0)) {\n const c = typeof confirm === 'boolean' ? undefined : confirm\n return {\n ...txData,\n confirmationHeight: await waitForTxConfirm(txHash, { onNode, confirm: c, ...options })\n }\n }\n return txData\n }\n return { hash: txHash, rawTx: tx }\n } catch (error) {\n throw Object.assign(error, {\n rawTx: tx,\n verifyTx: async () => await verifyTransaction(tx, onNode)\n })\n }\n}\n\ntype SendTransactionOptionsType = {\n onNode: Node\n onAccount?: AccountBase\n verify?: boolean\n waitMined?: boolean\n confirm?: boolean | number\n} & Parameters<typeof poll>[1] & Omit<Parameters<typeof waitForTxConfirm>[1], 'confirm'>\ninterface SendTransactionOptions extends SendTransactionOptionsType {}\ninterface SendTransactionReturnType extends Partial<TransformNodeType<SignedTx>> {\n hash: EncodedData<'th'>\n rawTx: EncodedData<'tx'>\n confirmationHeight?: number\n}\n\n/**\n * Wait for transaction confirmation\n * @param txHash - Transaction hash\n * @param options - Options\n * @param options.confirm - Number of micro blocks to wait for transaction confirmation\n * @param options.onNode - Node to use\n * @returns Current Height\n */\nexport async function waitForTxConfirm (\n txHash: EncodedData<'th'>,\n { confirm = 3, onNode, ...options }:\n { confirm?: number, onNode: Node } & Parameters<typeof awaitHeight>[1]\n): Promise<number> {\n const { blockHeight } = await onNode.getTransactionByHash(txHash)\n const height = await awaitHeight(blockHeight + confirm, { onNode, ...options })\n const { blockHeight: newBlockHeight } = await onNode.getTransactionByHash(txHash)\n switch (newBlockHeight) {\n case -1:\n throw new TxNotInChainError(txHash)\n case blockHeight:\n return height\n default:\n return await waitForTxConfirm(txHash, { onNode, confirm, ...options })\n }\n}\n\n/**\n * Get account by account public key\n * @param address - Account address (public key)\n * @param options - Options\n * @param options.height - Get account on specific block by block height\n * @param options.hash - Get account on specific block by micro block hash or key block hash\n * @param options.onNode - Node to use\n */\nexport async function getAccount (\n address: EncodedData<'ak' | 'ct'>,\n { height, hash, onNode }:\n { height?: number, hash?: EncodedData<'kh' | 'mh'>, onNode: Node }\n): Promise<TransformNodeType<AccountNode>> {\n if (height != null) return await onNode.getAccountByPubkeyAndHeight(address, height)\n if (hash != null) return await onNode.getAccountByPubkeyAndHash(address, hash)\n return await onNode.getAccountByPubkey(address)\n}\n\n/**\n * Request the balance of specified account\n * @param address - The public account address to obtain the balance for\n * @param options - Options\n * @param options.format\n * @param options.height - The chain height at which to obtain the balance for\n * (default: top of chain)\n * @param options.hash - The block hash on which to obtain the balance for (default: top of chain)\n */\nexport async function getBalance (\n address: EncodedData<'ak' | 'ct'>,\n { format = AE_AMOUNT_FORMATS.AETTOS, ...options }:\n { format?: AE_AMOUNT_FORMATS } & Parameters<typeof getAccount>[1]\n): Promise<string> {\n const { balance } = await getAccount(address, options).catch(() => ({ balance: 0n }))\n\n return formatAmount(balance, { targetDenomination: format })\n}\n\n/**\n * Obtain current height of the chain\n * @returns Current chain height\n */\nexport async function height ({ onNode }: { onNode: Node }): Promise<number> {\n return (await onNode.getCurrentKeyBlockHeight()).height\n}\n\n/**\n * Wait for the chain to reach a specific height\n * @param height - Height to wait for\n * @param options - Options\n * @param options.interval - Interval (in ms) at which to poll the chain\n * @param options.attempts - Number of polling attempts after which to fail\n * @param options.onNode - Node to use\n * @returns Current chain height\n */\nexport async function awaitHeight (\n height: number,\n { interval, attempts = 20, onNode, ...options }:\n { interval?: number, attempts?: number, onNode: Node }\n & Parameters<typeof _getPollInterval>[1]\n): Promise<number> {\n interval ??= _getPollInterval('block', options)\n let currentHeight\n for (let i = 0; i < attempts; i++) {\n if (i !== 0) await pause(interval)\n currentHeight = (await onNode.getCurrentKeyBlockHeight()).height\n if (currentHeight >= height) return currentHeight\n }\n throw new RequestTimedOutError((attempts - 1) * interval, currentHeight, height)\n}\n\n/**\n * Wait for a transaction to be mined\n * @param th - The hash of transaction to poll\n * @param options - Options\n * @param options.interval - Interval (in ms) at which to poll the chain\n * @param options.blocks - Number of blocks mined after which to fail\n * @param options.onNode - Node to use\n * @returns The transaction as it was mined\n */\nexport async function poll (\n th: EncodedData<'th'>,\n { blocks = 10, interval, onNode, ...options }:\n { blocks?: number, interval?: number, onNode: Node } & Parameters<typeof _getPollInterval>[1]\n): Promise<TransformNodeType<SignedTx>> {\n interval ??= _getPollInterval('microblock', options)\n const max = await height({ onNode }) + blocks\n do {\n const tx = await onNode.getTransactionByHash(th)\n if (tx.blockHeight !== -1) return tx\n await pause(interval)\n } while (await height({ onNode }) < max)\n throw new TxTimedOutError(blocks, th)\n}\n\n/**\n * Obtain current generation\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Current Generation\n */\nexport async function getCurrentGeneration (\n { onNode }: { onNode: Node }\n): Promise<TransformNodeType<Generation>> {\n return await onNode.getCurrentGeneration()\n}\n\n/**\n * Get generation by hash or height\n * @param hashOrHeight - Generation hash or height\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Generation\n */\nexport async function getGeneration (\n hashOrHeight: EncodedData<'kh'> | number, { onNode }: { onNode: Node }\n): Promise<TransformNodeType<Generation>> {\n if (typeof hashOrHeight === 'number') return await onNode.getGenerationByHeight(hashOrHeight)\n return await onNode.getGenerationByHash(hashOrHeight)\n}\n\n/**\n * Get micro block transactions\n * @param hash - Micro block hash\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Transactions\n */\nexport async function getMicroBlockTransactions (\n hash: EncodedData<'mh'>, { onNode }: { onNode: Node }\n): Promise<TransformNodeType<SignedTx[]>> {\n return (await onNode.getMicroBlockTransactionsByHash(hash)).transactions\n}\n\n/**\n * Get key block\n * @param hashOrHeight - Key block hash or height\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Key Block\n */\nexport async function getKeyBlock (\n hashOrHeight: EncodedData<'kh'> | number, { onNode }: { onNode: Node }\n): Promise<TransformNodeType<KeyBlock>> {\n if (typeof hashOrHeight === 'number') return await onNode.getKeyBlockByHeight(hashOrHeight)\n return await onNode.getKeyBlockByHash(hashOrHeight)\n}\n\n/**\n * Get micro block header\n * @param hash - Micro block hash\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Micro block header\n */\nexport async function getMicroBlockHeader (\n hash: EncodedData<'mh'>, { onNode }: { onNode: Node }\n): Promise<TransformNodeType<MicroBlockHeader>> {\n return await onNode.getMicroBlockHeaderByHash(hash)\n}\n\ninterface TxDryRunArguments {\n tx: EncodedData<'tx'>\n accountAddress: EncodedData<'ak'>\n top?: number\n txEvents?: any\n resolve: Function\n reject: Function\n}\nconst txDryRunRequests: Map<string, TxDryRunArguments[] & { timeout?: NodeJS.Timeout }> = new Map()\n\nasync function txDryRunHandler (key: string, onNode: Node): Promise<void> {\n const rs = txDryRunRequests.get(key)\n txDryRunRequests.delete(key)\n if (rs == null) throw new InternalError('Can\\'t get dry-run request')\n\n let dryRunRes\n try {\n dryRunRes = await onNode.protectedDryRunTxs({\n top: rs[0].top,\n txEvents: rs[0].txEvents,\n txs: rs.map(req => ({ tx: req.tx })),\n accounts: Array.from(new Set(rs.map(req => req.accountAddress)))\n .map(pubKey => ({ pubKey, amount: DRY_RUN_ACCOUNT.amount }))\n })\n } catch (error) {\n rs.forEach(({ reject }) => reject(error))\n return\n }\n\n const { results, txEvents } = dryRunRes\n results.forEach(({ result, reason, ...resultPayload }, idx) => {\n const { resolve, reject, tx, accountAddress } = rs[idx]\n if (result === 'ok') return resolve({ ...resultPayload, txEvents })\n reject(Object.assign(\n new DryRunError(reason as string), { tx, accountAddress }\n ))\n })\n}\n\n/**\n * Transaction dry-run\n * @param tx - transaction to execute\n * @param accountAddress - address that will be used to execute transaction\n * @param options - Options\n * @param options.top - hash of block on which to make dry-run\n * @param options.txEvents - collect and return on-chain tx events that would result from the call\n * @param options.combine - Enables combining of similar requests to a single dry-run call\n * @param options.onNode - Node to use\n */\nexport async function txDryRun (\n tx: EncodedData<'tx'>,\n accountAddress: EncodedData<'ak'>,\n { top, txEvents, combine, onNode }:\n { top?: number, txEvents?: boolean, combine?: boolean, onNode: Node }\n): Promise<{\n txEvents?: TransformNodeType<DryRunResults['txEvents']>\n } & TransformNodeType<DryRunResult>> {\n const key = combine === true ? [top, txEvents].join() : 'immediate'\n const requests = txDryRunRequests.get(key) ?? []\n txDryRunRequests.set(key, requests)\n return await new Promise((resolve, reject) => {\n requests.push({ tx, accountAddress, top, txEvents, resolve, reject })\n if (combine !== true) {\n void txDryRunHandler(key, onNode)\n return\n }\n requests.timeout ??= setTimeout(() => { void txDryRunHandler(key, onNode) })\n })\n}\n\n/**\n * Get contract byte code\n * @param contractId - Contract address\n * @param options - Options\n * @param options.onNode - Node to use\n */\nexport async function getContractByteCode (\n contractId: EncodedData<'ct'>, { onNode }: { onNode: Node }\n): Promise<TransformNodeType<ByteCode>> {\n return await onNode.getContractCode(contractId)\n}\n\n/**\n * Get contract entry\n * @param contractId - Contract address\n * @param options - Options\n * @param options.onNode - Node to use\n */\nexport async function getContract (\n contractId: EncodedData<'ct'>, { onNode }: { onNode: Node }\n): Promise<TransformNodeType<ContractObject>> {\n return await onNode.getContract(contractId)\n}\n\n/**\n * Get name entry\n * @param name - AENS name\n * @param options - Options\n * @param options.onNode - Node to use\n */\nexport async function getName (\n name: AensName, { onNode }: { onNode: Node }\n): Promise<TransformNodeType<NameEntry>> {\n return await onNode.getNameEntryByName(name)\n}\n\n/**\n * Resolve AENS name and return name hash\n * @param nameOrId - AENS name or address\n * @param key - in AENS pointers record\n * @param options - Options\n * @param options.verify - To ensure that name exist and have a corresponding pointer\n * // TODO: avoid that to don't trust to current api gateway\n * @param options.resolveByNode - Enables pointer resolving using node\n * @param options.onNode - Node to use\n * @returns Address or AENS name hash\n */\nexport async function resolveName <Type extends 'ak' | 'ct'> (\n nameOrId: AensName | EncodedData<Type>,\n key: string,\n { verify = true, resolveByNode = false, onNode }:\n { verify?: boolean, resolveByNode?: boolean, onNode: Node }\n): Promise<EncodedData<Type | 'nm'>> {\n try {\n const id = nameOrId as EncodedData<Type>\n decode(id)\n return id\n } catch (error) {}\n if (isNameValid(nameOrId)) {\n if (verify || resolveByNode) {\n const name = await onNode.getNameEntryByName(nameOrId)\n const pointer = name.pointers.find(pointer => pointer.key === key)\n if (pointer == null) throw new AensPointerContextError(nameOrId, key)\n if (resolveByNode) return pointer.id as EncodedData<Type>\n }\n return produceNameId(nameOrId)\n }\n throw new InvalidAensNameError(`Invalid name or address: ${nameOrId}`)\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;SACSA,iB,EAAmBC,Y;OACrBC,iB;SACEC,K;SACAC,W,EAAaC,a,EAAeC,M;SAC5BC,e;SAEPC,uB,EAAyBC,W,EAAaC,oB,EAAsBC,c,EAC5DC,oB,EAAsBC,e,EAAiBC,iB,EAAmBC,a;AAU5D,OAAO,SAASC,gBAAT,CACLC,IADK,QAIG;EAAA,IAFR;IAAEC,iBAAiB,GAAG,MAAtB;IAA8BC,gBAAgB,GAAG,IAAjD;IAAuDC,gBAAgB,GAAG;EAA1E,CAEQ;EACR,MAAMC,IAAI,GAAG;IACXC,KAAK,EAAEJ,iBADI;IAEXK,UAAU,EAAEJ;EAFD,EAGXF,IAHW,CAAb;EAIA,OAAOO,IAAI,CAACC,GAAL,CAASJ,IAAI,GAAG,CAAhB,EAAmBD,gBAAnB,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,eAAeM,eAAf,CACLC,EADK,SAI+B;EAAA,IAFpC;IAAEC,MAAF;IAAUC,SAAV;IAAqBC,MAAM,GAAG,IAA9B;IAAoCC,SAAS,GAAG,IAAhD;IAAsDC,OAAtD;IAA+D,GAAGC;EAAlE,CAEoC;;EACpC,IAAIH,MAAJ,EAAY;IACV,MAAMI,UAAU,GAAG,MAAMhC,iBAAiB,CAACyB,EAAD,EAAKC,MAAL,CAA1C;;IACA,IAAIM,UAAU,CAACC,MAAX,GAAoB,CAAxB,EAA2B;MACzB,MAAMC,OAAO,GAAG,sCACdF,UAAU,CAACG,GAAX,CAAgBC,CAAD,IAA4BA,CAAC,CAACF,OAA7C,EAAsDG,IAAtD,CAA2D,IAA3D,CADF;MA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AO,eAAeG,OAAf,CACLC,IADK,UAEkC;EAAA,IADvB;IAAE5G;EAAF,CACuB;EACvC,OAAO,MAAMA,MAAM,CAAC6G,kBAAP,CAA0BD,IAA1B,CAAb;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,eAAeE,WAAf,CACLC,QADK,EAELzC,GAFK,UAK8B;EAAA,IAFnC;IAAEpE,MAAM,GAAG,IAAX;IAAiB8G,aAAa,GAAG,KAAjC;IAAwChH;EAAxC,CAEmC;;EACnC,IAAI;IACF,MAAMiH,EAAE,GAAGF,QAAX;IACArI,MAAM,CAACuI,EAAD,CAAN;IACA,OAAOA,EAAP;EACD,CAJD,CAIE,OAAOrF,KAAP,EAAc,CAAE;;EAClB,IAAIpD,WAAW,CAACuI,QAAD,CAAf,EAA2B;IACzB,IAAI7G,MAAM,IAAI8G,aAAd,EAA6B;MAC3B,MAAMJ,IAAI,GAAG,MAAM5G,MAAM,CAAC6G,kBAAP,CAA0BE,QAA1B,CAAnB;MACA,MAAMG,OAAO,GAAGN,IAAI,CAACO,QAAL,CAAcC,IAAd,CAAmBF,OAAO,IAAIA,OAAO,CAAC5C,GAAR,KAAgBA,GAA9C,CAAhB;MACA,IAAI4C,OAAO,IAAI,IAAf,EAAqB,MAAM,IAAItI,uBAAJ,CAA4BmI,QAA5B,EAAsCzC,GAAtC,CAAN;MACrB,IAAI0C,aAAJ,EAAmB,OAAOE,OAAO,CAACD,EAAf;IACpB;;IACD,OAAOxI,aAAa,CAACsI,QAAD,CAApB;EACD;;EACD,MAAM,IAAIjI,oBAAJ,CAA0B,4BAA2BiI,QAAS,EAA9D,CAAN;AACD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ChannelState, ChannelMessage, ChannelFsm, SignTx } from './internal';
|
|
2
|
+
import { EncodedData } from '../utils/encoder';
|
|
3
|
+
import Channel from '.';
|
|
4
|
+
export declare function appendSignature(tx: EncodedData<'tx'>, signFn: SignTx): Promise<EncodedData<'tx'> | number | null>;
|
|
5
|
+
export declare function awaitingConnection(channel: Channel, message: ChannelMessage): ChannelFsm | undefined;
|
|
6
|
+
export declare function awaitingReconnection(channel: Channel, message: ChannelMessage, state: ChannelState): Promise<ChannelFsm>;
|
|
7
|
+
export declare function awaitingChannelCreateTx(channel: Channel, message: ChannelMessage): Promise<ChannelFsm | undefined>;
|
|
8
|
+
export declare function awaitingOnChainTx(channel: Channel, message: ChannelMessage): ChannelFsm | undefined;
|
|
9
|
+
export declare function awaitingBlockInclusion(channel: Channel, message: ChannelMessage): ChannelFsm | undefined;
|
|
10
|
+
export declare function awaitingOpenConfirmation(channel: Channel, message: ChannelMessage): ChannelFsm | undefined;
|
|
11
|
+
export declare function awaitingInitialState(channel: Channel, message: ChannelMessage): ChannelFsm | undefined;
|
|
12
|
+
export declare function channelOpen(channel: Channel, message: ChannelMessage, state: ChannelState): Promise<ChannelFsm | undefined>;
|
|
13
|
+
export declare namespace channelOpen {
|
|
14
|
+
var enter: (channel: Channel) => void;
|
|
15
|
+
}
|
|
16
|
+
export declare function awaitingOffChainTx(channel: Channel, message: ChannelMessage, state: ChannelState): Promise<ChannelFsm>;
|
|
17
|
+
export declare function awaitingOffChainUpdate(channel: Channel, message: ChannelMessage, state: ChannelState): ChannelFsm | undefined;
|
|
18
|
+
export declare function awaitingTxSignRequest(channel: Channel, message: ChannelMessage, state: ChannelState): Promise<ChannelFsm | undefined>;
|
|
19
|
+
export declare function awaitingUpdateConflict(channel: Channel, message: ChannelMessage, state: ChannelState): ChannelFsm;
|
|
20
|
+
export declare function awaitingShutdownTx(channel: Channel, message: ChannelMessage, state: ChannelState): Promise<ChannelFsm | undefined>;
|
|
21
|
+
export declare function awaitingShutdownOnChainTx(channel: Channel, message: ChannelMessage, state: ChannelState): ChannelFsm;
|
|
22
|
+
export declare function awaitingLeave(channel: Channel, message: ChannelMessage, state: ChannelState): ChannelFsm;
|
|
23
|
+
export declare function awaitingWithdrawTx(channel: Channel, message: ChannelMessage, state: ChannelState): Promise<ChannelFsm | undefined>;
|
|
24
|
+
export declare function awaitingWithdrawCompletion(channel: Channel, message: ChannelMessage, state: ChannelState): ChannelFsm;
|
|
25
|
+
export declare function awaitingDepositTx(channel: Channel, message: ChannelMessage, state: ChannelState): Promise<ChannelFsm | undefined>;
|
|
26
|
+
export declare function awaitingDepositCompletion(channel: Channel, message: ChannelMessage, state: ChannelState): ChannelFsm;
|
|
27
|
+
export declare function awaitingNewContractTx(channel: Channel, message: ChannelMessage, state: ChannelState): Promise<ChannelFsm | undefined>;
|
|
28
|
+
export declare function awaitingNewContractCompletion(channel: Channel, message: ChannelMessage, state: ChannelState): ChannelFsm;
|
|
29
|
+
export declare function awaitingCallContractUpdateTx(channel: Channel, message: ChannelMessage, state: ChannelState): Promise<ChannelFsm | undefined>;
|
|
30
|
+
export declare function awaitingCallContractForceProgressUpdate(channel: Channel, message: ChannelMessage, state: ChannelState): Promise<ChannelFsm | undefined>;
|
|
31
|
+
export declare function awaitingForceProgressCompletion(channel: Channel, message: ChannelMessage, state: ChannelState): ChannelFsm;
|
|
32
|
+
export declare function awaitingCallContractCompletion(channel: Channel, message: ChannelMessage, state: ChannelState): ChannelFsm;
|
|
33
|
+
export declare function awaitingCallsPruned(_channels: Channel[], message: ChannelMessage, state: ChannelState): ChannelFsm;
|
|
34
|
+
export declare function channelClosed(_channel: Channel, message: ChannelMessage, state: ChannelState): ChannelFsm;
|