@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
package/src/tx/builder/index.ts
CHANGED
|
@@ -4,166 +4,19 @@ import {
|
|
|
4
4
|
} from '../../utils/encoder';
|
|
5
5
|
import { AE_AMOUNT_FORMATS } from '../../utils/amount-formatter';
|
|
6
6
|
import { hash } from '../../utils/crypto';
|
|
7
|
-
import { Field } from './field-types';
|
|
7
|
+
import { BinaryData, Field } from './field-types';
|
|
8
8
|
import {
|
|
9
|
-
|
|
10
|
-
RawTxObject,
|
|
11
|
-
TX_SCHEMA,
|
|
12
|
-
TxField,
|
|
13
|
-
TxParamsCommon,
|
|
14
|
-
TxSchema,
|
|
15
|
-
TxTypeSchemas,
|
|
9
|
+
RawTxObject, TX_SCHEMA, TxField, TxSchema, TxTypeSchemas,
|
|
16
10
|
} from './schema';
|
|
17
11
|
import { Tag } from './constants';
|
|
18
12
|
import { buildContractId, readInt } from './helpers';
|
|
19
|
-
import {
|
|
20
|
-
import MPTree, { MPTreeBinary } from '../../utils/mptree';
|
|
21
|
-
import {
|
|
22
|
-
ArgumentError,
|
|
23
|
-
DecodeError,
|
|
24
|
-
InvalidTxParamsError,
|
|
25
|
-
SchemaNotFoundError,
|
|
26
|
-
} from '../../utils/errors';
|
|
13
|
+
import { ArgumentError, DecodeError, SchemaNotFoundError } from '../../utils/errors';
|
|
27
14
|
import { isKeyOfObject } from '../../utils/other';
|
|
28
15
|
|
|
29
16
|
/**
|
|
30
17
|
* JavaScript-based Transaction builder
|
|
31
18
|
*/
|
|
32
19
|
|
|
33
|
-
// SERIALIZE AND DESERIALIZE PART
|
|
34
|
-
function deserializeField(
|
|
35
|
-
value: any,
|
|
36
|
-
type: FIELD_TYPES | Field,
|
|
37
|
-
prefix?: Encoding | Encoding[],
|
|
38
|
-
): any {
|
|
39
|
-
if (value == null) return '';
|
|
40
|
-
switch (type) {
|
|
41
|
-
case FIELD_TYPES.ctVersion: {
|
|
42
|
-
const [vm, , abi] = value;
|
|
43
|
-
return {
|
|
44
|
-
vmVersion: readInt(Buffer.from([vm])),
|
|
45
|
-
abiVersion: readInt(Buffer.from([abi])),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
case FIELD_TYPES.bool:
|
|
49
|
-
return value[0] === 1;
|
|
50
|
-
case FIELD_TYPES.binary:
|
|
51
|
-
return encode(value, prefix as Encoding);
|
|
52
|
-
case FIELD_TYPES.stateTree:
|
|
53
|
-
return encode(value, Encoding.StateTrees);
|
|
54
|
-
case FIELD_TYPES.string:
|
|
55
|
-
return value.toString();
|
|
56
|
-
case FIELD_TYPES.payload:
|
|
57
|
-
return encode(value, Encoding.Bytearray);
|
|
58
|
-
case FIELD_TYPES.rlpBinary:
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
60
|
-
return unpackTx(encode(value, Encoding.Transaction));
|
|
61
|
-
case FIELD_TYPES.rlpBinaries:
|
|
62
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
63
|
-
return value.map((v: Buffer) => unpackTx(encode(v, Encoding.Transaction)));
|
|
64
|
-
case FIELD_TYPES.rawBinary:
|
|
65
|
-
return value;
|
|
66
|
-
case FIELD_TYPES.hex:
|
|
67
|
-
return value.toString('hex');
|
|
68
|
-
case FIELD_TYPES.offChainUpdates:
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
70
|
-
return value.map((v: Buffer) => unpackTx(encode(v, Encoding.Transaction)));
|
|
71
|
-
case FIELD_TYPES.callStack:
|
|
72
|
-
// TODO: fix this
|
|
73
|
-
return [readInt(value)];
|
|
74
|
-
case FIELD_TYPES.mptrees:
|
|
75
|
-
return value.map((t: MPTreeBinary) => new MPTree(t));
|
|
76
|
-
case FIELD_TYPES.sophiaCodeTypeInfo:
|
|
77
|
-
return value.reduce(
|
|
78
|
-
(acc: object, [funHash, fnName, argType, outType]: [
|
|
79
|
-
funHash: Buffer,
|
|
80
|
-
fnName: string,
|
|
81
|
-
argType: string,
|
|
82
|
-
outType: string,
|
|
83
|
-
]) => ({
|
|
84
|
-
...acc,
|
|
85
|
-
[fnName.toString()]: { funHash, argType, outType },
|
|
86
|
-
}),
|
|
87
|
-
{},
|
|
88
|
-
);
|
|
89
|
-
default:
|
|
90
|
-
if (typeof type === 'number') return value;
|
|
91
|
-
return type.deserialize(value);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function serializeField(value: any, type: FIELD_TYPES | Field, params: any): any {
|
|
96
|
-
switch (type) {
|
|
97
|
-
case FIELD_TYPES.bool:
|
|
98
|
-
return Buffer.from([(value === true) ? 1 : 0]);
|
|
99
|
-
case FIELD_TYPES.binary:
|
|
100
|
-
return decode(value);
|
|
101
|
-
case FIELD_TYPES.stateTree:
|
|
102
|
-
return decode(value);
|
|
103
|
-
case FIELD_TYPES.hex:
|
|
104
|
-
return Buffer.from(value, 'hex');
|
|
105
|
-
case FIELD_TYPES.signatures:
|
|
106
|
-
return value.map(Buffer.from);
|
|
107
|
-
case FIELD_TYPES.payload:
|
|
108
|
-
return typeof value === 'string' && value.split('_')[0] === 'ba'
|
|
109
|
-
? decode(value as Encoded.Bytearray)
|
|
110
|
-
: toBytes(value);
|
|
111
|
-
case FIELD_TYPES.string:
|
|
112
|
-
return toBytes(value);
|
|
113
|
-
case FIELD_TYPES.rlpBinary:
|
|
114
|
-
return value.rlpEncoded ?? value;
|
|
115
|
-
case FIELD_TYPES.mptrees:
|
|
116
|
-
return value.map((t: MPTree) => t.serialize());
|
|
117
|
-
case FIELD_TYPES.ctVersion:
|
|
118
|
-
return Buffer.from([...toBytes(value.vmVersion), 0, ...toBytes(value.abiVersion)]);
|
|
119
|
-
default:
|
|
120
|
-
if (typeof type === 'number') return value;
|
|
121
|
-
return type.serialize(value, params);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function validateField(
|
|
126
|
-
value: any,
|
|
127
|
-
type: FIELD_TYPES | Field,
|
|
128
|
-
): string | undefined {
|
|
129
|
-
// All fields are required
|
|
130
|
-
if (value == null) return 'Field is required';
|
|
131
|
-
|
|
132
|
-
// Validate type of value
|
|
133
|
-
switch (type) {
|
|
134
|
-
case FIELD_TYPES.ctVersion:
|
|
135
|
-
if (!(Boolean(value.abiVersion) && Boolean(value.vmVersion))) {
|
|
136
|
-
return 'Value must be an object with "vmVersion" and "abiVersion" fields';
|
|
137
|
-
}
|
|
138
|
-
return undefined;
|
|
139
|
-
default:
|
|
140
|
-
return undefined;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Validate transaction params
|
|
146
|
-
* @category transaction builder
|
|
147
|
-
* @param params - Object with tx params
|
|
148
|
-
* @param schema - Transaction schema
|
|
149
|
-
* @param excludeKeys - Array of keys to exclude for validation
|
|
150
|
-
* @returns Object with validation errors
|
|
151
|
-
*/
|
|
152
|
-
function validateParams(
|
|
153
|
-
params: any,
|
|
154
|
-
schema: TxField[],
|
|
155
|
-
{ excludeKeys = [] }: { excludeKeys: string[] },
|
|
156
|
-
): object {
|
|
157
|
-
const optionalFields = ['payload', 'nameFee', 'deposit', 'gasPrice', 'fee', 'gasLimit', 'amount'];
|
|
158
|
-
return Object.fromEntries(
|
|
159
|
-
schema
|
|
160
|
-
// TODO: allow optional keys in schema
|
|
161
|
-
.filter(([key]) => !excludeKeys.includes(key) && !optionalFields.includes(key))
|
|
162
|
-
.map(([key, type]) => [key, validateField(params[key], type)])
|
|
163
|
-
.filter(([, message]) => message),
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
20
|
/**
|
|
168
21
|
* Unpack binary transaction
|
|
169
22
|
* @category transaction builder
|
|
@@ -175,34 +28,29 @@ function unpackRawTx<Tx extends TxSchema>(
|
|
|
175
28
|
binary: Uint8Array | NestedUint8Array,
|
|
176
29
|
schema: TxField[],
|
|
177
30
|
): RawTxObject<Tx> {
|
|
31
|
+
if (binary.length !== schema.length) {
|
|
32
|
+
throw new ArgumentError('Transaction RLP length', schema.length, binary.length);
|
|
33
|
+
}
|
|
178
34
|
return schema
|
|
179
35
|
.reduce<any>(
|
|
180
36
|
(
|
|
181
37
|
acc,
|
|
182
|
-
[
|
|
38
|
+
[name, field],
|
|
183
39
|
index,
|
|
184
|
-
) =>
|
|
40
|
+
) => {
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
42
|
+
const deserialized = field.deserialize(binary[index] as BinaryData, { unpackTx });
|
|
43
|
+
return { ...acc, [name]: deserialized };
|
|
44
|
+
},
|
|
185
45
|
{},
|
|
186
46
|
);
|
|
187
47
|
}
|
|
188
48
|
|
|
189
|
-
/**
|
|
190
|
-
* @category transaction builder
|
|
191
|
-
*/
|
|
192
|
-
export interface BuiltTx<Tx extends TxSchema, Prefix extends Encoding> {
|
|
193
|
-
tx: Encoded.Generic<Prefix>;
|
|
194
|
-
rlpEncoded: Uint8Array;
|
|
195
|
-
binary: Uint8Array;
|
|
196
|
-
txObject: RawTxObject<Tx>;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
49
|
/**
|
|
200
50
|
* Build transaction hash
|
|
201
51
|
* @category transaction builder
|
|
202
|
-
* @param
|
|
203
|
-
* @param type - Transaction type
|
|
52
|
+
* @param params - Object with tx params
|
|
204
53
|
* @param options - options
|
|
205
|
-
* @param options.excludeKeys - Array of keys to exclude for validation and build
|
|
206
54
|
* @param options.denomination - Denomination of amounts
|
|
207
55
|
* @param options.prefix - Prefix of transaction
|
|
208
56
|
* @throws {@link InvalidTxParamsError}
|
|
@@ -211,78 +59,51 @@ export interface BuiltTx<Tx extends TxSchema, Prefix extends Encoding> {
|
|
|
211
59
|
* @returns object.rlpEncoded rlp encoded transaction
|
|
212
60
|
* @returns object.binary binary transaction
|
|
213
61
|
*/
|
|
214
|
-
export function buildTx<
|
|
215
|
-
|
|
216
|
-
|
|
62
|
+
export function buildTx<
|
|
63
|
+
TxType extends Tag,
|
|
64
|
+
E extends Encoding = Encoding.Transaction,
|
|
65
|
+
>(
|
|
66
|
+
params: { tag: TxType; version?: number } & Omit<TxTypeSchemas[TxType], 'tag' | 'version'>
|
|
67
|
+
// TODO: get it from gas-limit.ts somehow
|
|
68
|
+
& (TxType extends Tag.ContractCreateTx | Tag.ContractCallTx
|
|
69
|
+
| Tag.ChannelOffChainUpdateCallContract | Tag.GaAttachTx | Tag.GaMetaTx
|
|
70
|
+
? { gasMax?: number } : {}),
|
|
217
71
|
{
|
|
218
|
-
|
|
219
|
-
prefix = Encoding.Transaction,
|
|
220
|
-
vsn,
|
|
72
|
+
prefix,
|
|
221
73
|
denomination = AE_AMOUNT_FORMATS.AETTOS,
|
|
222
74
|
}: {
|
|
223
|
-
|
|
224
|
-
prefix?: Encoding;
|
|
225
|
-
vsn?: number;
|
|
75
|
+
prefix?: E;
|
|
226
76
|
denomination?: AE_AMOUNT_FORMATS;
|
|
227
77
|
} = {},
|
|
228
|
-
):
|
|
229
|
-
const schemas = TX_SCHEMA[
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const schema = schemas[vsn] as unknown as TxField[];
|
|
235
|
-
|
|
236
|
-
const params = _params as TxParamsCommon & { onNode: Node; denomination?: AE_AMOUNT_FORMATS };
|
|
237
|
-
params.VSN = vsn;
|
|
238
|
-
params.tag = type;
|
|
239
|
-
params.denomination = denomination;
|
|
240
|
-
const filteredSchema = schema.filter(([key]) => !excludeKeys.includes(key));
|
|
241
|
-
|
|
242
|
-
// Validation
|
|
243
|
-
const valid = validateParams(params, schema, { excludeKeys });
|
|
244
|
-
if (Object.keys(valid).length > 0) {
|
|
245
|
-
throw new InvalidTxParamsError(`Transaction build error. ${JSON.stringify(valid)}`);
|
|
78
|
+
): Encoded.Generic<E> {
|
|
79
|
+
const schemas = TX_SCHEMA[params.tag];
|
|
80
|
+
params.version ??= Math.max(...Object.keys(schemas).map((a) => +a));
|
|
81
|
+
if (!isKeyOfObject(params.version, schemas)) {
|
|
82
|
+
throw new SchemaNotFoundError('serialization', Tag[params.tag], params.version);
|
|
246
83
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
const rlpEncoded = rlpEncode(binary);
|
|
269
|
-
const tx = encode(rlpEncoded, prefix);
|
|
270
|
-
return {
|
|
271
|
-
tx,
|
|
272
|
-
rlpEncoded,
|
|
273
|
-
binary,
|
|
274
|
-
txObject: unpackRawTx<TxTypeSchemas[Tag]>(binary, schema),
|
|
275
|
-
} as any;
|
|
84
|
+
const schema = schemas[params.version] as unknown as TxField[];
|
|
85
|
+
|
|
86
|
+
const binary = schema.map(([key, field]: [keyof TxSchema, Field]) => (
|
|
87
|
+
field.serialize(
|
|
88
|
+
params[key],
|
|
89
|
+
{
|
|
90
|
+
...params,
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
92
|
+
unpackTx,
|
|
93
|
+
buildTx,
|
|
94
|
+
denomination,
|
|
95
|
+
rebuildTx: (overrideParams: any) => buildTx(
|
|
96
|
+
{ ...params, ...overrideParams },
|
|
97
|
+
{ denomination },
|
|
98
|
+
),
|
|
99
|
+
},
|
|
100
|
+
)
|
|
101
|
+
));
|
|
102
|
+
|
|
103
|
+
// @ts-expect-error looks like a TypeScript edge case
|
|
104
|
+
return encode(rlpEncode(binary), prefix ?? Encoding.Transaction);
|
|
276
105
|
}
|
|
277
106
|
|
|
278
|
-
/**
|
|
279
|
-
* @category transaction builder
|
|
280
|
-
*/
|
|
281
|
-
export interface TxUnpacked<Tx extends TxSchema> {
|
|
282
|
-
txType: Tag;
|
|
283
|
-
tx: RawTxObject<Tx>;
|
|
284
|
-
rlpEncoded: Uint8Array;
|
|
285
|
-
}
|
|
286
107
|
/**
|
|
287
108
|
* Unpack transaction hash
|
|
288
109
|
* @category transaction builder
|
|
@@ -295,20 +116,15 @@ export interface TxUnpacked<Tx extends TxSchema> {
|
|
|
295
116
|
export function unpackTx<TxType extends Tag>(
|
|
296
117
|
encodedTx: Encoded.Transaction | Encoded.Poi,
|
|
297
118
|
txType?: TxType,
|
|
298
|
-
):
|
|
299
|
-
const
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
if (
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
return {
|
|
308
|
-
txType: objId,
|
|
309
|
-
tx: unpackRawTx<TxTypeSchemas[TxType]>(binary, schema),
|
|
310
|
-
rlpEncoded,
|
|
311
|
-
};
|
|
119
|
+
): RawTxObject<TxTypeSchemas[TxType]> {
|
|
120
|
+
const binary = rlpDecode(decode(encodedTx));
|
|
121
|
+
const tag = +readInt(binary[0] as Buffer);
|
|
122
|
+
if (!isKeyOfObject(tag, TX_SCHEMA)) throw new DecodeError(`Unknown transaction tag: ${tag}`);
|
|
123
|
+
if (txType != null && txType !== tag) throw new DecodeError(`Expected transaction to have ${Tag[txType]} tag, got ${Tag[tag]} instead`);
|
|
124
|
+
const version = +readInt(binary[1] as Buffer);
|
|
125
|
+
if (!isKeyOfObject(version, TX_SCHEMA[tag])) throw new SchemaNotFoundError('deserialization', `tag ${tag}`, version);
|
|
126
|
+
const schema = TX_SCHEMA[tag][version];
|
|
127
|
+
return unpackRawTx<TxTypeSchemas[TxType]>(binary, schema);
|
|
312
128
|
}
|
|
313
129
|
|
|
314
130
|
/**
|
|
@@ -333,9 +149,9 @@ export function buildTxHash(rawTx: Encoded.Transaction | Uint8Array): Encoded.Tx
|
|
|
333
149
|
export function buildContractIdByContractTx(
|
|
334
150
|
contractTx: Encoded.Transaction,
|
|
335
151
|
): Encoded.ContractAddress {
|
|
336
|
-
const {
|
|
337
|
-
if (![Tag.ContractCreateTx, Tag.GaAttachTx].includes(
|
|
338
|
-
throw new ArgumentError('contractCreateTx', 'a contractCreateTx or gaAttach',
|
|
152
|
+
const { tag, ownerId, nonce } = unpackTx<Tag.ContractCreateTx | Tag.GaAttachTx>(contractTx);
|
|
153
|
+
if (![Tag.ContractCreateTx, Tag.GaAttachTx].includes(tag)) {
|
|
154
|
+
throw new ArgumentError('contractCreateTx', 'a contractCreateTx or gaAttach', tag);
|
|
339
155
|
}
|
|
340
|
-
return buildContractId(
|
|
156
|
+
return buildContractId(ownerId, +nonce);
|
|
341
157
|
}
|