@aeternity/aepp-sdk 12.0.0 → 12.1.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/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 +20764 -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 +35 -33
- 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 +170 -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/utils/mptree.ts
CHANGED
|
@@ -15,30 +15,32 @@
|
|
|
15
15
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
import
|
|
20
|
-
import {
|
|
18
|
+
/* eslint-disable default-case */
|
|
19
|
+
import { encode as rlpEncode } from 'rlp';
|
|
20
|
+
import type { Input } from 'rlp';
|
|
21
|
+
import { hash } from './crypto';
|
|
21
22
|
import {
|
|
22
23
|
MerkleTreeHashMismatchError,
|
|
23
24
|
MissingNodeInTreeError,
|
|
24
25
|
UnknownPathNibbleError,
|
|
25
|
-
UnknownNodeLengthError
|
|
26
|
-
} from './errors'
|
|
26
|
+
UnknownNodeLengthError,
|
|
27
|
+
} from './errors';
|
|
27
28
|
|
|
28
29
|
enum NodeType {
|
|
29
30
|
Branch,
|
|
30
31
|
Extension,
|
|
31
|
-
Leaf
|
|
32
|
+
Leaf,
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
export type MPTreeBinary = [Buffer, Array<[Buffer, Buffer[]]>]
|
|
35
|
+
export type MPTreeBinary = [Buffer, Array<[Buffer, Buffer[]]>];
|
|
35
36
|
|
|
36
37
|
export default class MPTree {
|
|
37
|
-
private readonly rootHash: string
|
|
38
|
-
private readonly nodes: { [key: string]: Buffer[] }
|
|
38
|
+
private readonly rootHash: string;
|
|
39
39
|
|
|
40
|
-
private
|
|
41
|
-
|
|
40
|
+
private readonly nodes: { [key: string]: Buffer[] };
|
|
41
|
+
|
|
42
|
+
private static nodeHash(node: Input): string {
|
|
43
|
+
return Buffer.from(hash(rlpEncode(node))).toString('hex');
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
/**
|
|
@@ -46,56 +48,56 @@ export default class MPTree {
|
|
|
46
48
|
* @param binary - Binary
|
|
47
49
|
* @returns Merkle Patricia Tree
|
|
48
50
|
*/
|
|
49
|
-
constructor
|
|
50
|
-
this.rootHash = binary[0].toString('hex')
|
|
51
|
+
constructor(binary: MPTreeBinary) {
|
|
52
|
+
this.rootHash = binary[0].toString('hex');
|
|
51
53
|
this.nodes = Object.fromEntries(
|
|
52
|
-
binary[1].map((node) => [node[0].toString('hex'), node[1]])
|
|
53
|
-
)
|
|
54
|
+
binary[1].map((node) => [node[0].toString('hex'), node[1]]),
|
|
55
|
+
);
|
|
54
56
|
|
|
55
|
-
if (this.nodes[this.rootHash] === undefined) throw new MissingNodeInTreeError('Can\'t find a node by root hash')
|
|
57
|
+
if (this.nodes[this.rootHash] === undefined) throw new MissingNodeInTreeError('Can\'t find a node by root hash');
|
|
56
58
|
Object.entries(this.nodes).forEach(([key, node]) => {
|
|
57
|
-
if (MPTree.nodeHash(node) !== key) throw new MerkleTreeHashMismatchError()
|
|
58
|
-
const { type, payload } = MPTree.parseNode(node)
|
|
59
|
+
if (MPTree.nodeHash(node) !== key) throw new MerkleTreeHashMismatchError();
|
|
60
|
+
const { type, payload } = MPTree.parseNode(node);
|
|
59
61
|
switch (type) {
|
|
60
62
|
case NodeType.Branch:
|
|
61
63
|
payload
|
|
62
64
|
.slice(0, 16)
|
|
63
|
-
.filter(n => n.length)
|
|
65
|
+
.filter((n) => n.length)
|
|
64
66
|
.forEach((n) => {
|
|
65
67
|
if (this.nodes[n.toString('hex')] === undefined) {
|
|
66
|
-
throw new MissingNodeInTreeError('Can\'t find a node by hash in branch node')
|
|
68
|
+
throw new MissingNodeInTreeError('Can\'t find a node by hash in branch node');
|
|
67
69
|
}
|
|
68
|
-
})
|
|
69
|
-
break
|
|
70
|
+
});
|
|
71
|
+
break;
|
|
70
72
|
case NodeType.Extension:
|
|
71
73
|
if (this.nodes[payload[0].toString('hex')] === undefined) {
|
|
72
|
-
throw new MissingNodeInTreeError('Can\'t find a node by hash in extension node')
|
|
74
|
+
throw new MissingNodeInTreeError('Can\'t find a node by hash in extension node');
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
|
-
})
|
|
77
|
+
});
|
|
76
78
|
}
|
|
77
79
|
|
|
78
|
-
isEqual
|
|
79
|
-
return this.rootHash === tree.rootHash
|
|
80
|
+
isEqual(tree: MPTree): boolean {
|
|
81
|
+
return this.rootHash === tree.rootHash;
|
|
80
82
|
}
|
|
81
83
|
|
|
82
|
-
private static parseNode
|
|
83
|
-
type: NodeType
|
|
84
|
-
payload: Buffer[]
|
|
85
|
-
path: string | null
|
|
84
|
+
private static parseNode(node: Buffer[]): {
|
|
85
|
+
type: NodeType;
|
|
86
|
+
payload: Buffer[];
|
|
87
|
+
path: string | null;
|
|
86
88
|
} {
|
|
87
89
|
switch (node.length) {
|
|
88
90
|
case 17:
|
|
89
|
-
return { type: NodeType.Branch, payload: node, path: null }
|
|
91
|
+
return { type: NodeType.Branch, payload: node, path: null };
|
|
90
92
|
case 2: {
|
|
91
|
-
const nibble = node[0][0] >> 4
|
|
92
|
-
if (nibble > 3) throw new UnknownPathNibbleError(nibble)
|
|
93
|
-
const type = nibble <= 1 ? NodeType.Extension : NodeType.Leaf
|
|
94
|
-
const slice = [0, 2].includes(nibble) ? 2 : 1
|
|
95
|
-
return { type, payload: [node[1]], path: node[0].toString('hex').slice(slice) }
|
|
93
|
+
const nibble = node[0][0] >> 4; // eslint-disable-line no-bitwise
|
|
94
|
+
if (nibble > 3) throw new UnknownPathNibbleError(nibble);
|
|
95
|
+
const type = nibble <= 1 ? NodeType.Extension : NodeType.Leaf;
|
|
96
|
+
const slice = [0, 2].includes(nibble) ? 2 : 1;
|
|
97
|
+
return { type, payload: [node[1]], path: node[0].toString('hex').slice(slice) };
|
|
96
98
|
}
|
|
97
99
|
default:
|
|
98
|
-
throw new UnknownNodeLengthError(node.length)
|
|
100
|
+
throw new UnknownNodeLengthError(node.length);
|
|
99
101
|
}
|
|
100
102
|
}
|
|
101
103
|
|
|
@@ -103,39 +105,40 @@ export default class MPTree {
|
|
|
103
105
|
* Serialize Merkle Patricia Tree
|
|
104
106
|
* @returns Binary
|
|
105
107
|
*/
|
|
106
|
-
serialize
|
|
108
|
+
serialize(): MPTreeBinary {
|
|
107
109
|
return [
|
|
108
110
|
Buffer.from(this.rootHash, 'hex'),
|
|
109
111
|
Object.entries(this.nodes).map(([mptHash, value]) => ([
|
|
110
112
|
Buffer.from(mptHash, 'hex'),
|
|
111
|
-
value
|
|
112
|
-
]))
|
|
113
|
-
]
|
|
113
|
+
value,
|
|
114
|
+
])),
|
|
115
|
+
];
|
|
114
116
|
}
|
|
115
117
|
|
|
116
118
|
/**
|
|
117
119
|
* Retrieve value from Merkle Patricia Tree
|
|
118
|
-
* @param
|
|
120
|
+
* @param _key - The key of the element to retrieve
|
|
119
121
|
* @returns Value associated to the specified key
|
|
120
122
|
*/
|
|
121
|
-
get
|
|
122
|
-
let searchFrom = this.rootHash
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
get(_key: string): Buffer | undefined {
|
|
124
|
+
let searchFrom = this.rootHash;
|
|
125
|
+
let key = _key;
|
|
126
|
+
while (true) { // eslint-disable-line no-constant-condition
|
|
127
|
+
const { type, payload, path } = MPTree.parseNode(this.nodes[searchFrom]);
|
|
125
128
|
switch (type) {
|
|
126
129
|
case NodeType.Branch:
|
|
127
|
-
if (key.length === 0) return payload[16]
|
|
128
|
-
searchFrom = payload[+`0x${key[0]}`].toString('hex')
|
|
129
|
-
key = key.
|
|
130
|
-
break
|
|
130
|
+
if (key.length === 0) return payload[16];
|
|
131
|
+
searchFrom = payload[+`0x${key[0]}`].toString('hex');
|
|
132
|
+
key = key.substring(1);
|
|
133
|
+
break;
|
|
131
134
|
case NodeType.Extension:
|
|
132
|
-
if (key.
|
|
133
|
-
searchFrom = payload[0].toString('hex')
|
|
134
|
-
key = key.
|
|
135
|
-
break
|
|
135
|
+
if (key.substring(0, path?.length) !== path) return undefined;
|
|
136
|
+
searchFrom = payload[0].toString('hex');
|
|
137
|
+
key = key.substring(path.length);
|
|
138
|
+
break;
|
|
136
139
|
case NodeType.Leaf:
|
|
137
|
-
if (path !== key) return undefined
|
|
138
|
-
return payload[0]
|
|
140
|
+
if (path !== key) return undefined;
|
|
141
|
+
return payload[0];
|
|
139
142
|
}
|
|
140
143
|
}
|
|
141
144
|
}
|
package/src/utils/other.ts
CHANGED
|
@@ -1,36 +1,44 @@
|
|
|
1
|
-
export const pause = async (duration: number): Promise<void> =>
|
|
2
|
-
|
|
1
|
+
export const pause = async (duration: number): Promise<void> => new Promise((resolve) => {
|
|
2
|
+
setTimeout(resolve, duration);
|
|
3
|
+
});
|
|
3
4
|
|
|
4
5
|
export const mapObject = <InputV, OutputV>(
|
|
5
6
|
object: { [k: string]: InputV },
|
|
6
7
|
fn: (
|
|
7
8
|
value: [string, InputV], index: number, array: Array<[string, InputV]>
|
|
8
|
-
) => [number | string, OutputV]
|
|
9
|
-
): { [k: string]: OutputV } => Object.fromEntries(Object.entries(object).map(fn))
|
|
9
|
+
) => [number | string, OutputV],
|
|
10
|
+
): { [k: string]: OutputV } => Object.fromEntries(Object.entries(object).map(fn));
|
|
10
11
|
|
|
11
12
|
// remove after dropping webpack4 support
|
|
12
13
|
const isWebpack4Buffer = (() => {
|
|
13
14
|
try {
|
|
14
|
-
Buffer.concat([Uint8Array.from([])])
|
|
15
|
-
return false
|
|
15
|
+
Buffer.concat([Uint8Array.from([])]);
|
|
16
|
+
return false;
|
|
16
17
|
} catch (error) {
|
|
17
|
-
return true
|
|
18
|
+
return true;
|
|
18
19
|
}
|
|
19
|
-
})()
|
|
20
|
+
})();
|
|
20
21
|
|
|
21
22
|
export const concatBuffers = isWebpack4Buffer
|
|
22
|
-
? (list: readonly Uint8Array[], totalLength?: number): Buffer =>
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
? (list: readonly Uint8Array[], totalLength?: number): Buffer => (
|
|
24
|
+
Buffer.concat(list.map((el) => Buffer.from(el)), totalLength)
|
|
25
|
+
)
|
|
26
|
+
: Buffer.concat;
|
|
25
27
|
|
|
26
28
|
/**
|
|
27
29
|
* Object key type guard
|
|
28
|
-
* @param key -
|
|
29
|
-
* @param object -
|
|
30
|
+
* @param key - Maybe object key
|
|
31
|
+
* @param object - Object
|
|
30
32
|
*/
|
|
31
|
-
export function isKeyOfObject<T>
|
|
32
|
-
key
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
export function isKeyOfObject<T>(key: string | number | symbol, object: T): key is keyof T {
|
|
34
|
+
return key in object;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Array item type guard
|
|
39
|
+
* @param item - Maybe array item
|
|
40
|
+
* @param array - Array
|
|
41
|
+
*/
|
|
42
|
+
export function isItemOfArray<T>(item: any, array: readonly T[]): item is T {
|
|
43
|
+
return array.includes(item);
|
|
36
44
|
}
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
export default function (
|
|
1
|
+
export default function semverSatisfies(
|
|
2
|
+
version: string,
|
|
3
|
+
geVersion: string,
|
|
4
|
+
ltVersion: string,
|
|
5
|
+
): boolean {
|
|
2
6
|
const getComponents = (v: string): number[] => v
|
|
3
|
-
.split(/[-+]/)[0].split('.').map(i => +i)
|
|
7
|
+
.split(/[-+]/)[0].split('.').map((i) => +i);
|
|
4
8
|
|
|
5
|
-
const versionComponents = getComponents(version)
|
|
6
|
-
const geComponents = getComponents(geVersion)
|
|
7
|
-
const ltComponents = getComponents(ltVersion)
|
|
9
|
+
const versionComponents = getComponents(version);
|
|
10
|
+
const geComponents = getComponents(geVersion);
|
|
11
|
+
const ltComponents = getComponents(ltVersion);
|
|
8
12
|
|
|
9
|
-
const base = Math.max(...versionComponents, ...geComponents, ...ltComponents) + 1
|
|
13
|
+
const base = Math.max(...versionComponents, ...geComponents, ...ltComponents) + 1;
|
|
10
14
|
const componentsToNumber = (components: number[]): number => components.reverse()
|
|
11
|
-
.reduce((acc, n, idx) => acc + n *
|
|
15
|
+
.reduce((acc, n, idx) => acc + n * base ** idx, 0);
|
|
12
16
|
|
|
13
|
-
const vNumber = componentsToNumber(versionComponents)
|
|
14
|
-
const geNumber = componentsToNumber(geComponents)
|
|
15
|
-
const ltNumber = componentsToNumber(ltComponents)
|
|
16
|
-
return vNumber >= geNumber && vNumber < ltNumber
|
|
17
|
+
const vNumber = componentsToNumber(versionComponents);
|
|
18
|
+
const geNumber = componentsToNumber(geComponents);
|
|
19
|
+
const ltNumber = componentsToNumber(ltComponents);
|
|
20
|
+
return vNumber >= geNumber && vNumber < ltNumber;
|
|
17
21
|
}
|
package/src/utils/string.ts
CHANGED
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
* @param s - String to convert
|
|
21
21
|
* @returns Converted string
|
|
22
22
|
*/
|
|
23
|
-
export function snakeToPascal
|
|
24
|
-
return s.replace(/_./g, match => match[1].toUpperCase())
|
|
23
|
+
export function snakeToPascal(s: string): string {
|
|
24
|
+
return s.replace(/_./g, (match) => match[1].toUpperCase());
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -29,8 +29,8 @@ export function snakeToPascal (s: string): string {
|
|
|
29
29
|
* @param s - String to convert
|
|
30
30
|
* @returns Converted string
|
|
31
31
|
*/
|
|
32
|
-
export function pascalToSnake
|
|
33
|
-
return s.replace(/[A-Z]/g, match => `_${match.toLowerCase()}`)
|
|
32
|
+
export function pascalToSnake(s: string): string {
|
|
33
|
+
return s.replace(/[A-Z]/g, (match) => `_${match.toLowerCase()}`);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/**
|
|
@@ -38,8 +38,8 @@ export function pascalToSnake (s: string): string {
|
|
|
38
38
|
* @param str - String to validate.
|
|
39
39
|
* @returns True if the string is valid hex, false otherwise.
|
|
40
40
|
*/
|
|
41
|
-
export function isHex
|
|
42
|
-
return str.length % 2 === 0 && /^[0-9a-f]+$/i.test(str)
|
|
41
|
+
export function isHex(str: string): boolean {
|
|
42
|
+
return str.length % 2 === 0 && /^[0-9a-f]+$/i.test(str);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
@@ -47,8 +47,8 @@ export function isHex (str: string): boolean {
|
|
|
47
47
|
* @param str - String to validate.
|
|
48
48
|
* @returns True if the string is valid base-64, false otherwise.
|
|
49
49
|
*/
|
|
50
|
-
export function isBase64
|
|
51
|
-
if (str.length % 4 > 0 || /[^0-9a-z+/=]/i.test(str)) return false
|
|
52
|
-
const index = str.indexOf('=')
|
|
53
|
-
return index === -1 || /={1,2}/.test(str.slice(index))
|
|
50
|
+
export function isBase64(str: string): boolean {
|
|
51
|
+
if (str.length % 4 > 0 || /[^0-9a-z+/=]/i.test(str)) return false;
|
|
52
|
+
const index = str.indexOf('=');
|
|
53
|
+
return index === -1 || /={1,2}/.test(str.slice(index));
|
|
54
54
|
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import BigNumber from 'bignumber.js';
|
|
3
|
-
import { AensName } from './constants';
|
|
4
|
-
import { EncodedData } from '../../utils/encoder';
|
|
5
|
-
declare type Int = number | string | BigNumber;
|
|
6
|
-
export declare class Field {
|
|
7
|
-
prototype: any;
|
|
8
|
-
static serialize(value: any, _txFields?: object): Buffer;
|
|
9
|
-
static deserialize(value: Buffer): any;
|
|
10
|
-
}
|
|
11
|
-
export declare class Name extends Field {
|
|
12
|
-
/**
|
|
13
|
-
* @param value - AENS name
|
|
14
|
-
*/
|
|
15
|
-
static serialize(value: AensName): Buffer;
|
|
16
|
-
/**
|
|
17
|
-
* @param value - AENS name
|
|
18
|
-
*/
|
|
19
|
-
static deserialize(value: Buffer): string;
|
|
20
|
-
}
|
|
21
|
-
export declare class NameId extends Field {
|
|
22
|
-
/**
|
|
23
|
-
* @param value - AENS name ID
|
|
24
|
-
*/
|
|
25
|
-
static serialize(value: AensName | EncodedData<'nm'>): Buffer;
|
|
26
|
-
/**
|
|
27
|
-
* @param value - AENS name ID Buffer
|
|
28
|
-
*/
|
|
29
|
-
static deserialize(value: Buffer): string;
|
|
30
|
-
}
|
|
31
|
-
export declare class NameFee extends Field {
|
|
32
|
-
/**
|
|
33
|
-
* @param value - AENS name fee Buffer
|
|
34
|
-
* @param txFields - Transaction fields
|
|
35
|
-
* @param txFields.name - AENS Name in transaction
|
|
36
|
-
*/
|
|
37
|
-
static serialize(value: Int | undefined, { name }: {
|
|
38
|
-
name: AensName;
|
|
39
|
-
}): Buffer;
|
|
40
|
-
/**
|
|
41
|
-
* @param value - AENS name fee Buffer
|
|
42
|
-
* @returns AENS name fee
|
|
43
|
-
*/
|
|
44
|
-
static deserialize(value: Buffer): string;
|
|
45
|
-
}
|
|
46
|
-
export declare class Deposit extends Field {
|
|
47
|
-
/**
|
|
48
|
-
* @param value - Deposit value in string format. Should be equal to '0'.
|
|
49
|
-
* @returns Deposit value Buffer.
|
|
50
|
-
*/
|
|
51
|
-
static serialize(value?: string): Buffer;
|
|
52
|
-
/**
|
|
53
|
-
* @param value - Deposit value Buffer.
|
|
54
|
-
* @returns Deposit value.
|
|
55
|
-
*/
|
|
56
|
-
static deserialize(value: Buffer): string;
|
|
57
|
-
}
|
|
58
|
-
export declare class GasPrice extends Field {
|
|
59
|
-
static serialize(value?: Int): Buffer;
|
|
60
|
-
static deserialize(value: Buffer): string;
|
|
61
|
-
}
|
|
62
|
-
export {};
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import _buffer from "buffer";
|
|
2
|
-
const {
|
|
3
|
-
Buffer: _Buffer
|
|
4
|
-
} = _buffer;
|
|
5
|
-
import { writeId, readId, produceNameId, getMinimumNameFee, readInt, writeInt, isNameValid } from "./helpers.mjs";
|
|
6
|
-
import { InsufficientNameFeeError, IllegalArgumentError } from "../../utils/errors.mjs";
|
|
7
|
-
import BigNumber from 'bignumber.js';
|
|
8
|
-
import { MIN_GAS_PRICE } from "./constants.mjs";
|
|
9
|
-
// todo: update me
|
|
10
|
-
// ? This is a TS workaround because this has to be a class with only static methods
|
|
11
|
-
export class Field {
|
|
12
|
-
static serialize(value) {
|
|
13
|
-
let _txFields = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
14
|
-
|
|
15
|
-
return _Buffer.from(value);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
static deserialize(value) {
|
|
19
|
-
return value.toString();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
export class Name extends Field {
|
|
24
|
-
/**
|
|
25
|
-
* @param value - AENS name
|
|
26
|
-
*/
|
|
27
|
-
static serialize(value) {
|
|
28
|
-
return _Buffer.from(value);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* @param value - AENS name
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
static deserialize(value) {
|
|
36
|
-
return value.toString();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
export class NameId extends Field {
|
|
41
|
-
/**
|
|
42
|
-
* @param value - AENS name ID
|
|
43
|
-
*/
|
|
44
|
-
static serialize(value) {
|
|
45
|
-
return writeId(isNameValid(value) ? produceNameId(value) : value);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* @param value - AENS name ID Buffer
|
|
49
|
-
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
static deserialize(value) {
|
|
53
|
-
return readId(value);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
export class NameFee extends Field {
|
|
58
|
-
/**
|
|
59
|
-
* @param value - AENS name fee Buffer
|
|
60
|
-
* @param txFields - Transaction fields
|
|
61
|
-
* @param txFields.name - AENS Name in transaction
|
|
62
|
-
*/
|
|
63
|
-
static serialize(value, _ref) {
|
|
64
|
-
var _value;
|
|
65
|
-
|
|
66
|
-
let {
|
|
67
|
-
name
|
|
68
|
-
} = _ref;
|
|
69
|
-
const minNameFee = getMinimumNameFee(name);
|
|
70
|
-
(_value = value) !== null && _value !== void 0 ? _value : value = minNameFee;
|
|
71
|
-
|
|
72
|
-
if (minNameFee.gt(value)) {
|
|
73
|
-
throw new InsufficientNameFeeError(new BigNumber(value), minNameFee);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return writeInt(value);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* @param value - AENS name fee Buffer
|
|
80
|
-
* @returns AENS name fee
|
|
81
|
-
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
static deserialize(value) {
|
|
85
|
-
return readInt(value);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
export class Deposit extends Field {
|
|
90
|
-
/**
|
|
91
|
-
* @param value - Deposit value in string format. Should be equal to '0'.
|
|
92
|
-
* @returns Deposit value Buffer.
|
|
93
|
-
*/
|
|
94
|
-
static serialize() {
|
|
95
|
-
let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '0';
|
|
96
|
-
if (parseInt(value) !== 0) throw new IllegalArgumentError(`Contract deposit is not refundable, so it should be equal 0, got ${value.toString()} instead`);
|
|
97
|
-
return writeInt(0);
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* @param value - Deposit value Buffer.
|
|
101
|
-
* @returns Deposit value.
|
|
102
|
-
*/
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
static deserialize(value) {
|
|
106
|
-
return readInt(value);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
export class GasPrice extends Field {
|
|
111
|
-
static serialize() {
|
|
112
|
-
let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : MIN_GAS_PRICE;
|
|
113
|
-
|
|
114
|
-
if (+value < MIN_GAS_PRICE) {
|
|
115
|
-
throw new IllegalArgumentError(`Gas price ${value.toString()} must be bigger then ${MIN_GAS_PRICE}`);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return writeInt(value);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
static deserialize(value) {
|
|
122
|
-
return readInt(value);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
//# sourceMappingURL=field-types.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"field-types.mjs","names":["writeId","readId","produceNameId","getMinimumNameFee","readInt","writeInt","isNameValid","InsufficientNameFeeError","IllegalArgumentError","BigNumber","MIN_GAS_PRICE","Field","serialize","value","_txFields","from","deserialize","toString","Name","NameId","NameFee","name","minNameFee","gt","Deposit","parseInt","GasPrice"],"sources":["../../../src/tx/builder/field-types.ts"],"sourcesContent":["import {\n writeId, readId, produceNameId, getMinimumNameFee, readInt, writeInt, isNameValid\n} from './helpers'\nimport { InsufficientNameFeeError, IllegalArgumentError } from '../../utils/errors'\nimport BigNumber from 'bignumber.js'\nimport { MIN_GAS_PRICE, AensName } from './constants'\nimport { EncodedData } from '../../utils/encoder'\n\ntype Int = number | string | BigNumber\n\n// todo: update me\n// ? This is a TS workaround because this has to be a class with only static methods\nexport class Field {\n public prototype: any\n\n static serialize (value: any, _txFields: object = {}): Buffer {\n return Buffer.from(value)\n }\n\n static deserialize (value: Buffer): any {\n return value.toString()\n }\n}\n\nexport class Name extends Field {\n /**\n * @param value - AENS name\n */\n static serialize (value: AensName): Buffer {\n return Buffer.from(value)\n }\n\n /**\n * @param value - AENS name\n */\n static deserialize (value: Buffer): string {\n return value.toString()\n }\n}\n\nexport class NameId extends Field {\n /**\n * @param value - AENS name ID\n */\n static serialize (value: AensName | EncodedData<'nm'>): Buffer {\n return writeId(isNameValid(value) ? produceNameId(value) : value)\n }\n\n /**\n * @param value - AENS name ID Buffer\n */\n static deserialize (value: Buffer): string {\n return readId(value)\n }\n}\n\nexport class NameFee extends Field {\n /**\n * @param value - AENS name fee Buffer\n * @param txFields - Transaction fields\n * @param txFields.name - AENS Name in transaction\n */\n static serialize (value: Int | undefined, { name }: { name: AensName }): Buffer {\n const minNameFee = getMinimumNameFee(name)\n value ??= minNameFee\n if (minNameFee.gt(value)) {\n throw new InsufficientNameFeeError(new BigNumber(value), minNameFee)\n }\n return writeInt(value)\n }\n\n /**\n * @param value - AENS name fee Buffer\n * @returns AENS name fee\n */\n static deserialize (value: Buffer): string {\n return readInt(value)\n }\n}\n\nexport class Deposit extends Field {\n /**\n * @param value - Deposit value in string format. Should be equal to '0'.\n * @returns Deposit value Buffer.\n */\n static serialize (value: string = '0'): Buffer {\n if (parseInt(value) !== 0) throw new IllegalArgumentError(`Contract deposit is not refundable, so it should be equal 0, got ${value.toString()} instead`)\n return writeInt(0)\n }\n\n /**\n * @param value - Deposit value Buffer.\n * @returns Deposit value.\n */\n static deserialize (value: Buffer): string {\n return readInt(value)\n }\n}\n\nexport class GasPrice extends Field {\n static serialize (value: Int = MIN_GAS_PRICE): Buffer {\n if (+value < MIN_GAS_PRICE) {\n throw new IllegalArgumentError(`Gas price ${value.toString()} must be bigger then ${MIN_GAS_PRICE}`)\n }\n return writeInt(value)\n }\n\n static deserialize (value: Buffer): string {\n return readInt(value)\n }\n}\n"],"mappings":";;;;SACEA,O,EAASC,M,EAAQC,a,EAAeC,iB,EAAmBC,O,EAASC,Q,EAAUC,W;SAE/DC,wB,EAA0BC,oB;AACnC,OAAOC,SAAP,MAAsB,cAAtB;SACSC,a;AAKT;AACA;AACA,OAAO,MAAMC,KAAN,CAAY;EAGD,OAATC,SAAS,CAAEC,KAAF,EAA8C;IAAA,IAAhCC,SAAgC,uEAAZ,EAAY;;IAC5D,OAAO,QAAOC,IAAP,CAAYF,KAAZ,CAAP;EACD;;EAEiB,OAAXG,WAAW,CAAEH,KAAF,EAAsB;IACtC,OAAOA,KAAK,CAACI,QAAN,EAAP;EACD;;AATgB;AAYnB,OAAO,MAAMC,IAAN,SAAmBP,KAAnB,CAAyB;EAC9B;AACF;AACA;EACkB,OAATC,SAAS,CAAEC,KAAF,EAA2B;IACzC,OAAO,QAAOE,IAAP,CAAYF,KAAZ,CAAP;EACD;EAED;AACF;AACA;;;EACoB,OAAXG,WAAW,CAAEH,KAAF,EAAyB;IACzC,OAAOA,KAAK,CAACI,QAAN,EAAP;EACD;;AAb6B;AAgBhC,OAAO,MAAME,MAAN,SAAqBR,KAArB,CAA2B;EAChC;AACF;AACA;EACkB,OAATC,SAAS,CAAEC,KAAF,EAA+C;IAC7D,OAAOb,OAAO,CAACM,WAAW,CAACO,KAAD,CAAX,GAAqBX,aAAa,CAACW,KAAD,CAAlC,GAA4CA,KAA7C,CAAd;EACD;EAED;AACF;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CAACG,KAAD,GAASH,aAAb,EAA4B;MAC1B,MAAM,IAAIF,oBAAJ,CAA0B,aAAYK,KAAK,CAACI,QAAN,EAAiB,wBAAuBP,aAAc,EAA5F,CAAN;IACD;;IACD,OAAOL,QAAQ,CAACQ,KAAD,CAAf;EACD;;EAEiB,OAAXG,WAAW,CAAEH,KAAF,EAAyB;IACzC,OAAOT,OAAO,CAACS,KAAD,CAAd;EACD;;AAViC"}
|
package/es/tx/min-fee.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import BigNumber from 'bignumber.js';
|
|
2
|
-
import { TX_TYPE, TxParamsCommon } from './builder/schema';
|
|
3
|
-
import { AE_AMOUNT_FORMATS } from '../utils/amount-formatter';
|
|
4
|
-
/**
|
|
5
|
-
* Calculate min fee
|
|
6
|
-
* @param txType - Transaction type
|
|
7
|
-
* @param options - Options object
|
|
8
|
-
* @param options.params - Tx params
|
|
9
|
-
* @example
|
|
10
|
-
* ```js
|
|
11
|
-
* calculateMinFee('spendTx', { gasLimit, params })
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
export default function calculateMinFee(txType: TX_TYPE, { params, vsn, denomination }: CalculateMinFeeOptions): BigNumber;
|
|
15
|
-
interface CalculateMinFeeOptions {
|
|
16
|
-
params: TxParamsCommon;
|
|
17
|
-
vsn?: number;
|
|
18
|
-
denomination?: AE_AMOUNT_FORMATS;
|
|
19
|
-
}
|
|
20
|
-
export {};
|
package/es/tx/min-fee.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"min-fee.mjs","names":["BigNumber","MIN_GAS_PRICE","TX_TYPE","buildTx","isKeyOfObject","BASE_GAS","GAS_PER_BYTE","KEY_BLOCK_INTERVAL","TX_FEE_BASE_GAS","txType","feeFactors","channelForceProgress","channelOffChain","channelOffChainCallContract","channelOffChainCreateContract","channelOffChainUpdateDeposit","channelOffChainUpdateWithdrawal","channelOffChainUpdateTransfer","contractCreate","contractCall","gaAttach","gaMeta","payingFor","factor","TX_FEE_OTHER_GAS","txSize","relativeTtl","innerTxSize","oracleRegister","oracleExtend","oracleQuery","oracleResponse","times","plus","Math","ceil","floor","minus","getOracleRelativeTtl","params","ttlKeys","buildFee","vsn","denomination","rlpEncoded","length","tx","encodedTx","calculateMinFee","fee","previousFee","eq"],"sources":["../../src/tx/min-fee.ts"],"sourcesContent":["import BigNumber from 'bignumber.js'\nimport { MIN_GAS_PRICE, TX_TYPE, TxParamsCommon } from './builder/schema'\nimport { AE_AMOUNT_FORMATS } from '../utils/amount-formatter'\nimport { buildTx } from './builder'\nimport { isKeyOfObject } from '../utils/other'\n\nconst BASE_GAS = 15000\nconst GAS_PER_BYTE = 20\nconst KEY_BLOCK_INTERVAL = 3\n\n/**\n * Calculate the Base fee gas\n * @see {@link https://github.com/aeternity/protocol/blob/master/consensus/README.md#gas}\n * @param txType - The transaction type\n * @returns The base fee\n * @example\n * ```js\n * TX_FEE_BASE('channelForceProgress') => new BigNumber(30 * 15000)\n * ```\n */\nconst TX_FEE_BASE_GAS = (txType: TX_TYPE): BigNumber => {\n const feeFactors = {\n [TX_TYPE.channelForceProgress]: 30,\n [TX_TYPE.channelOffChain]: 0,\n [TX_TYPE.channelOffChainCallContract]: 0,\n [TX_TYPE.channelOffChainCreateContract]: 0,\n [TX_TYPE.channelOffChainUpdateDeposit]: 0,\n [TX_TYPE.channelOffChainUpdateWithdrawal]: 0,\n [TX_TYPE.channelOffChainUpdateTransfer]: 0,\n [TX_TYPE.contractCreate]: 5,\n [TX_TYPE.contractCall]: 12,\n [TX_TYPE.gaAttach]: 5,\n [TX_TYPE.gaMeta]: 5,\n [TX_TYPE.payingFor]: 1 / 5\n } as const\n const factor = feeFactors[txType as keyof typeof feeFactors] ?? 1\n return new BigNumber(factor * BASE_GAS)\n}\n\n/**\n * Calculate fee for Other types of transactions\n * @see {@link https://github.com/aeternity/protocol/blob/master/consensus/README.md#gas}\n * @param txType - The transaction type\n * @param txSize - The transaction size\n * @returns parameters - The transaction parameters\n * @returns parameters.relativeTtl - The relative ttl\n * @returns parameters.innerTxSize - The size of the inner transaction\n * @returns The Other fee\n * @example\n * ```js\n * TX_FEE_OTHER_GAS('oracleResponse',10, { relativeTtl: 10, innerTxSize: 10 })\n * => new BigNumber(10).times(20).plus(Math.ceil(32000 * 10 / Math.floor(60 * 24 * 365 / 2)))\n * ```\n */\nconst TX_FEE_OTHER_GAS = (\n txType: TX_TYPE,\n txSize: number,\n { relativeTtl, innerTxSize }: { relativeTtl: number, innerTxSize: number }\n): BigNumber => {\n switch (txType) {\n case TX_TYPE.oracleRegister:\n case TX_TYPE.oracleExtend:\n case TX_TYPE.oracleQuery:\n case TX_TYPE.oracleResponse:\n return new BigNumber(txSize)\n .times(GAS_PER_BYTE)\n .plus(\n Math.ceil(32000 * relativeTtl / Math.floor(60 * 24 * 365 / KEY_BLOCK_INTERVAL))\n )\n case TX_TYPE.gaMeta:\n case TX_TYPE.payingFor:\n return new BigNumber(txSize).minus(innerTxSize).times(GAS_PER_BYTE)\n default:\n return new BigNumber(txSize).times(GAS_PER_BYTE)\n }\n}\n\nfunction getOracleRelativeTtl (params: any, txType: TX_TYPE): number {\n const ttlKeys = {\n [TX_TYPE.oracleRegister]: 'oracleTtlValue',\n [TX_TYPE.oracleExtend]: 'oracleTtlValue',\n [TX_TYPE.oracleQuery]: 'queryTtlValue',\n [TX_TYPE.oracleResponse]: 'responseTtlValue'\n } as const\n\n if (!isKeyOfObject(txType, ttlKeys)) return 1\n else return params[ttlKeys[txType]]\n}\n\n/**\n * Calculate fee based on tx type and params\n */\nfunction buildFee (\n txType: TX_TYPE,\n { params, vsn, denomination }:\n { params: TxParamsCommon, vsn?: number, denomination?: AE_AMOUNT_FORMATS }\n): BigNumber {\n const { rlpEncoded: { length } } = buildTx(params, txType, { vsn, denomination })\n\n return TX_FEE_BASE_GAS(txType)\n .plus(TX_FEE_OTHER_GAS(txType, length, {\n relativeTtl: getOracleRelativeTtl(params, txType),\n innerTxSize: [TX_TYPE.gaMeta, TX_TYPE.payingFor].includes(txType)\n ? params.tx.tx.encodedTx.rlpEncoded.length\n : 0\n }))\n .times(MIN_GAS_PRICE)\n}\n\n/**\n * Calculate min fee\n * @param txType - Transaction type\n * @param options - Options object\n * @param options.params - Tx params\n * @example\n * ```js\n * calculateMinFee('spendTx', { gasLimit, params })\n * ```\n */\nexport default function calculateMinFee (\n txType: TX_TYPE, { params, vsn, denomination }: CalculateMinFeeOptions\n): BigNumber {\n let fee = new BigNumber(0)\n let previousFee\n do {\n previousFee = fee\n fee = buildFee(txType, { params: { ...params, fee }, vsn, denomination })\n } while (!fee.eq(previousFee))\n return fee\n}\n\ninterface CalculateMinFeeOptions {\n params: TxParamsCommon\n vsn?: number\n denomination?: AE_AMOUNT_FORMATS\n}\n"],"mappings":";AAAA,OAAOA,SAAP,MAAsB,cAAtB;SACSC,a,EAAeC,O;SAEfC,O;SACAC,a;AAET,MAAMC,QAAQ,GAAG,KAAjB;AACA,MAAMC,YAAY,GAAG,EAArB;AACA,MAAMC,kBAAkB,GAAG,CAA3B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,eAAe,GAAIC,MAAD,IAAgC;EAAA;;EACtD,MAAMC,UAAU,GAAG;IACjB,CAACR,OAAO,CAACS,oBAAT,GAAgC,EADf;IAEjB,CAACT,OAAO,CAACU,eAAT,GAA2B,CAFV;IAGjB,CAACV,OAAO,CAACW,2BAAT,GAAuC,CAHtB;IAIjB,CAACX,OAAO,CAACY,6BAAT,GAAyC,CAJxB;IAKjB,CAACZ,OAAO,CAACa,4BAAT,GAAwC,CALvB;IAMjB,CAACb,OAAO,CAACc,+BAAT,GAA2C,CAN1B;IAOjB,CAACd,OAAO,CAACe,6BAAT,GAAyC,CAPxB;IAQjB,CAACf,OAAO,CAACgB,cAAT,GAA0B,CART;IASjB,CAAChB,OAAO,CAACiB,YAAT,GAAwB,EATP;IAUjB,CAACjB,OAAO,CAACkB,QA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