use of com.jd.blockchain.ledger.core.MerkleProofException in project jdchain-core by blockchain-jd-com.
the class MerkleSortTree method loadBytes.
/**
* 加载指定节点的内容,如果不存在,则抛出异常;
*
* @param nodeHash
* @return
*/
@SuppressWarnings("unused")
private byte[] loadBytes(byte[] key) {
Bytes storageKey = encodeStorageKey(key);
byte[] nodeBytes = KV_STORAGE.get(storageKey);
if (nodeBytes == null) {
throw new MerkleProofException("Merkle node does not exist! -- key=" + storageKey.toBase58());
}
return nodeBytes;
}
use of com.jd.blockchain.ledger.core.MerkleProofException in project jdchain-core by blockchain-jd-com.
the class MerkleSortTreeTest method testAddDuplicatedData.
@Test
public void testAddDuplicatedData() {
Random random = new Random();
byte[] data = new byte[32];
random.nextBytes(data);
MemoryKVStorage storage = new MemoryKVStorage();
// 配置选项设置为”不报告重复数据项“;
// 以不同的 id 重复设置两个相同的数据,预期不会报告异常;
MerkleProofException ex = null;
try {
TreeOptions options = TreeOptions.build().setDefaultHashAlgorithm(HASH_ALGORITHM.code()).setReportKeyStorageConfliction(false);
MerkleSortTree<byte[]> mst = MerkleSortTree.createBytesTree(options, DEFAULT_MKL_KEY_PREFIX, storage);
mst.set(1, data);
mst.set(2, data);
mst.commit();
} catch (MerkleProofException e) {
ex = e;
}
assertNull(ex);
// 配置选项设置为”报告重复数据项“;
// 以不同的 id 重复设置两个相同的数据,预期将报告异常;
ex = null;
try {
TreeOptions options = TreeOptions.build().setDefaultHashAlgorithm(HASH_ALGORITHM.code()).setReportKeyStorageConfliction(true);
MerkleSortTree<byte[]> mst = MerkleSortTree.createBytesTree(options, DEFAULT_MKL_KEY_PREFIX, storage);
mst.set(1, data);
mst.set(2, data);
mst.commit();
} catch (MerkleProofException e) {
ex = e;
}
assertNotNull(ex);
}
Aggregations