@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/builder/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _buffer from "buffer";
|
|
2
|
+
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
2
3
|
const {
|
|
3
4
|
Buffer: _Buffer
|
|
4
5
|
} = _buffer;
|
|
@@ -10,26 +11,19 @@ const {
|
|
|
10
11
|
} = _rlp;
|
|
11
12
|
import { AE_AMOUNT_FORMATS, formatAmount } from "../../utils/amount-formatter.mjs";
|
|
12
13
|
import { hash } from "../../utils/crypto.mjs";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { readInt, readId, readPointers, writeId, writeInt, buildPointers, encode, decode } from "./helpers.mjs";
|
|
14
|
+
import { FIELD_TYPES, TX_SCHEMA, TX_TYPE } from "./schema.mjs";
|
|
15
|
+
import { readInt, readId, readPointers, writeId, writeInt, buildPointers, encode, decode, buildContractId } from "./helpers.mjs";
|
|
16
16
|
import { toBytes } from "../../utils/bytes.mjs";
|
|
17
17
|
import MPTree from "../../utils/mptree.mjs";
|
|
18
|
-
import { InvalidTxParamsError, SchemaNotFoundError } from "../../utils/errors.mjs";
|
|
18
|
+
import { ArgumentError, InvalidTxParamsError, SchemaNotFoundError, DecodeError } from "../../utils/errors.mjs";
|
|
19
|
+
import { isKeyOfObject } from "../../utils/other.mjs";
|
|
19
20
|
/**
|
|
20
21
|
* JavaScript-based Transaction builder
|
|
21
|
-
* @module @aeternity/aepp-sdk/es/tx/builder
|
|
22
|
-
* @export TxBuilder
|
|
23
|
-
* @example import { TxBuilder } from '@aeternity/aepp-sdk'
|
|
24
22
|
*/
|
|
25
|
-
|
|
26
|
-
const ORACLE_TTL_TYPES = {
|
|
27
|
-
delta: 'delta',
|
|
28
|
-
block: 'block'
|
|
29
|
-
}; // SERIALIZE AND DESERIALIZE PART
|
|
23
|
+
// SERIALIZE AND DESERIALIZE PART
|
|
30
24
|
|
|
31
25
|
function deserializeField(value, type, prefix) {
|
|
32
|
-
if (
|
|
26
|
+
if (value == null) return '';
|
|
33
27
|
|
|
34
28
|
switch (type) {
|
|
35
29
|
case FIELD_TYPES.ctVersion:
|
|
@@ -43,8 +37,13 @@ function deserializeField(value, type, prefix) {
|
|
|
43
37
|
|
|
44
38
|
case FIELD_TYPES.amount:
|
|
45
39
|
case FIELD_TYPES.int:
|
|
40
|
+
case FIELD_TYPES.abiVersion:
|
|
41
|
+
case FIELD_TYPES.ttlType:
|
|
46
42
|
return readInt(value);
|
|
47
43
|
|
|
44
|
+
case FIELD_TYPES.shortInt:
|
|
45
|
+
return +readInt(value);
|
|
46
|
+
|
|
48
47
|
case FIELD_TYPES.id:
|
|
49
48
|
return readId(value);
|
|
50
49
|
|
|
@@ -70,10 +69,10 @@ function deserializeField(value, type, prefix) {
|
|
|
70
69
|
return readPointers(value);
|
|
71
70
|
|
|
72
71
|
case FIELD_TYPES.rlpBinary:
|
|
73
|
-
return unpackTx(value,
|
|
72
|
+
return unpackTx(encode(value, 'tx'));
|
|
74
73
|
|
|
75
74
|
case FIELD_TYPES.rlpBinaries:
|
|
76
|
-
return value.map(v => unpackTx(v,
|
|
75
|
+
return value.map(v => unpackTx(encode(v, 'tx')));
|
|
77
76
|
|
|
78
77
|
case FIELD_TYPES.rawBinary:
|
|
79
78
|
return value;
|
|
@@ -82,7 +81,7 @@ function deserializeField(value, type, prefix) {
|
|
|
82
81
|
return value.toString('hex');
|
|
83
82
|
|
|
84
83
|
case FIELD_TYPES.offChainUpdates:
|
|
85
|
-
return value.map(v => unpackTx(v,
|
|
84
|
+
return value.map(v => unpackTx(encode(v, 'tx')));
|
|
86
85
|
|
|
87
86
|
case FIELD_TYPES.callStack:
|
|
88
87
|
// TODO: fix this
|
|
@@ -119,17 +118,20 @@ function deserializeField(value, type, prefix) {
|
|
|
119
118
|
}, {});
|
|
120
119
|
|
|
121
120
|
default:
|
|
122
|
-
if (type
|
|
121
|
+
if (type instanceof Object && 'deserialize' in type) return type.deserialize(value);
|
|
123
122
|
return value;
|
|
124
123
|
}
|
|
125
124
|
}
|
|
126
125
|
|
|
127
|
-
function serializeField(value, type,
|
|
126
|
+
function serializeField(value, type, params) {
|
|
128
127
|
var _value$rlpEncoded;
|
|
129
128
|
|
|
130
129
|
switch (type) {
|
|
131
130
|
case FIELD_TYPES.amount:
|
|
132
131
|
case FIELD_TYPES.int:
|
|
132
|
+
case FIELD_TYPES.shortInt:
|
|
133
|
+
case FIELD_TYPES.abiVersion:
|
|
134
|
+
case FIELD_TYPES.ttlType:
|
|
133
135
|
return writeInt(value);
|
|
134
136
|
|
|
135
137
|
case FIELD_TYPES.id:
|
|
@@ -139,13 +141,13 @@ function serializeField(value, type, prefix, params) {
|
|
|
139
141
|
return value.map(writeId);
|
|
140
142
|
|
|
141
143
|
case FIELD_TYPES.bool:
|
|
142
|
-
return _Buffer.from([value ? 1 : 0]);
|
|
144
|
+
return _Buffer.from([value === true ? 1 : 0]);
|
|
143
145
|
|
|
144
146
|
case FIELD_TYPES.binary:
|
|
145
|
-
return decode(value
|
|
147
|
+
return decode(value);
|
|
146
148
|
|
|
147
149
|
case FIELD_TYPES.stateTree:
|
|
148
|
-
return decode(value
|
|
150
|
+
return decode(value);
|
|
149
151
|
|
|
150
152
|
case FIELD_TYPES.hex:
|
|
151
153
|
return _Buffer.from(value, 'hex');
|
|
@@ -154,7 +156,7 @@ function serializeField(value, type, prefix, params) {
|
|
|
154
156
|
return value.map(_Buffer.from);
|
|
155
157
|
|
|
156
158
|
case FIELD_TYPES.payload:
|
|
157
|
-
return typeof value === 'string' && value.split('_')[0] === 'ba' ? decode(value
|
|
159
|
+
return typeof value === 'string' && value.split('_')[0] === 'ba' ? decode(value) : toBytes(value);
|
|
158
160
|
|
|
159
161
|
case FIELD_TYPES.string:
|
|
160
162
|
return toBytes(value);
|
|
@@ -166,7 +168,7 @@ function serializeField(value, type, prefix, params) {
|
|
|
166
168
|
return (_value$rlpEncoded = value.rlpEncoded) !== null && _value$rlpEncoded !== void 0 ? _value$rlpEncoded : value;
|
|
167
169
|
|
|
168
170
|
case FIELD_TYPES.mptrees:
|
|
169
|
-
return value.map(t => t.serialize());
|
|
171
|
+
return value.map(t => t.serialize(''));
|
|
170
172
|
|
|
171
173
|
case FIELD_TYPES.ctVersion:
|
|
172
174
|
return _Buffer.from([...toBytes(value.vmVersion), 0, ...toBytes(value.abiVersion)]);
|
|
@@ -187,24 +189,25 @@ function serializeField(value, type, prefix, params) {
|
|
|
187
189
|
}
|
|
188
190
|
|
|
189
191
|
default:
|
|
190
|
-
if (type
|
|
192
|
+
if (type instanceof Object && 'serialize' in type) return type.serialize(value, params);
|
|
191
193
|
return value;
|
|
192
194
|
}
|
|
193
195
|
}
|
|
194
196
|
|
|
195
197
|
function validateField(value, type, prefix) {
|
|
196
198
|
// All fields are required
|
|
197
|
-
if (value
|
|
199
|
+
if (value == null) return 'Field is required'; // Validate type of value
|
|
198
200
|
|
|
199
201
|
switch (type) {
|
|
200
202
|
case FIELD_TYPES.amount:
|
|
201
203
|
case FIELD_TYPES.int:
|
|
204
|
+
case FIELD_TYPES.shortInt:
|
|
202
205
|
{
|
|
203
206
|
if (isNaN(value) && !BigNumber.isBigNumber(value)) {
|
|
204
|
-
return `${value} is not of type Number or BigNumber`;
|
|
207
|
+
return `${String(value)} is not of type Number or BigNumber`;
|
|
205
208
|
}
|
|
206
209
|
|
|
207
|
-
if (new BigNumber(value).lt(0)) return `${value} must be >= 0`;
|
|
210
|
+
if (new BigNumber(value).lt(0)) return `${String(value)} must be >= 0`;
|
|
208
211
|
return;
|
|
209
212
|
}
|
|
210
213
|
|
|
@@ -212,15 +215,19 @@ function validateField(value, type, prefix) {
|
|
|
212
215
|
{
|
|
213
216
|
const prefixes = Array.isArray(prefix) ? prefix : [prefix];
|
|
214
217
|
|
|
215
|
-
if (!prefixes.
|
|
216
|
-
|
|
218
|
+
if (!_includesInstanceProperty(prefixes).call(prefixes, value.split('_')[0])) {
|
|
219
|
+
if (prefix == null) {
|
|
220
|
+
return `'${String(value)}' prefix doesn't exist'`;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return `'${String(value)}' prefix doesn't match expected prefix '${prefix.toString()}'`;
|
|
217
224
|
}
|
|
218
225
|
|
|
219
226
|
return;
|
|
220
227
|
}
|
|
221
228
|
|
|
222
229
|
case FIELD_TYPES.ctVersion:
|
|
223
|
-
if (!(value
|
|
230
|
+
if (!(Boolean(value.abiVersion) && Boolean(value.vmVersion))) {
|
|
224
231
|
return 'Value must be an object with "vmVersion" and "abiVersion" fields';
|
|
225
232
|
}
|
|
226
233
|
|
|
@@ -229,7 +236,7 @@ function validateField(value, type, prefix) {
|
|
|
229
236
|
case FIELD_TYPES.pointers:
|
|
230
237
|
if (!Array.isArray(value)) return 'Value must be of type Array';
|
|
231
238
|
|
|
232
|
-
if (value.some(p => !(p
|
|
239
|
+
if (value.some(p => !(Boolean(p.key) && Boolean(p.id)))) {
|
|
233
240
|
return 'Value must contains only object\'s like \'{key: "account_pubkey", id: "ak_lkamsflkalsdalksdlasdlasdlamd"}\'';
|
|
234
241
|
}
|
|
235
242
|
|
|
@@ -245,9 +252,9 @@ function transformParams(params, schema) {
|
|
|
245
252
|
denomination
|
|
246
253
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
247
254
|
params = schema.filter(_ref2 => {
|
|
248
|
-
let [
|
|
255
|
+
let [, t] = _ref2;
|
|
249
256
|
return t === FIELD_TYPES.amount;
|
|
250
|
-
}).reduce((
|
|
257
|
+
}).reduce((params, _ref3) => {
|
|
251
258
|
let [key] = _ref3;
|
|
252
259
|
return { ...params,
|
|
253
260
|
[key]: formatAmount(params[key], {
|
|
@@ -255,290 +262,101 @@ function transformParams(params, schema) {
|
|
|
255
262
|
})
|
|
256
263
|
};
|
|
257
264
|
}, params);
|
|
258
|
-
|
|
259
|
-
let [k] = _ref4;
|
|
260
|
-
return k;
|
|
261
|
-
});
|
|
262
|
-
return Object.entries(params).reduce((acc, _ref5) => {
|
|
263
|
-
let [key, value] = _ref5;
|
|
264
|
-
if (schemaKeys.includes(key)) acc[key] = value;
|
|
265
|
-
|
|
266
|
-
if (['oracleTtl', 'queryTtl', 'responseTtl'].includes(key)) {
|
|
267
|
-
acc[`${key}Type`] = value.type === ORACLE_TTL_TYPES.delta ? 0 : 1;
|
|
268
|
-
acc[`${key}Value`] = value.value;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
return acc;
|
|
272
|
-
}, {});
|
|
273
|
-
} // INTERFACE
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
function getOracleRelativeTtl(params, txType) {
|
|
277
|
-
const ttlKey = {
|
|
278
|
-
[TX_TYPE.oracleRegister]: 'oracleTtl',
|
|
279
|
-
[TX_TYPE.oracleExtend]: 'oracleTtl',
|
|
280
|
-
[TX_TYPE.oracleQuery]: 'queryTtl',
|
|
281
|
-
[TX_TYPE.oracleResponse]: 'responseTtl'
|
|
282
|
-
}[txType];
|
|
283
|
-
|
|
284
|
-
if (params[ttlKey] || params[`${ttlKey}Value`]) {
|
|
285
|
-
return params[`${ttlKey}Value`] || params[ttlKey].value;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
return 1;
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Calculate min fee
|
|
292
|
-
* @function
|
|
293
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/index
|
|
294
|
-
* @rtype (txType, { gas = 0, params }) => String
|
|
295
|
-
* @param {String} txType - Transaction type
|
|
296
|
-
* @param {Options} options - Options object
|
|
297
|
-
* @param {String|Number} options.gas - Gas amount
|
|
298
|
-
* @param {Object} options.params - Tx params
|
|
299
|
-
* @return {String|Number}
|
|
300
|
-
* @example calculateMinFee('spendTx', { gas, params })
|
|
301
|
-
*/
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
export function calculateMinFee(txType, _ref6) {
|
|
305
|
-
let {
|
|
306
|
-
gas = 0,
|
|
307
|
-
params,
|
|
308
|
-
vsn
|
|
309
|
-
} = _ref6;
|
|
310
|
-
const multiplier = BigNumber(1e9); // 10^9 GAS_PRICE
|
|
311
|
-
|
|
312
|
-
if (!params) return BigNumber(DEFAULT_FEE).times(multiplier).toString(10);
|
|
313
|
-
let actualFee = buildFee(txType, {
|
|
314
|
-
params: { ...params,
|
|
315
|
-
fee: 0
|
|
316
|
-
},
|
|
317
|
-
multiplier,
|
|
318
|
-
gas,
|
|
319
|
-
vsn
|
|
320
|
-
});
|
|
321
|
-
let expected = BigNumber(0);
|
|
322
|
-
|
|
323
|
-
while (!actualFee.eq(expected)) {
|
|
324
|
-
actualFee = buildFee(txType, {
|
|
325
|
-
params: { ...params,
|
|
326
|
-
fee: actualFee
|
|
327
|
-
},
|
|
328
|
-
multiplier,
|
|
329
|
-
gas,
|
|
330
|
-
vsn
|
|
331
|
-
});
|
|
332
|
-
expected = actualFee;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
return expected.toString(10);
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Calculate fee based on tx type and params
|
|
339
|
-
* @param txType
|
|
340
|
-
* @param params
|
|
341
|
-
* @param gas
|
|
342
|
-
* @param multiplier
|
|
343
|
-
* @param vsn
|
|
344
|
-
* @return {BigNumber}
|
|
345
|
-
*/
|
|
346
|
-
|
|
347
|
-
function buildFee(txType, _ref7) {
|
|
348
|
-
let {
|
|
349
|
-
params,
|
|
350
|
-
gas = 0,
|
|
351
|
-
multiplier,
|
|
352
|
-
vsn
|
|
353
|
-
} = _ref7;
|
|
354
|
-
const {
|
|
355
|
-
rlpEncoded: txWithOutFee
|
|
356
|
-
} = buildTx({ ...params
|
|
357
|
-
}, txType, {
|
|
358
|
-
vsn
|
|
359
|
-
});
|
|
360
|
-
const txSize = txWithOutFee.length;
|
|
361
|
-
return TX_FEE_BASE_GAS(txType).plus(TX_FEE_OTHER_GAS(txType, txSize, {
|
|
362
|
-
relativeTtl: getOracleRelativeTtl(params, txType),
|
|
363
|
-
innerTxSize: [TX_TYPE.gaMeta, TX_TYPE.payingFor].includes(txType) ? params.tx.tx.encodedTx.rlpEncoded.length : 0
|
|
364
|
-
})).times(multiplier);
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* Calculate fee
|
|
368
|
-
* @function
|
|
369
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder
|
|
370
|
-
* @rtype (fee, txType, gas = 0) => String
|
|
371
|
-
* @param {String|Number} fee - fee
|
|
372
|
-
* @param {String} txType - Transaction type
|
|
373
|
-
* @param {Options} options - Options object
|
|
374
|
-
* @param {String|Number} options.gas - Gas amount
|
|
375
|
-
* @param {Object} options.params - Tx params
|
|
376
|
-
* @return {String|Number}
|
|
377
|
-
* @example calculateFee(null, 'spendTx', { gas, params })
|
|
378
|
-
*/
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
export function calculateFee() {
|
|
382
|
-
let fee = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
383
|
-
let txType = arguments.length > 1 ? arguments[1] : undefined;
|
|
384
|
-
let {
|
|
385
|
-
gas = 0,
|
|
386
|
-
params,
|
|
387
|
-
showWarning = true,
|
|
388
|
-
vsn
|
|
389
|
-
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
390
|
-
if (!params && showWarning) console.warn(`Can't build transaction fee, we will use DEFAULT_FEE(${DEFAULT_FEE})`);
|
|
391
|
-
return fee || calculateMinFee(txType, {
|
|
392
|
-
params,
|
|
393
|
-
gas,
|
|
394
|
-
vsn
|
|
395
|
-
});
|
|
265
|
+
return params;
|
|
396
266
|
}
|
|
397
267
|
/**
|
|
398
268
|
* Validate transaction params
|
|
399
|
-
* @
|
|
400
|
-
* @
|
|
401
|
-
* @param
|
|
402
|
-
* @
|
|
403
|
-
* @param {Array} excludeKeys Array of keys to exclude for validation
|
|
404
|
-
* @return {Object} Object with validation errors
|
|
269
|
+
* @param params - Object with tx params
|
|
270
|
+
* @param schema - Transaction schema
|
|
271
|
+
* @param excludeKeys - Array of keys to exclude for validation
|
|
272
|
+
* @returns Object with validation errors
|
|
405
273
|
*/
|
|
406
274
|
|
|
407
|
-
|
|
275
|
+
|
|
276
|
+
export function validateParams(params, schema, _ref4) {
|
|
408
277
|
let {
|
|
409
278
|
excludeKeys = []
|
|
410
|
-
} =
|
|
279
|
+
} = _ref4;
|
|
411
280
|
return Object.fromEntries(schema // TODO: allow optional keys in schema
|
|
412
|
-
.filter(
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
281
|
+
.filter(_ref5 => {
|
|
282
|
+
var _context;
|
|
283
|
+
|
|
284
|
+
let [key] = _ref5;
|
|
285
|
+
return !_includesInstanceProperty(excludeKeys).call(excludeKeys, key) && !_includesInstanceProperty(_context = ['payload', 'nameFee', 'deposit', 'gasPrice']).call(_context, key);
|
|
286
|
+
}).map(_ref6 => {
|
|
287
|
+
let [key, type, prefix] = _ref6;
|
|
417
288
|
return [key, validateField(params[key], type, prefix)];
|
|
418
|
-
}).filter(
|
|
419
|
-
let [, message] =
|
|
289
|
+
}).filter(_ref7 => {
|
|
290
|
+
let [, message] = _ref7;
|
|
420
291
|
return message;
|
|
421
292
|
}));
|
|
422
293
|
}
|
|
423
|
-
/**
|
|
424
|
-
* Build binary transaction
|
|
425
|
-
* @function
|
|
426
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder
|
|
427
|
-
* @param {Object} params Object with tx params
|
|
428
|
-
* @param {Array} schema Transaction schema
|
|
429
|
-
* @param {Object} [options={}] options
|
|
430
|
-
* @param {String[]} [options.excludeKeys=[]] Array of keys to exclude for validation and build
|
|
431
|
-
* @param {String} [options.denomination='aettos'] Denomination of amounts
|
|
432
|
-
* @throws {Error} Validation error
|
|
433
|
-
* @return {Array} Array with binary fields of transaction
|
|
434
|
-
*/
|
|
435
|
-
|
|
436
|
-
export function buildRawTx(params, schema) {
|
|
437
|
-
let {
|
|
438
|
-
excludeKeys = [],
|
|
439
|
-
denomination = AE_AMOUNT_FORMATS.AETTOS
|
|
440
|
-
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
441
|
-
const filteredSchema = schema.filter(_ref12 => {
|
|
442
|
-
let [key] = _ref12;
|
|
443
|
-
return !excludeKeys.includes(key);
|
|
444
|
-
}); // Transform `amount` type fields to `aettos`
|
|
445
|
-
|
|
446
|
-
params = transformParams(params, filteredSchema, {
|
|
447
|
-
denomination
|
|
448
|
-
}); // Validation
|
|
449
|
-
|
|
450
|
-
const valid = validateParams(params, schema, {
|
|
451
|
-
excludeKeys
|
|
452
|
-
});
|
|
453
|
-
|
|
454
|
-
if (Object.keys(valid).length) {
|
|
455
|
-
throw new InvalidTxParamsError('Transaction build error. ' + JSON.stringify(valid));
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
return filteredSchema.map(_ref13 => {
|
|
459
|
-
let [key, fieldType, prefix] = _ref13;
|
|
460
|
-
return serializeField(params[key], fieldType, prefix, params);
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
294
|
/**
|
|
464
295
|
* Unpack binary transaction
|
|
465
|
-
* @
|
|
466
|
-
* @
|
|
467
|
-
* @
|
|
468
|
-
* @param {Array} schema Transaction schema
|
|
469
|
-
* @return {Object} Object with transaction field's
|
|
296
|
+
* @param binary - Array with binary transaction field's
|
|
297
|
+
* @param schema - Transaction schema
|
|
298
|
+
* @returns Object with transaction field's
|
|
470
299
|
*/
|
|
471
300
|
|
|
472
301
|
export function unpackRawTx(binary, schema) {
|
|
473
|
-
return schema.reduce((acc,
|
|
474
|
-
let [key, fieldType, prefix] =
|
|
302
|
+
return schema.reduce((acc, _ref8, index) => {
|
|
303
|
+
let [key, fieldType, prefix] = _ref8;
|
|
475
304
|
return Object.assign(acc, {
|
|
476
305
|
[key]: deserializeField(binary[index], fieldType, prefix)
|
|
477
306
|
});
|
|
478
307
|
}, {});
|
|
479
308
|
}
|
|
480
|
-
/**
|
|
481
|
-
* Get transaction serialization/deserialization schema
|
|
482
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder
|
|
483
|
-
* @param {{ vsn: String, objId: Number, type: String }}
|
|
484
|
-
* @throws {Error} Schema not found error
|
|
485
|
-
* @return {Object} Schema
|
|
486
|
-
*/
|
|
487
|
-
|
|
488
|
-
const getSchema = _ref15 => {
|
|
489
|
-
let {
|
|
490
|
-
vsn,
|
|
491
|
-
objId,
|
|
492
|
-
type
|
|
493
|
-
} = _ref15;
|
|
494
|
-
const isDeserialize = !!objId;
|
|
495
|
-
const firstKey = isDeserialize ? objId : type;
|
|
496
|
-
const schema = isDeserialize ? TX_DESERIALIZATION_SCHEMA : TX_SERIALIZATION_SCHEMA;
|
|
497
|
-
|
|
498
|
-
if (!schema[firstKey]) {
|
|
499
|
-
throw new SchemaNotFoundError(`Transaction ${isDeserialize ? 'deserialization' : 'serialization'} not implemented for ${isDeserialize ? 'tag ' + objId : type}`);
|
|
500
|
-
}
|
|
501
309
|
|
|
502
|
-
if (!schema[firstKey][vsn]) {
|
|
503
|
-
throw new SchemaNotFoundError(`Transaction ${isDeserialize ? 'deserialization' : 'serialization'} not implemented for ${isDeserialize ? 'tag ' + objId : type} version ${vsn}`);
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
return schema[firstKey][vsn];
|
|
507
|
-
};
|
|
508
310
|
/**
|
|
509
311
|
* Build transaction hash
|
|
510
|
-
* @
|
|
511
|
-
* @
|
|
512
|
-
* @param
|
|
513
|
-
* @param
|
|
514
|
-
* @param
|
|
515
|
-
* @param
|
|
516
|
-
* @
|
|
517
|
-
* @
|
|
518
|
-
* @returns
|
|
519
|
-
* @returns
|
|
520
|
-
* @returns
|
|
521
|
-
* @returns {Array<Buffer>} object.binary binary transaction
|
|
312
|
+
* @param _params - Object with tx params
|
|
313
|
+
* @param type - Transaction type
|
|
314
|
+
* @param options - options
|
|
315
|
+
* @param options.excludeKeys - Array of keys to exclude for validation and build
|
|
316
|
+
* @param options.denomination - Denomination of amounts
|
|
317
|
+
* @param options.prefix - Prefix of transaction
|
|
318
|
+
* @throws {@link InvalidTxParamsError}
|
|
319
|
+
* @returns object
|
|
320
|
+
* @returns object.tx Base64Check transaction hash with 'tx_' prefix
|
|
321
|
+
* @returns object.rlpEncoded rlp encoded transaction
|
|
322
|
+
* @returns object.binary binary transaction
|
|
522
323
|
*/
|
|
324
|
+
export function buildTx(_params, type) {
|
|
325
|
+
var _vsn;
|
|
523
326
|
|
|
524
|
-
|
|
525
|
-
export function buildTx(params, type) {
|
|
526
327
|
let {
|
|
527
328
|
excludeKeys = [],
|
|
528
329
|
prefix = 'tx',
|
|
529
|
-
vsn
|
|
330
|
+
vsn,
|
|
530
331
|
denomination = AE_AMOUNT_FORMATS.AETTOS
|
|
531
332
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
532
|
-
const
|
|
533
|
-
|
|
534
|
-
|
|
333
|
+
const schemas = TX_SCHEMA[type];
|
|
334
|
+
(_vsn = vsn) !== null && _vsn !== void 0 ? _vsn : vsn = Math.max(...Object.keys(schemas).map(a => +a));
|
|
335
|
+
if (!isKeyOfObject(vsn, schemas)) throw new SchemaNotFoundError('serialization', TX_TYPE[type], vsn);
|
|
336
|
+
const schema = schemas[vsn];
|
|
337
|
+
let params = _params;
|
|
338
|
+
params.VSN = vsn;
|
|
339
|
+
params.tag = type;
|
|
340
|
+
const filteredSchema = schema.filter(_ref9 => {
|
|
341
|
+
let [key] = _ref9;
|
|
342
|
+
return !_includesInstanceProperty(excludeKeys).call(excludeKeys, key);
|
|
343
|
+
}); // Transform `amount` type fields to `aettos`
|
|
344
|
+
|
|
345
|
+
params = transformParams(params, filteredSchema, {
|
|
346
|
+
denomination
|
|
347
|
+
}); // Validation
|
|
348
|
+
|
|
349
|
+
const valid = validateParams(params, schema, {
|
|
350
|
+
excludeKeys
|
|
535
351
|
});
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
|
|
352
|
+
|
|
353
|
+
if (Object.keys(valid).length > 0) {
|
|
354
|
+
throw new InvalidTxParamsError('Transaction build error. ' + JSON.stringify(valid));
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
const binary = filteredSchema.map(_ref10 => {
|
|
358
|
+
let [key, fieldType] = _ref10;
|
|
359
|
+
return serializeField(params[key], fieldType, params);
|
|
542
360
|
}).filter(e => e !== undefined);
|
|
543
361
|
const rlpEncoded = rlpEncode(binary);
|
|
544
362
|
const tx = encode(rlpEncoded, prefix);
|
|
@@ -549,58 +367,58 @@ export function buildTx(params, type) {
|
|
|
549
367
|
txObject: unpackRawTx(binary, schema)
|
|
550
368
|
};
|
|
551
369
|
}
|
|
370
|
+
|
|
552
371
|
/**
|
|
553
372
|
* Unpack transaction hash
|
|
554
|
-
* @
|
|
555
|
-
* @
|
|
556
|
-
* @
|
|
557
|
-
*
|
|
558
|
-
* @
|
|
559
|
-
* @param {String} prefix - Prefix of data
|
|
560
|
-
* @returns {Object} object
|
|
561
|
-
* @returns {Object} object.tx Object with transaction param's
|
|
562
|
-
* @returns {Buffer} object.rlpEncoded rlp encoded transaction
|
|
563
|
-
* @returns {Array<Buffer>} object.binary binary transaction
|
|
373
|
+
* @param encodedTx - Transaction to unpack
|
|
374
|
+
* @param txType - Expected transaction type
|
|
375
|
+
* @returns object
|
|
376
|
+
* @returns object.tx Object with transaction param's
|
|
377
|
+
* @returns object.txType Transaction type
|
|
564
378
|
*/
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
let fromRlpBinary = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
568
|
-
let prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'tx';
|
|
569
|
-
const rlpEncoded = fromRlpBinary ? encodedTx : decode(encodedTx, prefix);
|
|
379
|
+
export function unpackTx(encodedTx, txType) {
|
|
380
|
+
const rlpEncoded = decode(encodedTx);
|
|
570
381
|
const binary = rlpDecode(rlpEncoded);
|
|
571
|
-
const objId = readInt(binary[0]);
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
382
|
+
const objId = +readInt(binary[0]);
|
|
383
|
+
if (!isKeyOfObject(objId, TX_SCHEMA)) throw new DecodeError(`Unknown transaction tag: ${objId}`);
|
|
384
|
+
if (txType != null && txType !== objId) throw new DecodeError(`Expected transaction to have ${TX_TYPE[txType]} tag, got ${TX_TYPE[objId]} instead`);
|
|
385
|
+
const vsn = +readInt(binary[1]);
|
|
386
|
+
if (!isKeyOfObject(vsn, TX_SCHEMA[objId])) throw new SchemaNotFoundError('deserialization', `tag ${objId}`, vsn);
|
|
387
|
+
const schema = TX_SCHEMA[objId][vsn];
|
|
577
388
|
return {
|
|
578
|
-
txType:
|
|
389
|
+
txType: objId,
|
|
579
390
|
tx: unpackRawTx(binary, schema),
|
|
580
|
-
rlpEncoded
|
|
581
|
-
binary
|
|
391
|
+
rlpEncoded
|
|
582
392
|
};
|
|
583
393
|
}
|
|
584
394
|
/**
|
|
585
395
|
* Build a transaction hash
|
|
586
|
-
* @
|
|
587
|
-
* @
|
|
588
|
-
* @param {String | Buffer} rawTx base64 or rlp encoded transaction
|
|
589
|
-
* @return {String} Transaction hash
|
|
396
|
+
* @param rawTx - base64 or rlp encoded transaction
|
|
397
|
+
* @returns Transaction hash
|
|
590
398
|
*/
|
|
591
399
|
|
|
592
400
|
export function buildTxHash(rawTx) {
|
|
593
|
-
const data = typeof rawTx === 'string' && rawTx.startsWith('tx_') ? decode(rawTx
|
|
401
|
+
const data = typeof rawTx === 'string' && rawTx.startsWith('tx_') ? decode(rawTx) : rawTx;
|
|
594
402
|
return encode(hash(data), 'th');
|
|
595
403
|
}
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
404
|
+
/**
|
|
405
|
+
* Build a contract public key by contractCreateTx or gaAttach
|
|
406
|
+
* @param contractTx - Transaction
|
|
407
|
+
* @returns Contract public key
|
|
408
|
+
*/
|
|
409
|
+
|
|
410
|
+
export function buildContractIdByContractTx(contractTx) {
|
|
411
|
+
var _context2;
|
|
412
|
+
|
|
413
|
+
const {
|
|
414
|
+
txType,
|
|
415
|
+
tx
|
|
416
|
+
} = unpackTx(contractTx);
|
|
417
|
+
|
|
418
|
+
if (!_includesInstanceProperty(_context2 = [TX_TYPE.contractCreate, TX_TYPE.gaAttach]).call(_context2, txType)) {
|
|
419
|
+
throw new ArgumentError('contractCreateTx', 'a contractCreateTx or gaAttach', txType);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
return buildContractId(tx.ownerId, +tx.nonce);
|
|
423
|
+
}
|
|
606
424
|
//# sourceMappingURL=index.mjs.map
|