1 | ;
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.isEmptyNode = isEmptyNode;
|
7 | exports.isKvNode = isKvNode;
|
8 | exports.isExtensionNode = isExtensionNode;
|
9 | exports.isLeafNode = isLeafNode;
|
10 | exports.isBranchNode = isBranchNode;
|
11 |
|
12 | var _types = require("../types");
|
13 |
|
14 | var _util = require("@polkadot/util");
|
15 |
|
16 | var _node = require("./node");
|
17 |
|
18 | // Copyright 2017-2019 @polkadot/trie-db authors & contributors
|
19 | // This software may be modified and distributed under the terms
|
20 | // of the Apache-2.0 license. See the LICENSE file for details.
|
21 |
|
22 | /**
|
23 | * @name isEmptyNode
|
24 | * @summary Returns true if node is NULL
|
25 | * @description Refer to [Merkle Patricia Trie specification](https://github.com/ethereum/wiki/wiki/Patricia-Tree#optimization)
|
26 | */
|
27 | function isEmptyNode(node) {
|
28 | return (0, _util.isNull)(node);
|
29 | }
|
30 | /**
|
31 | * @name isKvNode
|
32 | * @summary Returns true if node is not empty and contains a single key/value pair
|
33 | * @description Refer to [Merkle Patricia Trie specification](https://github.com/ethereum/wiki/wiki/Patricia-Tree#optimization)
|
34 | */
|
35 |
|
36 |
|
37 | function isKvNode(node) {
|
38 | return !isEmptyNode(node) && node.length === 2;
|
39 | }
|
40 | /**
|
41 | * @name isExtensionNode
|
42 | * @summary Returns true if node is an Extension 2-item node
|
43 | * @description Refer to [Merkle Patricia Trie specification](https://github.com/ethereum/wiki/wiki/Patricia-Tree#optimization)
|
44 | */
|
45 |
|
46 |
|
47 | function isExtensionNode(node) {
|
48 | return (0, _node.getNodeType)(node) === _types.NodeType.EXTENSION;
|
49 | }
|
50 | /**
|
51 | * @name isLeafNode
|
52 | * @summary Returns true if node is an Leaf 2-item node
|
53 | * @description Refer to [Merkle Patricia Trie specification](https://github.com/ethereum/wiki/wiki/Patricia-Tree#optimization)
|
54 | */
|
55 |
|
56 |
|
57 | function isLeafNode(node) {
|
58 | return (0, _node.getNodeType)(node) === _types.NodeType.LEAF;
|
59 | }
|
60 | /**
|
61 | * @name isBranchNode
|
62 | * @summary Returns true if node is an Branch 17-item node
|
63 | * @description Refer to [Merkle Patricia Trie specification](https://github.com/ethereum/wiki/wiki/Patricia-Tree#optimization)
|
64 | */
|
65 |
|
66 |
|
67 | function isBranchNode(node) {
|
68 | return !isEmptyNode(node) && node.length === 17;
|
69 | } |
\ | No newline at end of file |