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();
}
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!");
}
Aggregations