@aeternity/aepp-sdk 13.0.0-alpha.0 → 13.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/aesophia_cli +0 -0
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +1 -1
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +4206 -1127
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdkBase.d.ts +3 -3
- package/es/AeSdkBase.mjs +4 -0
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkMethods.d.ts +3 -4
- package/es/AeSdkMethods.mjs.map +1 -1
- package/es/Node.d.ts +4 -3
- package/es/Node.mjs +1 -1
- package/es/Node.mjs.map +1 -1
- package/es/account/Base.d.ts +2 -2
- package/es/account/Base.mjs.map +1 -1
- package/es/account/Generalized.mjs +5 -3
- package/es/account/Generalized.mjs.map +1 -1
- package/es/account/Ledger.mjs +2 -1
- package/es/account/Ledger.mjs.map +1 -1
- package/es/account/Memory.mjs +2 -1
- package/es/account/Memory.mjs.map +1 -1
- package/es/aens.d.ts +1 -1
- package/es/aens.mjs +5 -1
- package/es/aens.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +19 -4
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
- package/es/chain.d.ts +9 -1
- package/es/chain.mjs +4 -1
- package/es/chain.mjs.map +1 -1
- package/es/channel/Base.d.ts +6 -1
- package/es/channel/Base.mjs +9 -6
- package/es/channel/Base.mjs.map +1 -1
- package/es/channel/Contract.d.ts +8 -7
- package/es/channel/Contract.mjs +1 -1
- package/es/channel/Contract.mjs.map +1 -1
- package/es/channel/Spend.d.ts +3 -1
- package/es/channel/Spend.mjs +4 -2
- package/es/channel/Spend.mjs.map +1 -1
- package/es/channel/handlers.mjs +11 -9
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/internal.mjs +3 -1
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Contract.d.ts +21 -46
- package/es/contract/Contract.mjs +69 -52
- package/es/contract/Contract.mjs.map +1 -1
- package/es/contract/compiler/Base.d.ts +81 -0
- package/es/contract/compiler/Base.mjs +5 -0
- package/es/contract/compiler/Base.mjs.map +1 -0
- package/es/contract/compiler/Cli.d.ts +23 -0
- package/es/contract/compiler/Cli.mjs +155 -0
- package/es/contract/compiler/Cli.mjs.map +1 -0
- package/es/contract/compiler/Http.d.ts +32 -0
- package/es/contract/{CompilerHttp.mjs → compiler/Http.mjs} +64 -9
- package/es/contract/compiler/Http.mjs.map +1 -0
- package/es/contract/compiler/HttpNode.d.ts +17 -0
- package/es/contract/compiler/HttpNode.mjs +26 -0
- package/es/contract/compiler/HttpNode.mjs.map +1 -0
- package/es/contract/compiler/getFileSystem.d.ts +6 -0
- package/es/contract/compiler/getFileSystem.mjs +40 -0
- package/es/contract/compiler/getFileSystem.mjs.map +1 -0
- package/es/contract/ga.d.ts +5 -4
- package/es/contract/ga.mjs +11 -2
- package/es/contract/ga.mjs.map +1 -1
- package/es/index-browser.d.ts +39 -0
- package/es/index-browser.mjs +55 -0
- package/es/index-browser.mjs.map +1 -0
- package/es/index.d.ts +4 -38
- package/es/index.mjs +4 -53
- package/es/index.mjs.map +1 -1
- package/es/oracle.mjs +1 -1
- package/es/oracle.mjs.map +1 -1
- package/es/spend.mjs +1 -3
- package/es/spend.mjs.map +1 -1
- package/es/tx/builder/constants.d.ts +28 -1
- package/es/tx/builder/constants.mjs +32 -3
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/field-types/abi-version.d.ts +10 -0
- package/es/tx/builder/field-types/abi-version.mjs +20 -0
- package/es/tx/builder/field-types/abi-version.mjs.map +1 -0
- package/es/tx/builder/field-types/address.d.ts +5 -6
- package/es/tx/builder/field-types/address.mjs +17 -8
- package/es/tx/builder/field-types/address.mjs.map +1 -1
- package/es/tx/builder/field-types/array.d.ts +7 -0
- package/es/tx/builder/field-types/array.mjs +11 -0
- package/es/tx/builder/field-types/array.mjs.map +1 -0
- package/es/tx/builder/field-types/boolean.d.ts +6 -0
- package/es/tx/builder/field-types/boolean.mjs +13 -0
- package/es/tx/builder/field-types/boolean.mjs.map +1 -0
- package/es/tx/builder/field-types/coin-amount.d.ts +1 -1
- package/es/tx/builder/field-types/coin-amount.mjs.map +1 -1
- package/es/tx/builder/field-types/ct-version.d.ts +30 -0
- package/es/tx/builder/field-types/ct-version.mjs +48 -0
- package/es/tx/builder/field-types/ct-version.mjs.map +1 -0
- package/es/tx/builder/field-types/deposit.d.ts +1 -1
- package/es/tx/builder/field-types/deposit.mjs.map +1 -1
- package/es/tx/builder/field-types/encoded.d.ts +6 -0
- package/es/tx/builder/field-types/encoded.mjs +21 -0
- package/es/tx/builder/field-types/encoded.mjs.map +1 -0
- package/es/tx/builder/field-types/entry.d.ts +11 -0
- package/es/tx/builder/field-types/entry.mjs +31 -0
- package/es/tx/builder/field-types/entry.mjs.map +1 -0
- package/es/tx/builder/field-types/enumeration.d.ts +5 -3
- package/es/tx/builder/field-types/enumeration.mjs +11 -2
- package/es/tx/builder/field-types/enumeration.mjs.map +1 -1
- package/es/tx/builder/field-types/fee.d.ts +10 -7
- package/es/tx/builder/field-types/fee.mjs +24 -20
- package/es/tx/builder/field-types/fee.mjs.map +1 -1
- package/es/tx/builder/field-types/gas-limit.d.ts +5 -2
- package/es/tx/builder/field-types/gas-limit.mjs +9 -6
- package/es/tx/builder/field-types/gas-limit.mjs.map +1 -1
- package/es/tx/builder/field-types/gas-price.d.ts +1 -1
- package/es/tx/builder/field-types/index.d.ts +66 -28
- package/es/tx/builder/field-types/index.mjs +30 -12
- package/es/tx/builder/field-types/index.mjs.map +1 -1
- package/es/tx/builder/field-types/mptree.d.ts +37 -0
- package/es/tx/builder/field-types/mptree.mjs +268 -0
- package/es/tx/builder/field-types/mptree.mjs.map +1 -0
- package/es/tx/builder/field-types/name-fee.d.ts +1 -2
- package/es/tx/builder/field-types/name-fee.mjs.map +1 -1
- package/es/tx/builder/field-types/name-id.mjs +2 -1
- package/es/tx/builder/field-types/name-id.mjs.map +1 -1
- package/es/tx/builder/field-types/pointers.mjs +2 -2
- package/es/tx/builder/field-types/pointers.mjs.map +1 -1
- package/es/tx/builder/field-types/raw.d.ts +6 -0
- package/es/tx/builder/field-types/raw.mjs +13 -0
- package/es/tx/builder/field-types/raw.mjs.map +1 -0
- package/es/tx/builder/field-types/short-u-int-const.d.ts +5 -0
- package/es/tx/builder/field-types/short-u-int-const.mjs +16 -0
- package/es/tx/builder/field-types/short-u-int-const.mjs.map +1 -0
- package/es/tx/builder/field-types/string.d.ts +6 -0
- package/es/tx/builder/field-types/string.mjs +10 -0
- package/es/tx/builder/field-types/string.mjs.map +1 -0
- package/es/tx/builder/field-types/u-int.d.ts +1 -2
- package/es/tx/builder/field-types/u-int.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +11 -29
- package/es/tx/builder/index.mjs +50 -211
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +2111 -571
- package/es/tx/builder/schema.mjs +57 -125
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +5 -20
- package/es/tx/index.mjs +31 -88
- package/es/tx/index.mjs.map +1 -1
- package/es/tx/validator.d.ts +3 -5
- package/es/tx/validator.mjs +82 -95
- package/es/tx/validator.mjs.map +1 -1
- package/es/utils/bytes.mjs +1 -1
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/errors.d.ts +3 -8
- package/es/utils/errors.mjs +1 -11
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/other.d.ts +1 -1
- package/package.json +35 -27
- package/src/AeSdkBase.ts +6 -3
- package/src/AeSdkMethods.ts +3 -4
- package/src/Node.ts +6 -3
- package/src/account/Base.ts +2 -2
- package/src/account/Generalized.ts +2 -2
- package/src/account/Ledger.ts +1 -1
- package/src/account/Memory.ts +1 -1
- package/src/aens.ts +3 -2
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +18 -7
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +2 -2
- package/src/chain.ts +5 -3
- package/src/channel/Base.ts +13 -5
- package/src/channel/Contract.ts +11 -10
- package/src/channel/Spend.ts +7 -2
- package/src/channel/handlers.ts +10 -9
- package/src/channel/internal.ts +1 -1
- package/src/contract/Contract.ts +69 -79
- package/src/contract/compiler/Base.ts +94 -0
- package/src/contract/compiler/Cli.ts +134 -0
- package/src/contract/compiler/Http.ts +124 -0
- package/src/contract/compiler/HttpNode.ts +26 -0
- package/src/contract/compiler/getFileSystem.ts +42 -0
- package/src/contract/ga.ts +9 -6
- package/src/index-browser.ts +58 -0
- package/src/index.ts +4 -56
- package/src/oracle.ts +1 -1
- package/src/spend.ts +1 -1
- package/src/tx/builder/constants.ts +32 -3
- package/src/tx/builder/field-types/abi-version.ts +21 -0
- package/src/tx/builder/field-types/address.ts +23 -13
- package/src/tx/builder/field-types/array.ts +19 -0
- package/src/tx/builder/field-types/boolean.ts +9 -0
- package/src/tx/builder/field-types/coin-amount.ts +2 -1
- package/src/tx/builder/field-types/ct-version.ts +50 -0
- package/src/tx/builder/field-types/deposit.ts +1 -1
- package/src/tx/builder/field-types/encoded.ts +27 -0
- package/src/tx/builder/field-types/entry.ts +31 -0
- package/src/tx/builder/field-types/enumeration.ts +15 -4
- package/src/tx/builder/field-types/fee.ts +38 -18
- package/src/tx/builder/field-types/gas-limit.ts +12 -7
- package/src/tx/builder/field-types/index.ts +46 -17
- package/src/tx/builder/field-types/mptree.ts +242 -0
- package/src/tx/builder/field-types/name-fee.ts +1 -2
- package/src/tx/builder/field-types/name-id.ts +1 -1
- package/src/tx/builder/field-types/pointers.ts +2 -2
- package/src/tx/builder/field-types/raw.ts +9 -0
- package/src/tx/builder/field-types/short-u-int-const.ts +20 -0
- package/src/tx/builder/field-types/string.ts +11 -0
- package/src/tx/builder/field-types/u-int.ts +1 -3
- package/src/tx/builder/index.ts +63 -247
- package/src/tx/builder/schema.ts +273 -323
- package/src/tx/index.ts +37 -104
- package/src/tx/validator.ts +72 -95
- package/src/utils/bytes.ts +1 -1
- package/src/utils/errors.ts +4 -13
- package/types-legacy/ts4.2/AeSdkBase.d.ts +3 -3
- package/types-legacy/ts4.2/AeSdkMethods.d.ts +3 -4
- package/types-legacy/ts4.2/Node.d.ts +3 -3
- package/types-legacy/ts4.2/account/Base.d.ts +2 -2
- package/types-legacy/ts4.2/aens.d.ts +1 -1
- package/types-legacy/ts4.2/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
- package/types-legacy/ts4.2/chain.d.ts +9 -1
- package/types-legacy/ts4.2/channel/Base.d.ts +6 -1
- package/types-legacy/ts4.2/channel/Contract.d.ts +8 -7
- package/types-legacy/ts4.2/channel/Spend.d.ts +3 -1
- package/types-legacy/ts4.2/contract/Contract.d.ts +21 -46
- package/types-legacy/ts4.2/contract/compiler/Base.d.ts +81 -0
- package/types-legacy/ts4.2/contract/compiler/Cli.d.ts +23 -0
- package/types-legacy/ts4.2/contract/compiler/Http.d.ts +32 -0
- package/types-legacy/ts4.2/contract/compiler/HttpNode.d.ts +17 -0
- package/types-legacy/ts4.2/contract/compiler/getFileSystem.d.ts +6 -0
- package/types-legacy/ts4.2/contract/ga.d.ts +5 -4
- package/types-legacy/ts4.2/index-browser.d.ts +39 -0
- package/types-legacy/ts4.2/index.d.ts +4 -38
- package/types-legacy/ts4.2/tx/builder/constants.d.ts +28 -1
- package/types-legacy/ts4.2/tx/builder/field-types/abi-version.d.ts +10 -0
- package/types-legacy/ts4.2/tx/builder/field-types/address.d.ts +11 -12
- package/types-legacy/ts4.2/tx/builder/field-types/array.d.ts +7 -0
- package/types-legacy/ts4.2/tx/builder/field-types/boolean.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/coin-amount.d.ts +1 -1
- package/types-legacy/ts4.2/tx/builder/field-types/ct-version.d.ts +42 -0
- package/types-legacy/ts4.2/tx/builder/field-types/deposit.d.ts +1 -1
- package/types-legacy/ts4.2/tx/builder/field-types/encoded.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/entry.d.ts +11 -0
- package/types-legacy/ts4.2/tx/builder/field-types/enumeration.d.ts +5 -3
- package/types-legacy/ts4.2/tx/builder/field-types/fee.d.ts +10 -7
- package/types-legacy/ts4.2/tx/builder/field-types/gas-limit.d.ts +5 -2
- package/types-legacy/ts4.2/tx/builder/field-types/gas-price.d.ts +1 -1
- package/types-legacy/ts4.2/tx/builder/field-types/index.d.ts +72 -28
- package/types-legacy/ts4.2/tx/builder/field-types/mptree.d.ts +43 -0
- package/types-legacy/ts4.2/tx/builder/field-types/name-fee.d.ts +1 -2
- package/types-legacy/ts4.2/tx/builder/field-types/raw.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/short-u-int-const.d.ts +5 -0
- package/types-legacy/ts4.2/tx/builder/field-types/string.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/u-int.d.ts +1 -2
- package/types-legacy/ts4.2/tx/builder/index.d.ts +11 -29
- package/types-legacy/ts4.2/tx/builder/schema.d.ts +2380 -668
- package/types-legacy/ts4.2/tx/index.d.ts +5 -20
- package/types-legacy/ts4.2/tx/validator.d.ts +3 -5
- package/types-legacy/ts4.2/utils/errors.d.ts +3 -8
- package/types-legacy/ts4.2/utils/other.d.ts +1 -1
- package/types-legacy/ts4.5/AeSdkBase.d.ts +3 -3
- package/types-legacy/ts4.5/AeSdkMethods.d.ts +3 -4
- package/types-legacy/ts4.5/Node.d.ts +3 -3
- package/types-legacy/ts4.5/account/Base.d.ts +2 -2
- package/types-legacy/ts4.5/aens.d.ts +1 -1
- package/types-legacy/ts4.5/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
- package/types-legacy/ts4.5/chain.d.ts +9 -1
- package/types-legacy/ts4.5/channel/Base.d.ts +6 -1
- package/types-legacy/ts4.5/channel/Contract.d.ts +8 -7
- package/types-legacy/ts4.5/channel/Spend.d.ts +3 -1
- package/types-legacy/ts4.5/contract/Contract.d.ts +21 -46
- package/types-legacy/ts4.5/contract/compiler/Base.d.ts +81 -0
- package/types-legacy/ts4.5/contract/compiler/Cli.d.ts +23 -0
- package/types-legacy/ts4.5/contract/compiler/Http.d.ts +32 -0
- package/types-legacy/ts4.5/contract/compiler/HttpNode.d.ts +17 -0
- package/types-legacy/ts4.5/contract/compiler/getFileSystem.d.ts +6 -0
- package/types-legacy/ts4.5/contract/ga.d.ts +5 -4
- package/types-legacy/ts4.5/index-browser.d.ts +39 -0
- package/types-legacy/ts4.5/index.d.ts +4 -38
- package/types-legacy/ts4.5/tx/builder/constants.d.ts +28 -1
- package/types-legacy/ts4.5/tx/builder/field-types/abi-version.d.ts +10 -0
- package/types-legacy/ts4.5/tx/builder/field-types/address.d.ts +11 -12
- package/types-legacy/ts4.5/tx/builder/field-types/array.d.ts +7 -0
- package/types-legacy/ts4.5/tx/builder/field-types/boolean.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/coin-amount.d.ts +1 -1
- package/types-legacy/ts4.5/tx/builder/field-types/ct-version.d.ts +42 -0
- package/types-legacy/ts4.5/tx/builder/field-types/deposit.d.ts +1 -1
- package/types-legacy/ts4.5/tx/builder/field-types/encoded.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/entry.d.ts +11 -0
- package/types-legacy/ts4.5/tx/builder/field-types/enumeration.d.ts +5 -3
- package/types-legacy/ts4.5/tx/builder/field-types/fee.d.ts +10 -7
- package/types-legacy/ts4.5/tx/builder/field-types/gas-limit.d.ts +5 -2
- package/types-legacy/ts4.5/tx/builder/field-types/gas-price.d.ts +1 -1
- package/types-legacy/ts4.5/tx/builder/field-types/index.d.ts +72 -28
- package/types-legacy/ts4.5/tx/builder/field-types/mptree.d.ts +43 -0
- package/types-legacy/ts4.5/tx/builder/field-types/name-fee.d.ts +1 -2
- package/types-legacy/ts4.5/tx/builder/field-types/raw.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/short-u-int-const.d.ts +5 -0
- package/types-legacy/ts4.5/tx/builder/field-types/string.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/u-int.d.ts +1 -2
- package/types-legacy/ts4.5/tx/builder/index.d.ts +11 -29
- package/types-legacy/ts4.5/tx/builder/schema.d.ts +2380 -668
- package/types-legacy/ts4.5/tx/index.d.ts +5 -20
- package/types-legacy/ts4.5/tx/validator.d.ts +3 -5
- package/types-legacy/ts4.5/utils/errors.d.ts +3 -8
- package/types-legacy/ts4.5/utils/other.d.ts +1 -1
- package/es/contract/CompilerHttp.d.ts +0 -18
- package/es/contract/CompilerHttp.mjs.map +0 -1
- package/es/tx/builder/field-types/addresses.d.ts +0 -6
- package/es/tx/builder/field-types/addresses.mjs +0 -13
- package/es/tx/builder/field-types/addresses.mjs.map +0 -1
- package/es/utils/mptree.d.ts +0 -26
- package/es/utils/mptree.mjs +0 -143
- package/es/utils/mptree.mjs.map +0 -1
- package/src/contract/CompilerHttp.ts +0 -67
- package/src/tx/builder/field-types/addresses.ts +0 -18
- package/src/utils/mptree.ts +0 -145
- package/types-legacy/ts4.2/contract/CompilerHttp.d.ts +0 -18
- package/types-legacy/ts4.2/tx/builder/field-types/addresses.d.ts +0 -6
- package/types-legacy/ts4.2/utils/mptree.d.ts +0 -32
- package/types-legacy/ts4.5/contract/CompilerHttp.d.ts +0 -18
- package/types-legacy/ts4.5/tx/builder/field-types/addresses.d.ts +0 -6
- package/types-legacy/ts4.5/utils/mptree.d.ts +0 -32
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import _buffer from "buffer";
|
|
2
|
+
const {
|
|
3
|
+
Buffer: _Buffer
|
|
4
|
+
} = _buffer;
|
|
5
|
+
import { ConsensusProtocolVersion, VmVersion, AbiVersion } from "../constants.mjs"; // First abi/vm by default
|
|
6
|
+
export const ProtocolToVmAbi = {
|
|
7
|
+
[ConsensusProtocolVersion.Iris]: {
|
|
8
|
+
'contract-create': {
|
|
9
|
+
vmVersion: [VmVersion.Fate2],
|
|
10
|
+
abiVersion: [AbiVersion.Fate]
|
|
11
|
+
},
|
|
12
|
+
// TODO: Ensure that AEVM (Sophia?) is still available here
|
|
13
|
+
'contract-call': {
|
|
14
|
+
vmVersion: [],
|
|
15
|
+
abiVersion: [AbiVersion.Fate, AbiVersion.Sophia]
|
|
16
|
+
},
|
|
17
|
+
'oracle-call': {
|
|
18
|
+
vmVersion: [],
|
|
19
|
+
abiVersion: [AbiVersion.NoAbi, AbiVersion.Sophia]
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
export function getProtocolDetails(protocolVersion, type) {
|
|
24
|
+
var _protocol$vmVersion$;
|
|
25
|
+
const protocol = ProtocolToVmAbi[protocolVersion][type];
|
|
26
|
+
return {
|
|
27
|
+
vmVersion: (_protocol$vmVersion$ = protocol.vmVersion[0]) !== null && _protocol$vmVersion$ !== void 0 ? _protocol$vmVersion$ : VmVersion.Fate2,
|
|
28
|
+
abiVersion: protocol.abiVersion[0]
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export default {
|
|
32
|
+
serialize(value, _ref) {
|
|
33
|
+
var _value;
|
|
34
|
+
let {
|
|
35
|
+
consensusProtocolVersion = ConsensusProtocolVersion.Iris
|
|
36
|
+
} = _ref;
|
|
37
|
+
(_value = value) !== null && _value !== void 0 ? _value : value = getProtocolDetails(consensusProtocolVersion, 'contract-create');
|
|
38
|
+
return _Buffer.from([value.vmVersion, 0, value.abiVersion]);
|
|
39
|
+
},
|
|
40
|
+
deserialize(buffer) {
|
|
41
|
+
const [vm,, abi] = buffer;
|
|
42
|
+
return {
|
|
43
|
+
vmVersion: +vm,
|
|
44
|
+
abiVersion: +abi
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=ct-version.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ct-version.mjs","names":["ConsensusProtocolVersion","VmVersion","AbiVersion","ProtocolToVmAbi","Iris","vmVersion","Fate2","abiVersion","Fate","Sophia","NoAbi","getProtocolDetails","protocolVersion","type","protocol","serialize","value","consensusProtocolVersion","from","deserialize","buffer","vm","abi"],"sources":["../../../../src/tx/builder/field-types/ct-version.ts"],"sourcesContent":["import { ConsensusProtocolVersion, VmVersion, AbiVersion } from '../constants';\n\n// First abi/vm by default\nexport const ProtocolToVmAbi = {\n [ConsensusProtocolVersion.Iris]: {\n 'contract-create': {\n vmVersion: [VmVersion.Fate2], abiVersion: [AbiVersion.Fate],\n },\n // TODO: Ensure that AEVM (Sophia?) is still available here\n 'contract-call': {\n vmVersion: [], abiVersion: [AbiVersion.Fate, AbiVersion.Sophia],\n },\n 'oracle-call': {\n vmVersion: [], abiVersion: [AbiVersion.NoAbi, AbiVersion.Sophia],\n },\n },\n} as const;\n\nexport interface CtVersion {\n vmVersion: VmVersion;\n abiVersion: AbiVersion;\n}\n\nexport function getProtocolDetails(\n protocolVersion: ConsensusProtocolVersion,\n type: 'contract-create' | 'contract-call' | 'oracle-call',\n): CtVersion {\n const protocol = ProtocolToVmAbi[protocolVersion][type];\n return {\n vmVersion: protocol.vmVersion[0] ?? VmVersion.Fate2,\n abiVersion: protocol.abiVersion[0],\n };\n}\n\nexport default {\n serialize(\n value: CtVersion | undefined,\n { consensusProtocolVersion = ConsensusProtocolVersion.Iris }:\n { consensusProtocolVersion: ConsensusProtocolVersion },\n ): Buffer {\n value ??= getProtocolDetails(consensusProtocolVersion, 'contract-create');\n\n return Buffer.from([value.vmVersion, 0, value.abiVersion]);\n },\n\n deserialize(buffer: Buffer): CtVersion {\n const [vm, , abi] = buffer;\n return { vmVersion: +vm, abiVersion: +abi };\n },\n};\n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OAAO;MAAEf,SAAS,EAAE,CAACgB,EAAE;MAAEd,UAAU,EAAE,CAACe;IAAI,CAAC;EAC7C;AACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deposit.mjs","names":["coinAmount","IllegalArgumentError","serialize","value","options","toString"],"sources":["../../../../src/tx/builder/field-types/deposit.ts"],"sourcesContent":["import coinAmount from './coin-amount';\nimport { Int } from '
|
|
1
|
+
{"version":3,"file":"deposit.mjs","names":["coinAmount","IllegalArgumentError","serialize","value","options","toString"],"sources":["../../../../src/tx/builder/field-types/deposit.ts"],"sourcesContent":["import coinAmount from './coin-amount';\nimport { Int } from '../constants';\nimport { IllegalArgumentError } from '../../../utils/errors';\n\nexport default {\n ...coinAmount,\n\n /**\n * @param value - Deposit value in string format. Should be equal to '0'.\n * @param options - Options\n * @returns Deposit value Buffer.\n */\n serialize(\n value: Int | undefined,\n options: Parameters<typeof coinAmount['serialize']>[1],\n ): Buffer {\n value ??= 0;\n if (+value !== 0) throw new IllegalArgumentError(`Contract deposit is not refundable, so it should be equal 0, got ${value.toString()} instead`);\n return coinAmount.serialize(value, options);\n },\n};\n"],"mappings":"OAAOA,UAAU;AAAA,SAERC,oBAAoB;AAE7B,eAAe;EACb,GAAGD,UAAU;EAEb;AACF;AACA;AACA;AACA;EACEE,SAAS,CACPC,KAAsB,EACtBC,OAAsD,EAC9C;IAAA;IACR,UAAAD,KAAK,2CAALA,KAAK,GAAK,CAAC;IACX,IAAI,CAACA,KAAK,KAAK,CAAC,EAAE,MAAM,IAAIF,oBAAoB,CAAE,oEAAmEE,KAAK,CAACE,QAAQ,EAAG,UAAS,CAAC;IAChJ,OAAOL,UAAU,CAACE,SAAS,CAACC,KAAK,EAAEC,OAAO,CAAC;EAC7C;AACF,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Encoded, Encoding } from '../../../utils/encoder';
|
|
3
|
+
export default function genEncodedField<E extends Encoding, Optional extends boolean = false>(encoding: E, optional?: Optional): {
|
|
4
|
+
serialize: Optional extends true ? (value?: Encoded.Generic<E>) => Buffer : (value: Encoded.Generic<E>) => Buffer;
|
|
5
|
+
deserialize: (value: Buffer) => Encoded.Generic<Encoding>;
|
|
6
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import _buffer from "buffer";
|
|
2
|
+
const {
|
|
3
|
+
Buffer: _Buffer
|
|
4
|
+
} = _buffer;
|
|
5
|
+
import { decode, encode } from "../../../utils/encoder.mjs";
|
|
6
|
+
import { ArgumentError } from "../../../utils/errors.mjs";
|
|
7
|
+
export default function genEncodedField(encoding, optional) {
|
|
8
|
+
return {
|
|
9
|
+
serialize(encodedData) {
|
|
10
|
+
if (encodedData == null) {
|
|
11
|
+
if (optional === true) return _Buffer.from([]);
|
|
12
|
+
throw new ArgumentError('Encoded data', 'provided', encodedData);
|
|
13
|
+
}
|
|
14
|
+
return decode(encodedData);
|
|
15
|
+
},
|
|
16
|
+
deserialize(buffer) {
|
|
17
|
+
return encode(buffer, encoding);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=encoded.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoded.mjs","names":["decode","encode","ArgumentError","genEncodedField","encoding","optional","serialize","encodedData","from","deserialize","buffer"],"sources":["../../../../src/tx/builder/field-types/encoded.ts"],"sourcesContent":["import {\n decode, encode, Encoded, Encoding,\n} from '../../../utils/encoder';\nimport { ArgumentError } from '../../../utils/errors';\n\nexport default function genEncodedField<E extends Encoding, Optional extends boolean = false>(\n encoding: E,\n optional?: Optional,\n): {\n serialize: Optional extends true\n ? (value?: Encoded.Generic<E>) => Buffer : (value: Encoded.Generic<E>) => Buffer;\n deserialize: (value: Buffer) => Encoded.Generic<Encoding>;\n } {\n return {\n serialize(encodedData?: Encoded.Generic<E>) {\n if (encodedData == null) {\n if (optional === true) return Buffer.from([]);\n throw new ArgumentError('Encoded data', 'provided', encodedData);\n }\n return decode(encodedData);\n },\n\n deserialize(buffer) {\n return encode(buffer, encoding);\n },\n };\n}\n"],"mappings":";;;;SACEA,MAAM,EAAEC,MAAM;AAAA,SAEPC,aAAa;AAEtB,eAAe,SAASC,eAAe,CACrCC,QAAW,EACXC,QAAmB,EAKjB;EACF,OAAO;IACLC,SAAS,CAACC,WAAgC,EAAE;MAC1C,IAAIA,WAAW,IAAI,IAAI,EAAE;QACvB,IAAIF,QAAQ,KAAK,IAAI,EAAE,OAAO,QAAOG,IAAI,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAIN,aAAa,CAAC,cAAc,EAAE,UAAU,EAAEK,WAAW,CAAC;MAClE;MACA,OAAOP,MAAM,CAACO,WAAW,CAAC;IAC5B,CAAC;IAEDE,WAAW,CAACC,MAAM,EAAE;MAClB,OAAOT,MAAM,CAACS,MAAM,EAAEN,QAAQ,CAAC;IACjC;EACF,CAAC;AACH"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Tag } from '../constants';
|
|
3
|
+
import type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index';
|
|
4
|
+
export default function genEntryField<T extends Tag = Tag>(tag?: T): {
|
|
5
|
+
serialize: (value: any, options: {
|
|
6
|
+
buildTx: typeof buildTxType;
|
|
7
|
+
}) => Buffer;
|
|
8
|
+
deserialize: (value: Buffer, options: {
|
|
9
|
+
unpackTx: typeof unpackTxType;
|
|
10
|
+
}) => any;
|
|
11
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import _buffer from "buffer";
|
|
2
|
+
const {
|
|
3
|
+
Buffer: _Buffer
|
|
4
|
+
} = _buffer;
|
|
5
|
+
import { decode, encode, Encoding } from "../../../utils/encoder.mjs";
|
|
6
|
+
import { ArgumentError } from "../../../utils/errors.mjs";
|
|
7
|
+
export default function genEntryField(tag) {
|
|
8
|
+
return {
|
|
9
|
+
serialize(txParams, _ref) {
|
|
10
|
+
let {
|
|
11
|
+
buildTx
|
|
12
|
+
} = _ref;
|
|
13
|
+
if (ArrayBuffer.isView(txParams)) return _Buffer.from(txParams);
|
|
14
|
+
return decode(buildTx({
|
|
15
|
+
...txParams,
|
|
16
|
+
...(tag != null && {
|
|
17
|
+
tag
|
|
18
|
+
})
|
|
19
|
+
}));
|
|
20
|
+
},
|
|
21
|
+
deserialize(buf, _ref2) {
|
|
22
|
+
let {
|
|
23
|
+
unpackTx
|
|
24
|
+
} = _ref2;
|
|
25
|
+
const tx = unpackTx(encode(buf, Encoding.Transaction));
|
|
26
|
+
if (tag != null && tx.tag !== tag) throw new ArgumentError('Tag', tag, tx.tag);
|
|
27
|
+
return tx;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=entry.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry.mjs","names":["decode","encode","Encoding","ArgumentError","genEntryField","tag","serialize","txParams","buildTx","ArrayBuffer","isView","from","deserialize","buf","unpackTx","tx","Transaction"],"sources":["../../../../src/tx/builder/field-types/entry.ts"],"sourcesContent":["import { decode, encode, Encoding } from '../../../utils/encoder';\nimport { Tag } from '../constants';\nimport { ArgumentError } from '../../../utils/errors';\nimport type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index';\n\nexport default function genEntryField<T extends Tag = Tag>(tag?: T): {\n serialize: (\n // TODO: replace with `Parameters<typeof buildTxType<T>>[0]`,\n // but fix TS2502 value is referenced directly or indirectly in its own type annotation\n value: any,\n options: { buildTx: typeof buildTxType },\n ) => Buffer;\n deserialize: (\n value: Buffer, options: { unpackTx: typeof unpackTxType },\n // TODO: replace with `ReturnType<typeof unpackTxType<T>>`,\n // TS2577 Return type annotation circularly references itself\n ) => any;\n} {\n return {\n serialize(txParams, { buildTx }) {\n if (ArrayBuffer.isView(txParams)) return Buffer.from(txParams as any);\n return decode(buildTx({ ...txParams, ...tag != null && { tag } }));\n },\n\n deserialize(buf, { unpackTx }) {\n const tx = unpackTx(encode(buf, Encoding.Transaction));\n if (tag != null && tx.tag !== tag) throw new ArgumentError('Tag', tag, tx.tag);\n return tx;\n },\n };\n}\n"],"mappings":";;;;SAASA,MAAM,EAAEC,MAAM,EAAEC,QAAQ;AAAA,SAExBC,aAAa;AAGtB,eAAe,SAASC,aAAa,CAAsBC,GAAO,EAYhE;EACA,OAAO;IACLC,SAAS,CAACC,QAAQ,QAAe;MAAA,IAAb;QAAEC;MAAQ,CAAC;MAC7B,IAAIC,WAAW,CAACC,MAAM,CAACH,QAAQ,CAAC,EAAE,OAAO,QAAOI,IAAI,CAACJ,QAAQ,CAAQ;MACrE,OAAOP,MAAM,CAACQ,OAAO,CAAC;QAAE,GAAGD,QAAQ;QAAE,IAAGF,GAAG,IAAI,IAAI,IAAI;UAAEA;QAAI,CAAC;MAAC,CAAC,CAAC,CAAC;IACpE,CAAC;IAEDO,WAAW,CAACC,GAAG,SAAgB;MAAA,IAAd;QAAEC;MAAS,CAAC;MAC3B,MAAMC,EAAE,GAAGD,QAAQ,CAACb,MAAM,CAACY,GAAG,EAAEX,QAAQ,CAACc,WAAW,CAAC,CAAC;MACtD,IAAIX,GAAG,IAAI,IAAI,IAAIU,EAAE,CAACV,GAAG,KAAKA,GAAG,EAAE,MAAM,IAAIF,aAAa,CAAC,KAAK,EAAEE,GAAG,EAAEU,EAAE,CAACV,GAAG,CAAC;MAC9E,OAAOU,EAAE;IACX;EACF,CAAC;AACH"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
export default function genEnumerationField<Enum extends
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export default function genEnumerationField<Enum extends {
|
|
3
|
+
[key: string]: number | string;
|
|
4
|
+
}>(enm: Enum): {
|
|
5
|
+
serialize: (value: Enum[keyof Enum]) => Buffer;
|
|
6
|
+
deserialize: (value: Buffer) => Enum[keyof Enum];
|
|
5
7
|
};
|
|
@@ -3,18 +3,27 @@ const {
|
|
|
3
3
|
Buffer: _Buffer
|
|
4
4
|
} = _buffer;
|
|
5
5
|
import { ArgumentError } from "../../../utils/errors.mjs";
|
|
6
|
-
|
|
6
|
+
import { isItemOfArray } from "../../../utils/other.mjs";
|
|
7
|
+
export default function genEnumerationField(enm) {
|
|
8
|
+
const values = Object.values(enm).filter(v => typeof v === 'number');
|
|
7
9
|
return {
|
|
8
10
|
serialize(value) {
|
|
9
11
|
if (typeof value !== 'number') throw new ArgumentError('value', 'to be a number', value);
|
|
10
12
|
if (value > 0xff) throw new ArgumentError('value', 'to be less than 256', value);
|
|
13
|
+
if (!isItemOfArray(value, values)) {
|
|
14
|
+
throw new ArgumentError('value', 'to be a value of Enum', value);
|
|
15
|
+
}
|
|
11
16
|
return _Buffer.from([value]);
|
|
12
17
|
},
|
|
13
18
|
deserialize(buffer) {
|
|
14
19
|
if (buffer.length !== 1) {
|
|
15
20
|
throw new ArgumentError('buffer', 'to have single element', buffer.length);
|
|
16
21
|
}
|
|
17
|
-
|
|
22
|
+
const value = buffer[0];
|
|
23
|
+
if (!isItemOfArray(value, values)) {
|
|
24
|
+
throw new ArgumentError('value', 'to be a value of Enum', value);
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
18
27
|
}
|
|
19
28
|
};
|
|
20
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enumeration.mjs","names":["ArgumentError","genEnumerationField","serialize","value","from","deserialize","buffer","length"],"sources":["../../../../src/tx/builder/field-types/enumeration.ts"],"sourcesContent":["import { ArgumentError } from '../../../utils/errors';\n\nexport default function genEnumerationField
|
|
1
|
+
{"version":3,"file":"enumeration.mjs","names":["ArgumentError","isItemOfArray","genEnumerationField","enm","values","Object","filter","v","serialize","value","from","deserialize","buffer","length"],"sources":["../../../../src/tx/builder/field-types/enumeration.ts"],"sourcesContent":["import { ArgumentError } from '../../../utils/errors';\nimport { isItemOfArray } from '../../../utils/other';\n\nexport default function genEnumerationField<\n Enum extends { [key: string]: number | string },\n>(enm: Enum): {\n serialize: (value: Enum[keyof Enum]) => Buffer;\n deserialize: (value: Buffer) => Enum[keyof Enum];\n} {\n const values = Object.values(enm).filter((v) => typeof v === 'number');\n return {\n serialize(value) {\n if (typeof value !== 'number') throw new ArgumentError('value', 'to be a number', value);\n if (value > 0xff) throw new ArgumentError('value', 'to be less than 256', value);\n if (!isItemOfArray(value, values)) {\n throw new ArgumentError('value', 'to be a value of Enum', value);\n }\n return Buffer.from([value]);\n },\n\n deserialize(buffer) {\n if (buffer.length !== 1) {\n throw new ArgumentError('buffer', 'to have single element', buffer.length);\n }\n const value = buffer[0];\n if (!isItemOfArray(value, values)) {\n throw new ArgumentError('value', 'to be a value of Enum', value);\n }\n return value as Enum[keyof Enum];\n },\n };\n}\n"],"mappings":";;;;SAASA,aAAa;AAAA,SACbC,aAAa;AAEtB,eAAe,SAASC,mBAAmB,CAEzCC,GAAS,EAGT;EACA,MAAMC,MAAM,GAAGC,MAAM,CAACD,MAAM,CAACD,GAAG,CAAC,CAACG,MAAM,CAAEC,CAAC,IAAK,OAAOA,CAAC,KAAK,QAAQ,CAAC;EACtE,OAAO;IACLC,SAAS,CAACC,KAAK,EAAE;MACf,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE,MAAM,IAAIT,aAAa,CAAC,OAAO,EAAE,gBAAgB,EAAES,KAAK,CAAC;MACxF,IAAIA,KAAK,GAAG,IAAI,EAAE,MAAM,IAAIT,aAAa,CAAC,OAAO,EAAE,qBAAqB,EAAES,KAAK,CAAC;MAChF,IAAI,CAACR,aAAa,CAACQ,KAAK,EAAEL,MAAM,CAAC,EAAE;QACjC,MAAM,IAAIJ,aAAa,CAAC,OAAO,EAAE,uBAAuB,EAAES,KAAK,CAAC;MAClE;MACA,OAAO,QAAOC,IAAI,CAAC,CAACD,KAAK,CAAC,CAAC;IAC7B,CAAC;IAEDE,WAAW,CAACC,MAAM,EAAE;MAClB,IAAIA,MAAM,CAACC,MAAM,KAAK,CAAC,EAAE;QACvB,MAAM,IAAIb,aAAa,CAAC,QAAQ,EAAE,wBAAwB,EAAEY,MAAM,CAACC,MAAM,CAAC;MAC5E;MACA,MAAMJ,KAAK,GAAGG,MAAM,CAAC,CAAC,CAAC;MACvB,IAAI,CAACX,aAAa,CAACQ,KAAK,EAAEL,MAAM,CAAC,EAAE;QACjC,MAAM,IAAIJ,aAAa,CAAC,OAAO,EAAE,uBAAuB,EAAES,KAAK,CAAC;MAClE;MACA,OAAOA,KAAK;IACd;EACF,CAAC;AACH"}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import BigNumber from 'bignumber.js';
|
|
3
|
-
import {
|
|
3
|
+
import { Encoded } from '../../../utils/encoder';
|
|
4
|
+
import type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index';
|
|
4
5
|
/**
|
|
5
6
|
* Calculate fee based on tx type and params
|
|
6
7
|
*/
|
|
7
|
-
export declare function buildFee(
|
|
8
|
+
export declare function buildFee(builtTx: Encoded.Transaction, unpackTx: typeof unpackTxType, buildTx: typeof buildTxType): BigNumber;
|
|
8
9
|
declare const _default: {
|
|
9
|
-
serializeAettos(_value: string | undefined, {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
serializeAettos(_value: string | undefined, { rebuildTx, unpackTx, buildTx, _computingMinFee, _pickBiggerFee, }: {
|
|
11
|
+
rebuildTx: (params: any) => Encoded.Transaction;
|
|
12
|
+
unpackTx: typeof unpackTxType;
|
|
13
|
+
buildTx: typeof buildTxType;
|
|
14
|
+
_computingMinFee?: BigNumber | undefined;
|
|
15
|
+
_pickBiggerFee?: boolean | undefined;
|
|
13
16
|
}): string;
|
|
14
|
-
serialize(value: import("
|
|
17
|
+
serialize(value: import("../constants").Int | undefined, { denomination, ...options }: import("./coin-amount").Options): Buffer;
|
|
15
18
|
deserialize(value: Buffer): string;
|
|
16
19
|
};
|
|
17
20
|
export default _default;
|
|
@@ -3,6 +3,7 @@ import { IllegalArgumentError } from "../../../utils/errors.mjs";
|
|
|
3
3
|
import { MIN_GAS_PRICE, Tag } from "../constants.mjs";
|
|
4
4
|
import coinAmount from "./coin-amount.mjs";
|
|
5
5
|
import { isKeyOfObject } from "../../../utils/other.mjs";
|
|
6
|
+
import { decode } from "../../../utils/encoder.mjs";
|
|
6
7
|
const BASE_GAS = 15000;
|
|
7
8
|
const GAS_PER_BYTE = 20;
|
|
8
9
|
const KEY_BLOCK_INTERVAL = 3;
|
|
@@ -70,45 +71,45 @@ const TX_FEE_OTHER_GAS = (txType, txSize, _ref) => {
|
|
|
70
71
|
return new BigNumber(txSize).times(GAS_PER_BYTE);
|
|
71
72
|
}
|
|
72
73
|
};
|
|
73
|
-
function getOracleRelativeTtl(params
|
|
74
|
+
function getOracleRelativeTtl(params) {
|
|
74
75
|
const ttlKeys = {
|
|
75
76
|
[Tag.OracleRegisterTx]: 'oracleTtlValue',
|
|
76
77
|
[Tag.OracleExtendTx]: 'oracleTtlValue',
|
|
77
78
|
[Tag.OracleQueryTx]: 'queryTtlValue',
|
|
78
79
|
[Tag.OracleResponseTx]: 'responseTtlValue'
|
|
79
80
|
};
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
const {
|
|
82
|
+
tag
|
|
83
|
+
} = params;
|
|
84
|
+
if (!isKeyOfObject(tag, ttlKeys)) return 1;
|
|
85
|
+
return params[ttlKeys[tag]];
|
|
82
86
|
}
|
|
83
87
|
|
|
84
88
|
/**
|
|
85
89
|
* Calculate fee based on tx type and params
|
|
86
90
|
*/
|
|
87
|
-
export function buildFee(
|
|
91
|
+
export function buildFee(builtTx, unpackTx, buildTx) {
|
|
88
92
|
const {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
relativeTtl: getOracleRelativeTtl(txObject, txType),
|
|
96
|
-
innerTxSize: [Tag.GaMetaTx, Tag.PayingForTx].includes(txType) ? txObject.tx.tx.encodedTx.rlpEncoded.length : 0
|
|
93
|
+
length
|
|
94
|
+
} = decode(builtTx);
|
|
95
|
+
const txObject = unpackTx(builtTx);
|
|
96
|
+
return TX_FEE_BASE_GAS(txObject.tag).plus(TX_FEE_OTHER_GAS(txObject.tag, length, {
|
|
97
|
+
relativeTtl: getOracleRelativeTtl(txObject),
|
|
98
|
+
innerTxSize: txObject.tag === Tag.GaMetaTx || txObject.tag === Tag.PayingForTx ? decode(buildTx(txObject.tx.encodedTx)).length : 0
|
|
97
99
|
})).times(MIN_GAS_PRICE);
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
/**
|
|
101
103
|
* Calculate min fee
|
|
102
104
|
* @category transaction builder
|
|
103
|
-
* @param txType - Transaction type
|
|
104
105
|
* @param rebuildTx - Callback to get built transaction with specific fee
|
|
105
106
|
*/
|
|
106
|
-
function calculateMinFee(
|
|
107
|
+
function calculateMinFee(rebuildTx, unpackTx, buildTx) {
|
|
107
108
|
let fee = new BigNumber(0);
|
|
108
109
|
let previousFee;
|
|
109
110
|
do {
|
|
110
111
|
previousFee = fee;
|
|
111
|
-
fee = buildFee(
|
|
112
|
+
fee = buildFee(rebuildTx(fee), unpackTx, buildTx);
|
|
112
113
|
} while (!fee.eq(previousFee));
|
|
113
114
|
return fee;
|
|
114
115
|
}
|
|
@@ -116,16 +117,19 @@ export default {
|
|
|
116
117
|
...coinAmount,
|
|
117
118
|
serializeAettos(_value, _ref2) {
|
|
118
119
|
let {
|
|
119
|
-
txType,
|
|
120
120
|
rebuildTx,
|
|
121
|
-
|
|
121
|
+
unpackTx,
|
|
122
|
+
buildTx,
|
|
123
|
+
_computingMinFee,
|
|
124
|
+
_pickBiggerFee
|
|
122
125
|
} = _ref2;
|
|
123
|
-
if (_computingMinFee != null) return _computingMinFee;
|
|
124
|
-
const minFee = calculateMinFee(
|
|
126
|
+
if (_computingMinFee != null) return _computingMinFee.toFixed();
|
|
127
|
+
const minFee = calculateMinFee(fee => rebuildTx({
|
|
125
128
|
_computingMinFee: fee
|
|
126
|
-
}));
|
|
129
|
+
}), unpackTx, buildTx);
|
|
127
130
|
const value = new BigNumber(_value !== null && _value !== void 0 ? _value : minFee);
|
|
128
131
|
if (minFee.gt(value)) {
|
|
132
|
+
if (_pickBiggerFee === true) return minFee.toFixed();
|
|
129
133
|
throw new IllegalArgumentError(`Fee ${value.toString()} must be bigger then ${minFee}`);
|
|
130
134
|
}
|
|
131
135
|
return value.toFixed();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fee.mjs","names":["BigNumber","IllegalArgumentError","MIN_GAS_PRICE","Tag","coinAmount","isKeyOfObject","BASE_GAS","GAS_PER_BYTE","KEY_BLOCK_INTERVAL","TX_FEE_BASE_GAS","txType","feeFactors","ChannelForceProgressTx","ChannelOffChainTx","ChannelOffChainUpdateCallContract","ChannelOffChainUpdateCreateContract","ChannelOffChainUpdateDeposit","ChannelOffChainUpdateWithdraw","ChannelOffChainUpdateTransfer","ContractCreateTx","ContractCallTx","GaAttachTx","GaMetaTx","PayingForTx","factor","TX_FEE_OTHER_GAS","txSize","relativeTtl","innerTxSize","OracleRegisterTx","OracleExtendTx","OracleQueryTx","OracleResponseTx","times","plus","Math","ceil","floor","minus","getOracleRelativeTtl","params","ttlKeys","buildFee","
|
|
1
|
+
{"version":3,"file":"fee.mjs","names":["BigNumber","IllegalArgumentError","MIN_GAS_PRICE","Tag","coinAmount","isKeyOfObject","decode","BASE_GAS","GAS_PER_BYTE","KEY_BLOCK_INTERVAL","TX_FEE_BASE_GAS","txType","feeFactors","ChannelForceProgressTx","ChannelOffChainTx","ChannelOffChainUpdateCallContract","ChannelOffChainUpdateCreateContract","ChannelOffChainUpdateDeposit","ChannelOffChainUpdateWithdraw","ChannelOffChainUpdateTransfer","ContractCreateTx","ContractCallTx","GaAttachTx","GaMetaTx","PayingForTx","factor","TX_FEE_OTHER_GAS","txSize","relativeTtl","innerTxSize","OracleRegisterTx","OracleExtendTx","OracleQueryTx","OracleResponseTx","times","plus","Math","ceil","floor","minus","getOracleRelativeTtl","params","ttlKeys","tag","buildFee","builtTx","unpackTx","buildTx","length","txObject","tx","encodedTx","calculateMinFee","rebuildTx","fee","previousFee","eq","serializeAettos","_value","_computingMinFee","_pickBiggerFee","toFixed","minFee","value","gt","toString"],"sources":["../../../../src/tx/builder/field-types/fee.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport { IllegalArgumentError } from '../../../utils/errors';\nimport { MIN_GAS_PRICE, Tag } from '../constants';\nimport coinAmount from './coin-amount';\nimport { isKeyOfObject } from '../../../utils/other';\nimport { decode, Encoded } from '../../../utils/encoder';\nimport type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index';\n\nconst BASE_GAS = 15000;\nconst GAS_PER_BYTE = 20;\nconst KEY_BLOCK_INTERVAL = 3;\n\n/**\n * Calculate the Base fee gas\n * @see {@link https://github.com/aeternity/protocol/blob/master/consensus/README.md#gas}\n * @param txType - The transaction type\n * @returns The base fee\n * @example\n * ```js\n * TX_FEE_BASE('channelForceProgress') => new BigNumber(30 * 15000)\n * ```\n */\nconst TX_FEE_BASE_GAS = (txType: Tag): BigNumber => {\n const feeFactors = {\n [Tag.ChannelForceProgressTx]: 30,\n [Tag.ChannelOffChainTx]: 0,\n [Tag.ChannelOffChainUpdateCallContract]: 0,\n [Tag.ChannelOffChainUpdateCreateContract]: 0,\n [Tag.ChannelOffChainUpdateDeposit]: 0,\n [Tag.ChannelOffChainUpdateWithdraw]: 0,\n [Tag.ChannelOffChainUpdateTransfer]: 0,\n [Tag.ContractCreateTx]: 5,\n [Tag.ContractCallTx]: 12,\n [Tag.GaAttachTx]: 5,\n [Tag.GaMetaTx]: 5,\n [Tag.PayingForTx]: 1 / 5,\n } as const;\n const factor = feeFactors[txType as keyof typeof feeFactors] ?? 1;\n return new BigNumber(factor * BASE_GAS);\n};\n\n/**\n * Calculate fee for Other types of transactions\n * @see {@link https://github.com/aeternity/protocol/blob/master/consensus/README.md#gas}\n * @param txType - The transaction type\n * @param txSize - The transaction size\n * @returns parameters - The transaction parameters\n * @returns parameters.relativeTtl - The relative ttl\n * @returns parameters.innerTxSize - The size of the inner transaction\n * @returns The Other fee\n * @example\n * ```js\n * TX_FEE_OTHER_GAS('oracleResponse',10, { relativeTtl: 10, innerTxSize: 10 })\n * => new BigNumber(10).times(20).plus(Math.ceil(32000 * 10 / Math.floor(60 * 24 * 365 / 2)))\n * ```\n */\nconst TX_FEE_OTHER_GAS = (\n txType: Tag,\n txSize: number,\n { relativeTtl, innerTxSize }: { relativeTtl: number; innerTxSize: number },\n): BigNumber => {\n switch (txType) {\n case Tag.OracleRegisterTx:\n case Tag.OracleExtendTx:\n case Tag.OracleQueryTx:\n case Tag.OracleResponseTx:\n return new BigNumber(txSize)\n .times(GAS_PER_BYTE)\n .plus(\n Math.ceil((32000 * relativeTtl) / Math.floor((60 * 24 * 365) / KEY_BLOCK_INTERVAL)),\n );\n case Tag.GaMetaTx:\n case Tag.PayingForTx:\n return new BigNumber(txSize).minus(innerTxSize).times(GAS_PER_BYTE);\n default:\n return new BigNumber(txSize).times(GAS_PER_BYTE);\n }\n};\n\nfunction getOracleRelativeTtl(params: any): number {\n const ttlKeys = {\n [Tag.OracleRegisterTx]: 'oracleTtlValue',\n [Tag.OracleExtendTx]: 'oracleTtlValue',\n [Tag.OracleQueryTx]: 'queryTtlValue',\n [Tag.OracleResponseTx]: 'responseTtlValue',\n } as const;\n\n const { tag } = params;\n if (!isKeyOfObject(tag, ttlKeys)) return 1;\n return params[ttlKeys[tag]];\n}\n\n/**\n * Calculate fee based on tx type and params\n */\nexport function buildFee(\n builtTx: Encoded.Transaction,\n unpackTx: typeof unpackTxType,\n buildTx: typeof buildTxType,\n): BigNumber {\n const { length } = decode(builtTx);\n const txObject = unpackTx(builtTx);\n\n return TX_FEE_BASE_GAS(txObject.tag)\n .plus(TX_FEE_OTHER_GAS(txObject.tag, length, {\n relativeTtl: getOracleRelativeTtl(txObject),\n innerTxSize: txObject.tag === Tag.GaMetaTx || txObject.tag === Tag.PayingForTx\n ? decode(buildTx(txObject.tx.encodedTx)).length\n : 0,\n }))\n .times(MIN_GAS_PRICE);\n}\n\n/**\n * Calculate min fee\n * @category transaction builder\n * @param rebuildTx - Callback to get built transaction with specific fee\n */\nfunction calculateMinFee(\n rebuildTx: (value: BigNumber) => Encoded.Transaction,\n unpackTx: typeof unpackTxType,\n buildTx: typeof buildTxType,\n): BigNumber {\n let fee = new BigNumber(0);\n let previousFee;\n do {\n previousFee = fee;\n fee = buildFee(rebuildTx(fee), unpackTx, buildTx);\n } while (!fee.eq(previousFee));\n return fee;\n}\n\nexport default {\n ...coinAmount,\n\n serializeAettos(\n _value: string | undefined,\n {\n rebuildTx, unpackTx, buildTx, _computingMinFee, _pickBiggerFee,\n }: {\n rebuildTx: (params: any) => Encoded.Transaction;\n unpackTx: typeof unpackTxType;\n buildTx: typeof buildTxType;\n _computingMinFee?: BigNumber;\n _pickBiggerFee?: boolean;\n },\n ): string {\n if (_computingMinFee != null) return _computingMinFee.toFixed();\n const minFee = calculateMinFee(\n (fee) => rebuildTx({ _computingMinFee: fee }),\n unpackTx,\n buildTx,\n );\n const value = new BigNumber(_value ?? minFee);\n if (minFee.gt(value)) {\n if (_pickBiggerFee === true) return minFee.toFixed();\n throw new IllegalArgumentError(`Fee ${value.toString()} must be bigger then ${minFee}`);\n }\n return value.toFixed();\n },\n};\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,cAAc;AAAC,SAC5BC,oBAAoB;AAAA,SACpBC,aAAa,EAAEC,GAAG;AAAA,OACpBC,UAAU;AAAA,SACRC,aAAa;AAAA,SACbC,MAAM;AAGf,MAAMC,QAAQ,GAAG,KAAK;AACtB,MAAMC,YAAY,GAAG,EAAE;AACvB,MAAMC,kBAAkB,GAAG,CAAC;;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,eAAe,GAAIC,MAAW,IAAgB;EAAA;EAClD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BAAoB,CAAE,OAAM8D,KAAK,CAACE,QAAQ,EAAG,wBAAuBH,MAAO,EAAC,CAAC;IACzF;IACA,OAAOC,KAAK,CAACF,OAAO,EAAE;EACxB;AACF,CAAC"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Tag } from '../constants';
|
|
3
|
+
import type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index';
|
|
3
4
|
declare const _default: {
|
|
4
|
-
serialize(_value: number | undefined, {
|
|
5
|
-
|
|
5
|
+
serialize(_value: number | undefined, { tag, rebuildTx, unpackTx, buildTx, gasMax, _computingGasLimit, }: {
|
|
6
|
+
tag: Tag;
|
|
6
7
|
rebuildTx: (params: any) => any;
|
|
8
|
+
unpackTx: typeof unpackTxType;
|
|
9
|
+
buildTx: typeof buildTxType;
|
|
7
10
|
gasMax: number;
|
|
8
11
|
_computingGasLimit?: number | undefined;
|
|
9
12
|
}): Buffer;
|
|
@@ -2,22 +2,25 @@ import { IllegalArgumentError } from "../../../utils/errors.mjs";
|
|
|
2
2
|
import { MIN_GAS_PRICE, Tag, MAX_AUTH_FUN_GAS } from "../constants.mjs";
|
|
3
3
|
import shortUInt from "./short-u-int.mjs";
|
|
4
4
|
import { buildFee } from "./fee.mjs";
|
|
5
|
-
function calculateGasLimitMax(
|
|
6
|
-
return gasMax - +buildFee(
|
|
5
|
+
function calculateGasLimitMax(gasMax, rebuildTx, unpackTx, buildTx) {
|
|
6
|
+
return gasMax - +buildFee(rebuildTx(gasMax), unpackTx, buildTx).dividedBy(MIN_GAS_PRICE);
|
|
7
7
|
}
|
|
8
8
|
export default {
|
|
9
9
|
...shortUInt,
|
|
10
10
|
serialize(_value, _ref) {
|
|
11
11
|
let {
|
|
12
|
-
|
|
12
|
+
tag,
|
|
13
13
|
rebuildTx,
|
|
14
|
+
unpackTx,
|
|
15
|
+
buildTx,
|
|
14
16
|
gasMax = 6e6,
|
|
15
17
|
_computingGasLimit
|
|
16
18
|
} = _ref;
|
|
17
19
|
if (_computingGasLimit != null) return shortUInt.serialize(_computingGasLimit);
|
|
18
|
-
const gasLimitMax =
|
|
19
|
-
_computingGasLimit: gasLimit
|
|
20
|
-
|
|
20
|
+
const gasLimitMax = tag === Tag.GaMetaTx ? MAX_AUTH_FUN_GAS : calculateGasLimitMax(gasMax, gasLimit => rebuildTx({
|
|
21
|
+
_computingGasLimit: gasLimit,
|
|
22
|
+
_pickBiggerFee: true
|
|
23
|
+
}), unpackTx, buildTx);
|
|
21
24
|
const value = _value !== null && _value !== void 0 ? _value : gasLimitMax;
|
|
22
25
|
if (value > gasLimitMax) {
|
|
23
26
|
throw new IllegalArgumentError(`Gas limit ${value} must be less or equal to ${gasLimitMax}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gas-limit.mjs","names":["IllegalArgumentError","MIN_GAS_PRICE","Tag","MAX_AUTH_FUN_GAS","shortUInt","buildFee","calculateGasLimitMax","
|
|
1
|
+
{"version":3,"file":"gas-limit.mjs","names":["IllegalArgumentError","MIN_GAS_PRICE","Tag","MAX_AUTH_FUN_GAS","shortUInt","buildFee","calculateGasLimitMax","gasMax","rebuildTx","unpackTx","buildTx","dividedBy","serialize","_value","tag","_computingGasLimit","gasLimitMax","GaMetaTx","gasLimit","_pickBiggerFee","value"],"sources":["../../../../src/tx/builder/field-types/gas-limit.ts"],"sourcesContent":["import { IllegalArgumentError } from '../../../utils/errors';\nimport { MIN_GAS_PRICE, Tag, MAX_AUTH_FUN_GAS } from '../constants';\nimport shortUInt from './short-u-int';\nimport { buildFee } from './fee';\nimport type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index';\n\nfunction calculateGasLimitMax(\n gasMax: number,\n rebuildTx: (value: number) => any,\n unpackTx: typeof unpackTxType,\n buildTx: typeof buildTxType,\n): number {\n return gasMax - +buildFee(rebuildTx(gasMax), unpackTx, buildTx).dividedBy(MIN_GAS_PRICE);\n}\n\nexport default {\n ...shortUInt,\n\n serialize(\n _value: number | undefined,\n {\n tag, rebuildTx, unpackTx, buildTx, gasMax = 6e6, _computingGasLimit,\n }: {\n tag: Tag;\n rebuildTx: (params: any) => any;\n unpackTx: typeof unpackTxType;\n buildTx: typeof buildTxType;\n gasMax: number;\n _computingGasLimit?: number;\n },\n ): Buffer {\n if (_computingGasLimit != null) return shortUInt.serialize(_computingGasLimit);\n\n const gasLimitMax = tag === Tag.GaMetaTx ? MAX_AUTH_FUN_GAS : calculateGasLimitMax(\n gasMax,\n (gasLimit) => rebuildTx({ _computingGasLimit: gasLimit, _pickBiggerFee: true }),\n unpackTx,\n buildTx,\n );\n const value = _value ?? gasLimitMax;\n if (value > gasLimitMax) {\n throw new IllegalArgumentError(`Gas limit ${value} must be less or equal to ${gasLimitMax}`);\n }\n return shortUInt.serialize(value);\n },\n};\n"],"mappings":"SAASA,oBAAoB;AAAA,SACpBC,aAAa,EAAEC,GAAG,EAAEC,gBAAgB;AAAA,OACtCC,SAAS;AAAA,SACPC,QAAQ;AAGjB,SAASC,oBAAoB,CAC3BC,MAAc,EACdC,SAAiC,EACjCC,QAA6B,EAC7BC,OAA2B,EACnB;EACR,OAAOH,MAAM,GAAG,CAACF,QAAQ,CAACG,SAAS,CAACD,MAAM,CAAC,EAAEE,QAAQ,EAAEC,OAAO,CAAC,CAACC,SAAS,CAACV,aAAa,CAAC;AAC1F;AAEA,eAAe;EACb,GAAGG,SAAS;EAEZQ,SAAS,CACPC,MAA0B,QAWlB;IAAA,IAVR;MACEC,GAAG;MAAEN,SAAS;MAAEC,QAAQ;MAAEC,OAAO;MAAEH,MAAM,GAAG,GAAG;MAAEQ;IAQnD,CAAC;IAED,IAAIA,kBAAkB,IAAI,IAAI,EAAE,OAAOX,SAAS,CAACQ,SAAS,CAACG,kBAAkB,CAAC;IAE9E,MAAMC,WAAW,GAAGF,GAAG,KAAKZ,GAAG,CAACe,QAAQ,GAAGd,gBAAgB,GAAGG,oBAAoB,CAChFC,MAAM,EACLW,QAAQ,IAAKV,SAAS,CAAC;MAAEO,kBAAkB,EAAEG,QAAQ;MAAEC,cAAc,EAAE;IAAK,CAAC,CAAC,EAC/EV,QAAQ,EACRC,OAAO,CACR;IACD,MAAMU,KAAK,GAAGP,MAAM,aAANA,MAAM,cAANA,MAAM,GAAIG,WAAW;IACnC,IAAII,KAAK,GAAGJ,WAAW,EAAE;MACvB,MAAM,IAAIhB,oBAAoB,CAAE,aAAYoB,KAAM,6BAA4BJ,WAAY,EAAC,CAAC;IAC9F;IACA,OAAOZ,SAAS,CAACQ,SAAS,CAACQ,KAAK,CAAC;EACnC;AACF,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
declare const _default: {
|
|
3
3
|
serializeAettos(value?: string | undefined): string;
|
|
4
|
-
serialize(value: import("
|
|
4
|
+
serialize(value: import("../constants").Int | undefined, { denomination, ...options }: import("./coin-amount").Options): Buffer;
|
|
5
5
|
deserialize(value: Buffer): string;
|
|
6
6
|
};
|
|
7
7
|
export default _default;
|
|
@@ -1,45 +1,64 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import _address from './address';
|
|
3
|
-
import
|
|
3
|
+
import _array from './array';
|
|
4
|
+
import _encoded from './encoded';
|
|
5
|
+
import _entry from './entry';
|
|
4
6
|
import _enumeration from './enumeration';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
import _mptree from './mptree';
|
|
8
|
+
import _shortUIntConst from './short-u-int-const';
|
|
9
|
+
declare const abiVersion: {
|
|
10
|
+
serialize(value: import("../constants").AbiVersion | undefined, { tag, consensusProtocolVersion }: {
|
|
11
|
+
tag: import("../constants").Tag;
|
|
12
|
+
consensusProtocolVersion: import("../constants").ConsensusProtocolVersion;
|
|
13
|
+
}): Buffer;
|
|
14
|
+
deserialize(buffer: Buffer): import("../constants").AbiVersion;
|
|
12
15
|
};
|
|
13
|
-
declare const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
declare const address: typeof _address;
|
|
17
|
+
declare const array: typeof _array;
|
|
18
|
+
declare const boolean: {
|
|
19
|
+
serialize(value: boolean): Buffer;
|
|
20
|
+
deserialize(buffer: Buffer): boolean;
|
|
16
21
|
};
|
|
17
22
|
declare const coinAmount: {
|
|
18
23
|
serializeAettos(value: string | undefined): string;
|
|
19
|
-
serialize(value: import("
|
|
24
|
+
serialize(value: import("../constants").Int | undefined, { denomination, ...options }: import("./coin-amount").Options): Buffer;
|
|
20
25
|
deserialize(value: Buffer): string;
|
|
21
26
|
};
|
|
22
|
-
declare const
|
|
23
|
-
|
|
27
|
+
declare const ctVersion: {
|
|
28
|
+
serialize(value: import("./ct-version").CtVersion | undefined, { consensusProtocolVersion }: {
|
|
29
|
+
consensusProtocolVersion: import("../constants").ConsensusProtocolVersion;
|
|
30
|
+
}): Buffer;
|
|
31
|
+
deserialize(buffer: Buffer): import("./ct-version").CtVersion;
|
|
32
|
+
};
|
|
24
33
|
declare const deposit: {
|
|
25
|
-
serialize(value: import("
|
|
34
|
+
serialize(value: import("../constants").Int | undefined, options: import("./coin-amount").Options): Buffer;
|
|
26
35
|
serializeAettos(value: string | undefined): string;
|
|
27
36
|
deserialize(value: Buffer): string;
|
|
28
37
|
};
|
|
38
|
+
declare const encoded: typeof _encoded;
|
|
39
|
+
declare const entry: typeof _entry;
|
|
29
40
|
declare const enumeration: typeof _enumeration;
|
|
30
41
|
declare const fee: {
|
|
31
|
-
serializeAettos(_value: string | undefined, {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
serializeAettos(_value: string | undefined, { rebuildTx, unpackTx, buildTx, _computingMinFee, _pickBiggerFee, }: {
|
|
43
|
+
rebuildTx: (params: any) => `tx_${string}`;
|
|
44
|
+
unpackTx: typeof import("..").unpackTx;
|
|
45
|
+
buildTx: typeof import("..").buildTx;
|
|
46
|
+
_computingMinFee?: import("bignumber.js").BigNumber | undefined;
|
|
47
|
+
_pickBiggerFee?: boolean | undefined;
|
|
35
48
|
}): string;
|
|
36
|
-
serialize(value: import("
|
|
49
|
+
serialize(value: import("../constants").Int | undefined, { denomination, ...options }: import("./coin-amount").Options): Buffer;
|
|
50
|
+
deserialize(value: Buffer): string;
|
|
51
|
+
};
|
|
52
|
+
declare const field: {
|
|
53
|
+
serialize(value: string): Buffer;
|
|
37
54
|
deserialize(value: Buffer): string;
|
|
38
55
|
};
|
|
39
56
|
declare const gasLimit: {
|
|
40
|
-
serialize(_value: number | undefined, {
|
|
41
|
-
|
|
57
|
+
serialize(_value: number | undefined, { tag, rebuildTx, unpackTx, buildTx, gasMax, _computingGasLimit, }: {
|
|
58
|
+
tag: import("../constants").Tag;
|
|
42
59
|
rebuildTx: (params: any) => any;
|
|
60
|
+
unpackTx: typeof import("..").unpackTx;
|
|
61
|
+
buildTx: typeof import("..").buildTx;
|
|
43
62
|
gasMax: number;
|
|
44
63
|
_computingGasLimit?: number | undefined;
|
|
45
64
|
}): Buffer;
|
|
@@ -47,9 +66,10 @@ declare const gasLimit: {
|
|
|
47
66
|
};
|
|
48
67
|
declare const gasPrice: {
|
|
49
68
|
serializeAettos(value?: string | undefined): string;
|
|
50
|
-
serialize(value: import("
|
|
69
|
+
serialize(value: import("../constants").Int | undefined, { denomination, ...options }: import("./coin-amount").Options): Buffer;
|
|
51
70
|
deserialize(value: Buffer): string;
|
|
52
71
|
};
|
|
72
|
+
declare const mptree: typeof _mptree;
|
|
53
73
|
declare const name: {
|
|
54
74
|
serialize(value: `${string}.chain`): Buffer;
|
|
55
75
|
deserialize(value: Buffer): `${string}.chain`;
|
|
@@ -58,13 +78,13 @@ declare const nameFee: {
|
|
|
58
78
|
serializeAettos(_value: string | undefined, txFields: {
|
|
59
79
|
name: `${string}.chain`;
|
|
60
80
|
}): string;
|
|
61
|
-
serialize(value: import("
|
|
81
|
+
serialize(value: import("../constants").Int | undefined, txFields: {
|
|
62
82
|
name: `${string}.chain`;
|
|
63
83
|
} & import("./coin-amount").Options): Buffer;
|
|
64
84
|
deserialize(value: Buffer): string;
|
|
65
85
|
};
|
|
66
86
|
declare const nameId: {
|
|
67
|
-
serialize(value:
|
|
87
|
+
serialize(value: `${string}.chain` | `nm_${string}`): Buffer;
|
|
68
88
|
deserialize: (value: Buffer) => `nm_${string}`;
|
|
69
89
|
};
|
|
70
90
|
declare const pointers: {
|
|
@@ -75,8 +95,26 @@ declare const pointers: {
|
|
|
75
95
|
id: `ch_${string}` | `ct_${string}` | `ok_${string}` | `ak_${string}` | `cm_${string}` | `nm_${string}`;
|
|
76
96
|
})[];
|
|
77
97
|
};
|
|
98
|
+
declare const raw: {
|
|
99
|
+
serialize(buffer: Uint8Array): Buffer;
|
|
100
|
+
deserialize(buffer: Buffer): Buffer;
|
|
101
|
+
};
|
|
102
|
+
declare const shortUInt: {
|
|
103
|
+
serialize(value: number): Buffer;
|
|
104
|
+
deserialize(value: Buffer): number;
|
|
105
|
+
};
|
|
106
|
+
declare const shortUIntConst: typeof _shortUIntConst;
|
|
107
|
+
declare const string: {
|
|
108
|
+
serialize(string: string): Buffer;
|
|
109
|
+
deserialize(buffer: Buffer): string;
|
|
110
|
+
};
|
|
111
|
+
declare const uInt: {
|
|
112
|
+
serialize(value: import("../constants").Int): Buffer;
|
|
113
|
+
deserialize(value: Buffer): string;
|
|
114
|
+
};
|
|
115
|
+
export type BinaryData = Buffer | Buffer[] | Buffer[][] | Array<[Buffer, Array<[Buffer, Buffer[]]>]>;
|
|
78
116
|
export interface Field {
|
|
79
|
-
serialize: (value: any, options: any) =>
|
|
80
|
-
deserialize: (value:
|
|
117
|
+
serialize: (value: any, options: any) => BinaryData;
|
|
118
|
+
deserialize: (value: BinaryData, options: any) => any;
|
|
81
119
|
}
|
|
82
|
-
export {
|
|
120
|
+
export { abiVersion, address, array, boolean, coinAmount, ctVersion, deposit, encoded, entry, enumeration, fee, field, gasLimit, gasPrice, mptree, name, nameFee, nameId, pointers, raw, shortUInt, shortUIntConst, string, uInt, };
|