UNPKG

2.08 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.isEmptyNode = isEmptyNode;
7exports.isKvNode = isKvNode;
8exports.isExtensionNode = isExtensionNode;
9exports.isLeafNode = isLeafNode;
10exports.isBranchNode = isBranchNode;
11
12var _types = require("../types");
13
14var _util = require("@polkadot/util");
15
16var _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 */
27function 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
37function 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
47function 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
57function 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
67function isBranchNode(node) {
68 return !isEmptyNode(node) && node.length === 17;
69}
\No newline at end of file