Search in sources :

Example 6 with MerkleDataNode

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

the class MerkleSequenceDataset method getMerkleVersion.

/**
 * 返回默克尔树中记录的指定键的版本,在由默克尔树表示的数据集的快照中,这是指定键的最新版本,<br>
 * 但该版本有可能小于实际存储的最新版本(由于后续追加的新修改被之后生成的快照维护);
 *
 * @param key
 * @return 返回指定的键的版本;如果不存在,则返回 -1;
 */
private long getMerkleVersion(Bytes key) {
    long sn = getSN(key);
    if (sn < 0) {
        return -1;
    }
    MerkleDataNode mdn = merkleTree.getData(sn);
    if (mdn == null) {
        return -1;
    }
    return mdn.getVersion();
}
Also used : MerkleDataNode(com.jd.blockchain.ledger.MerkleDataNode)

Example 7 with MerkleDataNode

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

the class MerkleSequenceTree method getProof.

/**
 * 返回数据的默克尔证明;
 *
 * <p>
 * 如果不存在,则返回 null;
 * <p>
 * 如果 sn 超出范围,则引发 {@link IndexOutOfBoundsException} ;
 *
 * @param sn 数据的序列号;
 * @return 默克尔证明的实例;
 */
public MerkleProof getProof(long sn) {
    MerkleNode[] nodePath = new MerkleNode[root.level + 1];
    MerkleDataNode dataNode = seekPath(sn, nodePath);
    if (dataNode == null) {
        return null;
    }
    for (int i = 0; i < nodePath.length; i++) {
        if (i < nodePath.length - 1) {
            // PathNode will be changed on updating data;
            // So record the path info with the immutable ProofNodeEntry instead;
            PathNode n = (PathNode) nodePath[i];
            ProofNodeEntry p = new ProofNodeEntry();
            p.nodeHash = n.getNodeHash();
            p.level = n.getLevel();
            p.dataCount = n.getDataCount();
            p.startingSN = n.getStartingSN();
            nodePath[i] = p;
        }
    }
    HashDigest[] hashPaths = ArrayUtils.cast(nodePath, HashDigest.class, p -> p.getNodeHash());
    MerkleProofBuilder.create(hashPaths[0]);
    throw new IllegalStateException("Not implemented!");
}
Also used : HashDigest(com.jd.blockchain.crypto.HashDigest) MerkleDataNode(com.jd.blockchain.ledger.MerkleDataNode) MerkleNode(com.jd.blockchain.ledger.MerkleNode)

Aggregations

MerkleDataNode (com.jd.blockchain.ledger.MerkleDataNode)7 Bytes (utils.Bytes)4 HashDigest (com.jd.blockchain.crypto.HashDigest)2 MerkleNode (com.jd.blockchain.ledger.MerkleNode)2 CryptoSetting (com.jd.blockchain.ledger.CryptoSetting)1 MerkleProof (com.jd.blockchain.ledger.MerkleProof)1 MerkleSequenceTree (com.jd.blockchain.ledger.proof.MerkleSequenceTree)1 ExistancePolicyKVStorageMap (com.jd.blockchain.storage.service.utils.ExistancePolicyKVStorageMap)1 VersioningKVData (com.jd.blockchain.storage.service.utils.VersioningKVData)1 Random (java.util.Random)1 TreeMap (java.util.TreeMap)1 DataEntry (utils.DataEntry)1