diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleDataCluster.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleDataCluster.java new file mode 100644 index 00000000..d8adbcc2 --- /dev/null +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleDataCluster.java @@ -0,0 +1,76 @@ +package com.jd.blockchain.ledger.core; + +import java.util.Map; + +import com.jd.blockchain.crypto.HashDigest; +import com.jd.blockchain.ledger.CryptoSetting; +import com.jd.blockchain.ledger.MerkleProof; +import com.jd.blockchain.ledger.MerkleSnapshot; +import com.jd.blockchain.storage.service.ExPolicyKVStorage; +import com.jd.blockchain.storage.service.VersioningKVStorage; +import com.jd.blockchain.utils.Bytes; +import com.jd.blockchain.utils.Transactional; +import com.jd.blockchain.utils.VersioningMap; + +public class MerkleDataCluster implements Transactional, MerkleSnapshot { + + private boolean readonly; + + private MerkleDataSet rootDS; + + private Map partitions; + + /** + * Create an empty readable {@link MerkleDataCluster} instance; + */ + public MerkleDataCluster(CryptoSetting setting, Bytes keyPrefix, ExPolicyKVStorage exPolicyStorage, + VersioningKVStorage versioningStorage) { + this(null, setting, keyPrefix, exPolicyStorage, versioningStorage, false); + } + + /** + * Create an {@link MerkleDataCluster} instance; + * + * @param rootHash root hash of this {@link MerkleDataCluster} instance; + * @param readonly whether read only; + */ + public MerkleDataCluster(HashDigest rootHash, CryptoSetting setting, Bytes keyPrefix, + ExPolicyKVStorage exPolicyStorage, VersioningKVStorage versioningStorage, boolean readonly) { + this.rootDS = new MerkleDataSet(rootHash, setting, keyPrefix, exPolicyStorage, versioningStorage, readonly); + } + + @Override + public HashDigest getRootHash() { + return rootDS.getRootHash(); + } + + @Override + public boolean isUpdated() { + return rootDS.isUpdated(); + } + + public VersioningMap getPartition(Bytes name) { + return getPartition(name, false); + } + + public VersioningMap getPartition(Bytes name, boolean create) { + + } + + public VersioningMap createPartition(Bytes name) { + + } + + @Override + public void commit() { + // TODO Auto-generated method stub + + } + + @Override + public void cancel() { + // TODO Auto-generated method stub + + } + +} diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleDataSet.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleDataSet.java index 0ea23990..896a8f37 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleDataSet.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleDataSet.java @@ -31,11 +31,9 @@ public class MerkleDataSet implements Transactional, MerkleProvable, VersioningM */ public static final int MAX_SIZE_OF_VALUE = 4 * 1024 * 1024; - public static final String ORIG_KEY_SEPERATOR = LedgerConsts.KEY_SEPERATOR; - - public static final Bytes SN_PREFIX = Bytes.fromString("SN" + ORIG_KEY_SEPERATOR); - public static final Bytes DATA_PREFIX = Bytes.fromString("KV" + ORIG_KEY_SEPERATOR); - public static final Bytes MERKLE_TREE_PREFIX = Bytes.fromString("MKL" + ORIG_KEY_SEPERATOR); + public static final Bytes SN_PREFIX = Bytes.fromString("SN" + LedgerConsts.KEY_SEPERATOR); + public static final Bytes DATA_PREFIX = Bytes.fromString("KV" + LedgerConsts.KEY_SEPERATOR); + public static final Bytes MERKLE_TREE_PREFIX = Bytes.fromString("MKL" + LedgerConsts.KEY_SEPERATOR); private final Bytes snKeyPrefix; private final Bytes dataKeyPrefix;