@@ -23,7 +23,7 @@ import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.gateway.PeerService; | |||
import com.jd.blockchain.gateway.service.DataRetrievalService; | |||
import com.jd.blockchain.ledger.AccountHeader; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.ledger.ContractInfo; | |||
import com.jd.blockchain.ledger.KVDataEntry; | |||
import com.jd.blockchain.ledger.KVInfoVO; | |||
@@ -252,7 +252,7 @@ public class BlockBrowserController implements BlockchainExtendQueryService { | |||
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/accounts/address/{address}") | |||
@Override | |||
public AccountHeader getDataAccount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
public BlockchainIdentity getDataAccount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@PathVariable(name = "address") String address) { | |||
return peerService.getQueryService().getDataAccount(ledgerHash, address); | |||
@@ -594,7 +594,7 @@ public class BlockBrowserController implements BlockchainExtendQueryService { | |||
*/ | |||
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/users") | |||
@Override | |||
public AccountHeader[] getUsers(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
public BlockchainIdentity[] getUsers(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, | |||
@RequestParam(name = "count", required = false, defaultValue = "-1") int count) { | |||
return peerService.getQueryService().getUsers(ledgerHash, fromIndex, count); | |||
@@ -602,7 +602,7 @@ public class BlockBrowserController implements BlockchainExtendQueryService { | |||
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/accounts") | |||
@Override | |||
public AccountHeader[] getDataAccounts(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
public BlockchainIdentity[] getDataAccounts(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, | |||
@RequestParam(name = "count", required = false, defaultValue = "-1") int count) { | |||
return peerService.getQueryService().getDataAccounts(ledgerHash, fromIndex, count); | |||
@@ -610,7 +610,7 @@ public class BlockBrowserController implements BlockchainExtendQueryService { | |||
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/contracts") | |||
@Override | |||
public AccountHeader[] getContractAccounts(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
public BlockchainIdentity[] getContractAccounts(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, | |||
@RequestParam(name = "count", required = false, defaultValue = "-1") int count) { | |||
return peerService.getQueryService().getContractAccounts(ledgerHash, fromIndex, count); | |||
@@ -2,7 +2,7 @@ package com.jd.blockchain.ledger.core; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.AccountHeader; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.utils.Bytes; | |||
/** | |||
@@ -19,7 +19,7 @@ public interface AccountAccessPolicy { | |||
* @param account | |||
* @return Return true if it satisfies this policy, or false if it doesn't; | |||
*/ | |||
boolean checkDataWriting(AccountHeader account); | |||
boolean checkDataWriting(BlockchainIdentity account); | |||
boolean checkRegistering(Bytes address, PubKey pubKey); | |||
@@ -0,0 +1,44 @@ | |||
package com.jd.blockchain.ledger.core; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.ledger.BytesValue; | |||
import com.jd.blockchain.ledger.HashProof; | |||
import com.jd.blockchain.ledger.MerkleSnapshot; | |||
import com.jd.blockchain.utils.Bytes; | |||
import com.jd.blockchain.utils.VersioningMap; | |||
public class AccountDecorator implements LedgerAccount, HashProvable, MerkleSnapshot{ | |||
private MerkleAccount mklAccount; | |||
public AccountDecorator(MerkleAccount mklAccount) { | |||
this.mklAccount = mklAccount; | |||
} | |||
protected VersioningMap<Bytes, BytesValue> getHeaders() { | |||
return mklAccount.getHeaders(); | |||
} | |||
@Override | |||
public HashDigest getRootHash() { | |||
return mklAccount.getRootHash(); | |||
} | |||
@Override | |||
public HashProof getProof(Bytes key) { | |||
return mklAccount.getProof(key); | |||
} | |||
@Override | |||
public BlockchainIdentity getID() { | |||
return mklAccount.getID(); | |||
} | |||
@Override | |||
public VersioningMap<Bytes, BytesValue> getDataset() { | |||
return mklAccount.getDataset(); | |||
} | |||
} |
@@ -1,8 +0,0 @@ | |||
package com.jd.blockchain.ledger.core; | |||
import com.jd.blockchain.utils.Bytes; | |||
import com.jd.blockchain.utils.VersioningMap; | |||
public interface BytesKeyMap<V> extends VersioningMap<Bytes, V> { | |||
} |
@@ -1,78 +1,69 @@ | |||
package com.jd.blockchain.ledger.core; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.TypedBytesValue; | |||
import com.jd.blockchain.ledger.BytesValue; | |||
import com.jd.blockchain.ledger.ContractInfo; | |||
import com.jd.blockchain.ledger.MerkleProof; | |||
import com.jd.blockchain.ledger.TypedValue; | |||
import com.jd.blockchain.utils.Bytes; | |||
public class ContractAccount implements ContractInfo { | |||
public class ContractAccount extends AccountDecorator implements ContractInfo { | |||
private static final Bytes CONTRACT_INFO_PREFIX = Bytes.fromString("INFO" + LedgerConsts.KEY_SEPERATOR); | |||
private static final Bytes CHAIN_CODE_KEY = Bytes.fromString("CHAIN-CODE"); | |||
private MerkleAccount accBase; | |||
public ContractAccount(MerkleAccount accBase) { | |||
this.accBase = accBase; | |||
public ContractAccount(MerkleAccount mklAccount) { | |||
super(mklAccount); | |||
} | |||
@Override | |||
public Bytes getAddress() { | |||
return accBase.getAddress(); | |||
return getID().getAddress(); | |||
} | |||
@Override | |||
public PubKey getPubKey() { | |||
return accBase.getPubKey(); | |||
} | |||
@Override | |||
public HashDigest getRootHash() { | |||
return accBase.getRootHash(); | |||
return getID().getPubKey(); | |||
} | |||
public MerkleProof getChaincodeProof() { | |||
return accBase.getProof(CHAIN_CODE_KEY); | |||
} | |||
public MerkleProof getPropertyProof(Bytes key) { | |||
return accBase.getProof(encodePropertyKey(key)); | |||
} | |||
// public MerkleProof getChaincodeProof() { | |||
// return getHeaders().getProof(CHAIN_CODE_KEY); | |||
// } | |||
// | |||
// public MerkleProof getPropertyProof(Bytes key) { | |||
// return getHeaders().getProof(encodePropertyKey(key)); | |||
// } | |||
public long setChaincode(byte[] chaincode, long version) { | |||
BytesValue bytesValue = TypedBytesValue.fromBytes(chaincode); | |||
return accBase.setValue(CHAIN_CODE_KEY, bytesValue, version); | |||
BytesValue bytesValue = TypedValue.fromBytes(chaincode); | |||
return getHeaders().setValue(CHAIN_CODE_KEY, bytesValue, version); | |||
} | |||
public byte[] getChainCode() { | |||
return accBase.getValue(CHAIN_CODE_KEY).getValue().toBytes(); | |||
return getHeaders().getValue(CHAIN_CODE_KEY).getValue().toBytes(); | |||
} | |||
public byte[] getChainCode(long version) { | |||
return accBase.getValue(CHAIN_CODE_KEY, version).getValue().toBytes(); | |||
return getHeaders().getValue(CHAIN_CODE_KEY, version).getValue().toBytes(); | |||
} | |||
public long getChaincodeVersion() { | |||
return accBase.getVersion(CHAIN_CODE_KEY); | |||
return getHeaders().getVersion(CHAIN_CODE_KEY); | |||
} | |||
public long setProperty(Bytes key, String value, long version) { | |||
BytesValue bytesValue = TypedBytesValue.fromText(value); | |||
return accBase.setValue(encodePropertyKey(key), bytesValue, version); | |||
BytesValue bytesValue = TypedValue.fromText(value); | |||
return getHeaders().setValue(encodePropertyKey(key), bytesValue, version); | |||
} | |||
public String getProperty(Bytes key) { | |||
BytesValue bytesValue = accBase.getValue(encodePropertyKey(key)); | |||
return TypedBytesValue.toText(bytesValue); | |||
BytesValue bytesValue = getHeaders().getValue(encodePropertyKey(key)); | |||
return TypedValue.wrap(bytesValue).stringValue(); | |||
} | |||
public String getProperty(Bytes key, long version) { | |||
BytesValue bytesValue = accBase.getValue(encodePropertyKey(key), version); | |||
return TypedBytesValue.toText(bytesValue); | |||
BytesValue bytesValue = getHeaders().getValue(encodePropertyKey(key), version); | |||
return TypedValue.wrap(bytesValue).stringValue(); | |||
} | |||
private Bytes encodePropertyKey(Bytes key) { | |||
@@ -2,7 +2,7 @@ package com.jd.blockchain.ledger.core; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.AccountHeader; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.ledger.CryptoSetting; | |||
import com.jd.blockchain.ledger.DigitalSignature; | |||
import com.jd.blockchain.ledger.MerkleProof; | |||
@@ -17,17 +17,18 @@ public class ContractAccountSet implements Transactional, ContractAccountQuery { | |||
public ContractAccountSet(CryptoSetting cryptoSetting, String prefix, ExPolicyKVStorage exStorage, | |||
VersioningKVStorage verStorage, AccountAccessPolicy accessPolicy) { | |||
accountSet = new MerkleAccountSet(cryptoSetting, prefix, exStorage, verStorage, accessPolicy); | |||
accountSet = new MerkleAccountSet(cryptoSetting, Bytes.fromString(prefix), exStorage, verStorage, accessPolicy); | |||
} | |||
public ContractAccountSet(HashDigest dataRootHash, CryptoSetting cryptoSetting, String prefix, | |||
ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly, | |||
AccountAccessPolicy accessPolicy) { | |||
accountSet = new MerkleAccountSet(dataRootHash, cryptoSetting, prefix, exStorage, verStorage, readonly, accessPolicy); | |||
accountSet = new MerkleAccountSet(dataRootHash, cryptoSetting, Bytes.fromString(prefix), exStorage, verStorage, | |||
readonly, accessPolicy); | |||
} | |||
@Override | |||
public AccountHeader[] getHeaders(int fromIndex, int count) { | |||
public BlockchainIdentity[] getHeaders(int fromIndex, int count) { | |||
return accountSet.getHeaders(fromIndex, count); | |||
} | |||
@@ -1,268 +1,242 @@ | |||
package com.jd.blockchain.ledger.core; | |||
import com.jd.blockchain.binaryproto.BinaryProtocol; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.AccountHeader; | |||
import com.jd.blockchain.ledger.TypedBytesValue; | |||
import com.jd.blockchain.ledger.BytesValue; | |||
import com.jd.blockchain.ledger.KVDataEntry; | |||
import com.jd.blockchain.ledger.KVDataObject; | |||
import com.jd.blockchain.ledger.MerkleProof; | |||
import com.jd.blockchain.ledger.TypedValue; | |||
import com.jd.blockchain.utils.Bytes; | |||
public class DataAccount implements AccountHeader, MerkleProvable { | |||
private MerkleAccount baseAccount; | |||
public DataAccount(MerkleAccount accBase) { | |||
this.baseAccount = accBase; | |||
} | |||
@Override | |||
public Bytes getAddress() { | |||
return baseAccount.getAddress(); | |||
} | |||
@Override | |||
public PubKey getPubKey() { | |||
return baseAccount.getPubKey(); | |||
} | |||
@Override | |||
public HashDigest getRootHash() { | |||
return baseAccount.getRootHash(); | |||
} | |||
/** | |||
* 返回指定数据的存在性证明; | |||
*/ | |||
@Override | |||
public MerkleProof getProof(Bytes key) { | |||
return baseAccount.getProof(key); | |||
} | |||
public class DataAccount extends AccountDecorator { | |||
public DataAccount(MerkleAccount mklAccount) { | |||
super(mklAccount); | |||
} | |||
// /** | |||
// * Create or update the value associated the specified key if the version | |||
// * checking is passed.<br> | |||
// * | |||
// * The value of the key will be updated only if it's latest version equals the | |||
// * specified version argument. <br> | |||
// * If the key doesn't exist, the version checking will be ignored, and key will | |||
// * be created with a new sequence number as id. <br> | |||
// * It also could specify the version argument to -1 to ignore the version | |||
// * checking. | |||
// * <p> | |||
// * If updating is performed, the version of the key increase by 1. <br> | |||
// * If creating is performed, the version of the key initialize by 0. <br> | |||
// * | |||
// * @param key The key of data; | |||
// * @param value The value of data; | |||
// * @param version The expected version of the key. | |||
// * @return The new version of the key. <br> | |||
// * If the key is new created success, then return 0; <br> | |||
// * If the key is updated success, then return the new version;<br> | |||
// * If this operation fail by version checking or other reason, then | |||
// * return -1; | |||
// */ | |||
// public long setBytes(Bytes key, BytesValue value, long version) { | |||
// return super.getDataset().setValue(key, value, version); | |||
// } | |||
// | |||
// /** | |||
// * Create or update the value associated the specified key if the version | |||
// * checking is passed.<br> | |||
// * | |||
// * The value of the key will be updated only if it's latest version equals the | |||
// * specified version argument. <br> | |||
// * If the key doesn't exist, the version checking will be ignored, and key will | |||
// * be created with a new sequence number as id. <br> | |||
// * It also could specify the version argument to -1 to ignore the version | |||
// * checking. | |||
// * <p> | |||
// * If updating is performed, the version of the key increase by 1. <br> | |||
// * If creating is performed, the version of the key initialize by 0. <br> | |||
// * | |||
// * @param key The key of data; | |||
// * @param value The value of data; | |||
// * @param version The expected version of the key. | |||
// * @return The new version of the key. <br> | |||
// * If the key is new created success, then return 0; <br> | |||
// * If the key is updated success, then return the new version;<br> | |||
// * If this operation fail by version checking or other reason, then | |||
// * return -1; | |||
// */ | |||
// public long setBytes(Bytes key, String value, long version) { | |||
// BytesValue bytesValue = TypedValue.fromText(value); | |||
// return baseAccount.setValue(key, bytesValue, version); | |||
// } | |||
// | |||
// /** | |||
// * Create or update the value associated the specified key if the version | |||
// * checking is passed.<br> | |||
// * | |||
// * The value of the key will be updated only if it's latest version equals the | |||
// * specified version argument. <br> | |||
// * If the key doesn't exist, the version checking will be ignored, and key will | |||
// * be created with a new sequence number as id. <br> | |||
// * It also could specify the version argument to -1 to ignore the version | |||
// * checking. | |||
// * <p> | |||
// * If updating is performed, the version of the key increase by 1. <br> | |||
// * If creating is performed, the version of the key initialize by 0. <br> | |||
// * | |||
// * @param key The key of data; | |||
// * @param value The value of data; | |||
// * @param version The expected version of the key. | |||
// * @return The new version of the key. <br> | |||
// * If the key is new created success, then return 0; <br> | |||
// * If the key is updated success, then return the new version;<br> | |||
// * If this operation fail by version checking or other reason, then | |||
// * return -1; | |||
// */ | |||
// public long setBytes(Bytes key, byte[] value, long version) { | |||
// BytesValue bytesValue = TypedValue.fromBytes(value); | |||
// return baseAccount.setValue(key, bytesValue, version); | |||
// } | |||
// | |||
// /** | |||
// * Return the latest version entry associated the specified key; If the key | |||
// * doesn't exist, then return -1; | |||
// * | |||
// * @param key | |||
// * @return | |||
// */ | |||
// public long getDataVersion(String key) { | |||
// return baseAccount.getVersion(Bytes.fromString(key)); | |||
// } | |||
// | |||
// /** | |||
// * Return the latest version entry associated the specified key; If the key | |||
// * doesn't exist, then return -1; | |||
// * | |||
// * @param key | |||
// * @return | |||
// */ | |||
// public long getDataVersion(Bytes key) { | |||
// return baseAccount.getVersion(key); | |||
// } | |||
// | |||
// /** | |||
// * return the latest version's value; | |||
// * | |||
// * @param key | |||
// * @return return null if not exist; | |||
// */ | |||
// public BytesValue getBytes(String key) { | |||
// return baseAccount.getValue(Bytes.fromString(key)); | |||
// } | |||
// | |||
// /** | |||
// * return the latest version's value; | |||
// * | |||
// * @param key | |||
// * @return return null if not exist; | |||
// */ | |||
// public BytesValue getBytes(Bytes key) { | |||
// return baseAccount.getValue(key); | |||
// } | |||
// | |||
// /** | |||
// * return the specified version's value; | |||
// * | |||
// * @param key | |||
// * @param version | |||
// * @return return null if not exist; | |||
// */ | |||
// public BytesValue getBytes(String key, long version) { | |||
// return baseAccount.getValue(Bytes.fromString(key), version); | |||
// } | |||
// | |||
// /** | |||
// * return the specified version's value; | |||
// * | |||
// * @param key | |||
// * @param version | |||
// * @return return null if not exist; | |||
// */ | |||
// public BytesValue getBytes(Bytes key, long version) { | |||
// return baseAccount.getValue(key, version); | |||
// } | |||
/** | |||
* Create or update the value associated the specified key if the version | |||
* checking is passed.<br> | |||
* | |||
* The value of the key will be updated only if it's latest version equals the | |||
* specified version argument. <br> | |||
* If the key doesn't exist, the version checking will be ignored, and key will | |||
* be created with a new sequence number as id. <br> | |||
* It also could specify the version argument to -1 to ignore the version | |||
* checking. | |||
* <p> | |||
* If updating is performed, the version of the key increase by 1. <br> | |||
* If creating is performed, the version of the key initialize by 0. <br> | |||
* | |||
* @param key The key of data; | |||
* @param value The value of data; | |||
* @param version The expected version of the key. | |||
* @return The new version of the key. <br> | |||
* If the key is new created success, then return 0; <br> | |||
* If the key is updated success, then return the new version;<br> | |||
* If this operation fail by version checking or other reason, then | |||
* return -1; | |||
*/ | |||
public long setBytes(Bytes key, BytesValue value, long version) { | |||
return baseAccount.setValue(key, value, version); | |||
} | |||
/** | |||
* Create or update the value associated the specified key if the version | |||
* checking is passed.<br> | |||
* | |||
* The value of the key will be updated only if it's latest version equals the | |||
* specified version argument. <br> | |||
* If the key doesn't exist, the version checking will be ignored, and key will | |||
* be created with a new sequence number as id. <br> | |||
* It also could specify the version argument to -1 to ignore the version | |||
* checking. | |||
* <p> | |||
* If updating is performed, the version of the key increase by 1. <br> | |||
* If creating is performed, the version of the key initialize by 0. <br> | |||
* | |||
* @param key The key of data; | |||
* @param value The value of data; | |||
* @param version The expected version of the key. | |||
* @return The new version of the key. <br> | |||
* If the key is new created success, then return 0; <br> | |||
* If the key is updated success, then return the new version;<br> | |||
* If this operation fail by version checking or other reason, then | |||
* return -1; | |||
*/ | |||
public long setBytes(Bytes key, String value, long version) { | |||
BytesValue bytesValue = TypedBytesValue.fromText(value); | |||
return baseAccount.setValue(key, bytesValue, version); | |||
} | |||
/** | |||
* Create or update the value associated the specified key if the version | |||
* checking is passed.<br> | |||
* | |||
* The value of the key will be updated only if it's latest version equals the | |||
* specified version argument. <br> | |||
* If the key doesn't exist, the version checking will be ignored, and key will | |||
* be created with a new sequence number as id. <br> | |||
* It also could specify the version argument to -1 to ignore the version | |||
* checking. | |||
* <p> | |||
* If updating is performed, the version of the key increase by 1. <br> | |||
* If creating is performed, the version of the key initialize by 0. <br> | |||
* | |||
* @param key The key of data; | |||
* @param value The value of data; | |||
* @param version The expected version of the key. | |||
* @return The new version of the key. <br> | |||
* If the key is new created success, then return 0; <br> | |||
* If the key is updated success, then return the new version;<br> | |||
* If this operation fail by version checking or other reason, then | |||
* return -1; | |||
*/ | |||
public long setBytes(Bytes key, byte[] value, long version) { | |||
BytesValue bytesValue = TypedBytesValue.fromBytes(value); | |||
return baseAccount.setValue(key, bytesValue, version); | |||
} | |||
/** | |||
* Return the latest version entry associated the specified key; If the key | |||
* doesn't exist, then return -1; | |||
* | |||
* @param key | |||
* @return | |||
*/ | |||
public long getDataVersion(String key) { | |||
return baseAccount.getVersion(Bytes.fromString(key)); | |||
} | |||
/** | |||
* Return the latest version entry associated the specified key; If the key | |||
* doesn't exist, then return -1; | |||
* | |||
* @param key | |||
* @return | |||
*/ | |||
public long getDataVersion(Bytes key) { | |||
return baseAccount.getVersion(key); | |||
} | |||
/** | |||
* return the latest version's value; | |||
* | |||
* @param key | |||
* @return return null if not exist; | |||
*/ | |||
public BytesValue getBytes(String key) { | |||
return baseAccount.getValue(Bytes.fromString(key)); | |||
} | |||
/** | |||
* return the latest version's value; | |||
* | |||
* @param key | |||
* @return return null if not exist; | |||
*/ | |||
public BytesValue getBytes(Bytes key) { | |||
return baseAccount.getValue(key); | |||
} | |||
/** | |||
* return the specified version's value; | |||
* | |||
* @param key | |||
* @param version | |||
* @return return null if not exist; | |||
*/ | |||
public BytesValue getBytes(String key, long version) { | |||
return baseAccount.getValue(Bytes.fromString(key), version); | |||
} | |||
/** | |||
* return the specified version's value; | |||
* | |||
* @param key | |||
* @param version | |||
* @return return null if not exist; | |||
*/ | |||
public BytesValue getBytes(Bytes key, long version) { | |||
return baseAccount.getValue(key, version); | |||
} | |||
/** | |||
* @param key | |||
* @param version | |||
* @return | |||
*/ | |||
public KVDataEntry getDataEntry(String key, long version) { | |||
return getDataEntry(Bytes.fromString(key), version); | |||
} | |||
/** | |||
* @param key | |||
* @param version | |||
* @return | |||
*/ | |||
public KVDataEntry getDataEntry(Bytes key, long version) { | |||
BytesValue value = baseAccount.getValue(key, version); | |||
if (value == null) { | |||
return new KVDataObject(key.toUTF8String(), -1, null); | |||
}else { | |||
return new KVDataObject(key.toUTF8String(), version, value); | |||
} | |||
} | |||
/** | |||
* return the specified index's KVDataEntry; | |||
* | |||
* @param fromIndex | |||
* @param count | |||
* @return return null if not exist; | |||
*/ | |||
public KVDataEntry[] getDataEntries(int fromIndex, int count) { | |||
if (count == 0 || getDataEntriesTotalCount() == 0) { | |||
return null; | |||
} | |||
if (count == -1 || count > getDataEntriesTotalCount()) { | |||
fromIndex = 0; | |||
count = (int)getDataEntriesTotalCount(); | |||
} | |||
if (fromIndex < 0 || fromIndex > getDataEntriesTotalCount() - 1) { | |||
fromIndex = 0; | |||
} | |||
KVDataEntry[] kvDataEntries = new KVDataEntry[count]; | |||
byte[] value; | |||
String key; | |||
long ver; | |||
for (int i = 0; i < count; i++) { | |||
value = baseAccount.dataset.getValuesAtIndex(fromIndex); | |||
key = baseAccount.dataset.getKeyAtIndex(fromIndex); | |||
ver = baseAccount.dataset.getVersion(key); | |||
BytesValue decodeData = BinaryProtocol.decode(value); | |||
kvDataEntries[i] = new KVDataObject(key, ver, decodeData); | |||
fromIndex++; | |||
} | |||
return kvDataEntries; | |||
} | |||
/** | |||
* return the dataAccount's kv total count; | |||
* | |||
* @param | |||
* @param | |||
* @return return total count; | |||
*/ | |||
public long getDataEntriesTotalCount() { | |||
if(baseAccount == null){ | |||
return 0; | |||
} | |||
return baseAccount.dataset.getDataCount(); | |||
} | |||
// /** | |||
// * @param key | |||
// * @param version | |||
// * @return | |||
// */ | |||
// public KVDataEntry getDataEntry(String key, long version) { | |||
// return getDataEntry(Bytes.fromString(key), version); | |||
// } | |||
// | |||
// /** | |||
// * @param key | |||
// * @param version | |||
// * @return | |||
// */ | |||
// public KVDataEntry getDataEntry(Bytes key, long version) { | |||
// BytesValue value = baseAccount.getValue(key, version); | |||
// if (value == null) { | |||
// return new KVDataObject(key.toUTF8String(), -1, null); | |||
// }else { | |||
// return new KVDataObject(key.toUTF8String(), version, value); | |||
// } | |||
// } | |||
// | |||
// /** | |||
// * return the specified index's KVDataEntry; | |||
// * | |||
// * @param fromIndex | |||
// * @param count | |||
// * @return return null if not exist; | |||
// */ | |||
// | |||
// public KVDataEntry[] getDataEntries(int fromIndex, int count) { | |||
// if (count == 0 || getDataEntriesTotalCount() == 0) { | |||
// return null; | |||
// } | |||
// | |||
// if (count == -1 || count > getDataEntriesTotalCount()) { | |||
// fromIndex = 0; | |||
// count = (int)getDataEntriesTotalCount(); | |||
// } | |||
// | |||
// if (fromIndex < 0 || fromIndex > getDataEntriesTotalCount() - 1) { | |||
// fromIndex = 0; | |||
// } | |||
// | |||
// KVDataEntry[] kvDataEntries = new KVDataEntry[count]; | |||
// byte[] value; | |||
// String key; | |||
// long ver; | |||
// for (int i = 0; i < count; i++) { | |||
// value = baseAccount.dataset.getValuesAtIndex(fromIndex); | |||
// key = baseAccount.dataset.getKeyAtIndex(fromIndex); | |||
// ver = baseAccount.dataset.getVersion(key); | |||
// BytesValue decodeData = BinaryProtocol.decode(value); | |||
// kvDataEntries[i] = new KVDataObject(key, ver, decodeData); | |||
// fromIndex++; | |||
// } | |||
// | |||
// return kvDataEntries; | |||
// } | |||
// | |||
// /** | |||
// * return the dataAccount's kv total count; | |||
// * | |||
// * @param | |||
// * @param | |||
// * @return return total count; | |||
// */ | |||
// public long getDataEntriesTotalCount() { | |||
// if(baseAccount == null){ | |||
// return 0; | |||
// } | |||
// return baseAccount.dataset.getDataCount(); | |||
// } | |||
} |
@@ -2,7 +2,7 @@ package com.jd.blockchain.ledger.core; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.AccountHeader; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.ledger.CryptoSetting; | |||
import com.jd.blockchain.ledger.DigitalSignature; | |||
import com.jd.blockchain.ledger.MerkleProof; | |||
@@ -17,17 +17,18 @@ public class DataAccountSet implements Transactional, DataAccountQuery { | |||
public DataAccountSet(CryptoSetting cryptoSetting, String prefix, ExPolicyKVStorage exStorage, | |||
VersioningKVStorage verStorage, AccountAccessPolicy accessPolicy) { | |||
accountSet = new MerkleAccountSet(cryptoSetting, prefix, exStorage, verStorage, accessPolicy); | |||
accountSet = new MerkleAccountSet(cryptoSetting, Bytes.fromString(prefix), exStorage, verStorage, accessPolicy); | |||
} | |||
public DataAccountSet(HashDigest dataRootHash, CryptoSetting cryptoSetting, String prefix, | |||
ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly, | |||
AccountAccessPolicy accessPolicy) { | |||
accountSet = new MerkleAccountSet(dataRootHash, cryptoSetting, prefix, exStorage, verStorage, readonly, accessPolicy); | |||
accountSet = new MerkleAccountSet(dataRootHash, cryptoSetting, Bytes.fromString(prefix), exStorage, verStorage, | |||
readonly, accessPolicy); | |||
} | |||
@Override | |||
public AccountHeader[] getHeaders(int fromIndex, int count) { | |||
public BlockchainIdentity[] getHeaders(int fromIndex, int count) { | |||
return accountSet.getHeaders(fromIndex, count); | |||
} | |||
@@ -1,13 +1,13 @@ | |||
package com.jd.blockchain.ledger.core; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.ledger.AccountHeader; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.ledger.MerkleProof; | |||
import com.jd.blockchain.utils.Bytes; | |||
public class EmptyAccountSet<T> implements AccountQuery<T> { | |||
private static final AccountHeader[] EMPTY = {}; | |||
private static final BlockchainIdentity[] EMPTY = {}; | |||
@Override | |||
public HashDigest getRootHash() { | |||
@@ -20,7 +20,7 @@ public class EmptyAccountSet<T> implements AccountQuery<T> { | |||
} | |||
@Override | |||
public AccountHeader[] getHeaders(int fromIndex, int count) { | |||
public BlockchainIdentity[] getHeaders(int fromIndex, int count) { | |||
return EMPTY; | |||
} | |||
@@ -1,83 +0,0 @@ | |||
package com.jd.blockchain.ledger.core; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.ledger.AccountHeader; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.ledger.TypedBytesValue; | |||
import com.jd.blockchain.ledger.BytesValue; | |||
import com.jd.blockchain.ledger.MerkleProof; | |||
import com.jd.blockchain.ledger.TypedBytesValue; | |||
import com.jd.blockchain.utils.Bytes; | |||
import com.jd.blockchain.utils.Transactional; | |||
import com.jd.blockchain.utils.VersioningMap; | |||
/** | |||
* Super Type of concrete accounts, e.g. UserAccount, DataAccount, | |||
* ContractAccount etc.; | |||
* | |||
* @author huanghaiquan | |||
* | |||
* @param <H> Type of Account Header; | |||
*/ | |||
public class GenericAccount implements MerkleAccountHeader, MerkleProvable, Transactional { | |||
private MerkleAccount merkleAccount; | |||
/** | |||
* 头部类型; | |||
* | |||
* @param headerType | |||
*/ | |||
public GenericAccount(MerkleAccount merkleAccount) { | |||
this.merkleAccount = merkleAccount; | |||
} | |||
@Override | |||
public HashDigest getRootHash() { | |||
return merkleAccount.getRootHash(); | |||
} | |||
@Override | |||
public MerkleProof getProof(Bytes key) { | |||
key = buildInnerKey(key); | |||
return merkleAccount.getProof(key); | |||
} | |||
@Override | |||
public BlockchainIdentity getID() { | |||
return merkleAccount.getID(); | |||
} | |||
public TypedMap getDataset() { | |||
VersioningMap<Bytes, BytesValue> state = merkleAccount.getDataset(); | |||
return new TypedMap(state); | |||
} | |||
@Override | |||
public boolean isUpdated() { | |||
return merkleAccount.isUpdated(); | |||
} | |||
boolean isReadonly() { | |||
return merkleAccount.isReadonly(); | |||
} | |||
@Override | |||
public void commit() { | |||
merkleAccount.commit(); | |||
} | |||
@Override | |||
public void cancel() { | |||
merkleAccount.cancel(); | |||
} | |||
private Bytes buildInnerKey(Bytes key) { | |||
// TODO Auto-generated method stub | |||
return null; | |||
} | |||
} |
@@ -6,6 +6,7 @@ import java.util.List; | |||
import com.jd.blockchain.contract.ContractException; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.ledger.AccountHeader; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.ledger.BytesValue; | |||
import com.jd.blockchain.ledger.ContractInfo; | |||
import com.jd.blockchain.ledger.KVDataEntry; | |||
@@ -270,11 +271,11 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
} | |||
@Override | |||
public AccountHeader getDataAccount(HashDigest ledgerHash, String address) { | |||
public BlockchainIdentity getDataAccount(HashDigest ledgerHash, String address) { | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); | |||
return dataAccountSet.getAccount(Bytes.fromBase58(address)); | |||
return dataAccountSet.getAccount(Bytes.fromBase58(address)).getID(); | |||
} | |||
@Override | |||
@@ -292,12 +293,12 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
for (int i = 0; i < entries.length; i++) { | |||
final String currKey = keys[i]; | |||
ver = dataAccount == null ? -1 : dataAccount.getDataVersion(Bytes.fromString(currKey)); | |||
ver = dataAccount == null ? -1 : dataAccount.getDataset().getVersion(Bytes.fromString(currKey)); | |||
if (ver < 0) { | |||
entries[i] = new KVDataObject(currKey, -1, null); | |||
} else { | |||
BytesValue value = dataAccount.getBytes(Bytes.fromString(currKey), ver); | |||
BytesValue value = dataAccount.getDataset().getValue(Bytes.fromString(currKey), ver); | |||
entries[i] = new KVDataObject(currKey, ver, value); | |||
} | |||
} | |||
@@ -344,7 +345,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
if (ver < 0) { | |||
entries[i] = new KVDataObject(keys[i], -1, null); | |||
} else { | |||
if (dataAccount.getDataEntriesTotalCount() == 0 | |||
if (dataAccount.getDataset().getDataEntriesTotalCount() == 0 | |||
|| dataAccount.getBytes(Bytes.fromString(keys[i]), ver) == null) { | |||
// is the address is not exist; the result is null; | |||
entries[i] = new KVDataObject(keys[i], -1, null); | |||
@@ -388,7 +389,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
} | |||
@Override | |||
public AccountHeader[] getUsers(HashDigest ledgerHash, int fromIndex, int count) { | |||
public BlockchainIdentity[] getUsers(HashDigest ledgerHash, int fromIndex, int count) { | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); | |||
@@ -397,7 +398,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
} | |||
@Override | |||
public AccountHeader[] getDataAccounts(HashDigest ledgerHash, int fromIndex, int count) { | |||
public BlockchainIdentity[] getDataAccounts(HashDigest ledgerHash, int fromIndex, int count) { | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); | |||
@@ -406,7 +407,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
} | |||
@Override | |||
public AccountHeader[] getContractAccounts(HashDigest ledgerHash, int fromIndex, int count) { | |||
public BlockchainIdentity[] getContractAccounts(HashDigest ledgerHash, int fromIndex, int count) { | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); | |||
@@ -10,7 +10,7 @@ import com.jd.blockchain.ledger.HashProof; | |||
import com.jd.blockchain.ledger.LedgerException; | |||
import com.jd.blockchain.ledger.MerkleProof; | |||
import com.jd.blockchain.ledger.MerkleSnapshot; | |||
import com.jd.blockchain.ledger.TypedBytesValue; | |||
import com.jd.blockchain.ledger.TypedValue; | |||
import com.jd.blockchain.storage.service.ExPolicyKVStorage; | |||
import com.jd.blockchain.storage.service.VersioningKVStorage; | |||
import com.jd.blockchain.utils.Bytes; | |||
@@ -42,7 +42,7 @@ public class MerkleAccount implements LedgerAccount, HashProvable, MerkleSnapsho | |||
private MerkleDatasetAdapter headerDS; | |||
private MerkleDatasetAdapter dataDS; | |||
protected long version; | |||
/** | |||
@@ -55,18 +55,17 @@ public class MerkleAccount implements LedgerAccount, HashProvable, MerkleSnapsho | |||
* account's merkle dataset, but is stored by the outer invoker; | |||
* | |||
* @param accountID 身份; | |||
* @param version 版本; | |||
* @param cryptoSetting 密码参数; | |||
* @param keyPrefix 数据前缀; | |||
* @param exStorage | |||
* @param verStorage | |||
*/ | |||
public MerkleAccount(BlockchainIdentity accountID, long version, CryptoSetting cryptoSetting, Bytes keyPrefix, | |||
public MerkleAccount(BlockchainIdentity accountID, CryptoSetting cryptoSetting, Bytes keyPrefix, | |||
ExPolicyKVStorage exStorage, VersioningKVStorage verStorage) { | |||
this(accountID.getAddress(), accountID.getPubKey(), version, null, cryptoSetting, keyPrefix, exStorage, | |||
verStorage, false); | |||
this(accountID.getAddress(), accountID.getPubKey(), -1, null, cryptoSetting, keyPrefix, exStorage, verStorage, | |||
false); | |||
savePubKey(accountID.getPubKey()); | |||
initPubKey(accountID.getPubKey()); | |||
} | |||
/** | |||
@@ -89,14 +88,30 @@ public class MerkleAccount implements LedgerAccount, HashProvable, MerkleSnapsho | |||
this(address, null, version, dataRootHash, cryptoSetting, keyPrefix, exStorage, verStorage, readonly); | |||
} | |||
private MerkleAccount(Bytes address, PubKey pubKey, long version, HashDigest dataRootHash, | |||
CryptoSetting cryptoSetting, Bytes keyPrefix, ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, | |||
boolean readonly) { | |||
this.accountID = new BlockchainIdentityProxy(address, pubKey); | |||
/** | |||
* 内部构造器; | |||
* | |||
* @param address 账户地址; | |||
* @param pubKey 账户公钥; 如果为空,则会进行加载验证; | |||
* @param version 账户版本; | |||
* @param rootHash 账户根哈希; | |||
* @param cryptoSetting 密码参数设置; | |||
* @param keyPrefix 当前账户的 Key 前缀; | |||
* @param exStorage 单键存储服务; | |||
* @param verStorage 多版本存储服务; | |||
* @param readonly 是否只读; | |||
*/ | |||
private MerkleAccount(Bytes address, PubKey pubKey, long version, HashDigest rootHash, CryptoSetting cryptoSetting, | |||
Bytes keyPrefix, ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly) { | |||
// 初始化账户的身份; | |||
this.accountID = new AutoloadingID(address, pubKey); | |||
this.version = version; | |||
this.rootDS = new MerkleDataSet(dataRootHash, cryptoSetting, keyPrefix, exStorage, verStorage, readonly); | |||
// 初始化数据; | |||
// 加载“根数据集” | |||
this.rootDS = new MerkleDataSet(rootHash, cryptoSetting, keyPrefix, exStorage, verStorage, readonly); | |||
// 初始化数据修改监听器; | |||
DataChangedListener dataChangedListener = new DataChangedListener() { | |||
@Override | |||
public void onChanged(Bytes key, BytesValue value, long newVersion) { | |||
@@ -104,17 +119,20 @@ public class MerkleAccount implements LedgerAccount, HashProvable, MerkleSnapsho | |||
} | |||
}; | |||
// 加载“头数据集”; | |||
HashDigest headerRoot = loadHeaderRoot(); | |||
Bytes headerPrefix = keyPrefix.concat(HEADER_PREFIX); | |||
MerkleDataSet headerDataset = new MerkleDataSet(headerRoot, cryptoSetting, headerPrefix, exStorage, verStorage, | |||
readonly); | |||
this.headerDS = new MerkleDatasetAdapter(headerDataset, dataChangedListener); | |||
// 加载“主数据集” | |||
HashDigest dataRoot = loadDataRoot(); | |||
Bytes dataPrefix = keyPrefix.concat(DATA_PREFIX); | |||
MerkleDataSet dataDataset = new MerkleDataSet(dataRoot, cryptoSetting, dataPrefix, exStorage, verStorage, | |||
readonly); | |||
this.dataDS = new MerkleDatasetAdapter(dataDataset, dataChangedListener); | |||
} | |||
private HashDigest loadHeaderRoot() { | |||
@@ -133,6 +151,14 @@ public class MerkleAccount implements LedgerAccount, HashProvable, MerkleSnapsho | |||
return new HashDigest(hashBytes); | |||
} | |||
private long getHeaderRootVersion() { | |||
return rootDS.getVersion(KEY_HEADER_ROOT); | |||
} | |||
private long getDataRootVersion() { | |||
return rootDS.getVersion(KEY_DATA_ROOT); | |||
} | |||
public Bytes getAddress() { | |||
return accountID.getAddress(); | |||
} | |||
@@ -146,6 +172,10 @@ public class MerkleAccount implements LedgerAccount, HashProvable, MerkleSnapsho | |||
return accountID; | |||
} | |||
protected VersioningMap<Bytes, BytesValue> getHeaders() { | |||
return headerDS; | |||
} | |||
@Override | |||
public VersioningMap<Bytes, BytesValue> getDataset() { | |||
return dataDS; | |||
@@ -190,12 +220,12 @@ public class MerkleAccount implements LedgerAccount, HashProvable, MerkleSnapsho | |||
} | |||
/** | |||
* 保存公钥; | |||
* 初始化账户的公钥; | |||
* | |||
* @param pubKey | |||
*/ | |||
private void savePubKey(PubKey pubKey) { | |||
long v = headerDS.setValue(KEY_PUBKEY, TypedBytesValue.fromPubKey(pubKey), -1); | |||
private void initPubKey(PubKey pubKey) { | |||
long v = headerDS.setValue(KEY_PUBKEY, TypedValue.fromPubKey(pubKey), -1); | |||
if (v < 0) { | |||
throw new LedgerException("PubKey storage conflict!"); | |||
} | |||
@@ -208,7 +238,7 @@ public class MerkleAccount implements LedgerAccount, HashProvable, MerkleSnapsho | |||
*/ | |||
private PubKey loadPubKey() { | |||
BytesValue bytesValue = headerDS.getValue(KEY_PUBKEY); | |||
return TypedBytesValue.wrap(bytesValue).pubKeyValue(); | |||
return TypedValue.wrap(bytesValue).pubKeyValue(); | |||
} | |||
/** | |||
@@ -221,6 +251,19 @@ public class MerkleAccount implements LedgerAccount, HashProvable, MerkleSnapsho | |||
protected void onUpdated(Bytes key, BytesValue value, long newVersion) { | |||
} | |||
/** | |||
* 当账户数据提交后触发此方法;<br> | |||
* | |||
* 此方法默认会返回新的账户版本号,等于当前版本号加 1 ; | |||
* | |||
* @param newRootHash | |||
* @param currentVersion | |||
* @return | |||
*/ | |||
protected long onCommited(HashDigest newRootHash, long currentVersion) { | |||
return currentVersion + 1; | |||
} | |||
@Override | |||
public boolean isUpdated() { | |||
return dataDS.getDataset().isUpdated() || headerDS.getDataset().isUpdated() || rootDS.isUpdated(); | |||
@@ -228,26 +271,39 @@ public class MerkleAccount implements LedgerAccount, HashProvable, MerkleSnapsho | |||
@Override | |||
public void commit() { | |||
dataDS.getDataset().commit(); | |||
headerDS.getDataset().commit(); | |||
rootDS.setValue(key, value, version) | |||
baseDS.commit(); | |||
if (headerDS.dataset.isUpdated()) { | |||
headerDS.getDataset().commit(); | |||
long version = getHeaderRootVersion(); | |||
rootDS.setValue(KEY_HEADER_ROOT, headerDS.dataset.getRootHash().toBytes(), version); | |||
} | |||
if (dataDS.dataset.isUpdated()) { | |||
long version = getDataRootVersion(); | |||
dataDS.getDataset().commit(); | |||
rootDS.setValue(KEY_DATA_ROOT, dataDS.dataset.getRootHash().toBytes(), version); | |||
} | |||
if (rootDS.isUpdated()) { | |||
rootDS.commit(); | |||
this.version = onCommited(rootDS.getRootHash(), version); | |||
} | |||
} | |||
@Override | |||
public void cancel() { | |||
baseDS.cancel(); | |||
headerDS.getDataset().cancel(); | |||
dataDS.getDataset().cancel(); | |||
rootDS.cancel(); | |||
} | |||
private class BlockchainIdentityProxy implements BlockchainIdentity { | |||
// ---------------------- | |||
private class AutoloadingID implements BlockchainIdentity { | |||
private Bytes address; | |||
private PubKey pubKey; | |||
public BlockchainIdentityProxy(Bytes address, PubKey pubKey) { | |||
public AutoloadingID(Bytes address, PubKey pubKey) { | |||
this.address = address; | |||
this.pubKey = pubKey; | |||
} | |||
@@ -267,8 +323,6 @@ public class MerkleAccount implements LedgerAccount, HashProvable, MerkleSnapsho | |||
} | |||
// ---------------------- | |||
private static class MerkleDatasetAdapter implements VersioningMap<Bytes, BytesValue> { | |||
private static DataChangedListener NULL_LISTENER = new DataChangedListener() { | |||
@@ -8,8 +8,8 @@ import com.jd.blockchain.binaryproto.DataContractRegistry; | |||
import com.jd.blockchain.crypto.AddressEncoding; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.AccountHeader; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.ledger.BlockchainIdentityData; | |||
import com.jd.blockchain.ledger.BytesValue; | |||
import com.jd.blockchain.ledger.CryptoSetting; | |||
import com.jd.blockchain.ledger.LedgerException; | |||
@@ -18,21 +18,19 @@ 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.RegionMap; | |||
import com.jd.blockchain.utils.Transactional; | |||
import com.jd.blockchain.utils.VersioningMap; | |||
public abstract class MerkleAccountSet implements Transactional, MerkleProvable, AccountQuery<MerkleAccount> { | |||
public class MerkleAccountSet implements Transactional, MerkleProvable, AccountQuery<MerkleAccount> { | |||
private static final Bytes ACCOUNT_ROOT_PREFIX = Bytes.fromString("ROOT/"); | |||
// private static final Bytes ACCOUNT_ROOT_PREFIX = Bytes.fromString("ROOT/"); | |||
static { | |||
DataContractRegistry.register(MerkleSnapshot.class); | |||
DataContractRegistry.register(AccountHeader.class); | |||
DataContractRegistry.register(BlockchainIdentity.class); | |||
} | |||
private final Bytes keyPrefix; | |||
/** | |||
* 账户根哈希的数据集; | |||
*/ | |||
@@ -216,22 +214,14 @@ public abstract class MerkleAccountSet implements Transactional, MerkleProvable, | |||
} | |||
// Now, be sure that "acc == null", so get account from storage; | |||
byte[] bytes = merkleDataset.getValue(address, version); | |||
if (bytes == null) { | |||
return null; | |||
} | |||
// Set readonly for the old version account; | |||
boolean readonly = (version > -1 && version < latestVersion) || isReadonly(); | |||
// String prefix = address.concat(LedgerConsts.KEY_SEPERATOR); | |||
// ExPolicyKVStorage ss = PrefixAppender.prefix(prefix, baseExStorage); | |||
// VersioningKVStorage vs = PrefixAppender.prefix(prefix, baseVerStorage); | |||
// BaseAccount accDS = deserialize(bytes, cryptoSetting, ss, vs, readonly); | |||
Bytes prefix = keyPrefix.concat(address); | |||
acc = deserialize(bytes, cryptoSetting, prefix, readonly, latestVersion); | |||
// load account from storage; | |||
acc = loadAccount(address, readonly, version); | |||
if (acc == null) { | |||
return null; | |||
} | |||
if (!readonly) { | |||
// cache the latest version witch enable reading and writing; | |||
// readonly version of account not necessary to be cached; | |||
@@ -240,6 +230,10 @@ public abstract class MerkleAccountSet implements Transactional, MerkleProvable, | |||
return acc; | |||
} | |||
public MerkleAccount register(Bytes address, PubKey pubKey) { | |||
return register(new BlockchainIdentityData(address, pubKey)); | |||
} | |||
/** | |||
* 注册一个新账户; <br> | |||
* | |||
@@ -287,7 +281,7 @@ public abstract class MerkleAccountSet implements Transactional, MerkleProvable, | |||
// accExStorage, accVerStorage); | |||
Bytes prefix = keyPrefix.concat(address); | |||
InnerMerkleAccount acc = createInstance(accountId, cryptoSetting, prefix, -1); | |||
InnerMerkleAccount acc = createInstance(accountId, cryptoSetting, prefix); | |||
latestAccountsCache.put(address, acc); | |||
updated = true; | |||
@@ -301,24 +295,43 @@ public abstract class MerkleAccountSet implements Transactional, MerkleProvable, | |||
} | |||
} | |||
private InnerMerkleAccount createInstance(BlockchainIdentity header, CryptoSetting cryptoSetting, Bytes keyPrefix, | |||
long version) { | |||
return new InnerMerkleAccount(header, version, cryptoSetting, keyPrefix, baseExStorage, baseVerStorage); | |||
private InnerMerkleAccount createInstance(BlockchainIdentity header, CryptoSetting cryptoSetting, Bytes keyPrefix) { | |||
return new InnerMerkleAccount(header, cryptoSetting, keyPrefix, baseExStorage, baseVerStorage); | |||
} | |||
private InnerMerkleAccount deserialize(byte[] bytes, CryptoSetting cryptoSetting, Bytes keyPrefix, boolean readonly, | |||
long version) { | |||
BlockchainIdentity id = BinaryProtocol.decodeAs(bytes, BlockchainIdentity.class); | |||
private InnerMerkleAccount loadAccount(Bytes address, boolean readonly, long version) { | |||
// prefix; | |||
Bytes prefix = keyPrefix.concat(address); | |||
byte[] rootHashBytes = merkleDataset.getValue(address, version); | |||
if (rootHashBytes == null) { | |||
return null; | |||
} | |||
HashDigest rootHash = new HashDigest(rootHashBytes); | |||
return new InnerMerkleAccount(header.getID(), version, header.getRootHash(), cryptoSetting, keyPrefix, | |||
baseExStorage, baseVerStorage, readonly); | |||
return new InnerMerkleAccount(address, version, rootHash, cryptoSetting, prefix, baseExStorage, baseVerStorage, | |||
readonly); | |||
} | |||
// TODO: 优化:区块链身份(地址+公钥)与其 Merkle | |||
// 树根哈希分开独立存储;不必作为一个整块,避免状态数据写入时频繁重写公钥,尤其某些算法的公钥可能很大; | |||
private byte[] serialize(MerkleAccountHeader account) { | |||
return BinaryProtocol.encode(account, MerkleAccountHeader.class); | |||
// TODO:优化:区块链身份(地址+公钥)与其Merkle树根哈希分开独立存储; | |||
// 不必作为一个整块,避免状态数据写入时频繁重写公钥,尤其某些算法的公钥可能很大; | |||
/** | |||
* 保存账户的根哈希,返回账户的新版本; | |||
* | |||
* @param account | |||
* @return | |||
*/ | |||
private long saveAccount(InnerMerkleAccount account) { | |||
// 提交更改,更新哈希; | |||
long version = account.version; | |||
account.commit(); | |||
long newVersion = merkleDataset.setValue(account.getAddress(), account.getRootHash().toBytes(), version); | |||
if (newVersion < 0) { | |||
// Update fail; | |||
throw new LedgerException("Account updating fail! --[Address=" + account.getAddress() + "]"); | |||
} | |||
return newVersion; | |||
} | |||
@Override | |||
@@ -335,15 +348,7 @@ public abstract class MerkleAccountSet implements Transactional, MerkleProvable, | |||
for (InnerMerkleAccount acc : latestAccountsCache.values()) { | |||
// updated or new created; | |||
if (acc.isUpdated() || acc.version < 0) { | |||
// 提交更改,更新哈希; | |||
acc.commit(); | |||
byte[] value = serialize(acc); | |||
long ver = merkleDataset.setValue(acc.getID().getAddress(), value, acc.version); | |||
if (ver < 0) { | |||
// Update fail; | |||
throw new LedgerException( | |||
"Account updating fail! --[Address=" + acc.getID().getAddress() + "]"); | |||
} | |||
saveAccount(acc); | |||
} | |||
} | |||
merkleDataset.commit(); | |||
@@ -370,17 +375,22 @@ public abstract class MerkleAccountSet implements Transactional, MerkleProvable, | |||
updated = false; | |||
} | |||
/** | |||
* 内部实现的账户,监听和同步账户数据的变更; | |||
* | |||
* @author huanghaiquan | |||
* | |||
*/ | |||
private class InnerMerkleAccount extends MerkleAccount { | |||
public InnerMerkleAccount(BlockchainIdentity accountID, long version, CryptoSetting cryptoSetting, | |||
Bytes keyPrefix, ExPolicyKVStorage exStorage, VersioningKVStorage verStorage) { | |||
super(accountID, version, cryptoSetting, keyPrefix, exStorage, verStorage); | |||
public InnerMerkleAccount(BlockchainIdentity accountID, CryptoSetting cryptoSetting, Bytes keyPrefix, | |||
ExPolicyKVStorage exStorage, VersioningKVStorage verStorage) { | |||
super(accountID, cryptoSetting, keyPrefix, exStorage, verStorage); | |||
} | |||
public InnerMerkleAccount(BlockchainIdentity accountID, long version, HashDigest dataRootHash, | |||
CryptoSetting cryptoSetting, Bytes keyPrefix, ExPolicyKVStorage exStorage, | |||
VersioningKVStorage verStorage, boolean readonly) { | |||
super(accountID, version, dataRootHash, cryptoSetting, keyPrefix, exStorage, verStorage, readonly); | |||
public InnerMerkleAccount(Bytes address, long version, HashDigest dataRootHash, CryptoSetting cryptoSetting, | |||
Bytes keyPrefix, ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly) { | |||
super(address, version, dataRootHash, cryptoSetting, keyPrefix, exStorage, verStorage, readonly); | |||
} | |||
@Override | |||
@@ -49,17 +49,17 @@ public class MerkleDataCluster implements Transactional, MerkleSnapshot { | |||
return rootDS.isUpdated(); | |||
} | |||
public VersioningMap<Bytes, byte[]> getPartition(Bytes name) { | |||
return getPartition(name, false); | |||
} | |||
public VersioningMap<Bytes, byte[]> getPartition(Bytes name, boolean create) { | |||
} | |||
public VersioningMap<Bytes, byte[]> createPartition(Bytes name) { | |||
} | |||
// public VersioningMap<Bytes, byte[]> getPartition(Bytes name) { | |||
// return getPartition(name, false); | |||
// } | |||
// | |||
// public VersioningMap<Bytes, byte[]> getPartition(Bytes name, boolean create) { | |||
// | |||
// } | |||
// | |||
// public VersioningMap<Bytes, byte[]> createPartition(Bytes name) { | |||
// | |||
// } | |||
@Override | |||
public void commit() { | |||
@@ -1,7 +1,7 @@ | |||
package com.jd.blockchain.ledger.core; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.AccountHeader; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.utils.Bytes; | |||
/** | |||
@@ -15,7 +15,7 @@ import com.jd.blockchain.utils.Bytes; | |||
public class OpeningAccessPolicy implements AccountAccessPolicy { | |||
@Override | |||
public boolean checkDataWriting(AccountHeader account) { | |||
public boolean checkDataWriting(BlockchainIdentity account) { | |||
return true; | |||
} | |||
@@ -28,7 +28,7 @@ public class ParticipantDataset implements Transactional, MerkleProvable, Partic | |||
public ParticipantDataset(HashDigest merkleRootHash, CryptoSetting cryptoSetting, String prefix, | |||
ExPolicyKVStorage exPolicyStorage, VersioningKVStorage verStorage, boolean readonly) { | |||
dataset = new MerkleDataSet(merkleRootHash, cryptoSetting, prefix, exPolicyStorage, verStorage, readonly); | |||
dataset = new MerkleDataSet(merkleRootHash, cryptoSetting, Bytes.fromString(prefix), exPolicyStorage, verStorage, readonly); | |||
} | |||
@Override | |||
@@ -30,7 +30,8 @@ public class RolePrivilegeDataset implements Transactional, MerkleProvable, Role | |||
public RolePrivilegeDataset(HashDigest merkleRootHash, CryptoSetting cryptoSetting, String prefix, | |||
ExPolicyKVStorage exPolicyStorage, VersioningKVStorage verStorage, boolean readonly) { | |||
dataset = new MerkleDataSet(merkleRootHash, cryptoSetting, prefix, exPolicyStorage, verStorage, readonly); | |||
dataset = new MerkleDataSet(merkleRootHash, cryptoSetting, Bytes.fromString(prefix), exPolicyStorage, | |||
verStorage, readonly); | |||
} | |||
@Override | |||
@@ -255,7 +256,7 @@ public class RolePrivilegeDataset implements Transactional, MerkleProvable, Role | |||
public RolePrivileges getRolePrivilege(String roleName) { | |||
// 只返回最新版本; | |||
Bytes key = encodeKey(roleName); | |||
VersioningKVEntry kv = dataset.getDataEntry(key); | |||
VersioningKVEntry<Bytes, byte[]> kv = dataset.getDataEntry(key); | |||
if (kv == null) { | |||
return null; | |||
} | |||
@@ -265,7 +266,7 @@ public class RolePrivilegeDataset implements Transactional, MerkleProvable, Role | |||
@Override | |||
public RolePrivileges[] getRolePrivileges(int index, int count) { | |||
VersioningKVEntry[] kvEntries = dataset.getLatestDataEntries(index, count); | |||
VersioningKVEntry<Bytes, byte[]>[] kvEntries = dataset.getLatestDataEntries(index, count); | |||
RolePrivileges[] pns = new RolePrivileges[kvEntries.length]; | |||
PrivilegeSet privilege; | |||
for (int i = 0; i < pns.length; i++) { | |||
@@ -1,7 +0,0 @@ | |||
package com.jd.blockchain.ledger.core; | |||
import com.jd.blockchain.utils.VersioningMap; | |||
public interface StringKeyMap<V> extends VersioningMap<String, V> { | |||
} |
@@ -88,7 +88,8 @@ public class TransactionSet implements Transactional, TransactionQuery { | |||
public TransactionSet(HashDigest txRootHash, CryptoSetting setting, String keyPrefix, | |||
ExPolicyKVStorage merkleTreeStorage, VersioningKVStorage dataStorage, boolean readonly) { | |||
this.txStatePrefix = Bytes.fromString(keyPrefix + TX_STATE_PREFIX); | |||
this.txSet = new MerkleDataSet(txRootHash, setting, keyPrefix, merkleTreeStorage, dataStorage, readonly); | |||
this.txSet = new MerkleDataSet(txRootHash, setting, Bytes.fromString(keyPrefix), merkleTreeStorage, dataStorage, | |||
readonly); | |||
} | |||
/** | |||
@@ -1,12 +1,11 @@ | |||
package com.jd.blockchain.ledger.core; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.TypedBytesValue; | |||
import com.jd.blockchain.ledger.BytesValue; | |||
import com.jd.blockchain.ledger.UserAccountHeader; | |||
import com.jd.blockchain.ledger.LedgerException; | |||
import com.jd.blockchain.ledger.TypedValue; | |||
import com.jd.blockchain.ledger.UserInfo; | |||
import com.jd.blockchain.utils.Bytes; | |||
import com.jd.blockchain.utils.VersioningMap; | |||
/** | |||
* 用户账户; | |||
@@ -14,34 +13,54 @@ import com.jd.blockchain.utils.VersioningMap; | |||
* @author huanghaiquan | |||
* | |||
*/ | |||
public class UserAccount extends MerkleAccount{ //implements UserInfo { | |||
public class UserAccount extends AccountDecorator implements UserInfo { // implements UserInfo { | |||
private static final Bytes USER_INFO_PREFIX = Bytes.fromString("PROP" + LedgerConsts.KEY_SEPERATOR); | |||
private static final Bytes DATA_PUB_KEY = Bytes.fromString("DATA-PUBKEY"); | |||
// private MerkleAccount baseAccount; | |||
public UserAccount(MerkleAccount mklAccount) { | |||
super(mklAccount); | |||
} | |||
private PubKey dataPubKey; | |||
public UserAccount(VersioningMap baseAccount) { | |||
this.baseAccount = baseAccount; | |||
@Override | |||
public Bytes getAddress() { | |||
return getID().getAddress(); | |||
} | |||
@Override | |||
public PubKey getPubKey() { | |||
return getID().getPubKey(); | |||
} | |||
@Override | |||
public PubKey getDataPubKey() { | |||
BytesValue pkBytes = baseAccount.getValue(DATA_PUB_KEY); | |||
if (pkBytes == null) { | |||
return null; | |||
if (dataPubKey == null) { | |||
BytesValue pkBytes = getHeaders().getValue(DATA_PUB_KEY); | |||
if (pkBytes == null) { | |||
return null; | |||
} | |||
dataPubKey = new PubKey(pkBytes.getValue().toBytes()); | |||
} | |||
return new PubKey(pkBytes.getValue().toBytes()); | |||
return dataPubKey; | |||
} | |||
public long setDataPubKey(PubKey pubKey) { | |||
byte[] pkBytes = pubKey.toBytes(); | |||
return baseAccount.setValue(DATA_PUB_KEY, TypedBytesValue.fromBytes(pkBytes), -1); | |||
public void setDataPubKey(PubKey pubKey) { | |||
long version = getHeaders().getVersion(DATA_PUB_KEY); | |||
setDataPubKey(pubKey, version); | |||
} | |||
public long setDataPubKey(PubKey pubKey, long version) { | |||
byte[] pkBytes = pubKey.toBytes(); | |||
return baseAccount.setValue(DATA_PUB_KEY, TypedBytesValue.fromBytes(pkBytes), version); | |||
public void setDataPubKey(PubKey pubKey, long version) { | |||
TypedValue value = TypedValue.fromPubKey(dataPubKey); | |||
long newVersion = getHeaders().setValue(DATA_PUB_KEY, value, version); | |||
if (newVersion > -1) { | |||
dataPubKey = pubKey; | |||
} else { | |||
throw new LedgerException("Data public key was updated failed!"); | |||
} | |||
} | |||
public long setProperty(String key, String value, long version) { | |||
@@ -49,22 +68,22 @@ public class UserAccount extends MerkleAccount{ //implements UserInfo { | |||
} | |||
public long setProperty(Bytes key, String value, long version) { | |||
return baseAccount.setValue(encodePropertyKey(key), TypedBytesValue.fromText(value), version); | |||
return getHeaders().setValue(encodePropertyKey(key), TypedValue.fromText(value), version); | |||
} | |||
public String getProperty(Bytes key) { | |||
BytesValue value = baseAccount.getValue(encodePropertyKey(key)); | |||
BytesValue value = getHeaders().getValue(encodePropertyKey(key)); | |||
return value == null ? null : value.getValue().toUTF8String(); | |||
} | |||
public String getProperty(Bytes key, long version) { | |||
BytesValue value = baseAccount.getValue(encodePropertyKey(key), version); | |||
BytesValue value = getHeaders().getValue(encodePropertyKey(key), version); | |||
return value == null ? null : value.getValue().toUTF8String(); | |||
} | |||
private Bytes encodePropertyKey(Bytes key) { | |||
// return key.concatTo(USER_INFO_PREFIX); | |||
return USER_INFO_PREFIX.concat(key); | |||
} | |||
} |
@@ -2,7 +2,7 @@ package com.jd.blockchain.ledger.core; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.AccountHeader; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.ledger.CryptoSetting; | |||
import com.jd.blockchain.ledger.LedgerException; | |||
import com.jd.blockchain.ledger.MerkleProof; | |||
@@ -10,7 +10,6 @@ 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; | |||
/** | |||
* @author huanghaiquan | |||
@@ -22,19 +21,20 @@ public class UserAccountSet implements Transactional, UserAccountQuery { | |||
public UserAccountSet(CryptoSetting cryptoSetting, String keyPrefix, ExPolicyKVStorage simpleStorage, | |||
VersioningKVStorage versioningStorage, AccountAccessPolicy accessPolicy) { | |||
accountSet = new MerkleAccountSet(cryptoSetting, keyPrefix, simpleStorage, versioningStorage, accessPolicy); | |||
accountSet = new MerkleAccountSet(cryptoSetting, Bytes.fromString(keyPrefix), simpleStorage, versioningStorage, | |||
accessPolicy); | |||
} | |||
public UserAccountSet(HashDigest dataRootHash, CryptoSetting cryptoSetting, String keyPrefix, | |||
ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly, | |||
AccountAccessPolicy accessPolicy) { | |||
accountSet = new MerkleAccountSet(dataRootHash, cryptoSetting, keyPrefix, exStorage, verStorage, readonly, | |||
accessPolicy); | |||
accountSet = new MerkleAccountSet(dataRootHash, cryptoSetting, Bytes.fromString(keyPrefix), exStorage, | |||
verStorage, readonly, accessPolicy); | |||
} | |||
@Override | |||
public AccountHeader[] getHeaders(int fromIndex, int count) { | |||
return accountSet.getHeaders(fromIndex,count); | |||
public BlockchainIdentity[] getHeaders(int fromIndex, int count) { | |||
return accountSet.getHeaders(fromIndex, count); | |||
} | |||
/** | |||
@@ -50,7 +50,7 @@ public class UserAccountSet implements Transactional, UserAccountQuery { | |||
public boolean isReadonly() { | |||
return accountSet.isReadonly(); | |||
} | |||
void setReadonly() { | |||
accountSet.setReadonly(); | |||
} | |||
@@ -64,7 +64,7 @@ public class UserAccountSet implements Transactional, UserAccountQuery { | |||
public MerkleProof getProof(Bytes key) { | |||
return accountSet.getProof(key); | |||
} | |||
@Override | |||
public UserAccount getAccount(String address) { | |||
return getAccount(Bytes.fromBase58(address)); | |||
@@ -72,7 +72,7 @@ public class UserAccountSet implements Transactional, UserAccountQuery { | |||
@Override | |||
public UserAccount getAccount(Bytes address) { | |||
VersioningMap baseAccount = accountSet.getAccount(address); | |||
MerkleAccount baseAccount = accountSet.getAccount(address); | |||
return new UserAccount(baseAccount); | |||
} | |||
@@ -83,7 +83,7 @@ public class UserAccountSet implements Transactional, UserAccountQuery { | |||
@Override | |||
public UserAccount getAccount(Bytes address, long version) { | |||
VersioningMap baseAccount = accountSet.getAccount(address, version); | |||
MerkleAccount baseAccount = accountSet.getAccount(address, version); | |||
return new UserAccount(baseAccount); | |||
} | |||
@@ -94,14 +94,12 @@ public class UserAccountSet implements Transactional, UserAccountQuery { | |||
* | |||
* 如果指定的地址和公钥不匹配,则会引发 {@link LedgerException} 异常; | |||
* | |||
* @param address | |||
* 区块链地址; | |||
* @param pubKey | |||
* 公钥; | |||
* @param address 区块链地址; | |||
* @param pubKey 公钥; | |||
* @return 注册成功的用户对象; | |||
*/ | |||
public UserAccount register(Bytes address, PubKey pubKey) { | |||
VersioningMap baseAccount = accountSet.register(address, pubKey); | |||
MerkleAccount baseAccount = accountSet.register(address, pubKey); | |||
return new UserAccount(baseAccount); | |||
} | |||
@@ -35,7 +35,7 @@ public class UserRoleDataset implements Transactional, MerkleProvable, UserAutho | |||
public UserRoleDataset(HashDigest merkleRootHash, CryptoSetting cryptoSetting, String prefix, | |||
ExPolicyKVStorage exPolicyStorage, VersioningKVStorage verStorage, boolean readonly) { | |||
dataset = new MerkleDataSet(merkleRootHash, cryptoSetting, prefix, exPolicyStorage, verStorage, readonly); | |||
dataset = new MerkleDataSet(merkleRootHash, cryptoSetting, Bytes.fromString(prefix), exPolicyStorage, verStorage, readonly); | |||
} | |||
@Override | |||
@@ -168,7 +168,7 @@ public class UserRoleDataset implements Transactional, MerkleProvable, UserAutho | |||
@Override | |||
public UserRoles getUserRoles(Bytes userAddress) { | |||
// 只返回最新版本; | |||
VersioningKVEntry kv = dataset.getDataEntry(userAddress); | |||
VersioningKVEntry<Bytes, byte[]> kv = dataset.getDataEntry(userAddress); | |||
if (kv == null) { | |||
return null; | |||
} | |||
@@ -178,7 +178,7 @@ public class UserRoleDataset implements Transactional, MerkleProvable, UserAutho | |||
@Override | |||
public UserRoles[] getUserRoles() { | |||
VersioningKVEntry[] kvEntries = dataset.getLatestDataEntries(0, (int) dataset.getDataCount()); | |||
VersioningKVEntry<Bytes, byte[]>[] kvEntries = dataset.getLatestDataEntries(0, (int) dataset.getDataCount()); | |||
UserRoles[] pns = new UserRoles[kvEntries.length]; | |||
RoleSet roleset; | |||
for (int i = 0; i < pns.length; i++) { | |||
@@ -5,7 +5,24 @@ import java.util.List; | |||
import com.jd.blockchain.contract.LedgerContext; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.ledger.*; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.ledger.BytesValue; | |||
import com.jd.blockchain.ledger.ContractInfo; | |||
import com.jd.blockchain.ledger.DataAccountKVSetOperation; | |||
import com.jd.blockchain.ledger.DataAccountRegisterOperation; | |||
import com.jd.blockchain.ledger.KVDataEntry; | |||
import com.jd.blockchain.ledger.KVInfoVO; | |||
import com.jd.blockchain.ledger.LedgerAdminInfo; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
import com.jd.blockchain.ledger.LedgerInfo; | |||
import com.jd.blockchain.ledger.LedgerMetadata; | |||
import com.jd.blockchain.ledger.LedgerTransaction; | |||
import com.jd.blockchain.ledger.Operation; | |||
import com.jd.blockchain.ledger.ParticipantNode; | |||
import com.jd.blockchain.ledger.TransactionState; | |||
import com.jd.blockchain.ledger.TypedValue; | |||
import com.jd.blockchain.ledger.UserInfo; | |||
import com.jd.blockchain.ledger.UserRegisterOperation; | |||
import com.jd.blockchain.ledger.core.OperationHandleContext; | |||
import com.jd.blockchain.transaction.BlockchainQueryService; | |||
import com.jd.blockchain.transaction.DataAccountKVSetOperationBuilder; | |||
@@ -150,7 +167,7 @@ public class ContractLedgerContext implements LedgerContext { | |||
} | |||
@Override | |||
public AccountHeader getDataAccount(HashDigest ledgerHash, String address) { | |||
public BlockchainIdentity getDataAccount(HashDigest ledgerHash, String address) { | |||
return innerQueryService.getDataAccount(ledgerHash, address); | |||
} | |||
@@ -182,17 +199,17 @@ public class ContractLedgerContext implements LedgerContext { | |||
// ---------------------------user()---------------------------- | |||
@Override | |||
public AccountHeader[] getUsers(HashDigest ledgerHash, int fromIndex, int count) { | |||
public BlockchainIdentity[] getUsers(HashDigest ledgerHash, int fromIndex, int count) { | |||
return innerQueryService.getUsers(ledgerHash, fromIndex, count); | |||
} | |||
@Override | |||
public AccountHeader[] getDataAccounts(HashDigest ledgerHash, int fromIndex, int count) { | |||
public BlockchainIdentity[] getDataAccounts(HashDigest ledgerHash, int fromIndex, int count) { | |||
return innerQueryService.getDataAccounts(ledgerHash, fromIndex, count); | |||
} | |||
@Override | |||
public AccountHeader[] getContractAccounts(HashDigest ledgerHash, int fromIndex, int count) { | |||
public BlockchainIdentity[] getContractAccounts(HashDigest ledgerHash, int fromIndex, int count) { | |||
return innerQueryService.getContractAccounts(ledgerHash, fromIndex, count); | |||
} | |||
@@ -268,7 +285,7 @@ public class ContractLedgerContext implements LedgerContext { | |||
@Override | |||
public DataAccountKVSetOperationBuilder setText(String key, String value, long expVersion) { | |||
BytesValue bytesValue = TypedBytesValue.fromText(value); | |||
BytesValue bytesValue = TypedValue.fromText(value); | |||
this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion); | |||
handle(op); | |||
return this; | |||
@@ -276,7 +293,7 @@ public class ContractLedgerContext implements LedgerContext { | |||
@Override | |||
public DataAccountKVSetOperationBuilder setBytes(String key, Bytes value, long expVersion) { | |||
BytesValue bytesValue = TypedBytesValue.fromBytes(value); | |||
BytesValue bytesValue = TypedValue.fromBytes(value); | |||
this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion); | |||
handle(op); | |||
return this; | |||
@@ -284,7 +301,7 @@ public class ContractLedgerContext implements LedgerContext { | |||
@Override | |||
public DataAccountKVSetOperationBuilder setInt64(String key, long value, long expVersion) { | |||
BytesValue bytesValue = TypedBytesValue.fromInt64(value); | |||
BytesValue bytesValue = TypedValue.fromInt64(value); | |||
this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion); | |||
handle(op); | |||
return this; | |||
@@ -301,7 +318,7 @@ public class ContractLedgerContext implements LedgerContext { | |||
@Override | |||
public DataAccountKVSetOperationBuilder setJSON(String key, String value, long expVersion) { | |||
BytesValue bytesValue = TypedBytesValue.fromJSON(value); | |||
BytesValue bytesValue = TypedValue.fromJSON(value); | |||
this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion); | |||
handle(op); | |||
return this; | |||
@@ -309,7 +326,7 @@ public class ContractLedgerContext implements LedgerContext { | |||
@Override | |||
public DataAccountKVSetOperationBuilder setXML(String key, String value, long expVersion) { | |||
BytesValue bytesValue = TypedBytesValue.fromXML(value); | |||
BytesValue bytesValue = TypedValue.fromXML(value); | |||
this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion); | |||
handle(op); | |||
return this; | |||
@@ -317,7 +334,7 @@ public class ContractLedgerContext implements LedgerContext { | |||
@Override | |||
public DataAccountKVSetOperationBuilder setBytes(String key, byte[] value, long expVersion) { | |||
BytesValue bytesValue = TypedBytesValue.fromBytes(value); | |||
BytesValue bytesValue = TypedValue.fromBytes(value); | |||
this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion); | |||
handle(op); | |||
return this; | |||
@@ -325,7 +342,7 @@ public class ContractLedgerContext implements LedgerContext { | |||
@Override | |||
public DataAccountKVSetOperationBuilder setImage(String key, byte[] value, long expVersion) { | |||
BytesValue bytesValue = TypedBytesValue.fromImage(value); | |||
BytesValue bytesValue = TypedValue.fromImage(value); | |||
this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion); | |||
handle(op); | |||
return this; | |||
@@ -333,7 +350,7 @@ public class ContractLedgerContext implements LedgerContext { | |||
@Override | |||
public DataAccountKVSetOperationBuilder setTimestamp(String key, long value, long expVersion) { | |||
BytesValue bytesValue = TypedBytesValue.fromTimestamp(value); | |||
BytesValue bytesValue = TypedValue.fromTimestamp(value); | |||
this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion); | |||
handle(op); | |||
return this; | |||
@@ -37,7 +37,7 @@ public class DataAccountKVSetOperationHandle extends AbstractLedgerOperationHand | |||
KVWriteEntry[] writeSet = kvWriteOp.getWriteSet(); | |||
long v = -1L; | |||
for (KVWriteEntry kvw : writeSet) { | |||
v = account.setBytes(Bytes.fromString(kvw.getKey()), kvw.getValue(), kvw.getExpectedVersion()); | |||
v = account.getDataset().setValue(Bytes.fromString(kvw.getKey()), kvw.getValue(), kvw.getExpectedVersion()); | |||
if (v < 0) { | |||
throw new DataVersionConflictException(); | |||
} | |||
@@ -19,6 +19,7 @@ import com.jd.blockchain.ledger.core.MerkleAccount; | |||
import com.jd.blockchain.ledger.core.CryptoConfig; | |||
import com.jd.blockchain.ledger.core.OpeningAccessPolicy; | |||
import com.jd.blockchain.storage.service.utils.MemoryKVStorage; | |||
import com.jd.blockchain.utils.Bytes; | |||
public class AccountSetTest { | |||
@@ -43,7 +44,7 @@ public class AccountSetTest { | |||
cryptoConf.setHashAlgorithm(ClassicAlgorithm.SHA256); | |||
String keyPrefix = ""; | |||
MerkleAccountSet accset = new MerkleAccountSet(cryptoConf, keyPrefix, storage, storage, accessPolicy); | |||
MerkleAccountSet accset = new MerkleAccountSet(cryptoConf, Bytes.fromString(keyPrefix), storage, storage, accessPolicy); | |||
BlockchainKeypair userKey = BlockchainKeyGenerator.getInstance().generate(); | |||
accset.register(userKey.getAddress(), userKey.getPubKey()); | |||
@@ -56,7 +57,7 @@ public class AccountSetTest { | |||
HashDigest rootHash = accset.getRootHash(); | |||
assertNotNull(rootHash); | |||
MerkleAccountSet reloadAccSet = new MerkleAccountSet(rootHash, cryptoConf, keyPrefix, storage, storage, true, accessPolicy); | |||
MerkleAccountSet reloadAccSet = new MerkleAccountSet(rootHash, cryptoConf, Bytes.fromString(keyPrefix), storage, storage, true, accessPolicy); | |||
MerkleAccount reloadUserAcc = reloadAccSet.getAccount(userKey.getAddress()); | |||
assertNotNull(reloadUserAcc); | |||
assertTrue(reloadAccSet.contains(userKey.getAddress())); | |||
@@ -2,6 +2,7 @@ package test.com.jd.blockchain.ledger.core; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertTrue; | |||
import org.junit.Test; | |||
@@ -12,9 +13,9 @@ import com.jd.blockchain.crypto.service.classic.ClassicCryptoService; | |||
import com.jd.blockchain.crypto.service.sm.SMCryptoService; | |||
import com.jd.blockchain.ledger.BlockchainKeyGenerator; | |||
import com.jd.blockchain.ledger.BlockchainKeypair; | |||
import com.jd.blockchain.ledger.TypedBytesValue; | |||
import com.jd.blockchain.ledger.core.MerkleAccount; | |||
import com.jd.blockchain.ledger.TypedValue; | |||
import com.jd.blockchain.ledger.core.CryptoConfig; | |||
import com.jd.blockchain.ledger.core.MerkleAccount; | |||
import com.jd.blockchain.storage.service.utils.MemoryKVStorage; | |||
import com.jd.blockchain.utils.Bytes; | |||
@@ -48,38 +49,39 @@ public class BaseAccountTest { | |||
BlockchainKeypair bck = BlockchainKeyGenerator.getInstance().generate(); | |||
// 新建账户; | |||
MerkleAccount baseAccount = new MerkleAccount(bck.getIdentity(), cryptoConf, keyPrefix, testStorage, testStorage); | |||
assertFalse(baseAccount.isUpdated());// 空的账户; | |||
MerkleAccount baseAccount = new MerkleAccount(bck.getIdentity(), cryptoConf, Bytes.fromString(keyPrefix), | |||
testStorage, testStorage); | |||
assertTrue(baseAccount.isUpdated());//初始化新账户时,先写入PubKey; | |||
assertFalse(baseAccount.isReadonly()); | |||
// 在空白状态下写入数据; | |||
long v = baseAccount.setValue(Bytes.fromString("A"), TypedBytesValue.fromText("VALUE_A"), 0); | |||
long v = baseAccount.getDataset().setValue(Bytes.fromString("A"), TypedValue.fromText("VALUE_A"), 0); | |||
// 预期失败; | |||
assertEquals(-1, v); | |||
v = baseAccount.setValue(Bytes.fromString("A"), TypedBytesValue.fromText("VALUE_A"), 1); | |||
v = baseAccount.getDataset().setValue(Bytes.fromString("A"), TypedValue.fromText("VALUE_A"), 1); | |||
// 预期失败; | |||
assertEquals(-1, v); | |||
v = baseAccount.setValue(Bytes.fromString("A"), TypedBytesValue.fromText("VALUE_A"), -1); | |||
v = baseAccount.getDataset().setValue(Bytes.fromString("A"), TypedValue.fromText("VALUE_A"), -1); | |||
// 预期成功; | |||
assertEquals(0, v); | |||
v = baseAccount.setValue(Bytes.fromString("A"), TypedBytesValue.fromText("VALUE_A-1"), -1); | |||
v = baseAccount.getDataset().setValue(Bytes.fromString("A"), TypedValue.fromText("VALUE_A-1"), -1); | |||
// 已经存在版本,指定版本号-1,预期导致失败; | |||
assertEquals(-1, v); | |||
baseAccount.commit(); | |||
v = 0; | |||
for (int i = 0; i < 10; i++) { | |||
long s = baseAccount.setValue(Bytes.fromString("A"), TypedBytesValue.fromText("VALUE_A_" + i), v); | |||
long s = baseAccount.getDataset().setValue(Bytes.fromString("A"), TypedValue.fromText("VALUE_A_" + i), v); | |||
baseAccount.commit(); | |||
// 预期成功; | |||
assertEquals(v + 1, s); | |||
v++; | |||
} | |||
v = baseAccount.setValue(Bytes.fromString("A"), TypedBytesValue.fromText("VALUE_A_" + v), v + 1); | |||
v = baseAccount.getDataset().setValue(Bytes.fromString("A"), TypedValue.fromText("VALUE_A_" + v), v + 1); | |||
// 预期成功; | |||
assertEquals(-1, v); | |||
@@ -16,14 +16,36 @@ import static org.mockito.Mockito.when; | |||
import java.io.InputStream; | |||
import java.util.Random; | |||
import com.jd.blockchain.utils.io.BytesUtils; | |||
import com.jd.blockchain.ledger.*; | |||
import org.junit.Test; | |||
import org.mockito.Mockito; | |||
import com.jd.blockchain.binaryproto.BinaryProtocol; | |||
import com.jd.blockchain.binaryproto.DataContractRegistry; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.ledger.BlockchainKeyGenerator; | |||
import com.jd.blockchain.ledger.BlockchainKeypair; | |||
import com.jd.blockchain.ledger.BytesValue; | |||
import com.jd.blockchain.ledger.DataAccountRegisterOperation; | |||
import com.jd.blockchain.ledger.EndpointRequest; | |||
import com.jd.blockchain.ledger.KVDataEntry; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
import com.jd.blockchain.ledger.LedgerInitSetting; | |||
import com.jd.blockchain.ledger.LedgerPermission; | |||
import com.jd.blockchain.ledger.LedgerTransaction; | |||
import com.jd.blockchain.ledger.NodeRequest; | |||
import com.jd.blockchain.ledger.OperationResult; | |||
import com.jd.blockchain.ledger.ParticipantNode; | |||
import com.jd.blockchain.ledger.ParticipantRegisterOperation; | |||
import com.jd.blockchain.ledger.ParticipantStateUpdateOperation; | |||
import com.jd.blockchain.ledger.TransactionContent; | |||
import com.jd.blockchain.ledger.TransactionContentBody; | |||
import com.jd.blockchain.ledger.TransactionPermission; | |||
import com.jd.blockchain.ledger.TransactionRequest; | |||
import com.jd.blockchain.ledger.TransactionRequestBuilder; | |||
import com.jd.blockchain.ledger.TransactionResponse; | |||
import com.jd.blockchain.ledger.TransactionState; | |||
import com.jd.blockchain.ledger.TypedValue; | |||
import com.jd.blockchain.ledger.UserRegisterOperation; | |||
import com.jd.blockchain.ledger.core.DefaultOperationHandleRegisteration; | |||
import com.jd.blockchain.ledger.core.LedgerDataQuery; | |||
import com.jd.blockchain.ledger.core.LedgerDataset; | |||
@@ -43,6 +65,7 @@ import com.jd.blockchain.storage.service.utils.MemoryKVStorage; | |||
import com.jd.blockchain.transaction.BooleanValueHolder; | |||
import com.jd.blockchain.transaction.TxBuilder; | |||
import com.jd.blockchain.utils.Bytes; | |||
import com.jd.blockchain.utils.io.BytesUtils; | |||
import test.com.jd.blockchain.ledger.TxTestContract; | |||
import test.com.jd.blockchain.ledger.TxTestContractImpl; | |||
@@ -132,7 +155,7 @@ public class ContractInvokingTest { | |||
assertEquals(1, opResults.length); | |||
assertEquals(0, opResults[0].getIndex()); | |||
byte[] expectedRetnBytes = BinaryProtocol.encode(TypedBytesValue.fromInt64(issueAmount), BytesValue.class); | |||
byte[] expectedRetnBytes = BinaryProtocol.encode(TypedValue.fromInt64(issueAmount), BytesValue.class); | |||
byte[] reallyRetnBytes = BinaryProtocol.encode(opResults[0].getResult(), BytesValue.class); | |||
assertArrayEquals(expectedRetnBytes, reallyRetnBytes); | |||
@@ -218,7 +241,7 @@ public class ContractInvokingTest { | |||
TransactionBatchResultHandle txResultHandle = txbatchProcessor.prepare(); | |||
txResultHandle.commit(); | |||
BytesValue latestValue = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getValue(key, | |||
BytesValue latestValue = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataset().getValue(key, | |||
-1); | |||
System.out.printf("latest value=[%s] %s \r\n", latestValue.getType(), latestValue.getValue().toUTF8String()); | |||
@@ -1,20 +1,20 @@ | |||
package com.jd.blockchain.ledger; | |||
import com.jd.blockchain.binaryproto.DataContract; | |||
import com.jd.blockchain.binaryproto.DataField; | |||
import com.jd.blockchain.binaryproto.PrimitiveType; | |||
import com.jd.blockchain.consts.DataCodes; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.utils.Bytes; | |||
@DataContract(code= DataCodes.ACCOUNT_HEADER) | |||
public interface AccountHeader { //extends MerkleSnapshot{ | |||
@DataField(order=1, primitiveType = PrimitiveType.BYTES) | |||
Bytes getAddress(); | |||
@DataField(order=2, primitiveType = PrimitiveType.BYTES) | |||
PubKey getPubKey(); | |||
} | |||
//package com.jd.blockchain.ledger; | |||
// | |||
//import com.jd.blockchain.binaryproto.DataContract; | |||
//import com.jd.blockchain.binaryproto.DataField; | |||
//import com.jd.blockchain.binaryproto.PrimitiveType; | |||
//import com.jd.blockchain.consts.DataCodes; | |||
//import com.jd.blockchain.crypto.PubKey; | |||
//import com.jd.blockchain.utils.Bytes; | |||
// | |||
//@Deprecated | |||
//@DataContract(code= DataCodes.ACCOUNT_HEADER) | |||
//public interface AccountHeader { //extends MerkleSnapshot{ | |||
// | |||
// @DataField(order = 1, primitiveType = PrimitiveType.BYTES) | |||
// Bytes getAddress(); | |||
// | |||
// @DataField(order = 2, primitiveType=PrimitiveType.BYTES) | |||
// PubKey getPubKey(); | |||
// | |||
//} |
@@ -14,18 +14,18 @@ public class BytesDataList implements BytesValueList { | |||
} | |||
public static BytesValueList singleText(String value) { | |||
return new BytesDataList(TypedBytesValue.fromText(value)); | |||
return new BytesDataList(TypedValue.fromText(value)); | |||
} | |||
public static BytesValueList singleLong(long value) { | |||
return new BytesDataList(TypedBytesValue.fromInt64(value)); | |||
return new BytesDataList(TypedValue.fromInt64(value)); | |||
} | |||
public static BytesValueList singleInt(int value) { | |||
return new BytesDataList(TypedBytesValue.fromInt32(value)); | |||
return new BytesDataList(TypedValue.fromInt32(value)); | |||
} | |||
public static BytesValueList singleBoolean(boolean value) { | |||
return new BytesDataList(TypedBytesValue.fromBoolean(value)); | |||
return new BytesDataList(TypedValue.fromBoolean(value)); | |||
} | |||
} |
@@ -68,7 +68,7 @@ public class BytesValueEncoding { | |||
} | |||
// 将对象序列化 | |||
byte[] serialBytes = BinaryProtocol.encode(value, type); | |||
return TypedBytesValue.fromType(DataType.DATA_CONTRACT, serialBytes); | |||
return TypedValue.fromType(DataType.DATA_CONTRACT, serialBytes); | |||
} | |||
BytesValueResolver bytesValueResolver = CLASS_RESOLVER_MAP.get(type); | |||
if (bytesValueResolver == null) { | |||
@@ -6,7 +6,7 @@ import com.jd.blockchain.binaryproto.PrimitiveType; | |||
import com.jd.blockchain.consts.DataCodes; | |||
@DataContract(code= DataCodes.CONTRACT_ACCOUNT_HEADER) | |||
public interface ContractInfo extends AccountHeader { | |||
public interface ContractInfo extends BlockchainIdentity { | |||
@DataField(order=4, primitiveType= PrimitiveType.BYTES) | |||
byte[] getChainCode(); | |||
@@ -15,29 +15,29 @@ import com.jd.blockchain.utils.io.BytesUtils; | |||
* @author huanghaiquan | |||
* | |||
*/ | |||
public class TypedBytesValue implements BytesValue { | |||
public class TypedValue implements BytesValue { | |||
public static final BytesValue NIL = new TypedBytesValue(); | |||
public static final BytesValue NIL = new TypedValue(); | |||
private DataType type; | |||
private Bytes value; | |||
private TypedBytesValue(DataType type, byte[] bytes) { | |||
private TypedValue(DataType type, byte[] bytes) { | |||
this.type = type; | |||
this.value = new Bytes(bytes); | |||
} | |||
private TypedBytesValue(DataType type, Bytes bytes) { | |||
private TypedValue(DataType type, Bytes bytes) { | |||
this.type = type; | |||
this.value = bytes; | |||
} | |||
private TypedBytesValue(BytesValue bytesValue) { | |||
private TypedValue(BytesValue bytesValue) { | |||
this.type = bytesValue.getType(); | |||
this.value = bytesValue.getValue(); | |||
} | |||
private TypedBytesValue() { | |||
private TypedValue() { | |||
this.type = DataType.NIL; | |||
} | |||
@@ -383,28 +383,28 @@ public class TypedBytesValue implements BytesValue { | |||
return new SignatureDigest(toBytesArray()); | |||
} | |||
public static TypedBytesValue wrap(BytesValue value) { | |||
return new TypedBytesValue(value); | |||
public static TypedValue wrap(BytesValue value) { | |||
return new TypedValue(value); | |||
} | |||
public static TypedBytesValue fromType(DataType type, byte[] value) { | |||
return new TypedBytesValue(type, value); | |||
public static TypedValue fromType(DataType type, byte[] value) { | |||
return new TypedValue(type, value); | |||
} | |||
public static TypedBytesValue fromBytes(byte[] value) { | |||
return new TypedBytesValue(DataType.BYTES, value); | |||
public static TypedValue fromBytes(byte[] value) { | |||
return new TypedValue(DataType.BYTES, value); | |||
} | |||
public static TypedBytesValue fromBytes(Bytes value) { | |||
return new TypedBytesValue(DataType.BYTES, value); | |||
public static TypedValue fromBytes(Bytes value) { | |||
return new TypedValue(DataType.BYTES, value); | |||
} | |||
public static TypedBytesValue fromImage(byte[] value) { | |||
return new TypedBytesValue(DataType.IMG, value); | |||
public static TypedValue fromImage(byte[] value) { | |||
return new TypedValue(DataType.IMG, value); | |||
} | |||
public static TypedBytesValue fromImage(Bytes value) { | |||
return new TypedBytesValue(DataType.IMG, value); | |||
public static TypedValue fromImage(Bytes value) { | |||
return new TypedValue(DataType.IMG, value); | |||
} | |||
/** | |||
@@ -413,43 +413,43 @@ public class TypedBytesValue implements BytesValue { | |||
* @param value | |||
* @return | |||
*/ | |||
public static TypedBytesValue fromText(String value) { | |||
return new TypedBytesValue(DataType.TEXT, BytesUtils.toBytes(value)); | |||
public static TypedValue fromText(String value) { | |||
return new TypedValue(DataType.TEXT, BytesUtils.toBytes(value)); | |||
} | |||
public static TypedBytesValue fromJSON(String value) { | |||
return new TypedBytesValue(DataType.JSON, BytesUtils.toBytes(value)); | |||
public static TypedValue fromJSON(String value) { | |||
return new TypedValue(DataType.JSON, BytesUtils.toBytes(value)); | |||
} | |||
public static TypedBytesValue fromXML(String value) { | |||
return new TypedBytesValue(DataType.XML, BytesUtils.toBytes(value)); | |||
public static TypedValue fromXML(String value) { | |||
return new TypedValue(DataType.XML, BytesUtils.toBytes(value)); | |||
} | |||
public static TypedBytesValue fromInt32(int value) { | |||
return new TypedBytesValue(DataType.INT32, BytesUtils.toBytes(value)); | |||
public static TypedValue fromInt32(int value) { | |||
return new TypedValue(DataType.INT32, BytesUtils.toBytes(value)); | |||
} | |||
public static TypedBytesValue fromInt64(long value) { | |||
return new TypedBytesValue(DataType.INT64, BytesUtils.toBytes(value)); | |||
public static TypedValue fromInt64(long value) { | |||
return new TypedValue(DataType.INT64, BytesUtils.toBytes(value)); | |||
} | |||
public static TypedBytesValue fromInt16(short value) { | |||
return new TypedBytesValue(DataType.INT16, BytesUtils.toBytes(value)); | |||
public static TypedValue fromInt16(short value) { | |||
return new TypedValue(DataType.INT16, BytesUtils.toBytes(value)); | |||
} | |||
public static TypedBytesValue fromInt8(byte value) { | |||
return new TypedBytesValue(DataType.INT8, BytesUtils.toBytes(value)); | |||
public static TypedValue fromInt8(byte value) { | |||
return new TypedValue(DataType.INT8, BytesUtils.toBytes(value)); | |||
} | |||
public static TypedBytesValue fromTimestamp(long value) { | |||
return new TypedBytesValue(DataType.TIMESTAMP, BytesUtils.toBytes(value)); | |||
public static TypedValue fromTimestamp(long value) { | |||
return new TypedValue(DataType.TIMESTAMP, BytesUtils.toBytes(value)); | |||
} | |||
public static TypedBytesValue fromBoolean(boolean value) { | |||
return new TypedBytesValue(DataType.BOOLEAN, BytesUtils.toBytes(value)); | |||
public static TypedValue fromBoolean(boolean value) { | |||
return new TypedValue(DataType.BOOLEAN, BytesUtils.toBytes(value)); | |||
} | |||
public static TypedBytesValue fromPubKey(PubKey pubKey) { | |||
return new TypedBytesValue(DataType.PUB_KEY, pubKey.toBytes()); | |||
public static TypedValue fromPubKey(PubKey pubKey) { | |||
return new TypedValue(DataType.PUB_KEY, pubKey.toBytes()); | |||
} | |||
} |
@@ -5,7 +5,7 @@ import com.jd.blockchain.consts.DataCodes; | |||
import com.jd.blockchain.crypto.PubKey; | |||
@DataContract(code= DataCodes.USER_ACCOUNT_HEADER) | |||
public interface UserAccountHeader extends AccountHeader { | |||
public interface UserAccountHeader extends BlockchainIdentity { | |||
PubKey getDataPubKey(); | |||
@@ -1,6 +1,6 @@ | |||
package com.jd.blockchain.ledger.resolver; | |||
import com.jd.blockchain.ledger.TypedBytesValue; | |||
import com.jd.blockchain.ledger.TypedValue; | |||
import com.jd.blockchain.ledger.BytesValue; | |||
import com.jd.blockchain.ledger.DataType; | |||
import com.jd.blockchain.utils.Bytes; | |||
@@ -21,7 +21,7 @@ public class BooleanToBytesValueResolver extends AbstractBytesValueResolver { | |||
if (!isSupport(type)) { | |||
throw new IllegalStateException(String.format("Un-support encode Class[%s] Object !!!", type.getName())); | |||
} | |||
return TypedBytesValue.fromBoolean((boolean) value); | |||
return TypedValue.fromBoolean((boolean) value); | |||
} | |||
@Override | |||
@@ -1,6 +1,6 @@ | |||
package com.jd.blockchain.ledger.resolver; | |||
import com.jd.blockchain.ledger.TypedBytesValue; | |||
import com.jd.blockchain.ledger.TypedValue; | |||
import com.jd.blockchain.ledger.BytesValue; | |||
import com.jd.blockchain.ledger.DataType; | |||
import com.jd.blockchain.utils.Bytes; | |||
@@ -21,9 +21,9 @@ public class BytesToBytesValueResolver extends AbstractBytesValueResolver { | |||
throw new IllegalStateException(String.format("Un-support encode Class[%s] Object !!!", type.getName())); | |||
} | |||
if (type.equals(byte[].class)) { | |||
return TypedBytesValue.fromBytes((byte[]) value); | |||
return TypedValue.fromBytes((byte[]) value); | |||
} | |||
return TypedBytesValue.fromBytes((Bytes) value); | |||
return TypedValue.fromBytes((Bytes) value); | |||
} | |||
@Override | |||
@@ -1,6 +1,6 @@ | |||
package com.jd.blockchain.ledger.resolver; | |||
import com.jd.blockchain.ledger.TypedBytesValue; | |||
import com.jd.blockchain.ledger.TypedValue; | |||
import com.jd.blockchain.ledger.BytesValue; | |||
import com.jd.blockchain.ledger.DataType; | |||
import com.jd.blockchain.utils.Bytes; | |||
@@ -21,7 +21,7 @@ public class IntegerToBytesValueResolver extends AbstractBytesValueResolver { | |||
if (!isSupport(type)) { | |||
throw new IllegalStateException(String.format("Un-support encode Class[%s] Object !!!", type.getName())); | |||
} | |||
return TypedBytesValue.fromInt32((int) value); | |||
return TypedValue.fromInt32((int) value); | |||
} | |||
@Override | |||
@@ -1,6 +1,6 @@ | |||
package com.jd.blockchain.ledger.resolver; | |||
import com.jd.blockchain.ledger.TypedBytesValue; | |||
import com.jd.blockchain.ledger.TypedValue; | |||
import com.jd.blockchain.ledger.BytesValue; | |||
import com.jd.blockchain.ledger.DataType; | |||
import com.jd.blockchain.utils.Bytes; | |||
@@ -21,7 +21,7 @@ public class LongToBytesValueResolver extends AbstractBytesValueResolver { | |||
if (!isSupport(type)) { | |||
throw new IllegalStateException(String.format("Un-support encode Class[%s] Object !!!", type.getName())); | |||
} | |||
return TypedBytesValue.fromInt64((long)value); | |||
return TypedValue.fromInt64((long)value); | |||
} | |||
@Override | |||
@@ -1,6 +1,6 @@ | |||
package com.jd.blockchain.ledger.resolver; | |||
import com.jd.blockchain.ledger.TypedBytesValue; | |||
import com.jd.blockchain.ledger.TypedValue; | |||
import com.jd.blockchain.ledger.BytesValue; | |||
import com.jd.blockchain.ledger.DataType; | |||
import com.jd.blockchain.utils.Bytes; | |||
@@ -21,7 +21,7 @@ public class ShortToBytesValueResolver extends AbstractBytesValueResolver { | |||
if (!isSupport(type)) { | |||
throw new IllegalStateException(String.format("Un-support encode Class[%s] Object !!!", type.getName())); | |||
} | |||
return TypedBytesValue.fromInt16((short)value); | |||
return TypedValue.fromInt16((short)value); | |||
} | |||
@Override | |||
@@ -1,6 +1,6 @@ | |||
package com.jd.blockchain.ledger.resolver; | |||
import com.jd.blockchain.ledger.TypedBytesValue; | |||
import com.jd.blockchain.ledger.TypedValue; | |||
import com.jd.blockchain.ledger.BytesValue; | |||
import com.jd.blockchain.ledger.DataType; | |||
import com.jd.blockchain.utils.Bytes; | |||
@@ -26,10 +26,10 @@ public class StringToBytesValueResolver extends AbstractBytesValueResolver { | |||
// 类型判断 | |||
String valString = (String)value; | |||
if (JSONSerializeUtils.isJSON(valString)) { | |||
return TypedBytesValue.fromJSON(valString); | |||
return TypedValue.fromJSON(valString); | |||
} | |||
// 暂不处理XML格式 | |||
return TypedBytesValue.fromText(valString); | |||
return TypedValue.fromText(valString); | |||
} | |||
@Override | |||
@@ -3,7 +3,7 @@ package com.jd.blockchain.transaction; | |||
import org.springframework.cglib.core.Block; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.ledger.AccountHeader; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.ledger.ContractInfo; | |||
import com.jd.blockchain.ledger.KVDataEntry; | |||
import com.jd.blockchain.ledger.KVInfoVO; | |||
@@ -250,7 +250,7 @@ public interface BlockchainQueryService { | |||
* @param address | |||
* @return | |||
*/ | |||
AccountHeader getDataAccount(HashDigest ledgerHash, String address); | |||
BlockchainIdentity getDataAccount(HashDigest ledgerHash, String address); | |||
/** | |||
* 返回数据账户中指定的键的最新值; <br> | |||
@@ -306,7 +306,7 @@ public interface BlockchainQueryService { | |||
* @param count | |||
* @return | |||
*/ | |||
AccountHeader[] getUsers(HashDigest ledgerHash, int fromIndex, int count); | |||
BlockchainIdentity[] getUsers(HashDigest ledgerHash, int fromIndex, int count); | |||
/** | |||
* get data accounts by ledgerHash and its range; | |||
@@ -316,7 +316,7 @@ public interface BlockchainQueryService { | |||
* @param count | |||
* @return | |||
*/ | |||
AccountHeader[] getDataAccounts(HashDigest ledgerHash, int fromIndex, int count); | |||
BlockchainIdentity[] getDataAccounts(HashDigest ledgerHash, int fromIndex, int count); | |||
/** | |||
* get contract accounts by ledgerHash and its range; | |||
@@ -326,5 +326,5 @@ public interface BlockchainQueryService { | |||
* @param count | |||
* @return | |||
*/ | |||
AccountHeader[] getContractAccounts(HashDigest ledgerHash, int fromIndex, int count); | |||
BlockchainIdentity[] getContractAccounts(HashDigest ledgerHash, int fromIndex, int count); | |||
} |
@@ -1,7 +1,7 @@ | |||
package com.jd.blockchain.transaction; | |||
import com.jd.blockchain.ledger.BytesValue; | |||
import com.jd.blockchain.ledger.TypedBytesValue; | |||
import com.jd.blockchain.ledger.TypedValue; | |||
import com.jd.blockchain.ledger.DataAccountKVSetOperation; | |||
import com.jd.blockchain.utils.Bytes; | |||
@@ -26,14 +26,14 @@ public class DataAccountKVSetOperationBuilderImpl implements DataAccountKVSetOpe | |||
@Override | |||
public DataAccountKVSetOperationBuilder setBytes(String key, byte[] value, long expVersion) { | |||
BytesValue bytesValue = TypedBytesValue.fromBytes(value); | |||
BytesValue bytesValue = TypedValue.fromBytes(value); | |||
operation.set(key, bytesValue, expVersion); | |||
return this; | |||
} | |||
@Override | |||
public DataAccountKVSetOperationBuilder setImage(String key, byte[] value, long expVersion) { | |||
BytesValue bytesValue = TypedBytesValue.fromImage(value); | |||
BytesValue bytesValue = TypedValue.fromImage(value); | |||
operation.set(key, bytesValue, expVersion); | |||
return this; | |||
} | |||
@@ -45,42 +45,42 @@ public class DataAccountKVSetOperationBuilderImpl implements DataAccountKVSetOpe | |||
@Override | |||
public DataAccountKVSetOperationBuilder setText(String key, String value, long expVersion) { | |||
BytesValue bytesValue = TypedBytesValue.fromText(value); | |||
BytesValue bytesValue = TypedValue.fromText(value); | |||
operation.set(key, bytesValue, expVersion); | |||
return this; | |||
} | |||
@Override | |||
public DataAccountKVSetOperationBuilder setBytes(String key, Bytes value, long expVersion) { | |||
BytesValue bytesValue = TypedBytesValue.fromBytes(value); | |||
BytesValue bytesValue = TypedValue.fromBytes(value); | |||
operation.set(key, bytesValue, expVersion); | |||
return this; | |||
} | |||
@Override | |||
public DataAccountKVSetOperationBuilder setInt64(String key, long value, long expVersion) { | |||
BytesValue bytesValue = TypedBytesValue.fromInt64(value); | |||
BytesValue bytesValue = TypedValue.fromInt64(value); | |||
operation.set(key, bytesValue, expVersion); | |||
return this; | |||
} | |||
@Override | |||
public DataAccountKVSetOperationBuilder setJSON(String key, String value, long expVersion) { | |||
BytesValue bytesValue = TypedBytesValue.fromJSON(value); | |||
BytesValue bytesValue = TypedValue.fromJSON(value); | |||
operation.set(key, bytesValue, expVersion); | |||
return this; | |||
} | |||
@Override | |||
public DataAccountKVSetOperationBuilder setXML(String key, String value, long expVersion) { | |||
BytesValue bytesValue = TypedBytesValue.fromXML(value); | |||
BytesValue bytesValue = TypedValue.fromXML(value); | |||
operation.set(key, bytesValue, expVersion); | |||
return this; | |||
} | |||
@Override | |||
public DataAccountKVSetOperationBuilder setTimestamp(String key, long value, long expVersion) { | |||
BytesValue bytesValue = TypedBytesValue.fromTimestamp(value); | |||
BytesValue bytesValue = TypedValue.fromTimestamp(value); | |||
operation.set(key, bytesValue, expVersion); | |||
return this; | |||
} | |||
@@ -16,7 +16,7 @@ import org.junit.Test; | |||
import com.jd.blockchain.binaryproto.BinaryProtocol; | |||
import com.jd.blockchain.binaryproto.DataContractRegistry; | |||
import com.jd.blockchain.ledger.TypedBytesValue; | |||
import com.jd.blockchain.ledger.TypedValue; | |||
import com.jd.blockchain.ledger.BytesDataList; | |||
import com.jd.blockchain.ledger.BytesValueList; | |||
import com.jd.blockchain.ledger.ContractEventSendOperation; | |||
@@ -41,7 +41,7 @@ public class ContractEventSendOpTemplateTest { | |||
DataContractRegistry.register(ContractEventSendOperation.class); | |||
DataContractRegistry.register(Operation.class); | |||
String contractAddress = "zhangsan-address", event = "zhangsan-event"; | |||
BytesValueList args = new BytesDataList(TypedBytesValue.fromText("zhangsan-args")); | |||
BytesValueList args = new BytesDataList(TypedValue.fromText("zhangsan-args")); | |||
data = new ContractEventSendOpTemplate(Bytes.fromString(contractAddress), event, args); | |||
} | |||
@@ -16,7 +16,7 @@ import org.junit.Test; | |||
import com.jd.blockchain.binaryproto.BinaryProtocol; | |||
import com.jd.blockchain.binaryproto.DataContractRegistry; | |||
import com.jd.blockchain.ledger.TypedBytesValue; | |||
import com.jd.blockchain.ledger.TypedValue; | |||
import com.jd.blockchain.ledger.DataAccountKVSetOperation; | |||
import com.jd.blockchain.ledger.Operation; | |||
import com.jd.blockchain.transaction.DataAccountKVSetOpTemplate; | |||
@@ -41,11 +41,11 @@ public class DataAccountKVSetOpTemplateTest { | |||
String accountAddress = "zhangsandhakhdkah"; | |||
data = new DataAccountKVSetOpTemplate(Bytes.fromString(accountAddress)); | |||
KVData kvData1 = | |||
new KVData("test1", TypedBytesValue.fromText("zhangsan"), 9999L); | |||
new KVData("test1", TypedValue.fromText("zhangsan"), 9999L); | |||
KVData kvData2 = | |||
new KVData("test2", TypedBytesValue.fromText("lisi"), 9990L); | |||
new KVData("test2", TypedValue.fromText("lisi"), 9990L); | |||
KVData kvData3 = | |||
new KVData("test3", TypedBytesValue.fromText("wangwu"), 1990L); | |||
new KVData("test3", TypedValue.fromText("wangwu"), 1990L); | |||
data.set(kvData1); | |||
data.set(kvData2); | |||
data.set(kvData3); | |||
@@ -16,7 +16,7 @@ import org.junit.Test; | |||
import com.jd.blockchain.binaryproto.BinaryProtocol; | |||
import com.jd.blockchain.binaryproto.DataContractRegistry; | |||
import com.jd.blockchain.ledger.TypedBytesValue; | |||
import com.jd.blockchain.ledger.TypedValue; | |||
import com.jd.blockchain.ledger.DataAccountKVSetOperation; | |||
import com.jd.blockchain.transaction.DataAccountKVSetOpTemplate; | |||
import com.jd.blockchain.transaction.KVData; | |||
@@ -38,7 +38,7 @@ public class KVDataTest { | |||
byte[] value = "test-value".getBytes(); | |||
long expectedVersion = 9999L; | |||
kvData = new KVData(key, TypedBytesValue.fromBytes(value), expectedVersion); | |||
kvData = new KVData(key, TypedValue.fromBytes(value), expectedVersion); | |||
} | |||
@Test | |||
@@ -326,7 +326,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/accounts/address/{address}") | |||
@Override | |||
public AccountHeader getDataAccount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
public BlockchainIdentity getDataAccount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@PathVariable(name = "address") String address) { | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
@@ -350,11 +350,11 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
KVDataEntry[] entries = new KVDataEntry[keys.length]; | |||
long ver; | |||
for (int i = 0; i < entries.length; i++) { | |||
ver = dataAccount.getDataVersion(Bytes.fromString(keys[i])); | |||
ver = dataAccount.getDataset().getVersion(Bytes.fromString(keys[i])); | |||
if (ver < 0) { | |||
entries[i] = new KVDataObject(keys[i], -1, null); | |||
} else { | |||
BytesValue value = dataAccount.getBytes(Bytes.fromString(keys[i]), ver); | |||
BytesValue value = dataAccount.getDataset().getValue(Bytes.fromString(keys[i]), ver); | |||
entries[i] = new KVDataObject(keys[i], ver, value); | |||
} | |||
} | |||
@@ -405,11 +405,11 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
entries[i] = new KVDataObject(keys[i], -1, null); | |||
} else { | |||
if (dataAccount.getDataEntriesTotalCount() == 0 | |||
|| dataAccount.getBytes(Bytes.fromString(keys[i]), ver) == null) { | |||
|| dataAccount.getDataset().getValue(Bytes.fromString(keys[i]), ver) == null) { | |||
// is the address is not exist; the result is null; | |||
entries[i] = new KVDataObject(keys[i], -1, null); | |||
} else { | |||
BytesValue value = dataAccount.getBytes(Bytes.fromString(keys[i]), ver); | |||
BytesValue value = dataAccount.getDataset().getValue(Bytes.fromString(keys[i]), ver); | |||
entries[i] = new KVDataObject(keys[i], ver, value); | |||
} | |||
} | |||
@@ -468,7 +468,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
*/ | |||
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/users") | |||
@Override | |||
public AccountHeader[] getUsers(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
public BlockchainIdentity[] getUsers(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, | |||
@RequestParam(name = "count", required = false, defaultValue = "-1") int count) { | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
@@ -488,7 +488,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
*/ | |||
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/accounts") | |||
@Override | |||
public AccountHeader[] getDataAccounts(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
public BlockchainIdentity[] getDataAccounts(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, | |||
@RequestParam(name = "count", required = false, defaultValue = "-1") int count) { | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
@@ -500,7 +500,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/contracts") | |||
@Override | |||
public AccountHeader[] getContractAccounts(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
public BlockchainIdentity[] getContractAccounts(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, | |||
@RequestParam(name = "count", required = false, defaultValue = "-1") int count) { | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
@@ -151,7 +151,7 @@ public class ClientResolveUtil { | |||
String realValBase58 = valueObj.getJSONObject("value").getString("value"); | |||
String key = currWriteSetObj.getString("key"); | |||
DataType dataType = DataType.valueOf(typeStr); | |||
BytesValue bytesValue = TypedBytesValue.fromType(dataType, Base58Utils.decode(realValBase58)); | |||
BytesValue bytesValue = TypedValue.fromType(dataType, Base58Utils.decode(realValBase58)); | |||
KVData kvData = new KVData(key, bytesValue, expectedVersion); | |||
kvOperation.set(kvData); | |||
} | |||
@@ -1,7 +1,7 @@ | |||
package com.jd.blockchain.sdk.proxy; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.ledger.AccountHeader; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.ledger.ContractInfo; | |||
import com.jd.blockchain.ledger.KVDataEntry; | |||
import com.jd.blockchain.ledger.KVInfoVO; | |||
@@ -156,7 +156,7 @@ public abstract class BlockchainServiceProxy implements BlockchainService { | |||
} | |||
@Override | |||
public AccountHeader getDataAccount(HashDigest ledgerHash, String address) { | |||
public BlockchainIdentity getDataAccount(HashDigest ledgerHash, String address) { | |||
return getQueryService(ledgerHash).getDataAccount(ledgerHash, address); | |||
} | |||
@@ -189,17 +189,17 @@ public abstract class BlockchainServiceProxy implements BlockchainService { | |||
} | |||
@Override | |||
public AccountHeader[] getUsers(HashDigest ledgerHash, int fromIndex, int count) { | |||
public BlockchainIdentity[] getUsers(HashDigest ledgerHash, int fromIndex, int count) { | |||
return getQueryService(ledgerHash).getUsers(ledgerHash, fromIndex, count); | |||
} | |||
@Override | |||
public AccountHeader[] getDataAccounts(HashDigest ledgerHash, int fromIndex, int count) { | |||
public BlockchainIdentity[] getDataAccounts(HashDigest ledgerHash, int fromIndex, int count) { | |||
return getQueryService(ledgerHash).getDataAccounts(ledgerHash, fromIndex, count); | |||
} | |||
@Override | |||
public AccountHeader[] getContractAccounts(HashDigest ledgerHash, int fromIndex, int count) { | |||
public BlockchainIdentity[] getContractAccounts(HashDigest ledgerHash, int fromIndex, int count) { | |||
return getQueryService(ledgerHash).getContractAccounts(ledgerHash, fromIndex, count); | |||
} | |||
} |
@@ -487,7 +487,7 @@ public interface HttpBlockchainQueryService extends BlockchainExtendQueryService | |||
*/ | |||
@HttpAction(method=HttpMethod.GET, path="ledgers/{ledgerHash}/accounts/address/{address}") | |||
@Override | |||
AccountHeader getDataAccount(@PathParam(name="ledgerHash", converter=HashDigestToStringConverter.class) HashDigest ledgerHash, | |||
BlockchainIdentity getDataAccount(@PathParam(name="ledgerHash", converter=HashDigestToStringConverter.class) HashDigest ledgerHash, | |||
@PathParam(name="address") String address); | |||
/** | |||
@@ -569,7 +569,7 @@ public interface HttpBlockchainQueryService extends BlockchainExtendQueryService | |||
*/ | |||
@HttpAction(method = HttpMethod.GET, path = "ledgers/{ledgerHash}/users") | |||
@Override | |||
AccountHeader[] getUsers(@PathParam(name="ledgerHash", converter=HashDigestToStringConverter.class) HashDigest ledgerHash, | |||
BlockchainIdentity[] getUsers(@PathParam(name="ledgerHash", converter=HashDigestToStringConverter.class) HashDigest ledgerHash, | |||
@RequestParam(name="fromIndex", required = false) int fromIndex, | |||
@RequestParam(name="count", required = false) int count); | |||
@@ -582,7 +582,7 @@ public interface HttpBlockchainQueryService extends BlockchainExtendQueryService | |||
*/ | |||
@HttpAction(method = HttpMethod.GET, path = "ledgers/{ledgerHash}/accounts") | |||
@Override | |||
AccountHeader[] getDataAccounts(@PathParam(name="ledgerHash", converter=HashDigestToStringConverter.class) HashDigest ledgerHash, | |||
BlockchainIdentity[] getDataAccounts(@PathParam(name="ledgerHash", converter=HashDigestToStringConverter.class) HashDigest ledgerHash, | |||
@RequestParam(name="fromIndex", required = false) int fromIndex, | |||
@RequestParam(name="count", required = false) int count); | |||
@@ -595,7 +595,7 @@ public interface HttpBlockchainQueryService extends BlockchainExtendQueryService | |||
*/ | |||
@HttpAction(method = HttpMethod.GET, path = "ledgers/{ledgerHash}/contracts") | |||
@Override | |||
AccountHeader[] getContractAccounts(@PathParam(name="ledgerHash", converter=HashDigestToStringConverter.class) HashDigest ledgerHash, | |||
BlockchainIdentity[] getContractAccounts(@PathParam(name="ledgerHash", converter=HashDigestToStringConverter.class) HashDigest ledgerHash, | |||
@RequestParam(name="fromIndex", required = false) int fromIndex, | |||
@RequestParam(name="count", required = false) int count); | |||
@@ -19,7 +19,7 @@ import com.jd.blockchain.crypto.HashFunction; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.crypto.SignatureDigest; | |||
import com.jd.blockchain.crypto.SignatureFunction; | |||
import com.jd.blockchain.ledger.AccountHeader; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.ledger.BlockchainKeyGenerator; | |||
import com.jd.blockchain.ledger.BlockchainKeypair; | |||
import com.jd.blockchain.ledger.DigitalSignature; | |||
@@ -98,7 +98,7 @@ public class SDK_GateWay_Query_Test_ { | |||
System.out.println("contractCount=" + count); | |||
count = service.getContractCount(ledgerHash, hashDigest); | |||
System.out.println("contractCount=" + count); | |||
AccountHeader contract = service.getContract(ledgerHash, "12345678"); | |||
BlockchainIdentity contract = service.getContract(ledgerHash, "12345678"); | |||
System.out.println(contract); | |||
LedgerBlock block = service.getBlock(ledgerHash, hashDigest); | |||
@@ -109,7 +109,7 @@ public class SDK_GateWay_Query_Test_ { | |||
count = service.getDataAccountCount(ledgerHash, hashDigest); | |||
System.out.println("dataAccountCount=" + count); | |||
AccountHeader dataAccount = service.getDataAccount(ledgerHash, "1245633"); | |||
BlockchainIdentity dataAccount = service.getDataAccount(ledgerHash, "1245633"); | |||
System.out.println(dataAccount.getAddress()); | |||
count = service.getTransactionCount(ledgerHash, hashDigest); | |||
@@ -21,7 +21,7 @@ import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.gateway.GatewayConfigProperties.KeyPairConfig; | |||
import com.jd.blockchain.ledger.AccountHeader; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.ledger.BlockchainKeyGenerator; | |||
import com.jd.blockchain.ledger.BlockchainKeypair; | |||
import com.jd.blockchain.ledger.BytesValue; | |||
@@ -420,7 +420,7 @@ public class IntegrationTest { | |||
UserInfo userInfo = blockchainService.getUser(ledgerHash, userAddress.toString()); | |||
// getDataAccount | |||
AccountHeader accountHeader = blockchainService.getDataAccount(ledgerHash, dataAddress.toString()); | |||
BlockchainIdentity accountHeader = blockchainService.getDataAccount(ledgerHash, dataAddress.toString()); | |||
// getDataEntries | |||
@@ -660,9 +660,9 @@ public class IntegrationTest { | |||
LedgerQuery ledgerOfNode0 = node0.getLedgerManager().getLedger(ledgerHash); | |||
LedgerBlock block = ledgerOfNode0.getBlock(txResp.getBlockHeight()); | |||
BytesValue val1InDb = ledgerOfNode0.getDataAccountSet(block).getAccount(contractDataKey.getAddress()) | |||
.getBytes("A"); | |||
.getDataset().getValue("A"); | |||
BytesValue val2InDb = ledgerOfNode0.getDataAccountSet(block).getAccount(contractDataKey.getAddress()) | |||
.getBytes(KEY_TOTAL); | |||
.getDataset().getValue(KEY_TOTAL); | |||
} | |||
/** | |||
@@ -14,6 +14,7 @@ import com.jd.blockchain.storage.service.ExPolicyKVStorage; | |||
import com.jd.blockchain.storage.service.VersioningKVStorage; | |||
import com.jd.blockchain.storage.service.impl.redis.RedisConnectionFactory; | |||
import com.jd.blockchain.storage.service.utils.MemoryKVStorage; | |||
import com.jd.blockchain.utils.Bytes; | |||
public class MerkleDatasetPerformanceTester { | |||
@@ -156,12 +157,12 @@ public class MerkleDatasetPerformanceTester { | |||
for (int i = 0; i < round; i++) { | |||
for (int j = 0; j < batchCount; j++) { | |||
key = "data_" + startTs + "_" + randomId + "_" + (i * batchCount + j); | |||
long v = mds.getVersion(key); | |||
mds.setValue(key, data, v); | |||
long v = mds.getVersion(Bytes.fromString(key)); | |||
mds.setValue(Bytes.fromString(key), data, v); | |||
} | |||
mds.commit(); | |||
rootHash = mds.getRootHash(); | |||
mds = new MerkleDataSet(rootHash, cryptoConfig, MKL_KEY_PREFIX, exStorage, verStorage, false); | |||
mds = new MerkleDataSet(rootHash, cryptoConfig, Bytes.fromString(MKL_KEY_PREFIX), exStorage, verStorage, false); | |||
} | |||
long elapsedTs = System.currentTimeMillis() - startTs; | |||