Search in sources :

Example 1 with MerkleTree

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

the class MerkleHashTrieTest method buildMerkleRootHash.

private HashDigest buildMerkleRootHash(VersioningKVData<String, byte[]>[] datas) {
    MerkleTree merkleTree = newMerkleTree_with_committed(datas);
    HashDigest rootHash = merkleTree.getRootHash();
    return rootHash;
}
Also used : MerkleTree(com.jd.blockchain.ledger.merkletree.MerkleTree) HashDigest(com.jd.blockchain.crypto.HashDigest)

Example 2 with MerkleTree

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

the class MerkleHashTrieTest method testSpecialUseCase_1.

@Test
public void testSpecialUseCase_1() {
    CryptoSetting cryptoSetting = createCryptoSetting();
    MemoryKVStorage storage = new MemoryKVStorage();
    MerkleHashTrie merkleTree = new MerkleHashTrie(cryptoSetting, KEY_PREFIX, storage);
    byte[] key = Base58Utils.decode("j5sXmpcomtM2QMUNWeQWsF8bNFFnyeXoCjVAekEeLSscgY");
    byte[] value = BytesUtils.toBytes("Special Use-Case VALUE");
    long version = 0;
    merkleTree.setData(key, version, value);
    KVEntry mkdata = merkleTree.getData(key);
    assertNotNull(mkdata);
    merkleTree.commit();
    mkdata = merkleTree.getData(key);
    assertNotNull(mkdata);
    MerkleTree merkleTreeReload = new MerkleHashTrie(merkleTree.getRootHash(), cryptoSetting, KEY_PREFIX, storage, false);
    mkdata = merkleTreeReload.getData(key);
    assertNotNull(mkdata);
}
Also used : MerkleTree(com.jd.blockchain.ledger.merkletree.MerkleTree) CryptoSetting(com.jd.blockchain.ledger.CryptoSetting) KVEntry(com.jd.blockchain.ledger.merkletree.KVEntry) MerkleHashTrie(com.jd.blockchain.ledger.proof.MerkleHashTrie) MemoryKVStorage(com.jd.blockchain.storage.service.utils.MemoryKVStorage) Test(org.junit.Test)

Example 3 with MerkleTree

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

the class MerkleHashSortTreeTest method testSpecialUseCase_1.

@Test
public void testSpecialUseCase_1() {
    TreeOptions treeOptions = createTreeOptions();
    MemoryKVStorage storage = new MemoryKVStorage();
    MerkleHashSortTree merkleTree = new MerkleHashSortTree(treeOptions, KEY_PREFIX, storage);
    byte[] key = Base58Utils.decode("j5sXmpcomtM2QMUNWeQWsF8bNFFnyeXoCjVAekEeLSscgY");
    byte[] value = BytesUtils.toBytes("Special Use-Case VALUE");
    long version = 0;
    merkleTree.setData(key, version, value);
    KVEntry mkdata = merkleTree.getData(key);
    assertNotNull(mkdata);
    merkleTree.commit();
    mkdata = merkleTree.getData(key);
    assertNotNull(mkdata);
    MerkleTree merkleTreeReload = new MerkleHashSortTree(merkleTree.getRootHash(), treeOptions, KEY_PREFIX, storage);
    mkdata = merkleTreeReload.getData(key);
    assertNotNull(mkdata);
}
Also used : MerkleTree(com.jd.blockchain.ledger.merkletree.MerkleTree) KVEntry(com.jd.blockchain.ledger.merkletree.KVEntry) TreeOptions(com.jd.blockchain.ledger.merkletree.TreeOptions) MemoryKVStorage(com.jd.blockchain.storage.service.utils.MemoryKVStorage) MerkleHashSortTree(com.jd.blockchain.ledger.merkletree.MerkleHashSortTree) Test(org.junit.Test)

Example 4 with MerkleTree

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

the class MerkleHashSortTreeTest method buildMerkleRootHash.

private HashDigest buildMerkleRootHash(VersioningKVData<String, byte[]>[] datas) {
    MerkleTree merkleTree = newMerkleTree_with_committed(datas);
    HashDigest rootHash = merkleTree.getRootHash();
    return rootHash;
}
Also used : MerkleTree(com.jd.blockchain.ledger.merkletree.MerkleTree) HashDigest(com.jd.blockchain.crypto.HashDigest)

Aggregations

MerkleTree (com.jd.blockchain.ledger.merkletree.MerkleTree)4 HashDigest (com.jd.blockchain.crypto.HashDigest)2 KVEntry (com.jd.blockchain.ledger.merkletree.KVEntry)2 MemoryKVStorage (com.jd.blockchain.storage.service.utils.MemoryKVStorage)2 Test (org.junit.Test)2 CryptoSetting (com.jd.blockchain.ledger.CryptoSetting)1 MerkleHashSortTree (com.jd.blockchain.ledger.merkletree.MerkleHashSortTree)1 TreeOptions (com.jd.blockchain.ledger.merkletree.TreeOptions)1 MerkleHashTrie (com.jd.blockchain.ledger.proof.MerkleHashTrie)1