@aeternity/aepp-sdk 12.0.0 → 12.1.2
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/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -15
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +2 -1
- package/dist/aepp-sdk.browser.js.LICENSE.txt +1 -0
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +20765 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdk.d.ts +7 -7
- package/es/AeSdk.mjs.map +1 -1
- package/es/AeSdkAepp.d.ts +4 -3
- package/es/AeSdkAepp.mjs +2 -1
- package/es/AeSdkAepp.mjs.map +1 -1
- package/es/AeSdkBase.d.ts +22 -21
- package/es/AeSdkBase.mjs +25 -21
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkWallet.d.ts +4 -3
- package/es/AeSdkWallet.mjs +5 -1
- package/es/AeSdkWallet.mjs.map +1 -1
- package/es/Node.d.ts +7 -10
- package/es/Node.mjs +63 -57
- package/es/Node.mjs.map +1 -1
- package/es/account/Base.d.ts +7 -4
- package/es/account/Base.mjs +3 -3
- package/es/account/Base.mjs.map +1 -1
- package/es/account/Memory.d.ts +5 -4
- package/es/account/Memory.mjs +24 -2
- package/es/account/Memory.mjs.map +1 -1
- package/es/account/Rpc.d.ts +6 -6
- package/es/account/Rpc.mjs +3 -2
- package/es/account/Rpc.mjs.map +1 -1
- package/es/aens.d.ts +27 -14
- package/es/aens.mjs +27 -21
- package/es/aens.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/Browser.d.ts +2 -1
- package/es/aepp-wallet-communication/connection/Browser.mjs +5 -2
- package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +5 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection-proxy.d.ts +1 -0
- package/es/aepp-wallet-communication/connection-proxy.mjs +1 -0
- package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +1 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +5 -5
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/types.d.ts +8 -8
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
- package/es/aepp-wallet-communication/schema.d.ts +17 -2
- package/es/aepp-wallet-communication/schema.mjs +54 -17
- package/es/aepp-wallet-communication/schema.mjs.map +1 -1
- package/es/aepp-wallet-communication/wallet-detector.d.ts +2 -1
- package/es/aepp-wallet-communication/wallet-detector.mjs +2 -3
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
- package/es/apis/node/models/index.d.ts +6 -2
- package/es/apis/node/models/index.mjs.map +1 -1
- package/es/apis/node/models/mappers.mjs +4 -2
- package/es/apis/node/models/mappers.mjs.map +1 -1
- package/es/chain.d.ts +92 -64
- package/es/chain.mjs +190 -154
- package/es/chain.mjs.map +1 -1
- package/es/channel/handlers.d.ts +3 -3
- package/es/channel/handlers.mjs +42 -44
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/index.d.ts +43 -52
- package/es/channel/index.mjs +46 -49
- package/es/channel/index.mjs.map +1 -1
- package/es/channel/internal.d.ts +16 -15
- package/es/channel/internal.mjs +67 -62
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Compiler.d.ts +1 -0
- package/es/contract/Compiler.mjs +5 -4
- package/es/contract/Compiler.mjs.map +1 -1
- package/es/contract/aci.d.ts +17 -15
- package/es/contract/aci.mjs +58 -45
- package/es/contract/aci.mjs.map +1 -1
- package/es/contract/ga.d.ts +16 -15
- package/es/contract/ga.mjs +12 -7
- package/es/contract/ga.mjs.map +1 -1
- package/es/contract/methods.d.ts +9 -6
- package/es/contract/methods.mjs +9 -6
- package/es/contract/methods.mjs.map +1 -1
- package/es/deprecated/index.d.ts +143 -0
- package/es/deprecated/index.mjs +162 -0
- package/es/deprecated/index.mjs.map +1 -0
- package/es/deprecated/methods.d.ts +18 -0
- package/es/deprecated/methods.mjs +26 -0
- package/es/deprecated/methods.mjs.map +1 -0
- package/es/index.d.ts +4 -1
- package/es/index.mjs +4 -1
- package/es/index.mjs.map +1 -1
- package/es/oracle.d.ts +69 -62
- package/es/oracle.mjs +121 -103
- package/es/oracle.mjs.map +1 -1
- package/es/spend.d.ts +16 -15
- package/es/spend.mjs +19 -30
- package/es/spend.mjs.map +1 -1
- package/es/tx/builder/address.d.ts +25 -0
- package/es/tx/builder/address.mjs +45 -0
- package/es/tx/builder/address.mjs.map +1 -0
- package/es/tx/builder/constants.d.ts +55 -26
- package/es/tx/builder/constants.mjs +60 -38
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/field-types/coin-amount.d.ts +13 -0
- package/es/tx/builder/field-types/coin-amount.mjs +26 -0
- package/es/tx/builder/field-types/coin-amount.mjs.map +1 -0
- package/es/tx/builder/field-types/deposit.d.ts +15 -0
- package/es/tx/builder/field-types/deposit.mjs +19 -0
- package/es/tx/builder/field-types/deposit.mjs.map +1 -0
- package/es/tx/builder/field-types/fee.d.ts +25 -0
- package/es/tx/{min-fee.mjs → builder/field-types/fee.mjs} +62 -60
- package/es/tx/builder/field-types/fee.mjs.map +1 -0
- package/es/tx/builder/field-types/field.d.ts +6 -0
- package/es/tx/builder/field-types/field.mjs +15 -0
- package/es/tx/builder/field-types/field.mjs.map +1 -0
- package/es/tx/builder/field-types/gas-limit.d.ts +12 -0
- package/es/tx/builder/field-types/gas-limit.mjs +33 -0
- package/es/tx/builder/field-types/gas-limit.mjs.map +1 -0
- package/es/tx/builder/field-types/gas-price.d.ts +8 -0
- package/es/tx/builder/field-types/gas-price.mjs +18 -0
- package/es/tx/builder/field-types/gas-price.mjs.map +1 -0
- package/es/tx/builder/field-types/index.d.ts +70 -0
- package/es/tx/builder/field-types/index.mjs +25 -0
- package/es/tx/builder/field-types/index.mjs.map +1 -0
- package/es/tx/builder/field-types/name-fee.d.ts +20 -0
- package/es/tx/builder/field-types/name-fee.mjs +24 -0
- package/es/tx/builder/field-types/name-fee.mjs.map +1 -0
- package/es/tx/builder/field-types/name-id.d.ts +14 -0
- package/es/tx/builder/field-types/name-id.mjs +19 -0
- package/es/tx/builder/field-types/name-id.mjs.map +1 -0
- package/es/tx/builder/field-types/name.d.ts +13 -0
- package/es/tx/builder/field-types/name.mjs +18 -0
- package/es/tx/builder/field-types/name.mjs.map +1 -0
- package/es/tx/builder/field-types/short-u-int.d.ts +6 -0
- package/es/tx/builder/field-types/short-u-int.mjs +12 -0
- package/es/tx/builder/field-types/short-u-int.mjs.map +1 -0
- package/es/tx/builder/field-types/u-int.d.ts +8 -0
- package/es/tx/builder/field-types/u-int.mjs +14 -0
- package/es/tx/builder/field-types/u-int.mjs.map +1 -0
- package/es/tx/builder/helpers.d.ts +27 -33
- package/es/tx/builder/helpers.mjs +41 -47
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +25 -12
- package/es/tx/builder/index.mjs +74 -83
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +995 -144
- package/es/tx/builder/schema.mjs +121 -170
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +28 -27
- package/es/tx/index.mjs +97 -117
- package/es/tx/index.mjs.map +1 -1
- package/es/tx/validator.d.ts +4 -3
- package/es/tx/validator.mjs +79 -92
- package/es/tx/validator.mjs.map +1 -1
- package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -1
- package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -1
- package/es/typings/bip32-path/index.d.mjs.map +1 -1
- package/es/typings/blakejs/index.d.mjs.map +1 -1
- package/es/typings/sha-js/index.d.mjs +2 -0
- package/es/typings/sha-js/index.d.mjs.map +1 -0
- package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -1
- package/es/utils/amount-formatter.d.ts +9 -9
- package/es/utils/amount-formatter.mjs +17 -17
- package/es/utils/amount-formatter.mjs.map +1 -1
- package/es/utils/autorest.mjs +7 -7
- package/es/utils/autorest.mjs.map +1 -1
- package/es/utils/bignumber.mjs +2 -1
- package/es/utils/bignumber.mjs.map +1 -1
- package/es/utils/bytes.mjs +1 -1
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.d.ts +8 -23
- package/es/utils/crypto.mjs +15 -41
- package/es/utils/crypto.mjs.map +1 -1
- package/es/utils/encoder-types.d.ts +61 -0
- package/es/utils/encoder-types.mjs +36 -0
- package/es/utils/encoder-types.mjs.map +1 -0
- package/es/utils/encoder.d.ts +6 -7
- package/es/utils/encoder.mjs +42 -26
- package/es/utils/encoder.mjs.map +1 -1
- package/es/utils/errors.d.ts +1 -11
- package/es/utils/errors.mjs +4 -20
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.d.ts +18 -2
- package/es/utils/hd-wallet.mjs +64 -34
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/json-big.mjs +2 -2
- package/es/utils/json-big.mjs.map +1 -1
- package/es/utils/keystore.mjs +4 -2
- package/es/utils/keystore.mjs.map +1 -1
- package/es/utils/mptree.d.ts +2 -2
- package/es/utils/mptree.mjs +11 -6
- package/es/utils/mptree.mjs.map +1 -1
- package/es/utils/other.d.ts +8 -2
- package/es/utils/other.mjs +15 -3
- package/es/utils/other.mjs.map +1 -1
- package/es/utils/semver-satisfies.d.ts +1 -1
- package/es/utils/semver-satisfies.mjs +2 -2
- package/es/utils/semver-satisfies.mjs.map +1 -1
- package/es/utils/string.mjs.map +1 -1
- package/package.json +36 -34
- package/src/AeSdk.ts +30 -27
- package/src/AeSdkAepp.ts +93 -84
- package/src/AeSdkBase.ts +148 -130
- package/src/AeSdkWallet.ts +172 -156
- package/src/Node.ts +108 -102
- package/src/account/Base.ts +42 -32
- package/src/account/Memory.ts +45 -30
- package/src/account/Rpc.ts +32 -30
- package/src/aens.ts +124 -108
- package/src/aepp-wallet-communication/connection/Browser.ts +18 -15
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +22 -21
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +63 -52
- package/src/aepp-wallet-communication/connection-proxy.ts +8 -7
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +67 -61
- package/src/aepp-wallet-communication/rpc/types.ts +32 -32
- package/src/aepp-wallet-communication/schema.ts +117 -74
- package/src/aepp-wallet-communication/wallet-detector.ts +29 -28
- package/src/apis/node/code-model-v4.yaml +54 -20
- package/src/apis/node/models/index.ts +6 -2
- package/src/apis/node/models/mappers.ts +4 -2
- package/src/chain.ts +286 -228
- package/src/channel/handlers.ts +424 -372
- package/src/channel/index.ts +285 -251
- package/src/channel/internal.ts +248 -232
- package/src/contract/Compiler.ts +22 -21
- package/src/contract/aci.ts +267 -258
- package/src/contract/ga.ts +93 -72
- package/src/contract/methods.ts +32 -27
- package/src/deprecated/index.ts +172 -0
- package/src/deprecated/methods.ts +25 -0
- package/src/index.ts +37 -32
- package/src/oracle.ts +211 -189
- package/src/spend.ts +82 -70
- package/src/tx/builder/address.ts +50 -0
- package/src/tx/builder/constants.ts +82 -52
- package/src/tx/builder/field-types/coin-amount.ts +27 -0
- package/src/tx/builder/field-types/deposit.ts +21 -0
- package/src/tx/builder/field-types/fee.ts +143 -0
- package/src/tx/builder/field-types/field.ts +9 -0
- package/src/tx/builder/field-types/gas-limit.ts +41 -0
- package/src/tx/builder/field-types/gas-price.ts +16 -0
- package/src/tx/builder/field-types/index.ts +45 -0
- package/src/tx/builder/field-types/name-fee.ts +32 -0
- package/src/tx/builder/field-types/name-id.ts +20 -0
- package/src/tx/builder/field-types/name.ts +18 -0
- package/src/tx/builder/field-types/short-u-int.ts +11 -0
- package/src/tx/builder/field-types/u-int.ts +16 -0
- package/src/tx/builder/helpers.ts +112 -117
- package/src/tx/builder/index.ts +203 -197
- package/src/tx/builder/schema.ts +421 -465
- package/src/tx/index.ts +128 -135
- package/src/tx/validator.ts +165 -161
- package/src/typings/@aeternity__argon2-browser/index.d.ts +1 -1
- package/src/typings/@aeternity__uuid/index.d.ts +3 -1
- package/src/typings/bip32-path/index.d.ts +6 -6
- package/src/typings/blakejs/index.d.ts +4 -32
- package/src/typings/sha-js/index.d.ts +5 -0
- package/src/typings/tweetnacl-auth/index.d.ts +2 -2
- package/src/utils/amount-formatter.ts +41 -41
- package/src/utils/autorest.ts +57 -54
- package/src/utils/bignumber.ts +7 -6
- package/src/utils/bytes.ts +19 -19
- package/src/utils/crypto.ts +82 -94
- package/src/utils/encoder-types.ts +63 -0
- package/src/utils/encoder.ts +104 -56
- package/src/utils/errors.ts +246 -264
- package/src/utils/hd-wallet.ts +114 -82
- package/src/utils/json-big.ts +16 -15
- package/src/utils/keystore.ts +65 -62
- package/src/utils/mptree.ts +59 -56
- package/src/utils/other.ts +26 -18
- package/src/utils/semver-satisfies.ts +15 -11
- package/src/utils/string.ts +10 -10
- package/es/tx/builder/field-types.d.ts +0 -62
- package/es/tx/builder/field-types.mjs +0 -126
- package/es/tx/builder/field-types.mjs.map +0 -1
- package/es/tx/min-fee.d.ts +0 -20
- package/es/tx/min-fee.mjs.map +0 -1
- package/src/tx/builder/field-types.ts +0 -111
- package/src/tx/min-fee.ts +0 -136
package/src/tx/index.ts
CHANGED
|
@@ -22,178 +22,171 @@
|
|
|
22
22
|
* the creation of transactions to {@link Node}.
|
|
23
23
|
* These methods provide ability to create native transactions.
|
|
24
24
|
*/
|
|
25
|
+
import BigNumber from 'bignumber.js';
|
|
25
26
|
import {
|
|
26
|
-
ABI_VERSIONS, CtVersion, PROTOCOL_VM_ABI,
|
|
27
|
-
} from './builder/schema'
|
|
27
|
+
ABI_VERSIONS, CtVersion, PROTOCOL_VM_ABI, TX_TTL, TxParamsCommon,
|
|
28
|
+
} from './builder/schema';
|
|
29
|
+
import { Tag } from './builder/constants';
|
|
28
30
|
import {
|
|
29
|
-
ArgumentError, UnsupportedProtocolError, UnknownTxError, InvalidTxParamsError
|
|
30
|
-
} from '../utils/errors'
|
|
31
|
-
import
|
|
32
|
-
import
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import
|
|
36
|
-
import { isKeyOfObject } from '../utils/other'
|
|
37
|
-
import { AE_AMOUNT_FORMATS } from '../utils/amount-formatter'
|
|
31
|
+
ArgumentError, UnsupportedProtocolError, UnknownTxError, InvalidTxParamsError,
|
|
32
|
+
} from '../utils/errors';
|
|
33
|
+
import Node from '../Node';
|
|
34
|
+
import { Encoded } from '../utils/encoder';
|
|
35
|
+
import { buildTx as syncBuildTx, unpackTx } from './builder/index';
|
|
36
|
+
import { isKeyOfObject } from '../utils/other';
|
|
37
|
+
import { AE_AMOUNT_FORMATS } from '../utils/amount-formatter';
|
|
38
38
|
|
|
39
|
-
type Int = number | string | BigNumber
|
|
39
|
+
type Int = number | string | BigNumber;
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
export type BuildTxOptions <TxType extends TX_TYPE, OmitFields extends string> =
|
|
44
|
-
Omit<Parameters<typeof _buildTx<TxType>>[1], OmitFields>
|
|
45
|
-
|
|
46
|
-
// TODO: find a better name or rearrange methods
|
|
47
|
-
export async function _buildTx<TxType extends TX_TYPE> (
|
|
48
|
-
txType: TxType,
|
|
49
|
-
{ denomination, absoluteTtl, ..._params }:
|
|
50
|
-
Omit<Parameters<typeof syncBuildTx<TxType, 'tx'>>[0], 'fee' | 'nonce' | 'ttl' | 'ctVersion' | 'abiVersion'>
|
|
51
|
-
& {
|
|
52
|
-
onNode: Node
|
|
53
|
-
fee?: Int
|
|
54
|
-
nonce?: number
|
|
55
|
-
ttl?: number
|
|
56
|
-
denomination?: AE_AMOUNT_FORMATS
|
|
57
|
-
absoluteTtl?: boolean
|
|
58
|
-
}
|
|
59
|
-
& (TxType extends TX_TYPE.oracleExtend | TX_TYPE.oracleResponse ? { callerId: EncodedData<'ak'> } : {})
|
|
60
|
-
& (TxType extends TX_TYPE.contractCreate | TX_TYPE.gaAttach ? { ctVersion?: CtVersion } : {})
|
|
61
|
-
& (TxType extends TX_TYPE.contractCall | TX_TYPE.oracleRegister
|
|
62
|
-
? { abiVersion?: ABI_VERSIONS } : {})
|
|
63
|
-
): Promise<EncodedData<'tx'>> {
|
|
64
|
-
// TODO: avoid this assertion
|
|
65
|
-
const params = _params as unknown as TxParamsCommon & { onNode: Node }
|
|
66
|
-
let senderKey: keyof TxParamsCommon | '<absent>'
|
|
67
|
-
switch (txType) {
|
|
68
|
-
case TX_TYPE.spend:
|
|
69
|
-
case TX_TYPE.oracleQuery:
|
|
70
|
-
senderKey = 'senderId'
|
|
71
|
-
break
|
|
72
|
-
case TX_TYPE.nameClaim:
|
|
73
|
-
case TX_TYPE.nameUpdate:
|
|
74
|
-
case TX_TYPE.nameRevoke:
|
|
75
|
-
case TX_TYPE.nameTransfer:
|
|
76
|
-
case TX_TYPE.namePreClaim:
|
|
77
|
-
case TX_TYPE.oracleRegister:
|
|
78
|
-
senderKey = 'accountId'
|
|
79
|
-
break
|
|
80
|
-
case TX_TYPE.contractCreate:
|
|
81
|
-
case TX_TYPE.gaAttach:
|
|
82
|
-
senderKey = 'ownerId'
|
|
83
|
-
break
|
|
84
|
-
case TX_TYPE.contractCall:
|
|
85
|
-
case TX_TYPE.oracleExtend:
|
|
86
|
-
case TX_TYPE.oracleResponse:
|
|
87
|
-
senderKey = 'callerId'
|
|
88
|
-
break
|
|
89
|
-
case TX_TYPE.channelCloseSolo:
|
|
90
|
-
case TX_TYPE.channelSlash:
|
|
91
|
-
case TX_TYPE.channelSettle:
|
|
92
|
-
case TX_TYPE.channelSnapshotSolo:
|
|
93
|
-
senderKey = 'fromId'
|
|
94
|
-
break
|
|
95
|
-
case TX_TYPE.payingFor:
|
|
96
|
-
senderKey = 'payerId'
|
|
97
|
-
break
|
|
98
|
-
default:
|
|
99
|
-
throw new ArgumentError('txType', 'valid transaction type', txType)
|
|
100
|
-
}
|
|
101
|
-
// TODO: move specific cases to field-types
|
|
102
|
-
if ([TX_TYPE.contractCreate, TX_TYPE.gaAttach].includes(txType)) {
|
|
103
|
-
params.ctVersion = await getVmVersion(
|
|
104
|
-
TX_TYPE.contractCreate, { ...params, ...params.ctVersion }
|
|
105
|
-
)
|
|
106
|
-
}
|
|
107
|
-
if (txType === TX_TYPE.contractCall) {
|
|
108
|
-
params.abiVersion = (await getVmVersion(TX_TYPE.contractCall, params)).abiVersion
|
|
109
|
-
}
|
|
110
|
-
if (txType === TX_TYPE.oracleRegister) {
|
|
111
|
-
params.abiVersion ??= ABI_VERSIONS.NO_ABI
|
|
112
|
-
}
|
|
113
|
-
if (txType === TX_TYPE.payingFor) {
|
|
114
|
-
params.tx = unpackTx(params.tx)
|
|
115
|
-
}
|
|
116
|
-
const senderId = params[senderKey]
|
|
117
|
-
// TODO: do this check on TypeScript level
|
|
118
|
-
if (senderId == null) throw new InvalidTxParamsError(`Transaction field ${senderKey} is missed`)
|
|
119
|
-
const extraParams = await prepareTxParams(
|
|
120
|
-
txType, { ...params, senderId, denomination, absoluteTtl }
|
|
121
|
-
)
|
|
122
|
-
return syncBuildTx({ ...params, ...extraParams } as any, txType, { denomination }).tx
|
|
123
|
-
}
|
|
41
|
+
export type BuildTxOptions <TxType extends Tag, OmitFields extends string> =
|
|
42
|
+
Omit<Parameters<typeof _buildTx<TxType>>[1], OmitFields>;
|
|
124
43
|
|
|
125
44
|
/**
|
|
126
45
|
* Validated vm/abi version or get default based on transaction type and NODE version
|
|
127
|
-
*
|
|
46
|
+
* @category transaction builder
|
|
128
47
|
* @param txType - Type of transaction
|
|
129
48
|
* @param ctVersion - Object with vm and abi version fields
|
|
130
49
|
* @returns Object with vm/abi version
|
|
131
50
|
*/
|
|
132
|
-
export async function getVmVersion
|
|
133
|
-
txType:
|
|
134
|
-
): Promise<CtVersion
|
|
135
|
-
export async function getVmVersion
|
|
136
|
-
txType:
|
|
137
|
-
): Promise<Pick<CtVersion, 'abiVersion'
|
|
138
|
-
export async function getVmVersion
|
|
139
|
-
txType:
|
|
51
|
+
export async function getVmVersion(
|
|
52
|
+
txType: Tag.ContractCreateTx, ctVersion: Partial<CtVersion> & { onNode: Node }
|
|
53
|
+
): Promise<CtVersion>;
|
|
54
|
+
export async function getVmVersion(
|
|
55
|
+
txType: Tag, ctVersion: Partial<Pick<CtVersion, 'abiVersion'>> & { onNode: Node }
|
|
56
|
+
): Promise<Pick<CtVersion, 'abiVersion'>>;
|
|
57
|
+
export async function getVmVersion(
|
|
58
|
+
txType: Tag,
|
|
59
|
+
{ vmVersion, abiVersion, onNode }: Partial<CtVersion> & { onNode: Node },
|
|
140
60
|
): Promise<Partial<CtVersion>> {
|
|
141
|
-
const { consensusProtocolVersion } = await onNode.getNodeInfo()
|
|
61
|
+
const { consensusProtocolVersion } = await onNode.getNodeInfo();
|
|
142
62
|
if (!isKeyOfObject(consensusProtocolVersion, PROTOCOL_VM_ABI)) {
|
|
143
|
-
throw new UnsupportedProtocolError('Not supported consensus protocol version')
|
|
63
|
+
throw new UnsupportedProtocolError('Not supported consensus protocol version');
|
|
144
64
|
}
|
|
145
|
-
const supportedProtocol = PROTOCOL_VM_ABI[consensusProtocolVersion]
|
|
65
|
+
const supportedProtocol = PROTOCOL_VM_ABI[consensusProtocolVersion];
|
|
146
66
|
if (!isKeyOfObject(txType, supportedProtocol)) {
|
|
147
|
-
throw new UnknownTxError('Not supported tx type')
|
|
67
|
+
throw new UnknownTxError('Not supported tx type');
|
|
148
68
|
}
|
|
149
|
-
const protocolForTX = supportedProtocol[txType]
|
|
150
|
-
abiVersion ??= protocolForTX.abiVersion[0]
|
|
151
|
-
vmVersion ??= protocolForTX.vmVersion[0]
|
|
152
|
-
return { vmVersion, abiVersion }
|
|
69
|
+
const protocolForTX = supportedProtocol[txType];
|
|
70
|
+
abiVersion ??= protocolForTX.abiVersion[0];
|
|
71
|
+
vmVersion ??= protocolForTX.vmVersion[0];
|
|
72
|
+
return { vmVersion, abiVersion };
|
|
153
73
|
}
|
|
154
74
|
|
|
155
75
|
/**
|
|
156
76
|
* Calculate fee, get absolute ttl (ttl + height), get account nonce
|
|
157
|
-
*
|
|
77
|
+
* @category transaction builder
|
|
158
78
|
* @param txType - Type of transaction
|
|
159
79
|
* @param params - Object which contains all tx data
|
|
160
80
|
* @returns Object with account nonce, absolute ttl and transaction fee
|
|
161
81
|
*/
|
|
162
|
-
export async function prepareTxParams
|
|
163
|
-
txType:
|
|
82
|
+
export async function prepareTxParams(
|
|
83
|
+
txType: Tag,
|
|
164
84
|
{
|
|
165
85
|
senderId,
|
|
166
86
|
nonce,
|
|
167
87
|
ttl = TX_TTL,
|
|
168
|
-
fee: f,
|
|
169
88
|
absoluteTtl,
|
|
170
|
-
vsn,
|
|
171
89
|
strategy,
|
|
172
|
-
denomination,
|
|
173
90
|
onNode,
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
): Promise<{ fee: BigNumber, ttl: number, nonce: number }> {
|
|
91
|
+
}: PrepareTxParamsOptions,
|
|
92
|
+
): Promise<{ ttl: number; nonce: number }> {
|
|
177
93
|
nonce ??= (
|
|
178
94
|
await onNode.getAccountNextNonce(senderId, { strategy }).catch(() => ({ nextNonce: 1 }))
|
|
179
|
-
).nextNonce
|
|
95
|
+
).nextNonce;
|
|
180
96
|
|
|
181
97
|
if (ttl !== 0) {
|
|
182
|
-
if (ttl < 0) throw new ArgumentError('ttl', 'greater or equal to 0', ttl)
|
|
183
|
-
ttl += absoluteTtl === true ? 0 : (await onNode.getCurrentKeyBlock()).height
|
|
98
|
+
if (ttl < 0) throw new ArgumentError('ttl', 'greater or equal to 0', ttl);
|
|
99
|
+
ttl += absoluteTtl === true ? 0 : (await onNode.getCurrentKeyBlock()).height;
|
|
184
100
|
}
|
|
185
101
|
|
|
186
|
-
|
|
187
|
-
? new BigNumber(f)
|
|
188
|
-
: calculateMinFee(txType, { params: { ...txParams, senderId, nonce, ttl }, vsn, denomination })
|
|
189
|
-
return { fee, ttl, nonce }
|
|
102
|
+
return { ttl, nonce };
|
|
190
103
|
}
|
|
191
104
|
|
|
192
|
-
interface PrepareTxParamsOptions extends Pick<TxParamsCommon, 'nonce' | 'ttl'
|
|
193
|
-
senderId:
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
105
|
+
interface PrepareTxParamsOptions extends Pick<TxParamsCommon, 'nonce' | 'ttl'> {
|
|
106
|
+
senderId: Encoded.AccountAddress;
|
|
107
|
+
absoluteTtl?: boolean;
|
|
108
|
+
strategy?: 'continuity' | 'max';
|
|
109
|
+
onNode: Node;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// TODO: find a better name or rearrange methods
|
|
113
|
+
/**
|
|
114
|
+
* @category transaction builder
|
|
115
|
+
*/
|
|
116
|
+
export async function _buildTx<TxType extends Tag>(
|
|
117
|
+
txType: TxType,
|
|
118
|
+
{ denomination, absoluteTtl, ..._params }:
|
|
119
|
+
Omit<Parameters<typeof syncBuildTx<TxType, 'tx'>>[0], 'fee' | 'nonce' | 'ttl' | 'ctVersion' | 'abiVersion'>
|
|
120
|
+
& {
|
|
121
|
+
onNode: Node;
|
|
122
|
+
fee?: Int;
|
|
123
|
+
nonce?: number;
|
|
124
|
+
ttl?: number;
|
|
125
|
+
denomination?: AE_AMOUNT_FORMATS;
|
|
126
|
+
absoluteTtl?: boolean;
|
|
127
|
+
}
|
|
128
|
+
& (TxType extends Tag.OracleExtendTx | Tag.OracleResponseTx
|
|
129
|
+
? { callerId: Encoded.AccountAddress } : {})
|
|
130
|
+
& (TxType extends Tag.ContractCreateTx | Tag.GaAttachTx ? { ctVersion?: CtVersion } : {})
|
|
131
|
+
& (TxType extends Tag.ContractCallTx | Tag.OracleRegisterTx
|
|
132
|
+
? { abiVersion?: ABI_VERSIONS } : {}),
|
|
133
|
+
): Promise<Encoded.Transaction> {
|
|
134
|
+
// TODO: avoid this assertion
|
|
135
|
+
const params = _params as unknown as TxParamsCommon & { onNode: Node };
|
|
136
|
+
let senderKey: keyof TxParamsCommon | '<absent>';
|
|
137
|
+
switch (txType) {
|
|
138
|
+
case Tag.SpendTx:
|
|
139
|
+
case Tag.OracleQueryTx:
|
|
140
|
+
senderKey = 'senderId';
|
|
141
|
+
break;
|
|
142
|
+
case Tag.NameClaimTx:
|
|
143
|
+
case Tag.NameUpdateTx:
|
|
144
|
+
case Tag.NameRevokeTx:
|
|
145
|
+
case Tag.NameTransferTx:
|
|
146
|
+
case Tag.NamePreclaimTx:
|
|
147
|
+
case Tag.OracleRegisterTx:
|
|
148
|
+
senderKey = 'accountId';
|
|
149
|
+
break;
|
|
150
|
+
case Tag.ContractCreateTx:
|
|
151
|
+
case Tag.GaAttachTx:
|
|
152
|
+
senderKey = 'ownerId';
|
|
153
|
+
break;
|
|
154
|
+
case Tag.ContractCallTx:
|
|
155
|
+
case Tag.OracleExtendTx:
|
|
156
|
+
case Tag.OracleResponseTx:
|
|
157
|
+
senderKey = 'callerId';
|
|
158
|
+
break;
|
|
159
|
+
case Tag.ChannelCloseSoloTx:
|
|
160
|
+
case Tag.ChannelSlashTx:
|
|
161
|
+
case Tag.ChannelSettleTx:
|
|
162
|
+
case Tag.ChannelSnapshotSoloTx:
|
|
163
|
+
senderKey = 'fromId';
|
|
164
|
+
break;
|
|
165
|
+
case Tag.PayingForTx:
|
|
166
|
+
senderKey = 'payerId';
|
|
167
|
+
break;
|
|
168
|
+
default:
|
|
169
|
+
throw new ArgumentError('txType', 'valid transaction type', txType);
|
|
170
|
+
}
|
|
171
|
+
// TODO: move specific cases to field-types
|
|
172
|
+
if ([Tag.ContractCreateTx, Tag.GaAttachTx].includes(txType)) {
|
|
173
|
+
params.ctVersion = await getVmVersion(
|
|
174
|
+
Tag.ContractCreateTx,
|
|
175
|
+
{ ...params, ...params.ctVersion },
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
if (txType === Tag.ContractCallTx) {
|
|
179
|
+
params.abiVersion = (await getVmVersion(Tag.ContractCallTx, params)).abiVersion;
|
|
180
|
+
}
|
|
181
|
+
if (txType === Tag.OracleRegisterTx) {
|
|
182
|
+
params.abiVersion ??= ABI_VERSIONS.NO_ABI;
|
|
183
|
+
}
|
|
184
|
+
if (txType === Tag.PayingForTx) {
|
|
185
|
+
params.tx = unpackTx(params.tx);
|
|
186
|
+
}
|
|
187
|
+
const senderId = params[senderKey];
|
|
188
|
+
// TODO: do this check on TypeScript level
|
|
189
|
+
if (senderId == null) throw new InvalidTxParamsError(`Transaction field ${senderKey} is missed`);
|
|
190
|
+
const extraParams = await prepareTxParams(txType, { ...params, senderId, absoluteTtl });
|
|
191
|
+
return syncBuildTx({ ...params, ...extraParams } as any, txType, { denomination }).tx;
|
|
199
192
|
}
|