@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/tx/index.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
2
|
+
|
|
1
3
|
/*
|
|
2
4
|
* ISC License (ISC)
|
|
3
|
-
* Copyright (c)
|
|
5
|
+
* Copyright (c) 2022 aeternity developers
|
|
4
6
|
*
|
|
5
7
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
8
|
* purpose with or without fee is hereby granted, provided that the above
|
|
@@ -16,288 +18,192 @@
|
|
|
16
18
|
*/
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
|
-
*
|
|
20
|
-
* @module @aeternity/aepp-sdk/es/tx
|
|
21
|
-
* @export Tx
|
|
22
|
-
* @example import { Tx } from '@aeternity/aepp-sdk'
|
|
23
|
-
*/
|
|
24
|
-
import stampit from '@stamp/it';
|
|
25
|
-
import _stampRequired from '@stamp/required';
|
|
26
|
-
/**
|
|
27
|
-
* Basic Tx Stamp
|
|
21
|
+
* Transaction methods
|
|
28
22
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
23
|
+
* This is implementation of [Tx](api/tx.md) relays
|
|
24
|
+
* the creation of transactions to {@link Node}.
|
|
25
|
+
* These methods provide ability to create native transactions.
|
|
26
|
+
*/
|
|
27
|
+
import { ABI_VERSIONS, PROTOCOL_VM_ABI, TX_TYPE, TX_TTL } from "./builder/schema.mjs";
|
|
28
|
+
import { ArgumentError, UnsupportedProtocolError, UnknownTxError, InvalidTxParamsError } from "../utils/errors.mjs";
|
|
29
|
+
import BigNumber from 'bignumber.js';
|
|
30
|
+
import { buildTx as syncBuildTx, unpackTx } from "./builder/index.mjs";
|
|
31
|
+
import calculateMinFee from "./min-fee.mjs";
|
|
32
|
+
import { isKeyOfObject } from "../utils/other.mjs";
|
|
33
|
+
// TODO: find a better name or rearrange methods
|
|
34
|
+
export async function _buildTx(txType, _ref) {
|
|
35
|
+
var _context;
|
|
36
|
+
|
|
37
|
+
let {
|
|
38
|
+
denomination,
|
|
39
|
+
absoluteTtl,
|
|
40
|
+
..._params
|
|
41
|
+
} = _ref;
|
|
42
|
+
// TODO: avoid this assertion
|
|
43
|
+
const params = _params;
|
|
44
|
+
let senderKey;
|
|
45
|
+
|
|
46
|
+
switch (txType) {
|
|
47
|
+
case TX_TYPE.spend:
|
|
48
|
+
case TX_TYPE.oracleQuery:
|
|
49
|
+
senderKey = 'senderId';
|
|
50
|
+
break;
|
|
51
|
+
|
|
52
|
+
case TX_TYPE.nameClaim:
|
|
53
|
+
case TX_TYPE.nameUpdate:
|
|
54
|
+
case TX_TYPE.nameRevoke:
|
|
55
|
+
case TX_TYPE.nameTransfer:
|
|
56
|
+
case TX_TYPE.namePreClaim:
|
|
57
|
+
case TX_TYPE.oracleRegister:
|
|
58
|
+
senderKey = 'accountId';
|
|
59
|
+
break;
|
|
60
|
+
|
|
61
|
+
case TX_TYPE.contractCreate:
|
|
62
|
+
case TX_TYPE.gaAttach:
|
|
63
|
+
senderKey = 'ownerId';
|
|
64
|
+
break;
|
|
65
|
+
|
|
66
|
+
case TX_TYPE.contractCall:
|
|
67
|
+
case TX_TYPE.oracleExtend:
|
|
68
|
+
case TX_TYPE.oracleResponse:
|
|
69
|
+
senderKey = 'callerId';
|
|
70
|
+
break;
|
|
71
|
+
|
|
72
|
+
case TX_TYPE.channelCloseSolo:
|
|
73
|
+
case TX_TYPE.channelSlash:
|
|
74
|
+
case TX_TYPE.channelSettle:
|
|
75
|
+
case TX_TYPE.channelSnapshotSolo:
|
|
76
|
+
senderKey = 'fromId';
|
|
77
|
+
break;
|
|
78
|
+
|
|
79
|
+
case TX_TYPE.payingFor:
|
|
80
|
+
senderKey = 'payerId';
|
|
81
|
+
break;
|
|
42
82
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
nameUpdateTx: required,
|
|
53
|
-
nameRevokeTx: required,
|
|
54
|
-
contractCreateTx: required,
|
|
55
|
-
contractCallTx: required,
|
|
56
|
-
oracleRegisterTx: required,
|
|
57
|
-
oracleExtendTx: required,
|
|
58
|
-
oraclePostQueryTx: required,
|
|
59
|
-
oracleRespondTx: required,
|
|
60
|
-
getAccountNonce: required,
|
|
61
|
-
channelCloseSoloTx: required,
|
|
62
|
-
channelSlashTx: required,
|
|
63
|
-
channelSettleTx: required,
|
|
64
|
-
channelSnapshotSoloTx: required,
|
|
65
|
-
gaAttachTx: required,
|
|
66
|
-
getVmVersion: required,
|
|
67
|
-
prepareTxParams: required
|
|
83
|
+
default:
|
|
84
|
+
throw new ArgumentError('txType', 'valid transaction type', txType);
|
|
85
|
+
} // TODO: move specific cases to field-types
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
if (_includesInstanceProperty(_context = [TX_TYPE.contractCreate, TX_TYPE.gaAttach]).call(_context, txType)) {
|
|
89
|
+
params.ctVersion = await getVmVersion(TX_TYPE.contractCreate, { ...params,
|
|
90
|
+
...params.ctVersion
|
|
91
|
+
});
|
|
68
92
|
}
|
|
69
|
-
}));
|
|
70
|
-
/**
|
|
71
|
-
* Create a `spend_tx` transaction
|
|
72
|
-
* @function spendTx
|
|
73
|
-
* @instance
|
|
74
|
-
* @abstract
|
|
75
|
-
* @category async
|
|
76
|
-
* @rtype ({
|
|
77
|
-
* sender?: String,
|
|
78
|
-
* recipientId: String,
|
|
79
|
-
* amount: Number,
|
|
80
|
-
* fee?: Number,
|
|
81
|
-
* ttl?: Number,
|
|
82
|
-
* nonce?: Number,
|
|
83
|
-
* payload?: String
|
|
84
|
-
* }) => tx: Promise[String]
|
|
85
|
-
* @param {Object} options - The object to extract properties from
|
|
86
|
-
* @return {String} `spend_tx` transaction
|
|
87
|
-
*/
|
|
88
93
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
* @instance
|
|
93
|
-
* @abstract
|
|
94
|
-
* @category async
|
|
95
|
-
* @rtype ({
|
|
96
|
-
* account?: String, commitment: String, fee?: Number, ttl?: Number, nonce?: Number
|
|
97
|
-
* }) => tx: Promise[String]
|
|
98
|
-
* @param {Object} options - The object to extract properties from
|
|
99
|
-
* @return {String} `name_preclaim_tx` transaction
|
|
100
|
-
*/
|
|
94
|
+
if (txType === TX_TYPE.contractCall) {
|
|
95
|
+
params.abiVersion = (await getVmVersion(TX_TYPE.contractCall, params)).abiVersion;
|
|
96
|
+
}
|
|
101
97
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
* @function nameClaimTx
|
|
105
|
-
* @instance
|
|
106
|
-
* @abstract
|
|
107
|
-
* @category async
|
|
108
|
-
* @rtype ({
|
|
109
|
-
* account?: String, name: String, nameSalt: String, fee?: Number, ttl?: Number, nonce?: Number
|
|
110
|
-
* }) => tx: Promise[String]
|
|
111
|
-
* @param {Object} options - The object to extract properties from
|
|
112
|
-
* @return {String} `name_claim_tx` transaction
|
|
113
|
-
*/
|
|
98
|
+
if (txType === TX_TYPE.oracleRegister) {
|
|
99
|
+
var _params$abiVersion;
|
|
114
100
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
* @function nameTransferTx
|
|
118
|
-
* @instance
|
|
119
|
-
* @abstract
|
|
120
|
-
* @category async
|
|
121
|
-
* @rtype ({
|
|
122
|
-
* account?: String,
|
|
123
|
-
* nameId: String,
|
|
124
|
-
* recipientId: String,
|
|
125
|
-
* fee?: Number,
|
|
126
|
-
* ttl?: Number,
|
|
127
|
-
* nonce?: Number
|
|
128
|
-
* }) => tx: Promise[String]
|
|
129
|
-
* @param {Object} options - The object to extract properties from
|
|
130
|
-
* @return {String} `name_transfer_tx` transaction
|
|
131
|
-
*/
|
|
101
|
+
(_params$abiVersion = params.abiVersion) !== null && _params$abiVersion !== void 0 ? _params$abiVersion : params.abiVersion = ABI_VERSIONS.NO_ABI;
|
|
102
|
+
}
|
|
132
103
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
* @instance
|
|
137
|
-
* @abstract
|
|
138
|
-
* @category async
|
|
139
|
-
* @rtype ({
|
|
140
|
-
* account?: String,
|
|
141
|
-
* nameId: String,
|
|
142
|
-
* pointers: Object,
|
|
143
|
-
* nameTtl: Number,
|
|
144
|
-
* clientTtl: Number,
|
|
145
|
-
* fee?: Number,
|
|
146
|
-
* ttl?: Number,
|
|
147
|
-
* nonce?: Number
|
|
148
|
-
* }) => tx: Promise[String]
|
|
149
|
-
* @param {Object} options - The object to extract properties from
|
|
150
|
-
* @return {String} `name_update_tx` transaction
|
|
151
|
-
*/
|
|
104
|
+
if (txType === TX_TYPE.payingFor) {
|
|
105
|
+
params.tx = unpackTx(params.tx);
|
|
106
|
+
}
|
|
152
107
|
|
|
153
|
-
|
|
154
|
-
* Create a `name_revoke_tx` transaction
|
|
155
|
-
* @function nameRevokeTx
|
|
156
|
-
* @instance
|
|
157
|
-
* @abstract
|
|
158
|
-
* @category async
|
|
159
|
-
* @rtype ({
|
|
160
|
-
* account?: String, nameId: String, fee?: Number, ttl?: Number, nonce?: Number
|
|
161
|
-
* }) => tx: Promise[String]
|
|
162
|
-
* @param {Object} options - The object to extract properties from
|
|
163
|
-
* @return {String} `name_revoke_tx` transaction
|
|
164
|
-
*/
|
|
108
|
+
const senderId = params[senderKey]; // TODO: do this check on TypeScript level
|
|
165
109
|
|
|
110
|
+
if (senderId == null) throw new InvalidTxParamsError(`Transaction field ${senderKey} is missed`);
|
|
111
|
+
const extraParams = await prepareTxParams(txType, { ...params,
|
|
112
|
+
senderId,
|
|
113
|
+
denomination,
|
|
114
|
+
absoluteTtl
|
|
115
|
+
});
|
|
116
|
+
return syncBuildTx({ ...params,
|
|
117
|
+
...extraParams
|
|
118
|
+
}, txType, {
|
|
119
|
+
denomination
|
|
120
|
+
}).tx;
|
|
121
|
+
}
|
|
166
122
|
/**
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
* @
|
|
170
|
-
* @
|
|
171
|
-
* @
|
|
172
|
-
* @rtype ({
|
|
173
|
-
* owner: String,
|
|
174
|
-
* code: String,
|
|
175
|
-
* callData: String,
|
|
176
|
-
* vmVersion: Number,
|
|
177
|
-
* deposit: Number,
|
|
178
|
-
* amount: Number,
|
|
179
|
-
* gas: Number,
|
|
180
|
-
* gasPrice: Number,
|
|
181
|
-
* fee?: Number,
|
|
182
|
-
* ttl?: Number,
|
|
183
|
-
* nonce?: Number
|
|
184
|
-
* }) => tx: Promise[String]
|
|
185
|
-
* @param {Object} options - The object to extract properties from
|
|
186
|
-
* @return {String} `contract_create_tx` transaction
|
|
123
|
+
* Validated vm/abi version or get default based on transaction type and NODE version
|
|
124
|
+
*
|
|
125
|
+
* @param txType - Type of transaction
|
|
126
|
+
* @param ctVersion - Object with vm and abi version fields
|
|
127
|
+
* @returns Object with vm/abi version
|
|
187
128
|
*/
|
|
188
129
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
* @function contractCallTx
|
|
192
|
-
* @instance
|
|
193
|
-
* @abstract
|
|
194
|
-
* @category async
|
|
195
|
-
* @rtype ({
|
|
196
|
-
* callerId: String,
|
|
197
|
-
* contract: String,
|
|
198
|
-
* callData: String,
|
|
199
|
-
* vmVersion: Number,
|
|
200
|
-
* amount: Number,
|
|
201
|
-
* gas: Number,
|
|
202
|
-
* gasPrice: Number,
|
|
203
|
-
* fee?: Number,
|
|
204
|
-
* ttl?: Number,
|
|
205
|
-
* nonce?: Number
|
|
206
|
-
* }) => tx: Promise[String]
|
|
207
|
-
* @param {Object} options - The object to extract properties from
|
|
208
|
-
* @return {String} `contract_call_tx` transaction
|
|
209
|
-
*/
|
|
130
|
+
export async function getVmVersion(txType, _ref2) {
|
|
131
|
+
var _abiVersion, _vmVersion;
|
|
210
132
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
* queryFormat: String,
|
|
220
|
-
* responseFormat: String,
|
|
221
|
-
* queryFee: String|Number,
|
|
222
|
-
* oracleTtl: Object,
|
|
223
|
-
* vmVersion: Number = ORACLE_VM_VERSION,
|
|
224
|
-
* fee?: Number,
|
|
225
|
-
* ttl?: Number,
|
|
226
|
-
* nonce?: Number
|
|
227
|
-
* }) => tx: Promise[String]
|
|
228
|
-
* @param {Object} options - The object to extract properties from
|
|
229
|
-
* @return {String} `oracle_register_tx` transaction
|
|
230
|
-
*/
|
|
133
|
+
let {
|
|
134
|
+
vmVersion,
|
|
135
|
+
abiVersion,
|
|
136
|
+
onNode
|
|
137
|
+
} = _ref2;
|
|
138
|
+
const {
|
|
139
|
+
consensusProtocolVersion
|
|
140
|
+
} = await onNode.getNodeInfo();
|
|
231
141
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
* @instance
|
|
236
|
-
* @abstract
|
|
237
|
-
* @category async
|
|
238
|
-
* @rtype ({
|
|
239
|
-
* oracleId: String,
|
|
240
|
-
* callerId: String,
|
|
241
|
-
* oracleTtl: Object,
|
|
242
|
-
* fee?: Number,
|
|
243
|
-
* ttl: Number,
|
|
244
|
-
* nonce?: Number
|
|
245
|
-
* }) => tx: Promise[String]
|
|
246
|
-
* @param {Object} options - The object to extract properties from
|
|
247
|
-
* @return {String} `oracle_extend_tx` transaction
|
|
248
|
-
*/
|
|
142
|
+
if (!isKeyOfObject(consensusProtocolVersion, PROTOCOL_VM_ABI)) {
|
|
143
|
+
throw new UnsupportedProtocolError('Not supported consensus protocol version');
|
|
144
|
+
}
|
|
249
145
|
|
|
250
|
-
|
|
251
|
-
* Create a `oracle_post_query_tx` transaction
|
|
252
|
-
* @function oraclePostQuery
|
|
253
|
-
* @instance
|
|
254
|
-
* @abstract
|
|
255
|
-
* @category async
|
|
256
|
-
* @rtype ({
|
|
257
|
-
* oracleId: String,
|
|
258
|
-
* responseTtl: Object,
|
|
259
|
-
* query: String,
|
|
260
|
-
* queryTtl: Object,
|
|
261
|
-
* queryFee: String|Number,
|
|
262
|
-
* senderId: String,
|
|
263
|
-
* fee?: Number,
|
|
264
|
-
* ttl: Number,
|
|
265
|
-
* nonce?: Number
|
|
266
|
-
* }) => tx: Promise[String]
|
|
267
|
-
* @param {Object} options - The object to extract properties from
|
|
268
|
-
* @return {String} `oracle_post_query_tx` transaction
|
|
269
|
-
*/
|
|
146
|
+
const supportedProtocol = PROTOCOL_VM_ABI[consensusProtocolVersion];
|
|
270
147
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
* @instance
|
|
275
|
-
* @abstract
|
|
276
|
-
* @category async
|
|
277
|
-
* @rtype ({
|
|
278
|
-
* oracleId: String,
|
|
279
|
-
* callerId: String,
|
|
280
|
-
* responseTtl: Object,
|
|
281
|
-
* queryId: String,
|
|
282
|
-
* response: String,
|
|
283
|
-
* fee?: Number,
|
|
284
|
-
* ttl?: Number,
|
|
285
|
-
* nonce?: Number
|
|
286
|
-
* }) => tx: Promise[String]
|
|
287
|
-
* @param {Object} options - The object to extract properties from
|
|
288
|
-
* @return {String} `oracle_respond_tx` transaction
|
|
289
|
-
*/
|
|
148
|
+
if (!isKeyOfObject(txType, supportedProtocol)) {
|
|
149
|
+
throw new UnknownTxError('Not supported tx type');
|
|
150
|
+
}
|
|
290
151
|
|
|
152
|
+
const protocolForTX = supportedProtocol[txType];
|
|
153
|
+
(_abiVersion = abiVersion) !== null && _abiVersion !== void 0 ? _abiVersion : abiVersion = protocolForTX.abiVersion[0];
|
|
154
|
+
(_vmVersion = vmVersion) !== null && _vmVersion !== void 0 ? _vmVersion : vmVersion = protocolForTX.vmVersion[0];
|
|
155
|
+
return {
|
|
156
|
+
vmVersion,
|
|
157
|
+
abiVersion
|
|
158
|
+
};
|
|
159
|
+
}
|
|
291
160
|
/**
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
* @
|
|
295
|
-
* @
|
|
296
|
-
* @
|
|
297
|
-
* @rtype (address) => result: Number
|
|
298
|
-
* @param {String} address - Account public key
|
|
299
|
-
* @return {Number} Result
|
|
161
|
+
* Calculate fee, get absolute ttl (ttl + height), get account nonce
|
|
162
|
+
*
|
|
163
|
+
* @param txType - Type of transaction
|
|
164
|
+
* @param params - Object which contains all tx data
|
|
165
|
+
* @returns Object with account nonce, absolute ttl and transaction fee
|
|
300
166
|
*/
|
|
301
167
|
|
|
302
|
-
export
|
|
168
|
+
export async function prepareTxParams(txType, _ref3) {
|
|
169
|
+
var _nonce;
|
|
170
|
+
|
|
171
|
+
let {
|
|
172
|
+
senderId,
|
|
173
|
+
nonce,
|
|
174
|
+
ttl = TX_TTL,
|
|
175
|
+
fee: f,
|
|
176
|
+
absoluteTtl,
|
|
177
|
+
vsn,
|
|
178
|
+
strategy,
|
|
179
|
+
denomination,
|
|
180
|
+
onNode,
|
|
181
|
+
...txParams
|
|
182
|
+
} = _ref3;
|
|
183
|
+
(_nonce = nonce) !== null && _nonce !== void 0 ? _nonce : nonce = (await onNode.getAccountNextNonce(senderId, {
|
|
184
|
+
strategy
|
|
185
|
+
}).catch(() => ({
|
|
186
|
+
nextNonce: 1
|
|
187
|
+
}))).nextNonce;
|
|
188
|
+
|
|
189
|
+
if (ttl !== 0) {
|
|
190
|
+
if (ttl < 0) throw new ArgumentError('ttl', 'greater or equal to 0', ttl);
|
|
191
|
+
ttl += absoluteTtl === true ? 0 : (await onNode.getCurrentKeyBlock()).height;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const fee = f != null ? new BigNumber(f) : calculateMinFee(txType, {
|
|
195
|
+
params: { ...txParams,
|
|
196
|
+
senderId,
|
|
197
|
+
nonce,
|
|
198
|
+
ttl
|
|
199
|
+
},
|
|
200
|
+
vsn,
|
|
201
|
+
denomination
|
|
202
|
+
});
|
|
203
|
+
return {
|
|
204
|
+
fee,
|
|
205
|
+
ttl,
|
|
206
|
+
nonce
|
|
207
|
+
};
|
|
208
|
+
}
|
|
303
209
|
//# sourceMappingURL=index.mjs.map
|
package/es/tx/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tx/index.js"],"names":["stampit","Tx","required","methods","spendTx","namePreclaimTx","nameClaimTx","nameTransferTx","nameUpdateTx","nameRevokeTx","contractCreateTx","contractCallTx","oracleRegisterTx","oracleExtendTx","oraclePostQueryTx","oracleRespondTx","getAccountNonce","channelCloseSoloTx","channelSlashTx","channelSettleTx","channelSnapshotSoloTx","gaAttachTx","getVmVersion","prepareTxParams"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAOA,OAAP,MAAoB,WAApB;AACA,2BAAyB,iBAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACA,MAAMC,EAAE,GAAGD,OAAO,CAACE,QAAQ,CAAC;AAC1BC,EAAAA,OAAO,EAAE;AACPC,IAAAA,OAAO,EAAEF,QADF;AAEPG,IAAAA,cAAc,EAAEH,QAFT;AAGPI,IAAAA,WAAW,EAAEJ,QAHN;AAIPK,IAAAA,cAAc,EAAEL,QAJT;AAKPM,IAAAA,YAAY,EAAEN,QALP;AAMPO,IAAAA,YAAY,EAAEP,QANP;AAOPQ,IAAAA,gBAAgB,EAAER,QAPX;AAQPS,IAAAA,cAAc,EAAET,QART;AASPU,IAAAA,gBAAgB,EAAEV,QATX;AAUPW,IAAAA,cAAc,EAAEX,QAVT;AAWPY,IAAAA,iBAAiB,EAAEZ,QAXZ;AAYPa,IAAAA,eAAe,EAAEb,QAZV;AAaPc,IAAAA,eAAe,EAAEd,QAbV;AAcPe,IAAAA,kBAAkB,EAAEf,QAdb;AAePgB,IAAAA,cAAc,EAAEhB,QAfT;AAgBPiB,IAAAA,eAAe,EAAEjB,QAhBV;AAiBPkB,IAAAA,qBAAqB,EAAElB,QAjBhB;AAkBPmB,IAAAA,UAAU,EAAEnB,QAlBL;AAmBPoB,IAAAA,YAAY,EAAEpB,QAnBP;AAoBPqB,IAAAA,eAAe,EAAErB;AApBV;AADiB,CAAD,CAAT,CAAlB;AAyBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,eAAeD,EAAf","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2018 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Tx module\n * @module @aeternity/aepp-sdk/es/tx\n * @export Tx\n * @example import { Tx } from '@aeternity/aepp-sdk'\n */\n\nimport stampit from '@stamp/it'\nimport { required } from '@stamp/required'\n\n/**\n * Basic Tx Stamp\n *\n * Attempting to create instances from the Stamp without overwriting all\n * abstract methods using composition will result in an exception.\n *\n * Tx is one of the three basic building blocks of an\n * {@link module:@aeternity/aepp-sdk/es/ae--Ae} client and provides methods to\n * create aeternity transactions.\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx\n * @rtype Stamp\n * @param {Object} [options={}] - Initializer object\n * @return {Object} Tx instance\n * @example Tx()\n */\nconst Tx = stampit(required({\n methods: {\n spendTx: required,\n namePreclaimTx: required,\n nameClaimTx: required,\n nameTransferTx: required,\n nameUpdateTx: required,\n nameRevokeTx: required,\n contractCreateTx: required,\n contractCallTx: required,\n oracleRegisterTx: required,\n oracleExtendTx: required,\n oraclePostQueryTx: required,\n oracleRespondTx: required,\n getAccountNonce: required,\n channelCloseSoloTx: required,\n channelSlashTx: required,\n channelSettleTx: required,\n channelSnapshotSoloTx: required,\n gaAttachTx: required,\n getVmVersion: required,\n prepareTxParams: required\n }\n}))\n\n/**\n * Create a `spend_tx` transaction\n * @function spendTx\n * @instance\n * @abstract\n * @category async\n * @rtype ({\n * sender?: String,\n * recipientId: String,\n * amount: Number,\n * fee?: Number,\n * ttl?: Number,\n * nonce?: Number,\n * payload?: String\n * }) => tx: Promise[String]\n * @param {Object} options - The object to extract properties from\n * @return {String} `spend_tx` transaction\n */\n\n/**\n * Create a `name_preclaim_tx` transaction\n * @function namePreclaimTx\n * @instance\n * @abstract\n * @category async\n * @rtype ({\n * account?: String, commitment: String, fee?: Number, ttl?: Number, nonce?: Number\n * }) => tx: Promise[String]\n * @param {Object} options - The object to extract properties from\n * @return {String} `name_preclaim_tx` transaction\n */\n\n/**\n * Create a `name_claim_tx` transaction\n * @function nameClaimTx\n * @instance\n * @abstract\n * @category async\n * @rtype ({\n * account?: String, name: String, nameSalt: String, fee?: Number, ttl?: Number, nonce?: Number\n * }) => tx: Promise[String]\n * @param {Object} options - The object to extract properties from\n * @return {String} `name_claim_tx` transaction\n */\n\n/**\n * Create a `name_transfer_tx` transaction\n * @function nameTransferTx\n * @instance\n * @abstract\n * @category async\n * @rtype ({\n * account?: String,\n * nameId: String,\n * recipientId: String,\n * fee?: Number,\n * ttl?: Number,\n * nonce?: Number\n * }) => tx: Promise[String]\n * @param {Object} options - The object to extract properties from\n * @return {String} `name_transfer_tx` transaction\n */\n\n/**\n * Create a `name_update_tx` transaction\n * @function nameUpdateTx\n * @instance\n * @abstract\n * @category async\n * @rtype ({\n * account?: String,\n * nameId: String,\n * pointers: Object,\n * nameTtl: Number,\n * clientTtl: Number,\n * fee?: Number,\n * ttl?: Number,\n * nonce?: Number\n * }) => tx: Promise[String]\n * @param {Object} options - The object to extract properties from\n * @return {String} `name_update_tx` transaction\n */\n\n/**\n * Create a `name_revoke_tx` transaction\n * @function nameRevokeTx\n * @instance\n * @abstract\n * @category async\n * @rtype ({\n * account?: String, nameId: String, fee?: Number, ttl?: Number, nonce?: Number\n * }) => tx: Promise[String]\n * @param {Object} options - The object to extract properties from\n * @return {String} `name_revoke_tx` transaction\n */\n\n/**\n * Create a `contract_create_tx` transaction\n * @function contractCreateTx\n * @instance\n * @abstract\n * @category async\n * @rtype ({\n * owner: String,\n * code: String,\n * callData: String,\n * vmVersion: Number,\n * deposit: Number,\n * amount: Number,\n * gas: Number,\n * gasPrice: Number,\n * fee?: Number,\n * ttl?: Number,\n * nonce?: Number\n * }) => tx: Promise[String]\n * @param {Object} options - The object to extract properties from\n * @return {String} `contract_create_tx` transaction\n */\n\n/**\n * Create a `contract_call_tx` transaction\n * @function contractCallTx\n * @instance\n * @abstract\n * @category async\n * @rtype ({\n * callerId: String,\n * contract: String,\n * callData: String,\n * vmVersion: Number,\n * amount: Number,\n * gas: Number,\n * gasPrice: Number,\n * fee?: Number,\n * ttl?: Number,\n * nonce?: Number\n * }) => tx: Promise[String]\n * @param {Object} options - The object to extract properties from\n * @return {String} `contract_call_tx` transaction\n */\n\n/**\n * Create a `oracle_register_tx` transaction\n * @function oracleRegisterTx\n * @instance\n * @abstract\n * @category async\n * @rtype ({\n * accountId: String,\n * queryFormat: String,\n * responseFormat: String,\n * queryFee: String|Number,\n * oracleTtl: Object,\n * vmVersion: Number = ORACLE_VM_VERSION,\n * fee?: Number,\n * ttl?: Number,\n * nonce?: Number\n * }) => tx: Promise[String]\n * @param {Object} options - The object to extract properties from\n * @return {String} `oracle_register_tx` transaction\n */\n\n/**\n * Create a `oracle_extend_tx` transaction\n * @function oracleExtendTx\n * @instance\n * @abstract\n * @category async\n * @rtype ({\n * oracleId: String,\n * callerId: String,\n * oracleTtl: Object,\n * fee?: Number,\n * ttl: Number,\n * nonce?: Number\n * }) => tx: Promise[String]\n * @param {Object} options - The object to extract properties from\n * @return {String} `oracle_extend_tx` transaction\n */\n\n/**\n * Create a `oracle_post_query_tx` transaction\n * @function oraclePostQuery\n * @instance\n * @abstract\n * @category async\n * @rtype ({\n * oracleId: String,\n * responseTtl: Object,\n * query: String,\n * queryTtl: Object,\n * queryFee: String|Number,\n * senderId: String,\n * fee?: Number,\n * ttl: Number,\n * nonce?: Number\n * }) => tx: Promise[String]\n * @param {Object} options - The object to extract properties from\n * @return {String} `oracle_post_query_tx` transaction\n */\n\n/**\n * Create a `oracle_respond_tx` transaction\n * @function oracleRespondTx\n * @instance\n * @abstract\n * @category async\n * @rtype ({\n * oracleId: String,\n * callerId: String,\n * responseTtl: Object,\n * queryId: String,\n * response: String,\n * fee?: Number,\n * ttl?: Number,\n * nonce?: Number\n * }) => tx: Promise[String]\n * @param {Object} options - The object to extract properties from\n * @return {String} `oracle_respond_tx` transaction\n */\n\n/**\n * Get Account Nonce\n * @function getAccountNonce\n * @instance\n * @abstract\n * @category async\n * @rtype (address) => result: Number\n * @param {String} address - Account public key\n * @return {Number} Result\n */\n\nexport default Tx\n"],"file":"index.mjs"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["ABI_VERSIONS","PROTOCOL_VM_ABI","TX_TYPE","TX_TTL","ArgumentError","UnsupportedProtocolError","UnknownTxError","InvalidTxParamsError","BigNumber","buildTx","syncBuildTx","unpackTx","calculateMinFee","isKeyOfObject","_buildTx","txType","denomination","absoluteTtl","_params","params","senderKey","spend","oracleQuery","nameClaim","nameUpdate","nameRevoke","nameTransfer","namePreClaim","oracleRegister","contractCreate","gaAttach","contractCall","oracleExtend","oracleResponse","channelCloseSolo","channelSlash","channelSettle","channelSnapshotSolo","payingFor","ctVersion","getVmVersion","abiVersion","NO_ABI","tx","senderId","extraParams","prepareTxParams","vmVersion","onNode","consensusProtocolVersion","getNodeInfo","supportedProtocol","protocolForTX","nonce","ttl","fee","f","vsn","strategy","txParams","getAccountNextNonce","catch","nextNonce","getCurrentKeyBlock","height"],"sources":["../../src/tx/index.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2022 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Transaction methods\n *\n * This is implementation of [Tx](api/tx.md) relays\n * the creation of transactions to {@link Node}.\n * These methods provide ability to create native transactions.\n */\nimport {\n ABI_VERSIONS, CtVersion, PROTOCOL_VM_ABI, TX_TYPE, TX_TTL, TxParamsCommon\n} from './builder/schema'\nimport {\n ArgumentError, UnsupportedProtocolError, UnknownTxError, InvalidTxParamsError\n} from '../utils/errors'\nimport BigNumber from 'bignumber.js'\nimport Node from '../Node'\nimport { EncodedData } from '../utils/encoder'\nimport { buildTx as syncBuildTx, unpackTx } from './builder/index'\nimport calculateMinFee from './min-fee'\nimport { isKeyOfObject } from '../utils/other'\nimport { AE_AMOUNT_FORMATS } from '../utils/amount-formatter'\n\ntype Int = number | string | BigNumber\n\n// uses a new feature, probably typescript-eslint doesn't support it yet\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport type BuildTxOptions <TxType extends TX_TYPE, OmitFields extends string> =\n Omit<Parameters<typeof _buildTx<TxType>>[1], OmitFields>\n\n// TODO: find a better name or rearrange methods\nexport async function _buildTx<TxType extends TX_TYPE> (\n txType: TxType,\n { denomination, absoluteTtl, ..._params }:\n Omit<Parameters<typeof syncBuildTx<TxType, 'tx'>>[0], 'fee' | 'nonce' | 'ttl' | 'ctVersion' | 'abiVersion'>\n & {\n onNode: Node\n fee?: Int\n nonce?: number\n ttl?: number\n denomination?: AE_AMOUNT_FORMATS\n absoluteTtl?: boolean\n }\n & (TxType extends TX_TYPE.oracleExtend | TX_TYPE.oracleResponse ? { callerId: EncodedData<'ak'> } : {})\n & (TxType extends TX_TYPE.contractCreate | TX_TYPE.gaAttach ? { ctVersion?: CtVersion } : {})\n & (TxType extends TX_TYPE.contractCall | TX_TYPE.oracleRegister\n ? { abiVersion?: ABI_VERSIONS } : {})\n): Promise<EncodedData<'tx'>> {\n // TODO: avoid this assertion\n const params = _params as unknown as TxParamsCommon & { onNode: Node }\n let senderKey: keyof TxParamsCommon | '<absent>'\n switch (txType) {\n case TX_TYPE.spend:\n case TX_TYPE.oracleQuery:\n senderKey = 'senderId'\n break\n case TX_TYPE.nameClaim:\n case TX_TYPE.nameUpdate:\n case TX_TYPE.nameRevoke:\n case TX_TYPE.nameTransfer:\n case TX_TYPE.namePreClaim:\n case TX_TYPE.oracleRegister:\n senderKey = 'accountId'\n break\n case TX_TYPE.contractCreate:\n case TX_TYPE.gaAttach:\n senderKey = 'ownerId'\n break\n case TX_TYPE.contractCall:\n case TX_TYPE.oracleExtend:\n case TX_TYPE.oracleResponse:\n senderKey = 'callerId'\n break\n case TX_TYPE.channelCloseSolo:\n case TX_TYPE.channelSlash:\n case TX_TYPE.channelSettle:\n case TX_TYPE.channelSnapshotSolo:\n senderKey = 'fromId'\n break\n case TX_TYPE.payingFor:\n senderKey = 'payerId'\n break\n default:\n throw new ArgumentError('txType', 'valid transaction type', txType)\n }\n // TODO: move specific cases to field-types\n if ([TX_TYPE.contractCreate, TX_TYPE.gaAttach].includes(txType)) {\n params.ctVersion = await getVmVersion(\n TX_TYPE.contractCreate, { ...params, ...params.ctVersion }\n )\n }\n if (txType === TX_TYPE.contractCall) {\n params.abiVersion = (await getVmVersion(TX_TYPE.contractCall, params)).abiVersion\n }\n if (txType === TX_TYPE.oracleRegister) {\n params.abiVersion ??= ABI_VERSIONS.NO_ABI\n }\n if (txType === TX_TYPE.payingFor) {\n params.tx = unpackTx(params.tx)\n }\n const senderId = params[senderKey]\n // TODO: do this check on TypeScript level\n if (senderId == null) throw new InvalidTxParamsError(`Transaction field ${senderKey} is missed`)\n const extraParams = await prepareTxParams(\n txType, { ...params, senderId, denomination, absoluteTtl }\n )\n return syncBuildTx({ ...params, ...extraParams } as any, txType, { denomination }).tx\n}\n\n/**\n * Validated vm/abi version or get default based on transaction type and NODE version\n *\n * @param txType - Type of transaction\n * @param ctVersion - Object with vm and abi version fields\n * @returns Object with vm/abi version\n */\nexport async function getVmVersion (\n txType: TX_TYPE.contractCreate, ctVersion: Partial<CtVersion> & { onNode: Node }\n): Promise<CtVersion>\nexport async function getVmVersion (\n txType: TX_TYPE, ctVersion: Partial<Pick<CtVersion, 'abiVersion'>> & { onNode: Node }\n): Promise<Pick<CtVersion, 'abiVersion'>>\nexport async function getVmVersion (\n txType: TX_TYPE, { vmVersion, abiVersion, onNode }: Partial<CtVersion> & { onNode: Node }\n): Promise<Partial<CtVersion>> {\n const { consensusProtocolVersion } = await onNode.getNodeInfo()\n if (!isKeyOfObject(consensusProtocolVersion, PROTOCOL_VM_ABI)) {\n throw new UnsupportedProtocolError('Not supported consensus protocol version')\n }\n const supportedProtocol = PROTOCOL_VM_ABI[consensusProtocolVersion]\n if (!isKeyOfObject(txType, supportedProtocol)) {\n throw new UnknownTxError('Not supported tx type')\n }\n const protocolForTX = supportedProtocol[txType]\n abiVersion ??= protocolForTX.abiVersion[0]\n vmVersion ??= protocolForTX.vmVersion[0]\n return { vmVersion, abiVersion }\n}\n\n/**\n * Calculate fee, get absolute ttl (ttl + height), get account nonce\n *\n * @param txType - Type of transaction\n * @param params - Object which contains all tx data\n * @returns Object with account nonce, absolute ttl and transaction fee\n */\nexport async function prepareTxParams (\n txType: TX_TYPE,\n {\n senderId,\n nonce,\n ttl = TX_TTL,\n fee: f,\n absoluteTtl,\n vsn,\n strategy,\n denomination,\n onNode,\n ...txParams\n }: PrepareTxParamsOptions\n): Promise<{ fee: BigNumber, ttl: number, nonce: number }> {\n nonce ??= (\n await onNode.getAccountNextNonce(senderId, { strategy }).catch(() => ({ nextNonce: 1 }))\n ).nextNonce\n\n if (ttl !== 0) {\n if (ttl < 0) throw new ArgumentError('ttl', 'greater or equal to 0', ttl)\n ttl += absoluteTtl === true ? 0 : (await onNode.getCurrentKeyBlock()).height\n }\n\n const fee = f != null\n ? new BigNumber(f)\n : calculateMinFee(txType, { params: { ...txParams, senderId, nonce, ttl }, vsn, denomination })\n return { fee, ttl, nonce }\n}\n\ninterface PrepareTxParamsOptions extends Pick<TxParamsCommon, 'nonce' | 'ttl' | 'fee'> {\n senderId: EncodedData<'ak'>\n vsn?: number\n absoluteTtl?: boolean\n strategy?: 'continuity' | 'max'\n denomination?: AE_AMOUNT_FORMATS\n onNode: Node\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
|
+
import { TX_TYPE, TxParamsCommon } from './builder/schema';
|
|
3
|
+
import { AE_AMOUNT_FORMATS } from '../utils/amount-formatter';
|
|
4
|
+
/**
|
|
5
|
+
* Calculate min fee
|
|
6
|
+
* @param txType - Transaction type
|
|
7
|
+
* @param options - Options object
|
|
8
|
+
* @param options.params - Tx params
|
|
9
|
+
* @example
|
|
10
|
+
* ```js
|
|
11
|
+
* calculateMinFee('spendTx', { gasLimit, params })
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export default function calculateMinFee(txType: TX_TYPE, { params, vsn, denomination }: CalculateMinFeeOptions): BigNumber;
|
|
15
|
+
interface CalculateMinFeeOptions {
|
|
16
|
+
params: TxParamsCommon;
|
|
17
|
+
vsn?: number;
|
|
18
|
+
denomination?: AE_AMOUNT_FORMATS;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
2
|
+
import BigNumber from 'bignumber.js';
|
|
3
|
+
import { MIN_GAS_PRICE, TX_TYPE } from "./builder/schema.mjs";
|
|
4
|
+
import { buildTx } from "./builder/index.mjs";
|
|
5
|
+
import { isKeyOfObject } from "../utils/other.mjs";
|
|
6
|
+
const BASE_GAS = 15000;
|
|
7
|
+
const GAS_PER_BYTE = 20;
|
|
8
|
+
const KEY_BLOCK_INTERVAL = 3;
|
|
9
|
+
/**
|
|
10
|
+
* Calculate the Base fee gas
|
|
11
|
+
* @see {@link https://github.com/aeternity/protocol/blob/master/consensus/README.md#gas}
|
|
12
|
+
* @param txType - The transaction type
|
|
13
|
+
* @returns The base fee
|
|
14
|
+
* @example
|
|
15
|
+
* ```js
|
|
16
|
+
* TX_FEE_BASE('channelForceProgress') => new BigNumber(30 * 15000)
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const TX_FEE_BASE_GAS = txType => {
|
|
21
|
+
var _feeFactors;
|
|
22
|
+
|
|
23
|
+
const feeFactors = {
|
|
24
|
+
[TX_TYPE.channelForceProgress]: 30,
|
|
25
|
+
[TX_TYPE.channelOffChain]: 0,
|
|
26
|
+
[TX_TYPE.channelOffChainCallContract]: 0,
|
|
27
|
+
[TX_TYPE.channelOffChainCreateContract]: 0,
|
|
28
|
+
[TX_TYPE.channelOffChainUpdateDeposit]: 0,
|
|
29
|
+
[TX_TYPE.channelOffChainUpdateWithdrawal]: 0,
|
|
30
|
+
[TX_TYPE.channelOffChainUpdateTransfer]: 0,
|
|
31
|
+
[TX_TYPE.contractCreate]: 5,
|
|
32
|
+
[TX_TYPE.contractCall]: 12,
|
|
33
|
+
[TX_TYPE.gaAttach]: 5,
|
|
34
|
+
[TX_TYPE.gaMeta]: 5,
|
|
35
|
+
[TX_TYPE.payingFor]: 1 / 5
|
|
36
|
+
};
|
|
37
|
+
const factor = (_feeFactors = feeFactors[txType]) !== null && _feeFactors !== void 0 ? _feeFactors : 1;
|
|
38
|
+
return new BigNumber(factor * BASE_GAS);
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Calculate fee for Other types of transactions
|
|
42
|
+
* @see {@link https://github.com/aeternity/protocol/blob/master/consensus/README.md#gas}
|
|
43
|
+
* @param txType - The transaction type
|
|
44
|
+
* @param txSize - The transaction size
|
|
45
|
+
* @returns parameters - The transaction parameters
|
|
46
|
+
* @returns parameters.relativeTtl - The relative ttl
|
|
47
|
+
* @returns parameters.innerTxSize - The size of the inner transaction
|
|
48
|
+
* @returns The Other fee
|
|
49
|
+
* @example
|
|
50
|
+
* ```js
|
|
51
|
+
* TX_FEE_OTHER_GAS('oracleResponse',10, { relativeTtl: 10, innerTxSize: 10 })
|
|
52
|
+
* => new BigNumber(10).times(20).plus(Math.ceil(32000 * 10 / Math.floor(60 * 24 * 365 / 2)))
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
const TX_FEE_OTHER_GAS = (txType, txSize, _ref) => {
|
|
58
|
+
let {
|
|
59
|
+
relativeTtl,
|
|
60
|
+
innerTxSize
|
|
61
|
+
} = _ref;
|
|
62
|
+
|
|
63
|
+
switch (txType) {
|
|
64
|
+
case TX_TYPE.oracleRegister:
|
|
65
|
+
case TX_TYPE.oracleExtend:
|
|
66
|
+
case TX_TYPE.oracleQuery:
|
|
67
|
+
case TX_TYPE.oracleResponse:
|
|
68
|
+
return new BigNumber(txSize).times(GAS_PER_BYTE).plus(Math.ceil(32000 * relativeTtl / Math.floor(60 * 24 * 365 / KEY_BLOCK_INTERVAL)));
|
|
69
|
+
|
|
70
|
+
case TX_TYPE.gaMeta:
|
|
71
|
+
case TX_TYPE.payingFor:
|
|
72
|
+
return new BigNumber(txSize).minus(innerTxSize).times(GAS_PER_BYTE);
|
|
73
|
+
|
|
74
|
+
default:
|
|
75
|
+
return new BigNumber(txSize).times(GAS_PER_BYTE);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
function getOracleRelativeTtl(params, txType) {
|
|
80
|
+
const ttlKeys = {
|
|
81
|
+
[TX_TYPE.oracleRegister]: 'oracleTtlValue',
|
|
82
|
+
[TX_TYPE.oracleExtend]: 'oracleTtlValue',
|
|
83
|
+
[TX_TYPE.oracleQuery]: 'queryTtlValue',
|
|
84
|
+
[TX_TYPE.oracleResponse]: 'responseTtlValue'
|
|
85
|
+
};
|
|
86
|
+
if (!isKeyOfObject(txType, ttlKeys)) return 1;else return params[ttlKeys[txType]];
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Calculate fee based on tx type and params
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
function buildFee(txType, _ref2) {
|
|
94
|
+
var _context;
|
|
95
|
+
|
|
96
|
+
let {
|
|
97
|
+
params,
|
|
98
|
+
vsn,
|
|
99
|
+
denomination
|
|
100
|
+
} = _ref2;
|
|
101
|
+
const {
|
|
102
|
+
rlpEncoded: {
|
|
103
|
+
length
|
|
104
|
+
}
|
|
105
|
+
} = buildTx(params, txType, {
|
|
106
|
+
vsn,
|
|
107
|
+
denomination
|
|
108
|
+
});
|
|
109
|
+
return TX_FEE_BASE_GAS(txType).plus(TX_FEE_OTHER_GAS(txType, length, {
|
|
110
|
+
relativeTtl: getOracleRelativeTtl(params, txType),
|
|
111
|
+
innerTxSize: _includesInstanceProperty(_context = [TX_TYPE.gaMeta, TX_TYPE.payingFor]).call(_context, txType) ? params.tx.tx.encodedTx.rlpEncoded.length : 0
|
|
112
|
+
})).times(MIN_GAS_PRICE);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Calculate min fee
|
|
116
|
+
* @param txType - Transaction type
|
|
117
|
+
* @param options - Options object
|
|
118
|
+
* @param options.params - Tx params
|
|
119
|
+
* @example
|
|
120
|
+
* ```js
|
|
121
|
+
* calculateMinFee('spendTx', { gasLimit, params })
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
export default function calculateMinFee(txType, _ref3) {
|
|
127
|
+
let {
|
|
128
|
+
params,
|
|
129
|
+
vsn,
|
|
130
|
+
denomination
|
|
131
|
+
} = _ref3;
|
|
132
|
+
let fee = new BigNumber(0);
|
|
133
|
+
let previousFee;
|
|
134
|
+
|
|
135
|
+
do {
|
|
136
|
+
previousFee = fee;
|
|
137
|
+
fee = buildFee(txType, {
|
|
138
|
+
params: { ...params,
|
|
139
|
+
fee
|
|
140
|
+
},
|
|
141
|
+
vsn,
|
|
142
|
+
denomination
|
|
143
|
+
});
|
|
144
|
+
} while (!fee.eq(previousFee));
|
|
145
|
+
|
|
146
|
+
return fee;
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=min-fee.mjs.map
|