Search in sources :

Example 6 with MerkleNode

use of com.jd.blockchain.ledger.MerkleNode in project jdchain-core by blockchain-jd-com.

the class MerkleSequenceTree method getMaxDataNode.

private DataNode getMaxDataNode() {
    MerkleNode node = root;
    PathNode pathNode;
    int idx = -1;
    while (node.getLevel() > 0) {
        pathNode = (PathNode) node;
        // find the last child, because all children are ascension sorted by sn;
        for (idx = pathNode.childrenHashes.length - 1; idx > -1; idx--) {
            if (pathNode.childrenHashes[idx] != null) {
                break;
            }
        }
        if (idx == -1) {
            // no child;
            return null;
        }
        // if child node have been loaded, then load it;
        if (pathNode.children[idx] == null) {
            if (pathNode.getLevel() > 1) {
                // load path node;
                PathNode child = loadPathNode(pathNode.childrenHashes[idx], setting.getAutoVerifyHash());
                pathNode.attachChildNode(child, idx);
            } else {
                DataNode child = loadDataNode(pathNode.childrenHashes[idx], setting.getAutoVerifyHash());
                pathNode.attachChildNode(child, idx);
            }
        }
        node = pathNode.children[idx];
    }
    return (DataNode) node;
}
Also used : MerkleDataNode(com.jd.blockchain.ledger.MerkleDataNode) MerkleNode(com.jd.blockchain.ledger.MerkleNode)

Aggregations

MerkleNode (com.jd.blockchain.ledger.MerkleNode)6 HashDigest (com.jd.blockchain.crypto.HashDigest)5 CryptoSetting (com.jd.blockchain.ledger.CryptoSetting)4 MerkleSequenceTree (com.jd.blockchain.ledger.proof.MerkleSequenceTree)4 ExistancePolicyKVStorageMap (com.jd.blockchain.storage.service.utils.ExistancePolicyKVStorageMap)4 Random (java.util.Random)4 TreeMap (java.util.TreeMap)4 MerkleDataNode (com.jd.blockchain.ledger.MerkleDataNode)3 Test (org.junit.Test)3 MerkleProof (com.jd.blockchain.ledger.MerkleProof)1 LinkedList (java.util.LinkedList)1