# Conflicts: # source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/handles/ContractCodeDeployOperationHandle.java # source/tools/tools-mocker/src/main/java/com/jd/blockchain/mocker/MockerNodeContext.javatags/1.1.0
@@ -6,19 +6,20 @@ import java.util.List; | |||
import java.util.Map; | |||
import java.util.concurrent.ConcurrentHashMap; | |||
import com.jd.blockchain.ledger.core.handles.*; | |||
import org.springframework.stereotype.Component; | |||
import com.jd.blockchain.ledger.LedgerException; | |||
import com.jd.blockchain.ledger.Operation; | |||
import com.jd.blockchain.transaction.ContractCodeDeployOpTemplate; | |||
import com.jd.blockchain.transaction.ContractEventSendOpTemplate; | |||
import com.jd.blockchain.transaction.DataAccountKVSetOpTemplate; | |||
import com.jd.blockchain.transaction.DataAccountRegisterOpTemplate; | |||
import com.jd.blockchain.transaction.LedgerInitOpTemplate; | |||
import com.jd.blockchain.transaction.RolesConfigureOpTemplate; | |||
import com.jd.blockchain.transaction.UserAuthorizeOpTemplate; | |||
import com.jd.blockchain.transaction.UserRegisterOpTemplate; | |||
import com.jd.blockchain.ledger.core.handles.ContractCodeDeployOperationHandle; | |||
import com.jd.blockchain.ledger.core.handles.DataAccountKVSetOperationHandle; | |||
import com.jd.blockchain.ledger.core.handles.DataAccountRegisterOperationHandle; | |||
import com.jd.blockchain.ledger.core.handles.JVMContractEventSendOperationHandle; | |||
import com.jd.blockchain.ledger.core.handles.LedgerInitOperationHandle; | |||
import com.jd.blockchain.ledger.core.handles.ParticipantRegisterOperationHandle; | |||
import com.jd.blockchain.ledger.core.handles.ParticipantStateUpdateOperationHandle; | |||
import com.jd.blockchain.ledger.core.handles.RolesConfigureOperationHandle; | |||
import com.jd.blockchain.ledger.core.handles.UserAuthorizeOperationHandle; | |||
import com.jd.blockchain.ledger.core.handles.UserRegisterOperationHandle; | |||
@Component | |||
public class DefaultOperationHandleRegisteration implements OperationHandleRegisteration { | |||
@@ -118,12 +119,4 @@ public class DefaultOperationHandleRegisteration implements OperationHandleRegis | |||
} | |||
return hdl; | |||
} | |||
private static class OpHandleStub { | |||
private Class<? extends Operation> operationType; | |||
private OperationHandle operationHandle; | |||
} | |||
} |
@@ -5,7 +5,9 @@ import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.SignatureDigest; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.ledger.BlockchainIdentityData; | |||
import com.jd.blockchain.ledger.BlockchainKeypair; | |||
import com.jd.blockchain.ledger.DigitalSignature; | |||
import com.jd.blockchain.ledger.LedgerAdminInfo; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
import com.jd.blockchain.ledger.LedgerInitException; | |||
import com.jd.blockchain.ledger.LedgerInitOperation; | |||
@@ -29,12 +31,14 @@ import com.jd.blockchain.transaction.TxRequestBuilder; | |||
public class LedgerInitializer { | |||
private static final FullPermissionedSecurityManager FULL_PERMISSION_SECURITY_MANAGER = new FullPermissionedSecurityManager(); | |||
private static final LedgerQuery EMPTY_LEDGER =new EmptyLedgerQuery(); | |||
private static final LedgerDataQuery EMPTY_LEDGER_DATA_QUERY = new EmptyLedgerDataset(); | |||
private static final OperationHandleRegisteration DEFAULT_OP_HANDLE_REG = new DefaultOperationHandleRegisteration(); | |||
private LedgerService EMPTY_LEDGERS = new LedgerManager(); | |||
// private LedgerService EMPTY_LEDGERS = new LedgerManager(); | |||
private LedgerInitSetting initSetting; | |||
@@ -75,15 +79,6 @@ public class LedgerInitializer { | |||
return initTxContent; | |||
} | |||
private static SecurityInitSettings createDefaultSecurityInitSettings() { | |||
// TODO throw new IllegalStateException("Not implemented!"); | |||
return null; | |||
} | |||
// public static LedgerInitializer create(LedgerInitSetting initSetting) { | |||
// return create(initSetting, createDefaultSecurityInitSettings()); | |||
// } | |||
public static LedgerInitializer create(LedgerInitSetting initSetting, SecurityInitSettings securityInitSettings) { | |||
// 生成创世交易; | |||
TransactionContent initTxContent = buildGenesisTransaction(initSetting, securityInitSettings); | |||
@@ -143,6 +138,10 @@ public class LedgerInitializer { | |||
public SignatureDigest signTransaction(PrivKey privKey) { | |||
return SignatureUtils.sign(initTxContent, privKey); | |||
} | |||
public DigitalSignature signTransaction(BlockchainKeypair key) { | |||
return SignatureUtils.sign(initTxContent, key); | |||
} | |||
/** | |||
* 准备创建账本; | |||
@@ -204,12 +203,103 @@ public class LedgerInitializer { | |||
TransactionRequest txRequest = txReqBuilder.buildRequest(); | |||
TransactionBatchProcessor txProcessor = new TransactionBatchProcessor(FULL_PERMISSION_SECURITY_MANAGER, | |||
ledgerEditor, EMPTY_LEDGER_DATA_QUERY, DEFAULT_OP_HANDLE_REG, EMPTY_LEDGERS); | |||
ledgerEditor, EMPTY_LEDGER, DEFAULT_OP_HANDLE_REG); | |||
txProcessor.schedule(txRequest); | |||
txResultsHandle = txProcessor.prepare(); | |||
return txResultsHandle.getBlock(); | |||
} | |||
private static class EmptyLedgerQuery implements LedgerQuery{ | |||
private EmptyLedgerDataset dataset; | |||
@Override | |||
public HashDigest getHash() { | |||
return null; | |||
} | |||
@Override | |||
public long getLatestBlockHeight() { | |||
return 0; | |||
} | |||
@Override | |||
public HashDigest getLatestBlockHash() { | |||
return null; | |||
} | |||
@Override | |||
public LedgerBlock getLatestBlock() { | |||
return null; | |||
} | |||
@Override | |||
public HashDigest getBlockHash(long height) { | |||
return null; | |||
} | |||
@Override | |||
public LedgerBlock getBlock(long height) { | |||
return null; | |||
} | |||
@Override | |||
public LedgerAdminInfo getAdminInfo() { | |||
return null; | |||
} | |||
@Override | |||
public LedgerAdminInfo getAdminInfo(LedgerBlock block) { | |||
return null; | |||
} | |||
@Override | |||
public LedgerBlock getBlock(HashDigest hash) { | |||
return null; | |||
} | |||
@Override | |||
public LedgerDataQuery getDataSet(LedgerBlock block) { | |||
return dataset; | |||
} | |||
@Override | |||
public TransactionSet getTransactionSet(LedgerBlock block) { | |||
return null; | |||
} | |||
@Override | |||
public UserAccountQuery getUserAccountSet(LedgerBlock block) { | |||
return dataset.getUserAccountSet(); | |||
} | |||
@Override | |||
public DataAccountQuery getDataAccountSet(LedgerBlock block) { | |||
return dataset.getDataAccountSet(); | |||
} | |||
@Override | |||
public ContractAccountQuery getContractAccountSet(LedgerBlock block) { | |||
return dataset.getContractAccountset(); | |||
} | |||
@Override | |||
public LedgerBlock retrieveLatestBlock() { | |||
return null; | |||
} | |||
@Override | |||
public long retrieveLatestBlockHeight() { | |||
return 0; | |||
} | |||
@Override | |||
public HashDigest retrieveLatestBlockHash() { | |||
return null; | |||
} | |||
} | |||
} |
@@ -1,7 +1,6 @@ | |||
package com.jd.blockchain.ledger.core; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.ledger.LedgerInitSetting; | |||
import com.jd.blockchain.storage.service.KVStorageService; | |||
/** | |||
@@ -14,7 +13,7 @@ public interface LedgerManage extends LedgerService { | |||
static final String LEDGER_PREFIX = "LDG://"; | |||
LedgerRepository register(HashDigest ledgerHash, KVStorageService storageService); | |||
LedgerQuery register(HashDigest ledgerHash, KVStorageService storageService); | |||
void unregister(HashDigest ledgerHash); | |||
@@ -22,14 +22,6 @@ import com.jd.blockchain.utils.codec.Base58Utils; | |||
*/ | |||
public class LedgerManager implements LedgerManage { | |||
// @Autowired | |||
// private ExistentialKVStorage exPolicyStorage; | |||
// | |||
// @Autowired | |||
// private VersioningKVStorage versioningStorage; | |||
// private PrivilegeModelSetting privilegeModel = new PrivilegeModelConfig(); | |||
private Map<HashDigest, LedgerRepositoryContext> ledgers = new HashMap<>(); | |||
@Override | |||
@@ -158,6 +150,7 @@ public class LedgerManager implements LedgerManage { | |||
public final LedgerRepository ledgerRepo; | |||
@SuppressWarnings("unused") | |||
public final KVStorageService storageService; | |||
public LedgerRepositoryContext(LedgerRepository ledgerRepo, KVStorageService storageService) { | |||
@@ -0,0 +1,112 @@ | |||
package com.jd.blockchain.ledger.core; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.ledger.LedgerAdminInfo; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
public interface LedgerQuery { | |||
/** | |||
* 账本哈希,这是账本的唯一标识; | |||
* | |||
* @return | |||
*/ | |||
HashDigest getHash(); | |||
/** | |||
* 最新区块高度; | |||
* | |||
* @return | |||
*/ | |||
long getLatestBlockHeight(); | |||
/** | |||
* 最新区块哈希; | |||
* | |||
* @return | |||
*/ | |||
HashDigest getLatestBlockHash(); | |||
/** | |||
* 最新区块; | |||
* | |||
* @return | |||
*/ | |||
LedgerBlock getLatestBlock(); | |||
/** | |||
* 指定高度的区块哈希; | |||
* | |||
* @param height | |||
* @return | |||
*/ | |||
HashDigest getBlockHash(long height); | |||
/** | |||
* 指定高度的区块; | |||
* | |||
* @param height | |||
* @return | |||
*/ | |||
LedgerBlock getBlock(long height); | |||
LedgerAdminInfo getAdminInfo(); | |||
LedgerAdminInfo getAdminInfo(LedgerBlock block); | |||
LedgerBlock getBlock(HashDigest hash); | |||
LedgerDataQuery getDataSet(LedgerBlock block); | |||
TransactionSet getTransactionSet(LedgerBlock block); | |||
UserAccountQuery getUserAccountSet(LedgerBlock block); | |||
DataAccountQuery getDataAccountSet(LedgerBlock block); | |||
ContractAccountQuery getContractAccountSet(LedgerBlock block); | |||
default LedgerDataQuery getDataSet() { | |||
return getDataSet(getLatestBlock()); | |||
} | |||
default TransactionSet getTransactionSet() { | |||
return getTransactionSet(getLatestBlock()); | |||
} | |||
default UserAccountQuery getUserAccountSet() { | |||
return getUserAccountSet(getLatestBlock()); | |||
} | |||
default DataAccountQuery getDataAccountSet() { | |||
return getDataAccountSet(getLatestBlock()); | |||
} | |||
default ContractAccountQuery getContractAccountset() { | |||
return getContractAccountSet(getLatestBlock()); | |||
} | |||
/** | |||
* 重新检索最新区块,同时更新缓存; | |||
* | |||
* @return | |||
*/ | |||
LedgerBlock retrieveLatestBlock(); | |||
/** | |||
* 重新检索最新区块,同时更新缓存; | |||
* | |||
* @return | |||
*/ | |||
long retrieveLatestBlockHeight(); | |||
/** | |||
* 重新检索最新区块哈希,同时更新缓存; | |||
* | |||
* @return | |||
*/ | |||
HashDigest retrieveLatestBlockHash(); | |||
} |
@@ -14,6 +14,7 @@ import com.jd.blockchain.ledger.KVDataVO; | |||
import com.jd.blockchain.ledger.KVInfoVO; | |||
import com.jd.blockchain.ledger.LedgerAdminInfo; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
import com.jd.blockchain.ledger.LedgerException; | |||
import com.jd.blockchain.ledger.LedgerInfo; | |||
import com.jd.blockchain.ledger.LedgerMetadata; | |||
import com.jd.blockchain.ledger.LedgerTransaction; | |||
@@ -27,21 +28,30 @@ import com.jd.blockchain.utils.QueryUtil; | |||
public class LedgerQueryService implements BlockchainQueryService { | |||
private static final KVDataEntry[] EMPTY_ENTRIES = new KVDataEntry[0]; | |||
private HashDigest[] ledgerHashs; | |||
private LedgerService ledgerService; | |||
private LedgerQuery ledger; | |||
public LedgerQueryService(LedgerService ledgerService) { | |||
this.ledgerService = ledgerService; | |||
public LedgerQueryService(LedgerQuery ledger) { | |||
this.ledger = ledger; | |||
this.ledgerHashs = new HashDigest[] {ledger.getHash()}; | |||
} | |||
private void checkLedgerHash(HashDigest ledgerHash) { | |||
if (!ledgerHashs[0].equals(ledgerHash)) { | |||
throw new LedgerException("Unsupport cross chain query!"); | |||
} | |||
} | |||
@Override | |||
public HashDigest[] getLedgerHashs() { | |||
return ledgerService.getLedgerHashs(); | |||
return ledgerHashs; | |||
} | |||
@Override | |||
public LedgerInfo getLedger(HashDigest ledgerHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerInfo ledgerInfo = new LedgerInfo(); | |||
ledgerInfo.setHash(ledger.getHash()); | |||
ledgerInfo.setLatestBlockHash(ledger.getLatestBlockHash()); | |||
@@ -51,7 +61,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public LedgerAdminInfo getLedgerAdminInfo(HashDigest ledgerHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
LedgerAdminInfo administration = ledger.getAdminInfo(block); | |||
return administration; | |||
@@ -69,19 +79,19 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public LedgerBlock getBlock(HashDigest ledgerHash, long height) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
return ledger.getBlock(height); | |||
} | |||
@Override | |||
public LedgerBlock getBlock(HashDigest ledgerHash, HashDigest blockHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
return ledger.getBlock(blockHash); | |||
} | |||
@Override | |||
public long getTransactionCount(HashDigest ledgerHash, long height) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getBlock(height); | |||
TransactionSet txset = ledger.getTransactionSet(block); | |||
return txset.getTotalCount(); | |||
@@ -89,7 +99,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public long getTransactionCount(HashDigest ledgerHash, HashDigest blockHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getBlock(blockHash); | |||
TransactionSet txset = ledger.getTransactionSet(block); | |||
return txset.getTotalCount(); | |||
@@ -97,7 +107,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public long getTransactionTotalCount(HashDigest ledgerHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
TransactionSet txset = ledger.getTransactionSet(block); | |||
return txset.getTotalCount(); | |||
@@ -105,7 +115,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public long getDataAccountCount(HashDigest ledgerHash, long height) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getBlock(height); | |||
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); | |||
return dataAccountSet.getTotalCount(); | |||
@@ -113,7 +123,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public long getDataAccountCount(HashDigest ledgerHash, HashDigest blockHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getBlock(blockHash); | |||
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); | |||
return dataAccountSet.getTotalCount(); | |||
@@ -121,7 +131,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public long getDataAccountTotalCount(HashDigest ledgerHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); | |||
return dataAccountSet.getTotalCount(); | |||
@@ -129,7 +139,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public long getUserCount(HashDigest ledgerHash, long height) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getBlock(height); | |||
UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); | |||
return userAccountSet.getTotalCount(); | |||
@@ -137,7 +147,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public long getUserCount(HashDigest ledgerHash, HashDigest blockHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getBlock(blockHash); | |||
UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); | |||
return userAccountSet.getTotalCount(); | |||
@@ -145,7 +155,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public long getUserTotalCount(HashDigest ledgerHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); | |||
return userAccountSet.getTotalCount(); | |||
@@ -153,7 +163,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public long getContractCount(HashDigest ledgerHash, long height) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getBlock(height); | |||
ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); | |||
return contractAccountSet.getTotalCount(); | |||
@@ -161,7 +171,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public long getContractCount(HashDigest ledgerHash, HashDigest blockHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getBlock(blockHash); | |||
ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); | |||
return contractAccountSet.getTotalCount(); | |||
@@ -169,7 +179,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public long getContractTotalCount(HashDigest ledgerHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); | |||
return contractAccountSet.getTotalCount(); | |||
@@ -177,7 +187,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public LedgerTransaction[] getTransactions(HashDigest ledgerHash, long height, int fromIndex, int count) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock ledgerBlock = ledger.getBlock(height); | |||
TransactionSet transactionSet = ledger.getTransactionSet(ledgerBlock); | |||
int lastHeightTxTotalNums = 0; | |||
@@ -206,7 +216,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public LedgerTransaction[] getTransactions(HashDigest ledgerHash, HashDigest blockHash, int fromIndex, int count) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock ledgerBlock = ledger.getBlock(blockHash); | |||
long height = ledgerBlock.getHeight(); | |||
TransactionSet transactionSet = ledger.getTransactionSet(ledgerBlock); | |||
@@ -236,7 +246,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public LedgerTransaction getTransactionByContentHash(HashDigest ledgerHash, HashDigest contentHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
TransactionSet txset = ledger.getTransactionSet(block); | |||
return txset.get(contentHash); | |||
@@ -244,7 +254,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public TransactionState getTransactionStateByContentHash(HashDigest ledgerHash, HashDigest contentHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
TransactionSet txset = ledger.getTransactionSet(block); | |||
return txset.getTxState(contentHash); | |||
@@ -252,7 +262,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public UserInfo getUser(HashDigest ledgerHash, String address) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); | |||
return userAccountSet.getUser(address); | |||
@@ -261,7 +271,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public AccountHeader getDataAccount(HashDigest ledgerHash, String address) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); | |||
return dataAccountSet.getDataAccount(Bytes.fromBase58(address)); | |||
@@ -272,7 +282,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
if (keys == null || keys.length == 0) { | |||
return EMPTY_ENTRIES; | |||
} | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); | |||
DataAccount dataAccount = dataAccountSet.getDataAccount(Bytes.fromBase58(address)); | |||
@@ -320,7 +330,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
throw new ContractException("keys.length!=versions.length!"); | |||
} | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); | |||
DataAccount dataAccount = dataAccountSet.getDataAccount(Bytes.fromBase58(address)); | |||
@@ -350,8 +360,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public KVDataEntry[] getDataEntries(HashDigest ledgerHash, String address, int fromIndex, int count) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); | |||
DataAccount dataAccount = dataAccountSet.getDataAccount(Bytes.fromBase58(address)); | |||
@@ -362,8 +371,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public long getDataEntriesTotalCount(HashDigest ledgerHash, String address) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); | |||
DataAccount dataAccount = dataAccountSet.getDataAccount(Bytes.fromBase58(address)); | |||
@@ -373,7 +381,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public ContractInfo getContract(HashDigest ledgerHash, String address) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); | |||
return contractAccountSet.getContract(Bytes.fromBase58(address)); | |||
@@ -381,7 +389,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public AccountHeader[] getUsers(HashDigest ledgerHash, int fromIndex, int count) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); | |||
int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) userAccountSet.getTotalCount()); | |||
@@ -390,7 +398,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public AccountHeader[] getDataAccounts(HashDigest ledgerHash, int fromIndex, int count) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); | |||
int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) dataAccountSet.getTotalCount()); | |||
@@ -399,7 +407,7 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
@Override | |||
public AccountHeader[] getContractAccounts(HashDigest ledgerHash, int fromIndex, int count) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
checkLedgerHash(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); | |||
int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) contractAccountSet.getTotalCount()); | |||
@@ -2,112 +2,8 @@ package com.jd.blockchain.ledger.core; | |||
import java.io.Closeable; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.ledger.LedgerAdminInfo; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
public interface LedgerRepository extends Closeable, LedgerQuery { | |||
public interface LedgerRepository extends Closeable { | |||
/** | |||
* 账本哈希,这是账本的唯一标识; | |||
* | |||
* @return | |||
*/ | |||
HashDigest getHash(); | |||
/** | |||
* 最新区块高度; | |||
* | |||
* @return | |||
*/ | |||
long getLatestBlockHeight(); | |||
/** | |||
* 最新区块哈希; | |||
* | |||
* @return | |||
*/ | |||
HashDigest getLatestBlockHash(); | |||
/** | |||
* 最新区块; | |||
* | |||
* @return | |||
*/ | |||
LedgerBlock getLatestBlock(); | |||
/** | |||
* 指定高度的区块哈希; | |||
* | |||
* @param height | |||
* @return | |||
*/ | |||
HashDigest getBlockHash(long height); | |||
/** | |||
* 指定高度的区块; | |||
* | |||
* @param height | |||
* @return | |||
*/ | |||
LedgerBlock getBlock(long height); | |||
LedgerAdminInfo getAdminInfo(); | |||
LedgerAdminInfo getAdminInfo(LedgerBlock block); | |||
LedgerBlock getBlock(HashDigest hash); | |||
LedgerDataQuery getDataSet(LedgerBlock block); | |||
TransactionSet getTransactionSet(LedgerBlock block); | |||
UserAccountQuery getUserAccountSet(LedgerBlock block); | |||
DataAccountQuery getDataAccountSet(LedgerBlock block); | |||
ContractAccountQuery getContractAccountSet(LedgerBlock block); | |||
default LedgerDataQuery getDataSet() { | |||
return getDataSet(getLatestBlock()); | |||
} | |||
default TransactionSet getTransactionSet() { | |||
return getTransactionSet(getLatestBlock()); | |||
} | |||
default UserAccountQuery getUserAccountSet() { | |||
return getUserAccountSet(getLatestBlock()); | |||
} | |||
default DataAccountQuery getDataAccountSet() { | |||
return getDataAccountSet(getLatestBlock()); | |||
} | |||
default ContractAccountQuery getContractAccountSet() { | |||
return getContractAccountSet(getLatestBlock()); | |||
} | |||
/** | |||
* 重新检索最新区块,同时更新缓存; | |||
* | |||
* @return | |||
*/ | |||
LedgerBlock retrieveLatestBlock(); | |||
/** | |||
* 重新检索最新区块,同时更新缓存; | |||
* | |||
* @return | |||
*/ | |||
long retrieveLatestBlockHeight(); | |||
/** | |||
* 重新检索最新区块哈希,同时更新缓存; | |||
* | |||
* @return | |||
*/ | |||
HashDigest retrieveLatestBlockHash(); | |||
/** | |||
* 创建新区块的编辑器; | |||
@@ -27,6 +27,6 @@ public interface OperationHandle { | |||
* @return | |||
*/ | |||
BytesValue process(Operation op, LedgerDataset newBlockDataset, TransactionRequestExtension requestContext, | |||
LedgerDataQuery previousBlockDataset, OperationHandleContext handleContext, LedgerService ledgerService); | |||
LedgerQuery ledger, OperationHandleContext handleContext); | |||
} |
@@ -42,13 +42,11 @@ public class TransactionBatchProcessor implements TransactionBatchProcess { | |||
private LedgerSecurityManager securityManager; | |||
private LedgerService ledgerService; | |||
private LedgerEditor newBlockEditor; | |||
private LedgerDataQuery ledgerQueryer; | |||
private LedgerQuery ledger; | |||
private OperationHandleRegisteration opHandles; | |||
private OperationHandleRegisteration handlesRegisteration; | |||
// 新创建的交易; | |||
private LedgerBlock block; | |||
@@ -59,18 +57,53 @@ public class TransactionBatchProcessor implements TransactionBatchProcess { | |||
private TransactionBatchResult batchResult; | |||
public HashDigest getLedgerHash() { | |||
return ledger.getHash(); | |||
} | |||
/** | |||
* @param newBlockEditor 新区块的数据编辑器; | |||
* @param ledgerQueryer 账本查询器,只包含新区块的前一个区块的数据集;即未提交新区块之前的经过共识的账本最新数据集; | |||
* @param opHandles 操作处理对象注册表; | |||
*/ | |||
public TransactionBatchProcessor(LedgerSecurityManager securityManager, LedgerEditor newBlockEditor, | |||
LedgerDataQuery ledgerQueryer, OperationHandleRegisteration opHandles, LedgerService ledgerService) { | |||
LedgerQuery ledger, OperationHandleRegisteration opHandles) { | |||
this.securityManager = securityManager; | |||
this.newBlockEditor = newBlockEditor; | |||
this.ledgerQueryer = ledgerQueryer; | |||
this.opHandles = opHandles; | |||
this.ledgerService = ledgerService; | |||
this.ledger = ledger; | |||
this.handlesRegisteration = opHandles; | |||
} | |||
public TransactionBatchProcessor(LedgerRepository ledgerRepo, OperationHandleRegisteration handlesRegisteration) { | |||
this.ledger = ledgerRepo; | |||
this.handlesRegisteration = handlesRegisteration; | |||
LedgerBlock ledgerBlock = ledgerRepo.getLatestBlock(); | |||
LedgerDataQuery ledgerDataQuery = ledgerRepo.getDataSet(ledgerBlock); | |||
LedgerAdminDataQuery previousAdminDataset = ledgerDataQuery.getAdminDataset(); | |||
this.securityManager = new LedgerSecurityManagerImpl(previousAdminDataset.getAdminInfo().getRolePrivileges(), | |||
previousAdminDataset.getAdminInfo().getUserRoles(), previousAdminDataset.getParticipantDataset(), | |||
ledgerDataQuery.getUserAccountSet()); | |||
this.newBlockEditor = ledgerRepo.createNextBlock(); | |||
} | |||
public static TransactionBatchProcess create(LedgerRepository ledgerRepo, | |||
OperationHandleRegisteration handlesRegisteration) { | |||
LedgerBlock ledgerBlock = ledgerRepo.getLatestBlock(); | |||
LedgerEditor newBlockEditor = ledgerRepo.createNextBlock(); | |||
LedgerDataQuery previousBlockDataset = ledgerRepo.getDataSet(ledgerBlock); | |||
LedgerAdminDataQuery previousAdminDataset = previousBlockDataset.getAdminDataset(); | |||
LedgerSecurityManager securityManager = new LedgerSecurityManagerImpl( | |||
previousAdminDataset.getAdminInfo().getRolePrivileges(), | |||
previousAdminDataset.getAdminInfo().getUserRoles(), previousAdminDataset.getParticipantDataset(), | |||
previousBlockDataset.getUserAccountSet()); | |||
TransactionBatchProcessor processor = new TransactionBatchProcessor(securityManager, newBlockEditor, ledgerRepo, | |||
handlesRegisteration); | |||
return processor; | |||
} | |||
/* | |||
@@ -228,16 +261,15 @@ public class TransactionBatchProcessor implements TransactionBatchProcess { | |||
public void handle(Operation operation) { | |||
// assert; Instance of operation are one of User related operations or | |||
// DataAccount related operations; | |||
OperationHandle hdl = opHandles.getHandle(operation.getClass()); | |||
hdl.process(operation, dataset, request, ledgerQueryer, this, ledgerService); | |||
OperationHandle hdl = handlesRegisteration.getHandle(operation.getClass()); | |||
hdl.process(operation, dataset, request, ledger, this); | |||
} | |||
}; | |||
OperationHandle opHandle; | |||
int opIndex = 0; | |||
for (Operation op : ops) { | |||
opHandle = opHandles.getHandle(op.getClass()); | |||
BytesValue opResult = opHandle.process(op, dataset, request, ledgerQueryer, handleContext, | |||
ledgerService); | |||
opHandle = handlesRegisteration.getHandle(op.getClass()); | |||
BytesValue opResult = opHandle.process(op, dataset, request, ledger, handleContext); | |||
if (opResult != null) { | |||
operationResults.add(new OperationResultData(opIndex, opResult)); | |||
} | |||
@@ -335,8 +367,8 @@ public class TransactionBatchProcessor implements TransactionBatchProcess { | |||
if (batchResult != null) { | |||
throw new IllegalStateException("Batch result has already been prepared or canceled!"); | |||
} | |||
block = newBlockEditor.prepare(); | |||
batchResult = new TransactionBatchResultHandleImpl(); | |||
this.block = newBlockEditor.prepare(); | |||
this.batchResult = new TransactionBatchResultHandleImpl(); | |||
return (TransactionBatchResultHandle) batchResult; | |||
} | |||
@@ -361,10 +393,12 @@ public class TransactionBatchProcessor implements TransactionBatchProcess { | |||
@Override | |||
public long blockHeight() { | |||
if (block != null) { | |||
return block.getHeight(); | |||
} | |||
return 0; | |||
// if (block != null) { | |||
// return block.getHeight(); | |||
// } | |||
// return 0; | |||
return ledger.getLatestBlockHeight(); | |||
} | |||
private void commitSuccess() { | |||
@@ -6,7 +6,6 @@ import java.util.concurrent.ConcurrentHashMap; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
import com.jd.blockchain.service.TransactionBatchProcess; | |||
import com.jd.blockchain.service.TransactionEngine; | |||
@@ -38,17 +37,8 @@ public class TransactionEngineImpl implements TransactionEngine { | |||
LedgerRepository ledgerRepo = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock ledgerBlock = ledgerRepo.getLatestBlock(); | |||
LedgerEditor newBlockEditor = ledgerRepo.createNextBlock(); | |||
LedgerDataQuery previousBlockDataset = ledgerRepo.getDataSet(ledgerBlock); | |||
LedgerAdminDataQuery previousAdminDataset = previousBlockDataset.getAdminDataset(); | |||
LedgerSecurityManager securityManager = new LedgerSecurityManagerImpl( | |||
previousAdminDataset.getAdminInfo().getRolePrivileges(), | |||
previousAdminDataset.getAdminInfo().getUserRoles(), previousAdminDataset.getParticipantDataset(), | |||
previousBlockDataset.getUserAccountSet()); | |||
batch = new InnerTransactionBatchProcessor(ledgerHash, securityManager, newBlockEditor, previousBlockDataset, | |||
opHdlRegs, ledgerService, ledgerBlock.getHeight()); | |||
batch = new InnerTransactionBatchProcessor(ledgerRepo, | |||
opHdlRegs); | |||
batchs.put(ledgerHash, batch); | |||
return batch; | |||
} | |||
@@ -66,22 +56,16 @@ public class TransactionEngineImpl implements TransactionEngine { | |||
private HashDigest ledgerHash; | |||
private long blockHeight; | |||
/** | |||
* 创建交易批处理器; | |||
* | |||
* @param ledgerHash 账本哈希; | |||
* @param newBlockEditor 新区块的数据编辑器; | |||
* @param previousBlockDataset 新区块的前一个区块的数据集;即未提交新区块之前的经过共识的账本最新数据集; | |||
* @param opHandles 操作处理对象注册表; | |||
* @param ledgerRepo 账本; | |||
* @param handlesRegisteration 操作处理对象注册表; | |||
* @param blockHeight | |||
*/ | |||
public InnerTransactionBatchProcessor(HashDigest ledgerHash, LedgerSecurityManager securityManager, | |||
LedgerEditor newBlockEditor, LedgerDataQuery previousBlockDataset, | |||
OperationHandleRegisteration opHandles, LedgerService ledgerService, long blockHeight) { | |||
super(securityManager, newBlockEditor, previousBlockDataset, opHandles, ledgerService); | |||
this.ledgerHash = ledgerHash; | |||
this.blockHeight = blockHeight; | |||
public InnerTransactionBatchProcessor(LedgerRepository ledgerRepo, | |||
OperationHandleRegisteration handlesRegisteration) { | |||
super(ledgerRepo, handlesRegisteration); | |||
} | |||
@Override | |||
@@ -96,9 +80,5 @@ public class TransactionEngineImpl implements TransactionEngine { | |||
finishBatch(ledgerHash); | |||
} | |||
@Override | |||
public long blockHeight() { | |||
return this.blockHeight; | |||
} | |||
} | |||
} |
@@ -21,9 +21,9 @@ class UserRolesPrivileges { | |||
private Bytes userAddress; | |||
private PrivilegeBitset<LedgerPermission> ledgerPrivileges; | |||
private LedgerPrivilege ledgerPrivileges; | |||
private PrivilegeBitset<TransactionPermission> transactionPrivileges; | |||
private TransactionPrivilege transactionPrivileges; | |||
public UserRolesPrivileges(Bytes userAddress, RolesPolicy policy, Collection<RolePrivileges> privilegesList) { | |||
this.userAddress = userAddress; | |||
@@ -4,9 +4,8 @@ import com.jd.blockchain.binaryproto.DataContractRegistry; | |||
import com.jd.blockchain.ledger.BytesValue; | |||
import com.jd.blockchain.ledger.Operation; | |||
import com.jd.blockchain.ledger.TransactionPermission; | |||
import com.jd.blockchain.ledger.core.LedgerDataQuery; | |||
import com.jd.blockchain.ledger.core.LedgerDataset; | |||
import com.jd.blockchain.ledger.core.LedgerService; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.ledger.core.MultiIDsPolicy; | |||
import com.jd.blockchain.ledger.core.OperationHandle; | |||
import com.jd.blockchain.ledger.core.OperationHandleContext; | |||
@@ -37,7 +36,7 @@ public abstract class AbstractLedgerOperationHandle<T extends Operation> impleme | |||
// public final boolean support(Class<?> operationType) { | |||
// return SUPPORTED_OPERATION_TYPE.isAssignableFrom(operationType); | |||
// } | |||
@Override | |||
public Class<?> getOperationType() { | |||
return SUPPORTED_OPERATION_TYPE; | |||
@@ -45,8 +44,7 @@ public abstract class AbstractLedgerOperationHandle<T extends Operation> impleme | |||
@Override | |||
public final BytesValue process(Operation op, LedgerDataset newBlockDataset, | |||
TransactionRequestExtension requestContext, LedgerDataQuery previousBlockDataset, | |||
OperationHandleContext handleContext, LedgerService ledgerService) { | |||
TransactionRequestExtension requestContext, LedgerQuery ledger, OperationHandleContext handleContext) { | |||
// 权限校验; | |||
SecurityPolicy securityPolicy = SecurityContext.getContextUsersPolicy(); | |||
securityPolicy.checkEndpointPermission(TransactionPermission.DIRECT_OPERATION, MultiIDsPolicy.AT_LEAST_ONE); | |||
@@ -54,20 +52,12 @@ public abstract class AbstractLedgerOperationHandle<T extends Operation> impleme | |||
// 操作账本; | |||
@SuppressWarnings("unchecked") | |||
T concretedOp = (T) op; | |||
doProcess(concretedOp, newBlockDataset, requestContext, previousBlockDataset, handleContext, ledgerService); | |||
doProcess(concretedOp, newBlockDataset, requestContext, ledger, handleContext); | |||
// 账本操作没有返回值; | |||
return null; | |||
} | |||
/** | |||
* @param op | |||
* @param newBlockDataset | |||
* @param requestContext | |||
* @param previousBlockDataset | |||
* @param handleContext | |||
* @param ledgerService | |||
*/ | |||
protected abstract void doProcess(T op, LedgerDataset newBlockDataset, TransactionRequestExtension requestContext, | |||
LedgerDataQuery previousBlockDataset, OperationHandleContext handleContext, LedgerService ledgerService); | |||
LedgerQuery ledger, OperationHandleContext handleContext); | |||
} |
@@ -11,10 +11,9 @@ import com.jd.blockchain.ledger.Operation; | |||
import com.jd.blockchain.ledger.TransactionPermission; | |||
import com.jd.blockchain.ledger.core.ContractAccount; | |||
import com.jd.blockchain.ledger.core.ContractAccountQuery; | |||
import com.jd.blockchain.ledger.core.LedgerDataQuery; | |||
import com.jd.blockchain.ledger.core.LedgerDataset; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.ledger.core.LedgerQueryService; | |||
import com.jd.blockchain.ledger.core.LedgerService; | |||
import com.jd.blockchain.ledger.core.MultiIDsPolicy; | |||
import com.jd.blockchain.ledger.core.OperationHandle; | |||
import com.jd.blockchain.ledger.core.OperationHandleContext; | |||
@@ -24,7 +23,7 @@ import com.jd.blockchain.ledger.core.TransactionRequestExtension; | |||
@Service | |||
public abstract class AbtractContractEventSendOperationHandle implements OperationHandle { | |||
@Override | |||
public Class<?> getOperationType() { | |||
return ContractEventSendOperation.class; | |||
@@ -32,7 +31,7 @@ public abstract class AbtractContractEventSendOperationHandle implements Operati | |||
@Override | |||
public BytesValue process(Operation op, LedgerDataset newBlockDataset, TransactionRequestExtension requestContext, | |||
LedgerDataQuery previousBlockDataset, OperationHandleContext opHandleContext, LedgerService ledgerService) { | |||
LedgerQuery ledger, OperationHandleContext opHandleContext) { | |||
// 权限校验; | |||
SecurityPolicy securityPolicy = SecurityContext.getContextUsersPolicy(); | |||
securityPolicy.checkEndpointPermission(TransactionPermission.CONTRACT_OPERATION, MultiIDsPolicy.AT_LEAST_ONE); | |||
@@ -40,23 +39,21 @@ public abstract class AbtractContractEventSendOperationHandle implements Operati | |||
// 操作账本; | |||
ContractEventSendOperation contractOP = (ContractEventSendOperation) op; | |||
return doProcess(requestContext, contractOP, newBlockDataset, previousBlockDataset, opHandleContext, | |||
ledgerService); | |||
return doProcess(requestContext, contractOP, newBlockDataset, ledger, opHandleContext); | |||
} | |||
private BytesValue doProcess(TransactionRequestExtension request, ContractEventSendOperation contractOP, | |||
LedgerDataset newBlockDataset, LedgerDataQuery previousBlockDataset, OperationHandleContext opHandleContext, | |||
LedgerService ledgerService) { | |||
LedgerDataset newBlockDataset, LedgerQuery ledger, OperationHandleContext opHandleContext) { | |||
// 先从账本校验合约的有效性; | |||
// 注意:必须在前一个区块的数据集中进行校验,因为那是经过共识的数据;从当前新区块链数据集校验则会带来攻击风险:未经共识的合约得到执行; | |||
ContractAccountQuery contractSet = previousBlockDataset.getContractAccountset(); | |||
ContractAccountQuery contractSet = ledger.getContractAccountset(); | |||
if (!contractSet.contains(contractOP.getContractAddress())) { | |||
throw new LedgerException(String.format("Contract was not registered! --[ContractAddress=%s]", | |||
contractOP.getContractAddress())); | |||
} | |||
// 创建合约的账本上下文实例; | |||
LedgerQueryService queryService = new LedgerQueryService(ledgerService); | |||
LedgerQueryService queryService = new LedgerQueryService(ledger); | |||
ContractLedgerContext ledgerContext = new ContractLedgerContext(queryService, opHandleContext); | |||
// 先检查合约引擎是否已经加载合约;如果未加载,再从账本中读取合约代码并装载到引擎中执行; | |||
@@ -1,6 +1,5 @@ | |||
package com.jd.blockchain.ledger.core.handles; | |||
import com.jd.blockchain.contract.ContractJarUtils; | |||
import com.jd.blockchain.ledger.ContractCodeDeployOperation; | |||
import com.jd.blockchain.ledger.LedgerPermission; | |||
import com.jd.blockchain.ledger.core.LedgerDataQuery; | |||
@@ -22,6 +21,8 @@ public class ContractCodeDeployOperationHandle extends AbstractLedgerOperationHa | |||
protected void doProcess(ContractCodeDeployOperation op, LedgerDataset newBlockDataset, | |||
TransactionRequestExtension requestContext, LedgerDataQuery previousBlockDataset, | |||
OperationHandleContext handleContext, LedgerService ledgerService) { | |||
TransactionRequestExtension requestContext, LedgerQuery ledger, | |||
OperationHandleContext handleContext) { | |||
// TODO: 请求者应该提供合约账户的公钥签名,以确保注册人对注册的地址和公钥具有合法的使用权; | |||
@@ -6,9 +6,8 @@ import com.jd.blockchain.ledger.DataAccountKVSetOperation.KVWriteEntry; | |||
import com.jd.blockchain.ledger.DataVersionConflictException; | |||
import com.jd.blockchain.ledger.LedgerPermission; | |||
import com.jd.blockchain.ledger.core.DataAccount; | |||
import com.jd.blockchain.ledger.core.LedgerDataQuery; | |||
import com.jd.blockchain.ledger.core.LedgerDataset; | |||
import com.jd.blockchain.ledger.core.LedgerService; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.ledger.core.MultiIDsPolicy; | |||
import com.jd.blockchain.ledger.core.OperationHandleContext; | |||
import com.jd.blockchain.ledger.core.SecurityContext; | |||
@@ -24,8 +23,8 @@ public class DataAccountKVSetOperationHandle extends AbstractLedgerOperationHand | |||
@Override | |||
protected void doProcess(DataAccountKVSetOperation kvWriteOp, LedgerDataset newBlockDataset, | |||
TransactionRequestExtension requestContext, LedgerDataQuery previousBlockDataset, | |||
OperationHandleContext handleContext, LedgerService ledgerService) { | |||
TransactionRequestExtension requestContext, LedgerQuery ledger, | |||
OperationHandleContext handleContext) { | |||
// 权限校验; | |||
SecurityPolicy securityPolicy = SecurityContext.getContextUsersPolicy(); | |||
securityPolicy.checkEndpointPermission(LedgerPermission.WRITE_DATA_ACCOUNT, MultiIDsPolicy.AT_LEAST_ONE); | |||
@@ -3,9 +3,8 @@ package com.jd.blockchain.ledger.core.handles; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.ledger.DataAccountRegisterOperation; | |||
import com.jd.blockchain.ledger.LedgerPermission; | |||
import com.jd.blockchain.ledger.core.LedgerDataQuery; | |||
import com.jd.blockchain.ledger.core.LedgerDataset; | |||
import com.jd.blockchain.ledger.core.LedgerService; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.ledger.core.MultiIDsPolicy; | |||
import com.jd.blockchain.ledger.core.OperationHandleContext; | |||
import com.jd.blockchain.ledger.core.SecurityContext; | |||
@@ -17,11 +16,10 @@ public class DataAccountRegisterOperationHandle extends AbstractLedgerOperationH | |||
public DataAccountRegisterOperationHandle() { | |||
super(DataAccountRegisterOperation.class); | |||
} | |||
@Override | |||
protected void doProcess(DataAccountRegisterOperation op, LedgerDataset newBlockDataset, | |||
TransactionRequestExtension requestContext, LedgerDataQuery previousBlockDataset, | |||
OperationHandleContext handleContext, LedgerService ledgerService) { | |||
TransactionRequestExtension requestContext, LedgerQuery ledger, OperationHandleContext handleContext) { | |||
// TODO: 请求者应该提供数据账户的公钥签名,以更好地确保注册人对该地址和公钥具有合法使用权; | |||
// 权限校验; | |||
@@ -3,9 +3,8 @@ package com.jd.blockchain.ledger.core.handles; | |||
import com.jd.blockchain.ledger.BytesValue; | |||
import com.jd.blockchain.ledger.LedgerInitOperation; | |||
import com.jd.blockchain.ledger.Operation; | |||
import com.jd.blockchain.ledger.core.LedgerDataQuery; | |||
import com.jd.blockchain.ledger.core.LedgerDataset; | |||
import com.jd.blockchain.ledger.core.LedgerService; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.ledger.core.OperationHandle; | |||
import com.jd.blockchain.ledger.core.OperationHandleContext; | |||
import com.jd.blockchain.ledger.core.TransactionRequestExtension; | |||
@@ -19,7 +18,7 @@ public class LedgerInitOperationHandle implements OperationHandle { | |||
@Override | |||
public BytesValue process(Operation op, LedgerDataset newBlockDataset, TransactionRequestExtension requestContext, | |||
LedgerDataQuery previousBlockDataset, OperationHandleContext handleContext, LedgerService ledgerService) { | |||
LedgerQuery ledger,OperationHandleContext handleContext) { | |||
// 对初始化操作不需要做任何处理; | |||
return null; | |||
} | |||
@@ -2,8 +2,21 @@ package com.jd.blockchain.ledger.core.handles; | |||
import com.jd.blockchain.crypto.AddressEncoding; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.*; | |||
import com.jd.blockchain.ledger.core.*; | |||
import com.jd.blockchain.ledger.LedgerPermission; | |||
import com.jd.blockchain.ledger.ParticipantInfo; | |||
import com.jd.blockchain.ledger.ParticipantInfoData; | |||
import com.jd.blockchain.ledger.ParticipantNode; | |||
import com.jd.blockchain.ledger.ParticipantNodeState; | |||
import com.jd.blockchain.ledger.ParticipantRegisterOperation; | |||
import com.jd.blockchain.ledger.UserRegisterOperation; | |||
import com.jd.blockchain.ledger.core.LedgerAdminDataset; | |||
import com.jd.blockchain.ledger.core.LedgerDataset; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.ledger.core.MultiIDsPolicy; | |||
import com.jd.blockchain.ledger.core.OperationHandleContext; | |||
import com.jd.blockchain.ledger.core.SecurityContext; | |||
import com.jd.blockchain.ledger.core.SecurityPolicy; | |||
import com.jd.blockchain.ledger.core.TransactionRequestExtension; | |||
import com.jd.blockchain.transaction.UserRegisterOpTemplate; | |||
import com.jd.blockchain.utils.Bytes; | |||
@@ -15,8 +28,8 @@ public class ParticipantRegisterOperationHandle extends AbstractLedgerOperationH | |||
@Override | |||
protected void doProcess(ParticipantRegisterOperation op, LedgerDataset newBlockDataset, | |||
TransactionRequestExtension requestContext, LedgerDataQuery previousBlockDataset, | |||
OperationHandleContext handleContext, LedgerService ledgerService) { | |||
TransactionRequestExtension requestContext, LedgerQuery previousBlockDataset, | |||
OperationHandleContext handleContext) { | |||
// 权限校验; | |||
SecurityPolicy securityPolicy = SecurityContext.getContextUsersPolicy(); | |||
@@ -28,7 +41,7 @@ public class ParticipantRegisterOperationHandle extends AbstractLedgerOperationH | |||
ParticipantInfo participantInfo = new ParticipantInfoData(participantRegOp.getParticipantName(), participantRegOp.getParticipantIdentity().getPubKey(), participantRegOp.getNetworkAddress()); | |||
ParticipantNode participantNode = new PartNode((int)(adminAccountDataSet.getParticipantCount()), participantInfo.getName(), participantInfo.getPubKey(), ParticipantNodeState.REGISTED); | |||
ParticipantNode participantNode = new PartNode((int)(adminAccountDataSet.getParticipantCount()), participantInfo.getName(), participantInfo.getPubKey(), ParticipantNodeState.REGISTERED); | |||
//add new participant as consensus node | |||
adminAccountDataSet.addParticipant(participantNode); | |||
@@ -4,8 +4,22 @@ import com.jd.blockchain.consensus.ConsensusProvider; | |||
import com.jd.blockchain.consensus.ConsensusProviders; | |||
import com.jd.blockchain.crypto.AddressEncoding; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.*; | |||
import com.jd.blockchain.ledger.core.*; | |||
import com.jd.blockchain.ledger.LedgerPermission; | |||
import com.jd.blockchain.ledger.LedgerSettings; | |||
import com.jd.blockchain.ledger.ParticipantInfo; | |||
import com.jd.blockchain.ledger.ParticipantInfoData; | |||
import com.jd.blockchain.ledger.ParticipantNode; | |||
import com.jd.blockchain.ledger.ParticipantNodeState; | |||
import com.jd.blockchain.ledger.ParticipantStateUpdateOperation; | |||
import com.jd.blockchain.ledger.core.LedgerAdminDataset; | |||
import com.jd.blockchain.ledger.core.LedgerConfiguration; | |||
import com.jd.blockchain.ledger.core.LedgerDataset; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.ledger.core.MultiIDsPolicy; | |||
import com.jd.blockchain.ledger.core.OperationHandleContext; | |||
import com.jd.blockchain.ledger.core.SecurityContext; | |||
import com.jd.blockchain.ledger.core.SecurityPolicy; | |||
import com.jd.blockchain.ledger.core.TransactionRequestExtension; | |||
import com.jd.blockchain.utils.Bytes; | |||
@@ -16,8 +30,8 @@ public class ParticipantStateUpdateOperationHandle extends AbstractLedgerOperati | |||
@Override | |||
protected void doProcess(ParticipantStateUpdateOperation op, LedgerDataset newBlockDataset, | |||
TransactionRequestExtension requestContext, LedgerDataQuery previousBlockDataset, | |||
OperationHandleContext handleContext, LedgerService ledgerService) { | |||
TransactionRequestExtension requestContext, LedgerQuery previousBlockDataset, | |||
OperationHandleContext handleContext) { | |||
// 权限校验; | |||
SecurityPolicy securityPolicy = SecurityContext.getContextUsersPolicy(); | |||
@@ -35,7 +49,7 @@ public class ParticipantStateUpdateOperationHandle extends AbstractLedgerOperati | |||
for(int i = 0; i < participants.length; i++) { | |||
if (stateUpdateOperation.getParticipantIdentity().getPubKey().equals(participants[i].getPubKey())) { | |||
participantNode = new PartNode(participants[i].getId(), participants[i].getName(), participants[i].getPubKey(), ParticipantNodeState.CONSENSUSED); | |||
participantNode = new PartNode(participants[i].getId(), participants[i].getName(), participants[i].getPubKey(), ParticipantNodeState.ACTIVED); | |||
break; | |||
} | |||
} | |||
@@ -5,9 +5,8 @@ import com.jd.blockchain.ledger.RolePrivilegeSettings; | |||
import com.jd.blockchain.ledger.RolePrivileges; | |||
import com.jd.blockchain.ledger.RolesConfigureOperation; | |||
import com.jd.blockchain.ledger.RolesConfigureOperation.RolePrivilegeEntry; | |||
import com.jd.blockchain.ledger.core.LedgerDataQuery; | |||
import com.jd.blockchain.ledger.core.LedgerDataset; | |||
import com.jd.blockchain.ledger.core.LedgerService; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.ledger.core.MultiIDsPolicy; | |||
import com.jd.blockchain.ledger.core.OperationHandleContext; | |||
import com.jd.blockchain.ledger.core.SecurityContext; | |||
@@ -22,8 +21,7 @@ public class RolesConfigureOperationHandle extends AbstractLedgerOperationHandle | |||
@Override | |||
protected void doProcess(RolesConfigureOperation operation, LedgerDataset newBlockDataset, | |||
TransactionRequestExtension request, LedgerDataQuery previousBlockDataset, | |||
OperationHandleContext handleContext, LedgerService ledgerService) { | |||
TransactionRequestExtension request, LedgerQuery ledger, OperationHandleContext handleContext) { | |||
// 权限校验; | |||
SecurityPolicy securityPolicy = SecurityContext.getContextUsersPolicy(); | |||
securityPolicy.checkEndpointPermission(LedgerPermission.CONFIGURE_ROLES, MultiIDsPolicy.AT_LEAST_ONE); | |||
@@ -10,9 +10,8 @@ import com.jd.blockchain.ledger.UserAuthorizeOperation; | |||
import com.jd.blockchain.ledger.UserAuthorizeOperation.UserRolesEntry; | |||
import com.jd.blockchain.ledger.UserRoles; | |||
import com.jd.blockchain.ledger.UserRolesSettings; | |||
import com.jd.blockchain.ledger.core.LedgerDataQuery; | |||
import com.jd.blockchain.ledger.core.LedgerDataset; | |||
import com.jd.blockchain.ledger.core.LedgerService; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.ledger.core.MultiIDsPolicy; | |||
import com.jd.blockchain.ledger.core.OperationHandleContext; | |||
import com.jd.blockchain.ledger.core.SecurityContext; | |||
@@ -28,8 +27,8 @@ public class UserAuthorizeOperationHandle extends AbstractLedgerOperationHandle< | |||
@Override | |||
protected void doProcess(UserAuthorizeOperation operation, LedgerDataset newBlockDataset, | |||
TransactionRequestExtension request, LedgerDataQuery previousBlockDataset, | |||
OperationHandleContext handleContext, LedgerService ledgerService) { | |||
TransactionRequestExtension request, LedgerQuery ledger, | |||
OperationHandleContext handleContext) { | |||
// 权限校验; | |||
SecurityPolicy securityPolicy = SecurityContext.getContextUsersPolicy(); | |||
securityPolicy.checkEndpointPermission(LedgerPermission.CONFIGURE_ROLES, MultiIDsPolicy.AT_LEAST_ONE); | |||
@@ -3,9 +3,8 @@ package com.jd.blockchain.ledger.core.handles; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.ledger.LedgerPermission; | |||
import com.jd.blockchain.ledger.UserRegisterOperation; | |||
import com.jd.blockchain.ledger.core.LedgerDataQuery; | |||
import com.jd.blockchain.ledger.core.LedgerDataset; | |||
import com.jd.blockchain.ledger.core.LedgerService; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.ledger.core.MultiIDsPolicy; | |||
import com.jd.blockchain.ledger.core.OperationHandleContext; | |||
import com.jd.blockchain.ledger.core.SecurityContext; | |||
@@ -21,8 +20,7 @@ public class UserRegisterOperationHandle extends AbstractLedgerOperationHandle<U | |||
@Override | |||
protected void doProcess(UserRegisterOperation op, LedgerDataset newBlockDataset, | |||
TransactionRequestExtension requestContext, LedgerDataQuery previousBlockDataset, | |||
OperationHandleContext handleContext, LedgerService ledgerService) { | |||
TransactionRequestExtension requestContext, LedgerQuery ledger, OperationHandleContext handleContext) { | |||
// 权限校验; | |||
SecurityPolicy securityPolicy = SecurityContext.getContextUsersPolicy(); | |||
securityPolicy.checkEndpointPermission(LedgerPermission.REGISTER_USER, MultiIDsPolicy.AT_LEAST_ONE); | |||
@@ -112,7 +112,7 @@ public class ContractInvokingTest { | |||
LedgerEditor newBlockEditor = ledgerRepo.createNextBlock(); | |||
LedgerSecurityManager securityManager = getSecurityManager(); | |||
TransactionBatchProcessor txbatchProcessor = new TransactionBatchProcessor(securityManager, newBlockEditor, | |||
previousBlockDataset, opReg, ledgerManager); | |||
ledgerRepo, opReg); | |||
// 构建基于接口调用合约的交易请求,用于测试合约调用; | |||
TxBuilder txBuilder = new TxBuilder(ledgerHash); | |||
@@ -186,7 +186,7 @@ public class ContractInvokingTest { | |||
// 加载合约 | |||
LedgerEditor newBlockEditor = ledgerRepo.createNextBlock(); | |||
TransactionBatchProcessor txbatchProcessor = new TransactionBatchProcessor(getSecurityManager(), newBlockEditor, | |||
previousBlockDataset, opReg, ledgerManager); | |||
ledgerRepo, opReg); | |||
String key = TxTestContractImpl.KEY; | |||
String value = "VAL"; | |||
@@ -333,7 +333,7 @@ public class ContractInvokingTest { | |||
LedgerDataQuery previousBlockDataset = ledgerRepo.getDataSet(preBlock); | |||
LedgerEditor newBlockEditor = ledgerRepo.createNextBlock(); | |||
TransactionBatchProcessor txbatchProcessor = new TransactionBatchProcessor(getSecurityManager(), newBlockEditor, | |||
previousBlockDataset, opReg, ledgerService); | |||
ledgerRepo, opReg); | |||
TxBuilder txBuilder = new TxBuilder(ledgerRepo.getHash()); | |||
txDefinitor.buildTx(txBuilder); | |||
@@ -368,7 +368,7 @@ public class ContractInvokingTest { | |||
// 加载合约 | |||
LedgerEditor newBlockEditor = ledgerRepo.createNextBlock(); | |||
TransactionBatchProcessor txbatchProcessor = new TransactionBatchProcessor(getSecurityManager(), newBlockEditor, | |||
previousBlockDataset, opReg, ledgerManager); | |||
ledgerRepo, opReg); | |||
// 注册数据账户; | |||
TxBuilder txBuilder = new TxBuilder(ledgerHash); | |||
@@ -399,7 +399,7 @@ public class ContractInvokingTest { | |||
LedgerEditor newBlockEditor = ledgerRepo.createNextBlock(); | |||
LedgerSecurityManager securityManager = getSecurityManager(); | |||
TransactionBatchProcessor txbatchProcessor = new TransactionBatchProcessor(securityManager, newBlockEditor, | |||
previousBlockDataset, opReg, ledgerManager); | |||
ledgerRepo, opReg); | |||
// 构建基于接口调用合约的交易请求,用于测试合约调用; | |||
TxBuilder txBuilder = new TxBuilder(ledgerHash); | |||
@@ -50,7 +50,7 @@ public class LedgerAdminDatasetTest { | |||
parties[i].setHostAddress(new NetworkAddress("192.168.10." + (10 + i), 10010 + 10 * i)); | |||
parties[i].setName("Participant[" + i + "]"); | |||
parties[i].setPubKey(bckeys[i].getPubKey()); | |||
parties[i].setParticipantState(ParticipantNodeState.CONSENSUSED); | |||
parties[i].setParticipantState(ParticipantNodeState.ACTIVED); | |||
} | |||
ConsensusParticipantData[] parties1 = Arrays.copyOf(parties, 4); | |||
initSetting.setConsensusParticipants(parties1); | |||
@@ -77,7 +77,7 @@ public class LedgerInitOperationTest { | |||
parties[i].setHostAddress(new NetworkAddress("192.168.10." + (10 + i), 10010 + 10 * i)); | |||
parties[i].setName("Participant[" + i + "]"); | |||
parties[i].setPubKey(keys[i].getPubKey()); | |||
parties[i].setParticipantState(ParticipantNodeState.CONSENSUSED); | |||
parties[i].setParticipantState(ParticipantNodeState.ACTIVED); | |||
} | |||
ConsensusParticipantData[] parties1 = Arrays.copyOf(parties, 4); | |||
@@ -116,7 +116,7 @@ public class LedgerInitOperationTest { | |||
for (int i = 0; i < parties.length; i++) { | |||
keys[i] = BlockchainKeyGenerator.getInstance().generate(); | |||
parties[i] = new ParticipantCertData(AddressEncoding.generateAddress(keys[i].getPubKey()), | |||
"Participant[" + i + "]", keys[i].getPubKey(), ParticipantNodeState.CONSENSUSED); | |||
"Participant[" + i + "]", keys[i].getPubKey(), ParticipantNodeState.ACTIVED); | |||
} | |||
ParticipantCertData[] parties1 = Arrays.copyOf(parties, 4); | |||
@@ -81,7 +81,7 @@ public class LedgerInitSettingSerializeTest { | |||
parties[i].setHostAddress(new NetworkAddress("192.168.10." + (10 + i), 10010 + 10 * i)); | |||
parties[i].setName("Participant[" + i + "]"); | |||
parties[i].setPubKey(keys[i].getPubKey()); | |||
parties[i].setParticipantState(ParticipantNodeState.CONSENSUSED); | |||
parties[i].setParticipantState(ParticipantNodeState.ACTIVED); | |||
} | |||
ConsensusParticipantData[] parties1 = Arrays.copyOf(parties, 4); | |||
@@ -124,7 +124,7 @@ public class LedgerInitSettingSerializeTest { | |||
for (int i = 0; i < parties.length; i++) { | |||
keys[i] = BlockchainKeyGenerator.getInstance().generate(); | |||
parties[i] = new ParticipantCertData(AddressEncoding.generateAddress(keys[i].getPubKey()), | |||
"Participant[" + i + "]", keys[i].getPubKey(), ParticipantNodeState.CONSENSUSED); | |||
"Participant[" + i + "]", keys[i].getPubKey(), ParticipantNodeState.ACTIVED); | |||
} | |||
ParticipantCertData[] parties1 = Arrays.copyOf(parties, 4); | |||
@@ -205,7 +205,7 @@ public class LedgerManagerTest { | |||
parties[0].setPubKey(kp0.getPubKey()); | |||
parties[0].setAddress(AddressEncoding.generateAddress(kp0.getPubKey())); | |||
parties[0].setHostAddress(new NetworkAddress("127.0.0.1", 9000)); | |||
parties[0].setParticipantState(ParticipantNodeState.CONSENSUSED); | |||
parties[0].setParticipantState(ParticipantNodeState.ACTIVED); | |||
parties[1] = new ConsensusParticipantData(); | |||
parties[1].setId(1); | |||
@@ -214,7 +214,7 @@ public class LedgerManagerTest { | |||
parties[1].setPubKey(kp1.getPubKey()); | |||
parties[1].setAddress(AddressEncoding.generateAddress(kp1.getPubKey())); | |||
parties[1].setHostAddress(new NetworkAddress("127.0.0.1", 9010)); | |||
parties[1].setParticipantState(ParticipantNodeState.CONSENSUSED); | |||
parties[1].setParticipantState(ParticipantNodeState.ACTIVED); | |||
parties[2] = new ConsensusParticipantData(); | |||
parties[2].setId(2); | |||
@@ -223,7 +223,7 @@ public class LedgerManagerTest { | |||
parties[2].setPubKey(kp2.getPubKey()); | |||
parties[2].setAddress(AddressEncoding.generateAddress(kp2.getPubKey())); | |||
parties[2].setHostAddress(new NetworkAddress("127.0.0.1", 9020)); | |||
parties[2].setParticipantState(ParticipantNodeState.CONSENSUSED); | |||
parties[2].setParticipantState(ParticipantNodeState.ACTIVED); | |||
parties[3] = new ConsensusParticipantData(); | |||
parties[3].setId(3); | |||
@@ -232,7 +232,7 @@ public class LedgerManagerTest { | |||
parties[3].setPubKey(kp3.getPubKey()); | |||
parties[3].setAddress(AddressEncoding.generateAddress(kp3.getPubKey())); | |||
parties[3].setHostAddress(new NetworkAddress("127.0.0.1", 9030)); | |||
parties[3].setParticipantState(ParticipantNodeState.CONSENSUSED); | |||
parties[3].setParticipantState(ParticipantNodeState.ACTIVED); | |||
initSetting.setConsensusParticipants(parties); | |||
@@ -186,7 +186,7 @@ public class LedgerMetaDataTest { | |||
// NetworkAddress consensusAddress = new NetworkAddress("192.168.1.1", 9001, | |||
// false); | |||
Bytes address = AddressEncoding.generateAddress(pubKey); | |||
ParticipantCertData participantCertData = new ParticipantCertData(address, name, pubKey, ParticipantNodeState.CONSENSUSED); | |||
ParticipantCertData participantCertData = new ParticipantCertData(address, name, pubKey, ParticipantNodeState.ACTIVED); | |||
// encode and decode | |||
byte[] encodeBytes = BinaryProtocol.encode(participantCertData, ParticipantNode.class); | |||
@@ -68,7 +68,7 @@ public class LedgerTestUtils { | |||
parties[i].setPubKey(partiKeys[i].getPubKey()); | |||
parties[i].setAddress(AddressEncoding.generateAddress(partiKeys[i].getPubKey())); | |||
parties[i].setHostAddress(new NetworkAddress("192.168.1." + (10 + i), 9000)); | |||
parties[i].setParticipantState(ParticipantNodeState.CONSENSUSED); | |||
parties[i].setParticipantState(ParticipantNodeState.ACTIVED); | |||
} | |||
@@ -96,7 +96,7 @@ public class TransactionBatchProcessorTest { | |||
OperationHandleRegisteration opReg = new DefaultOperationHandleRegisteration(); | |||
LedgerSecurityManager securityManager = getSecurityManager(); | |||
TransactionBatchProcessor txbatchProcessor = new TransactionBatchProcessor(securityManager, newBlockEditor, | |||
previousBlockDataset, opReg, ledgerManager); | |||
ledgerRepo, opReg); | |||
// 注册新用户; | |||
BlockchainKeypair userKeypair = BlockchainKeyGenerator.getInstance().generate(); | |||
@@ -156,7 +156,7 @@ public class TransactionBatchProcessorTest { | |||
OperationHandleRegisteration opReg = new DefaultOperationHandleRegisteration(); | |||
LedgerSecurityManager securityManager = getSecurityManager(); | |||
TransactionBatchProcessor txbatchProcessor = new TransactionBatchProcessor(securityManager, newBlockEditor, | |||
previousBlockDataset, opReg, ledgerManager); | |||
ledgerRepo, opReg); | |||
// 注册新用户; | |||
BlockchainKeypair userKeypair1 = BlockchainKeyGenerator.getInstance().generate(); | |||
@@ -214,7 +214,7 @@ public class TransactionBatchProcessorTest { | |||
OperationHandleRegisteration opReg = new DefaultOperationHandleRegisteration(); | |||
LedgerSecurityManager securityManager = getSecurityManager(); | |||
TransactionBatchProcessor txbatchProcessor = new TransactionBatchProcessor(securityManager, newBlockEditor, | |||
previousBlockDataset, opReg, ledgerManager); | |||
ledgerRepo, opReg); | |||
// 注册新用户; | |||
BlockchainKeypair userKeypair1 = BlockchainKeyGenerator.getInstance().generate(); | |||
@@ -295,7 +295,7 @@ public class TransactionBatchProcessorTest { | |||
OperationHandleRegisteration opReg = new DefaultOperationHandleRegisteration(); | |||
LedgerSecurityManager securityManager = getSecurityManager(); | |||
TransactionBatchProcessor txbatchProcessor = new TransactionBatchProcessor(securityManager, newBlockEditor, | |||
previousBlockDataset, opReg, ledgerManager); | |||
ledgerRepo, opReg); | |||
BlockchainKeypair dataAccountKeypair = BlockchainKeyGenerator.getInstance().generate(); | |||
TransactionRequest transactionRequest1 = LedgerTestUtils.createTxRequest_DataAccountReg(dataAccountKeypair, | |||
@@ -322,8 +322,7 @@ public class TransactionBatchProcessorTest { | |||
newBlockEditor = ledgerRepo.createNextBlock(); | |||
previousBlockDataset = ledgerRepo.getDataSet(ledgerRepo.getLatestBlock()); | |||
txbatchProcessor = new TransactionBatchProcessor(securityManager, newBlockEditor, previousBlockDataset, opReg, | |||
ledgerManager); | |||
txbatchProcessor = new TransactionBatchProcessor(securityManager, newBlockEditor, ledgerRepo, opReg); | |||
txbatchProcessor.schedule(txreq1); | |||
txbatchProcessor.schedule(txreq2); | |||
@@ -362,8 +361,7 @@ public class TransactionBatchProcessorTest { | |||
newBlockEditor = ledgerRepo.createNextBlock(); | |||
previousBlockDataset = ledgerRepo.getDataSet(ledgerRepo.getLatestBlock()); | |||
txbatchProcessor = new TransactionBatchProcessor(securityManager, newBlockEditor, previousBlockDataset, opReg, | |||
ledgerManager); | |||
txbatchProcessor = new TransactionBatchProcessor(securityManager, newBlockEditor, ledgerRepo, opReg); | |||
txbatchProcessor.schedule(txreq5); | |||
// 预期会产生版本冲突异常; DataVersionConflictionException; | |||
@@ -326,7 +326,7 @@ public class LedgerInitProperties { | |||
.parseBoolean(PropertiesUtils.getRequiredProperty(props, initializerSecureKey)); | |||
NetworkAddress initializerAddress = new NetworkAddress(initializerHost, initializerPort, initializerSecure); | |||
parti.setInitializerAddress(initializerAddress); | |||
parti.setParticipantNodeState(ParticipantNodeState.CONSENSUSED); | |||
parti.setParticipantNodeState(ParticipantNodeState.ACTIVED); | |||
initProps.addConsensusParticipant(parti); | |||
} | |||
@@ -4,6 +4,7 @@ import com.jd.blockchain.binaryproto.EnumContract; | |||
import com.jd.blockchain.binaryproto.EnumField; | |||
import com.jd.blockchain.binaryproto.PrimitiveType; | |||
import com.jd.blockchain.consts.DataCodes; | |||
import com.jd.blockchain.utils.Int8Code; | |||
/** | |||
* 账本相关的权限,这些权限属于全局性的; | |||
@@ -12,7 +13,7 @@ import com.jd.blockchain.consts.DataCodes; | |||
* | |||
*/ | |||
@EnumContract(code = DataCodes.ENUM_LEDGER_PERMISSION) | |||
public enum LedgerPermission { | |||
public enum LedgerPermission implements Int8Code{ | |||
/** | |||
* 配置角色的权限;<br> | |||
@@ -44,17 +45,17 @@ public enum LedgerPermission { | |||
* | |||
* 如果不具备此项权限,则无法注册用户; | |||
*/ | |||
REGISTER_USER((byte) 0x11), | |||
REGISTER_USER((byte) 0x06), | |||
/** | |||
* 注册数据账户;<br> | |||
*/ | |||
REGISTER_DATA_ACCOUNT((byte) 0x12), | |||
REGISTER_DATA_ACCOUNT((byte) 0x07), | |||
/** | |||
* 注册合约;<br> | |||
*/ | |||
REGISTER_CONTRACT((byte) 0x13), | |||
REGISTER_CONTRACT((byte) 0x08), | |||
/** | |||
* 升级合约 | |||
@@ -64,12 +65,12 @@ public enum LedgerPermission { | |||
/** | |||
* 设置用户属性;<br> | |||
*/ | |||
SET_USER_ATTRIBUTES((byte) 0x15), | |||
SET_USER_ATTRIBUTES((byte) 0x09), | |||
/** | |||
* 写入数据账户;<br> | |||
*/ | |||
WRITE_DATA_ACCOUNT((byte) 0x16), | |||
WRITE_DATA_ACCOUNT((byte) 0x0A), | |||
/** | |||
* 参与方核准交易;<br> | |||
@@ -78,14 +79,14 @@ public enum LedgerPermission { | |||
* <p> | |||
* 只对交易请求的节点签名列表{@link TransactionRequest#getNodeSignatures()}的用户产生影响; | |||
*/ | |||
APPROVE_TX((byte) 0x0C), | |||
APPROVE_TX((byte) 0x0B), | |||
/** | |||
* 参与方共识交易;<br> | |||
* | |||
* 如果不具备此项权限,则无法作为共识节点接入并对交易进行共识; | |||
*/ | |||
CONSENSUS_TX((byte) 0x0D); | |||
CONSENSUS_TX((byte) 0x0C); | |||
@EnumField(type = PrimitiveType.INT8) | |||
public final byte CODE; | |||
@@ -94,4 +95,9 @@ public enum LedgerPermission { | |||
this.CODE = code; | |||
} | |||
@Override | |||
public byte getCode() { | |||
return CODE; | |||
} | |||
} |
@@ -8,22 +8,16 @@ package com.jd.blockchain.ledger; | |||
*/ | |||
public class LedgerPrivilege extends PrivilegeBitset<LedgerPermission> { | |||
private static final CodeIndexer<LedgerPermission> CODE_INDEXER = new LedgerPermissionCodeIndexer(); | |||
public LedgerPrivilege() { | |||
super(CODE_INDEXER); | |||
} | |||
public LedgerPrivilege(byte[] codeBytes) { | |||
super(codeBytes, CODE_INDEXER); | |||
super(codeBytes); | |||
} | |||
private static class LedgerPermissionCodeIndexer implements CodeIndexer<LedgerPermission> { | |||
@Override | |||
public int getCodeIndex(LedgerPermission permission) { | |||
return permission.CODE & 0xFF; | |||
} | |||
@Override | |||
public LedgerPrivilege clone() { | |||
return (LedgerPrivilege) super.clone(); | |||
} | |||
} |
@@ -18,12 +18,12 @@ public enum ParticipantNodeState { | |||
/** | |||
* 已注册; | |||
*/ | |||
REGISTED((byte) 0), | |||
REGISTERED((byte) 0), | |||
/** | |||
* 已共识; | |||
* 已激活; | |||
*/ | |||
CONSENSUSED((byte) 1); | |||
ACTIVED((byte) 1); | |||
@EnumField(type= PrimitiveType.INT8) | |||
public final byte CODE; | |||
@@ -2,6 +2,7 @@ package com.jd.blockchain.ledger; | |||
import java.util.BitSet; | |||
import com.jd.blockchain.utils.Int8Code; | |||
import com.jd.blockchain.utils.io.BytesSerializable; | |||
/** | |||
@@ -10,43 +11,46 @@ import com.jd.blockchain.utils.io.BytesSerializable; | |||
* @author huanghaiquan | |||
* | |||
*/ | |||
public class PrivilegeBitset<E extends Enum<?>> implements Privilege<E>, BytesSerializable { | |||
// 加入前缀位,可避免序列化时输出空的字节数组; | |||
private static final boolean[] PREFIX = { false, false, false, true, false, false, false, true }; | |||
private static final int OFFSET = PREFIX.length; | |||
private static final int MAX_SIZE = 256 - PREFIX.length; | |||
public abstract class PrivilegeBitset<E extends Enum<?> & Int8Code> implements Privilege<E>, BytesSerializable, Cloneable { | |||
// 加入1个字节的前缀位 0xF1,可避免序列化时输出空的字节数组; | |||
private static final byte PREFIX = (byte) 0xF1; | |||
private static final byte[] PREFIX_BYTES = { PREFIX }; | |||
private static final int OFFSET = 8; | |||
private static final int MAX_SIZE = 32; | |||
private BitSet permissionBits; | |||
// 前缀中置为 1 的位数,值 0xF1 有 5 个比特位为 1; | |||
private static final int PREFIX_CARDINALITY = 5; | |||
private CodeIndexer<E> codeIndexer; | |||
private BitSet permissionBits; | |||
public PrivilegeBitset(CodeIndexer<E> codeIndexer) { | |||
this.permissionBits = new BitSet(); | |||
this.codeIndexer = codeIndexer; | |||
public PrivilegeBitset() { | |||
// 设置前缀; | |||
for (int i = 0; i < PREFIX.length; i++) { | |||
permissionBits.set(i, PREFIX[i]); | |||
} | |||
this.permissionBits = BitSet.valueOf(PREFIX_BYTES); | |||
} | |||
public PrivilegeBitset(byte[] codeBytes, CodeIndexer<E> codeIndexer) { | |||
/** | |||
* @param codeBytes 权限的字节位; | |||
* @param codeIndexer | |||
*/ | |||
public PrivilegeBitset(byte[] codeBytes) { | |||
// 检查长度; | |||
if (codeBytes.length == 0) { | |||
throw new IllegalArgumentException("Empty code bytes!"); | |||
} | |||
if (codeBytes.length > MAX_SIZE) { | |||
throw new IllegalArgumentException( | |||
"The size of code bytes specified to PrivilegeBitset exceed the max size[" + MAX_SIZE + "]!"); | |||
} | |||
this.permissionBits = BitSet.valueOf(codeBytes); | |||
this.codeIndexer = codeIndexer; | |||
// 校验前缀; | |||
for (int i = 0; i < PREFIX.length; i++) { | |||
if (permissionBits.get(i) != PREFIX[i]) { | |||
throw new IllegalArgumentException("The code bytes is not match the privilege prefix code!"); | |||
} | |||
if (codeBytes[0] != PREFIX) { | |||
throw new IllegalArgumentException("The code bytes is not match the privilege prefix code!"); | |||
} | |||
this.permissionBits = BitSet.valueOf(codeBytes); | |||
} | |||
private PrivilegeBitset(BitSet bits, CodeIndexer<E> codeIndexer) { | |||
protected PrivilegeBitset(BitSet bits) { | |||
this.permissionBits = bits; | |||
this.codeIndexer = codeIndexer; | |||
} | |||
public boolean isEnable(E permission) { | |||
@@ -134,15 +138,29 @@ public class PrivilegeBitset<E extends Enum<?>> implements Privilege<E>, BytesSe | |||
return this; | |||
} | |||
public PrivilegeBitset<E> clone() { | |||
return new PrivilegeBitset<E>((BitSet) permissionBits.clone(), codeIndexer); | |||
@Override | |||
public Privilege<E> clone() { | |||
try { | |||
BitSet bitSet = (BitSet) permissionBits.clone(); | |||
@SuppressWarnings("unchecked") | |||
PrivilegeBitset<E> privilege = (PrivilegeBitset<E>) super.clone(); | |||
privilege.permissionBits = bitSet; | |||
return privilege; | |||
} catch (CloneNotSupportedException e) { | |||
throw new IllegalStateException(e.getMessage(), e); | |||
} | |||
} | |||
protected BitSet cloneBitSet() { | |||
return (BitSet) permissionBits.clone(); | |||
} | |||
private int index(E permission) { | |||
return OFFSET + codeIndexer.getCodeIndex(permission); | |||
return OFFSET + permission.getCode(); | |||
} | |||
static interface CodeIndexer<E extends Enum<?>> { | |||
int getCodeIndex(E permission); | |||
public int getPermissionCount() { | |||
return permissionBits.cardinality() - PREFIX_CARDINALITY; | |||
} | |||
} |
@@ -4,6 +4,7 @@ import com.jd.blockchain.binaryproto.EnumContract; | |||
import com.jd.blockchain.binaryproto.EnumField; | |||
import com.jd.blockchain.binaryproto.PrimitiveType; | |||
import com.jd.blockchain.consts.DataCodes; | |||
import com.jd.blockchain.utils.Int8Code; | |||
/** | |||
* TxPermission 交易权限表示一个用户可以发起的交易类型; | |||
@@ -12,7 +13,7 @@ import com.jd.blockchain.consts.DataCodes; | |||
* | |||
*/ | |||
@EnumContract(code = DataCodes.ENUM_TX_PERMISSION) | |||
public enum TransactionPermission { | |||
public enum TransactionPermission implements Int8Code { | |||
/** | |||
* 交易中包含指令操作; | |||
@@ -31,4 +32,9 @@ public enum TransactionPermission { | |||
this.CODE = code; | |||
} | |||
@Override | |||
public byte getCode() { | |||
return CODE; | |||
} | |||
} |
@@ -2,22 +2,16 @@ package com.jd.blockchain.ledger; | |||
public class TransactionPrivilege extends PrivilegeBitset<TransactionPermission> { | |||
private static final CodeIndexer<TransactionPermission> CODE_INDEXER = new TransactionPermissionCodeIndexer(); | |||
public TransactionPrivilege() { | |||
super(CODE_INDEXER); | |||
} | |||
public TransactionPrivilege(byte[] codeBytes) { | |||
super(codeBytes, CODE_INDEXER); | |||
super(codeBytes); | |||
} | |||
private static class TransactionPermissionCodeIndexer implements CodeIndexer<TransactionPermission> { | |||
@Override | |||
public int getCodeIndex(TransactionPermission permission) { | |||
return permission.CODE & 0xFF; | |||
} | |||
@Override | |||
public TransactionPrivilege clone() { | |||
return (TransactionPrivilege) super.clone(); | |||
} | |||
} |
@@ -1,6 +1,7 @@ | |||
package com.jd.blockchain.ledger; | |||
import java.util.Collection; | |||
import java.util.Collections; | |||
import java.util.Set; | |||
import java.util.TreeSet; | |||
@@ -49,7 +50,7 @@ public class UserRoles implements RoleSet { | |||
public RolesPolicy getPolicy() { | |||
return policy; | |||
} | |||
public void setPolicy(RolesPolicy policy) { | |||
this.policy = policy; | |||
} | |||
@@ -62,6 +63,10 @@ public class UserRoles implements RoleSet { | |||
public String[] getRoles() { | |||
return roles.toArray(new String[roles.size()]); | |||
} | |||
public Set<String> getRoleSet(){ | |||
return Collections.unmodifiableSet(roles); | |||
} | |||
public long getVersion() { | |||
return version; | |||
@@ -17,7 +17,7 @@ import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.ledger.core.ContractAccountQuery; | |||
import com.jd.blockchain.ledger.core.DataAccount; | |||
import com.jd.blockchain.ledger.core.DataAccountQuery; | |||
import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.ledger.core.LedgerService; | |||
import com.jd.blockchain.ledger.core.ParticipantCertData; | |||
import com.jd.blockchain.ledger.core.TransactionSet; | |||
@@ -42,7 +42,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}") | |||
@Override | |||
public LedgerInfo getLedger(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
// TODO: 需要配置返回值的 spring MsgQueueMessageDispatcher | |||
// ,对返回对象仅仅序列化声明的返回值类型的属性,而不是整个对象本身; | |||
LedgerInfo ledgerInfo = new LedgerInfo(); | |||
@@ -55,7 +55,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/participants") | |||
@Override | |||
public ParticipantNode[] getConsensusParticipants(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerAdminInfo ledgerAdministration = ledger.getAdminInfo(); | |||
long participantCount = ledgerAdministration.getParticipantCount(); | |||
if (participantCount <= 0) { | |||
@@ -76,7 +76,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/admininfo") | |||
@Override | |||
public LedgerAdminInfo getLedgerAdminInfo(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerAdminInfo ledgerAdministration = ledger.getAdminInfo(); | |||
return ledgerAdministration; | |||
} | |||
@@ -84,7 +84,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/metadata") | |||
@Override | |||
public LedgerMetadata getLedgerMetadata(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerAdminInfo ledgerAdministration = ledger.getAdminInfo(); | |||
LedgerMetadata ledgerMetadata = ledgerAdministration.getMetadata(); | |||
return ledgerMetadata; | |||
@@ -94,7 +94,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@Override | |||
public LedgerBlock getBlock(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@PathVariable(name = "blockHeight") long blockHeight) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
// TODO: 需要配置返回值的 spring MsgQueueMessageDispatcher | |||
// ,对返回对象仅仅序列化声明的返回值类型的属性,而不是整个对象本身; | |||
return ledger.getBlock(blockHeight); | |||
@@ -104,7 +104,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@Override | |||
public LedgerBlock getBlock(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@PathVariable(name = "blockHash") HashDigest blockHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
// TODO: 需要配置返回值的 spring MsgQueueMessageDispatcher | |||
// ,对返回对象仅仅序列化声明的返回值类型的属性,而不是整个对象本身; | |||
return ledger.getBlock(blockHash); | |||
@@ -114,7 +114,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@Override | |||
public long getTransactionCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@PathVariable(name = "blockHeight") long blockHeight) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getBlock(blockHeight); | |||
TransactionSet txSet = ledger.getTransactionSet(block); | |||
return txSet.getTotalCount(); | |||
@@ -124,7 +124,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@Override | |||
public long getTransactionCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@PathVariable(name = "blockHash") HashDigest blockHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getBlock(blockHash); | |||
TransactionSet txSet = ledger.getTransactionSet(block); | |||
return txSet.getTotalCount(); | |||
@@ -133,7 +133,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/txs/count") | |||
@Override | |||
public long getTransactionTotalCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
TransactionSet txSet = ledger.getTransactionSet(block); | |||
return txSet.getTotalCount(); | |||
@@ -143,7 +143,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@Override | |||
public long getDataAccountCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@PathVariable(name = "blockHeight") long height) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getBlock(height); | |||
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); | |||
return dataAccountSet.getTotalCount(); | |||
@@ -153,7 +153,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@Override | |||
public long getDataAccountCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@PathVariable(name = "blockHash") HashDigest blockHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getBlock(blockHash); | |||
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); | |||
return dataAccountSet.getTotalCount(); | |||
@@ -162,7 +162,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/accounts/count") | |||
@Override | |||
public long getDataAccountTotalCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); | |||
return dataAccountSet.getTotalCount(); | |||
@@ -172,7 +172,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@Override | |||
public long getUserCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@PathVariable(name = "blockHeight") long height) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getBlock(height); | |||
UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); | |||
return userAccountSet.getTotalCount(); | |||
@@ -182,7 +182,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@Override | |||
public long getUserCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@PathVariable(name = "blockHash") HashDigest blockHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getBlock(blockHash); | |||
UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); | |||
return userAccountSet.getTotalCount(); | |||
@@ -191,7 +191,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/users/count") | |||
@Override | |||
public long getUserTotalCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); | |||
return userAccountSet.getTotalCount(); | |||
@@ -201,7 +201,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@Override | |||
public long getContractCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@PathVariable(name = "blockHeight") long height) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getBlock(height); | |||
ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); | |||
return contractAccountSet.getTotalCount(); | |||
@@ -211,7 +211,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@Override | |||
public long getContractCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@PathVariable(name = "blockHash") HashDigest blockHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getBlock(blockHash); | |||
ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); | |||
return contractAccountSet.getTotalCount(); | |||
@@ -220,7 +220,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/contracts/count") | |||
@Override | |||
public long getContractTotalCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); | |||
return contractAccountSet.getTotalCount(); | |||
@@ -233,7 +233,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, | |||
@RequestParam(name = "count", required = false, defaultValue = "-1") int count) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock ledgerBlock = ledger.getBlock(blockHeight); | |||
TransactionSet transactionSet = ledger.getTransactionSet(ledgerBlock); | |||
int lastHeightTxTotalNums = 0; | |||
@@ -266,7 +266,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@PathVariable(name = "blockHash") HashDigest blockHash, | |||
@RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, | |||
@RequestParam(name = "count", required = false, defaultValue = "-1") int count) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock ledgerBlock = ledger.getBlock(blockHash); | |||
long height = ledgerBlock.getHeight(); | |||
TransactionSet transactionSet = ledger.getTransactionSet(ledgerBlock); | |||
@@ -298,7 +298,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@Override | |||
public LedgerTransaction getTransactionByContentHash(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@PathVariable(name = "contentHash") HashDigest contentHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
TransactionSet txset = ledger.getTransactionSet(block); | |||
return txset.get(contentHash); | |||
@@ -308,7 +308,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@Override | |||
public TransactionState getTransactionStateByContentHash(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@PathVariable(name = "contentHash") HashDigest contentHash) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
TransactionSet txset = ledger.getTransactionSet(block); | |||
return txset.getTxState(contentHash); | |||
@@ -318,7 +318,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@Override | |||
public UserInfo getUser(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@PathVariable(name = "address") String address) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); | |||
return userAccountSet.getUser(address); | |||
@@ -328,7 +328,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@Override | |||
public AccountHeader getDataAccount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@PathVariable(name = "address") String address) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); | |||
return dataAccountSet.getDataAccount(Bytes.fromBase58(address)); | |||
@@ -342,7 +342,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
if (keys == null || keys.length == 0) { | |||
return null; | |||
} | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); | |||
DataAccount dataAccount = dataAccountSet.getDataAccount(Bytes.fromBase58(address)); | |||
@@ -391,7 +391,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
throw new ContractException("keys.length!=versions.length!"); | |||
} | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); | |||
DataAccount dataAccount = dataAccountSet.getDataAccount(Bytes.fromBase58(address)); | |||
@@ -426,7 +426,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, | |||
@RequestParam(name = "count", required = false, defaultValue = "-1") int count) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); | |||
DataAccount dataAccount = dataAccountSet.getDataAccount(Bytes.fromBase58(address)); | |||
@@ -440,7 +440,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
public long getDataEntriesTotalCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@PathVariable(name = "address") String address) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); | |||
DataAccount dataAccount = dataAccountSet.getDataAccount(Bytes.fromBase58(address)); | |||
@@ -452,7 +452,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
@Override | |||
public ContractInfo getContract(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@PathVariable(name = "address") String address) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); | |||
return contractAccountSet.getContract(Bytes.fromBase58(address)); | |||
@@ -471,7 +471,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
public AccountHeader[] getUsers(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, | |||
@RequestParam(name = "count", required = false, defaultValue = "-1") int count) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); | |||
int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) userAccountSet.getTotalCount()); | |||
@@ -491,7 +491,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
public AccountHeader[] getDataAccounts(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, | |||
@RequestParam(name = "count", required = false, defaultValue = "-1") int count) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); | |||
int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) dataAccountSet.getTotalCount()); | |||
@@ -503,7 +503,7 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
public AccountHeader[] getContractAccounts(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, | |||
@RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, | |||
@RequestParam(name = "count", required = false, defaultValue = "-1") int count) { | |||
LedgerRepository ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); | |||
LedgerBlock block = ledger.getLatestBlock(); | |||
ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); | |||
int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) contractAccountSet.getTotalCount()); | |||
@@ -35,7 +35,7 @@ import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.ledger.LedgerAdminInfo; | |||
import com.jd.blockchain.ledger.core.LedgerAdminDataQuery; | |||
import com.jd.blockchain.ledger.core.LedgerManage; | |||
import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.peer.ConsensusRealm; | |||
import com.jd.blockchain.peer.LedgerBindingConfigAware; | |||
import com.jd.blockchain.peer.PeerManage; | |||
@@ -212,7 +212,7 @@ public class ManagementController implements LedgerBindingConfigAware, PeerManag | |||
LedgerBindingConfig.BindingConfig bindingConfig = config.getLedger(ledgerHash); | |||
DbConnection dbConnNew = connFactory.connect(bindingConfig.getDbConnection().getUri(), | |||
bindingConfig.getDbConnection().getPassword()); | |||
LedgerRepository ledgerRepository = ledgerManager.register(ledgerHash, dbConnNew.getStorageService()); | |||
LedgerQuery ledgerRepository = ledgerManager.register(ledgerHash, dbConnNew.getStorageService()); | |||
// load provider; | |||
LedgerAdminInfo ledgerAdminAccount = ledgerRepository.getAdminInfo(); | |||
@@ -81,7 +81,7 @@ public class SDK_GateWay_Participant_State_Update_Test_ { | |||
NetworkAddress networkAddress = new NetworkAddress("127.0.0.1", 20000); | |||
txTemp.states().update(user.getIdentity(),networkAddress, ParticipantNodeState.CONSENSUSED); | |||
txTemp.states().update(user.getIdentity(),networkAddress, ParticipantNodeState.ACTIVED); | |||
// TX 准备就绪; | |||
PreparedTransaction prepTx = txTemp.prepare(); | |||
@@ -13,9 +13,9 @@ | |||
<modules> | |||
<module>test-consensus-client</module> | |||
<module>test-consensus-node</module> | |||
<module>test-ledger-core</module> | |||
<module>test-ledger</module> | |||
<module>test-integration</module> | |||
</modules> | |||
</modules> | |||
<build> | |||
<plugins> | |||
@@ -38,7 +38,7 @@ import com.jd.blockchain.ledger.UserInfo; | |||
import com.jd.blockchain.ledger.core.DataAccountQuery; | |||
import com.jd.blockchain.ledger.core.LedgerManage; | |||
import com.jd.blockchain.ledger.core.LedgerManager; | |||
import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.sdk.BlockchainService; | |||
import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||
import com.jd.blockchain.storage.service.KVStorageService; | |||
@@ -150,16 +150,16 @@ public class IntegrationTest { | |||
private void testConsistencyAmongNodes(IntegratedContext context) { | |||
int[] ids = context.getNodeIds(); | |||
Node[] nodes = new Node[ids.length]; | |||
LedgerRepository[] ledgers = new LedgerRepository[ids.length]; | |||
LedgerQuery[] ledgers = new LedgerQuery[ids.length]; | |||
for (int i = 0; i < nodes.length; i++) { | |||
nodes[i] = context.getNode(ids[i]); | |||
HashDigest ledgerHash = nodes[i].getLedgerManager().getLedgerHashs()[0]; | |||
ledgers[i] = nodes[i].getLedgerManager().getLedger(ledgerHash); | |||
} | |||
LedgerRepository ledger0 = ledgers[0]; | |||
LedgerQuery ledger0 = ledgers[0]; | |||
LedgerBlock latestBlock0 = ledger0.retrieveLatestBlock(); | |||
for (int i = 1; i < ledgers.length; i++) { | |||
LedgerRepository otherLedger = ledgers[i]; | |||
LedgerQuery otherLedger = ledgers[i]; | |||
LedgerBlock otherLatestBlock = otherLedger.retrieveLatestBlock(); | |||
} | |||
} | |||
@@ -212,7 +212,7 @@ public class IntegrationTest { | |||
TransactionResponse txResp = prepTx.commit(); | |||
Node node0 = context.getNode(0); | |||
LedgerRepository ledgerOfNode0 = node0.getLedgerManager().getLedger(ledgerHash); | |||
LedgerQuery ledgerOfNode0 = node0.getLedgerManager().getLedger(ledgerHash); | |||
ledgerOfNode0.retrieveLatestBlock(); // 更新内存 | |||
// 先验证应答 | |||
@@ -250,7 +250,7 @@ public class IntegrationTest { | |||
KVStorageService storageService = node0.getStorageDB().connect(memDbConnString).getStorageService(); | |||
LedgerRepository ledgerOfNode0 = ledgerManager.register(ledgerHash, storageService); | |||
LedgerQuery ledgerOfNode0 = ledgerManager.register(ledgerHash, storageService); | |||
return user; | |||
} | |||
@@ -282,7 +282,7 @@ public class IntegrationTest { | |||
KVStorageService storageService = node0.getStorageDB().connect(memDbConnString).getStorageService(); | |||
LedgerRepository ledgerOfNode0 = ledgerManager.register(ledgerHash, storageService); | |||
LedgerQuery ledgerOfNode0 = ledgerManager.register(ledgerHash, storageService); | |||
long latestBlockHeight = ledgerOfNode0.retrieveLatestBlockHeight(); | |||
return dataAccount; | |||
@@ -301,7 +301,7 @@ public class IntegrationTest { | |||
KVStorageService storageService = node0.getStorageDB().connect(memDbConnString).getStorageService(); | |||
LedgerRepository ledgerOfNode0 = ledgerManager.register(ledgerHash, storageService); | |||
LedgerQuery ledgerOfNode0 = ledgerManager.register(ledgerHash, storageService); | |||
// getLedgerHashs | |||
HashDigest[] ledgerHashs = blockchainService.getLedgerHashs(); | |||
@@ -494,10 +494,10 @@ public class IntegrationTest { | |||
HashDigest ledgerHash2 = callback2.waitReturn(); | |||
HashDigest ledgerHash3 = callback3.waitReturn(); | |||
LedgerRepository ledger0 = nodeCtx0.registLedger(ledgerHash0); | |||
LedgerRepository ledger1 = nodeCtx1.registLedger(ledgerHash1); | |||
LedgerRepository ledger2 = nodeCtx2.registLedger(ledgerHash2); | |||
LedgerRepository ledger3 = nodeCtx3.registLedger(ledgerHash3); | |||
LedgerQuery ledger0 = nodeCtx0.registLedger(ledgerHash0); | |||
LedgerQuery ledger1 = nodeCtx1.registLedger(ledgerHash1); | |||
LedgerQuery ledger2 = nodeCtx2.registLedger(ledgerHash2); | |||
LedgerQuery ledger3 = nodeCtx3.registLedger(ledgerHash3); | |||
IntegratedContext context = new IntegratedContext(); | |||
@@ -577,7 +577,7 @@ public class IntegrationTest { | |||
txResp.getContentHash(); | |||
Node node0 = context.getNode(0); | |||
LedgerRepository ledgerOfNode0 = node0.getLedgerManager().getLedger(ledgerHash); | |||
LedgerQuery ledgerOfNode0 = node0.getLedgerManager().getLedger(ledgerHash); | |||
LedgerBlock block = ledgerOfNode0.getBlock(txResp.getBlockHeight()); | |||
byte[] contractCodeInDb = ledgerOfNode0.getContractAccountSet(block).getContract(contractDeployKey.getAddress()) | |||
.getChainCode(); | |||
@@ -615,7 +615,7 @@ public class IntegrationTest { | |||
LedgerInfo latestLedgerInfo = blockchainService.getLedger(ledgerHash); | |||
Node node0 = context.getNode(0); | |||
LedgerRepository ledgerOfNode0 = node0.getLedgerManager().getLedger(ledgerHash); | |||
LedgerQuery ledgerOfNode0 = node0.getLedgerManager().getLedger(ledgerHash); | |||
LedgerBlock backgroundLedgerBlock = ledgerOfNode0.retrieveLatestBlock(); | |||
// 验证合约中的赋值,外部可以获得; | |||
@@ -657,7 +657,7 @@ public class IntegrationTest { | |||
// 验证结果; | |||
Node node0 = context.getNode(0); | |||
LedgerRepository ledgerOfNode0 = node0.getLedgerManager().getLedger(ledgerHash); | |||
LedgerQuery ledgerOfNode0 = node0.getLedgerManager().getLedger(ledgerHash); | |||
LedgerBlock block = ledgerOfNode0.getBlock(txResp.getBlockHeight()); | |||
BytesValue val1InDb = ledgerOfNode0.getDataAccountSet(block).getDataAccount(contractDataKey.getAddress()) | |||
.getBytes("A"); | |||
@@ -30,7 +30,7 @@ import com.jd.blockchain.ledger.TransactionTemplate; | |||
import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
import com.jd.blockchain.ledger.core.LedgerManager; | |||
import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.sdk.BlockchainService; | |||
import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||
import com.jd.blockchain.storage.service.DbConnection; | |||
@@ -118,7 +118,7 @@ public class ConsensusTest { | |||
BlockchainKeypair[] keys = generateKeys(batchSize); | |||
HashDigest ledgerHash = node0.getLedgerManager().getLedgerHashs()[0]; | |||
LedgerRepository ledger = node0.getLedgerManager().getLedger(ledgerHash); | |||
LedgerQuery ledger = node0.getLedgerManager().getLedger(ledgerHash); | |||
PreparedTransaction[] ptxs = prepareTransactions_RegisterDataAcount(keys, node0.getPartiKeyPair(), ledgerHash, | |||
blockchainService); | |||
@@ -339,7 +339,7 @@ public class ConsensusTest { | |||
this.serverAddress = serverAddress; | |||
} | |||
public LedgerRepository registLedger(HashDigest ledgerHash) { | |||
public LedgerQuery registLedger(HashDigest ledgerHash) { | |||
// LedgerManage ledgerManager = ctx.getBean(LedgerManage.class); | |||
// | |||
// DbConnectionFactory dbConnFactory = ctx.getBean(DbConnectionFactory.class); | |||
@@ -347,7 +347,7 @@ public class ConsensusTest { | |||
// dbConnConfig.getPassword()); | |||
DbConnection conn = db.connect(dbConnConfig.getUri(), dbConnConfig.getPassword()); | |||
LedgerRepository ledgerRepo = ledgerManager.register(ledgerHash, conn.getStorageService()); | |||
LedgerQuery ledgerRepo = ledgerManager.register(ledgerHash, conn.getStorageService()); | |||
return ledgerRepo; | |||
} | |||
@@ -32,7 +32,7 @@ import com.jd.blockchain.ledger.TransactionTemplate; | |||
import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
import com.jd.blockchain.ledger.core.LedgerManager; | |||
import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.sdk.BlockchainService; | |||
import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||
import com.jd.blockchain.storage.service.DbConnection; | |||
@@ -116,7 +116,7 @@ public class GlobalPerformanceTest { | |||
BlockchainKeypair[] keys = generateKeys(batchSize); | |||
HashDigest ledgerHash = node0.getLedgerManager().getLedgerHashs()[0]; | |||
LedgerRepository ledger = node0.getLedgerManager().getLedger(ledgerHash); | |||
LedgerQuery ledger = node0.getLedgerManager().getLedger(ledgerHash); | |||
PreparedTransaction[] ptxs = prepareTransactions_RegisterDataAcount(keys, node0.getPartiKeyPair(), ledgerHash, | |||
blockchainService); | |||
@@ -338,7 +338,7 @@ public class GlobalPerformanceTest { | |||
this.serverAddress = serverAddress; | |||
} | |||
public LedgerRepository registLedger(HashDigest ledgerHash) { | |||
public LedgerQuery registLedger(HashDigest ledgerHash) { | |||
// LedgerManage ledgerManager = ctx.getBean(LedgerManage.class); | |||
// | |||
// DbConnectionFactory dbConnFactory = ctx.getBean(DbConnectionFactory.class); | |||
@@ -347,7 +347,7 @@ public class GlobalPerformanceTest { | |||
DbConnection conn = db.connect(dbConnConfig.getUri(), dbConnConfig.getPassword()); | |||
conns.add(conn); | |||
LedgerRepository ledgerRepo = ledgerManager.register(ledgerHash, conn.getStorageService()); | |||
LedgerQuery ledgerRepo = ledgerManager.register(ledgerHash, conn.getStorageService()); | |||
return ledgerRepo; | |||
} | |||
@@ -25,7 +25,7 @@ import com.jd.blockchain.ledger.core.CryptoConfig; | |||
import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
import com.jd.blockchain.ledger.core.LedgerManager; | |||
import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.ledger.core.UserAccount; | |||
import com.jd.blockchain.ledger.core.UserAccountQuery; | |||
import com.jd.blockchain.storage.service.utils.MemoryDBConnFactory; | |||
@@ -106,10 +106,10 @@ public class LedgerInitializeTest { | |||
HashDigest ledgerHash2 = callback2.waitReturn(); | |||
HashDigest ledgerHash3 = callback3.waitReturn(); | |||
LedgerRepository ledger0 = node0.registLedger(ledgerHash0, memoryConnString[0]); | |||
LedgerRepository ledger1 = node1.registLedger(ledgerHash1, memoryConnString[1]); | |||
LedgerRepository ledger2 = node2.registLedger(ledgerHash2, memoryConnString[2]); | |||
LedgerRepository ledger3 = node3.registLedger(ledgerHash3, memoryConnString[3]); | |||
LedgerQuery ledger0 = node0.registLedger(ledgerHash0, memoryConnString[0]); | |||
LedgerQuery ledger1 = node1.registLedger(ledgerHash1, memoryConnString[1]); | |||
LedgerQuery ledger2 = node2.registLedger(ledgerHash2, memoryConnString[2]); | |||
LedgerQuery ledger3 = node3.registLedger(ledgerHash3, memoryConnString[3]); | |||
LedgerBlock genesisBlock = ledger0.getLatestBlock(); | |||
@@ -221,7 +221,7 @@ public class LedgerInitializeTest { | |||
return invoker.start(); | |||
} | |||
public LedgerRepository registLedger(HashDigest ledgerHash, String connString) { | |||
public LedgerQuery registLedger(HashDigest ledgerHash, String connString) { | |||
return ledgerManager.register(ledgerHash, memoryDBConnFactory.connect(connString).getStorageService()); | |||
} | |||
} | |||
@@ -30,7 +30,7 @@ import com.jd.blockchain.ledger.UserRegisterOperation; | |||
import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
import com.jd.blockchain.ledger.core.LedgerManager; | |||
import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.ledger.core.UserAccount; | |||
import com.jd.blockchain.ledger.core.UserAccountQuery; | |||
import com.jd.blockchain.storage.service.DbConnection; | |||
@@ -294,10 +294,10 @@ public class LedgerInitializeWebTest { | |||
HashDigest ledgerHash2 = callback2.waitReturn(); | |||
HashDigest ledgerHash3 = callback3.waitReturn(); | |||
LedgerRepository ledger0 = node0.registLedger(ledgerHash0); | |||
LedgerRepository ledger1 = node1.registLedger(ledgerHash1); | |||
LedgerRepository ledger2 = node2.registLedger(ledgerHash2); | |||
LedgerRepository ledger3 = node3.registLedger(ledgerHash3); | |||
LedgerQuery ledger0 = node0.registLedger(ledgerHash0); | |||
LedgerQuery ledger1 = node1.registLedger(ledgerHash1); | |||
LedgerQuery ledger2 = node2.registLedger(ledgerHash2); | |||
LedgerQuery ledger3 = node3.registLedger(ledgerHash3); | |||
LedgerBlock genesisBlock = ledger0.getLatestBlock(); | |||
@@ -390,7 +390,7 @@ public class LedgerInitializeWebTest { | |||
this.serverAddress = serverAddress; | |||
} | |||
public LedgerRepository registLedger(HashDigest ledgerHash) { | |||
public LedgerQuery registLedger(HashDigest ledgerHash) { | |||
// LedgerManage ledgerManager = ctx.getBean(LedgerManage.class); | |||
// | |||
// DbConnectionFactory dbConnFactory = ctx.getBean(DbConnectionFactory.class); | |||
@@ -400,7 +400,7 @@ public class LedgerInitializeWebTest { | |||
// DbConnection conn = db.connect(dbConnConfig.getUri(), | |||
// dbConnConfig.getPassword()); | |||
DbConnection conn = db.connect(dbConnConfig.getUri()); | |||
LedgerRepository ledgerRepo = ledgerManager.register(ledgerHash, conn.getStorageService()); | |||
LedgerQuery ledgerRepo = ledgerManager.register(ledgerHash, conn.getStorageService()); | |||
return ledgerRepo; | |||
} | |||
@@ -285,7 +285,7 @@ public class LedgerPerformanceTest { | |||
LedgerDataQuery previousDataSet = ledger.getDataSet(latestBlock); | |||
LedgerEditor newEditor = ledger.createNextBlock(); | |||
TransactionBatchProcessor txProc = new TransactionBatchProcessor(DEFAULT_SECURITY_MANAGER, newEditor, | |||
previousDataSet, opHandler, ledgerManager); | |||
ledger, opHandler); | |||
// 准备请求 | |||
int totalCount = batchSize * batchCount; | |||
@@ -323,7 +323,7 @@ public class LedgerPerformanceTest { | |||
LedgerEditor newEditor = ledger.createNextBlock(); | |||
TransactionBatchProcessor txProc = new TransactionBatchProcessor(DEFAULT_SECURITY_MANAGER, newEditor, | |||
previousDataSet, opHandler, ledgerManager); | |||
ledger, opHandler); | |||
testTxExec(txList, i * batchSize, batchSize, txProc); | |||
@@ -31,7 +31,7 @@ import com.jd.blockchain.ledger.core.LedgerConfiguration; | |||
import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
import com.jd.blockchain.ledger.core.LedgerManager; | |||
import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.storage.service.DbConnectionFactory; | |||
import com.jd.blockchain.tools.initializer.DBConnectionConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProcess; | |||
@@ -88,7 +88,7 @@ public class Utils { | |||
public static ParticipantNode[] loadParticipantNodes() { | |||
ParticipantNode[] participantNodes = new ParticipantNode[PUB_KEYS.length]; | |||
for (int i = 0; i < PUB_KEYS.length; i++) { | |||
participantNodes[i] = new PartNode(i, KeyGenUtils.decodePubKey(PUB_KEYS[i]), ParticipantNodeState.CONSENSUSED); | |||
participantNodes[i] = new PartNode(i, KeyGenUtils.decodePubKey(PUB_KEYS[i]), ParticipantNodeState.ACTIVED); | |||
} | |||
return participantNodes; | |||
} | |||
@@ -188,7 +188,7 @@ public class Utils { | |||
return invoker.start(); | |||
} | |||
public LedgerRepository registLedger(HashDigest ledgerHash, DBConnectionConfig dbConnConf) { | |||
public LedgerQuery registLedger(HashDigest ledgerHash, DBConnectionConfig dbConnConf) { | |||
return ledgerManager.register(ledgerHash, dbConnFactory.connect(dbConnConf.getUri()).getStorageService()); | |||
} | |||
} | |||
@@ -36,7 +36,7 @@ import com.jd.blockchain.crypto.AddressEncoding; | |||
import com.jd.blockchain.crypto.AsymmetricKeypair; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.ledger.core.LedgerManager; | |||
import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.sdk.BlockchainService; | |||
import com.jd.blockchain.storage.service.DbConnection; | |||
import com.jd.blockchain.storage.service.DbConnectionFactory; | |||
@@ -201,7 +201,7 @@ public class IntegrationBase { | |||
ParticipantInfoData participantInfoData = new ParticipantInfoData("peer4", participantKeyPair.getPubKey(), new NetworkAddress("127.0.0.1", 20000)); | |||
txTpl.states().update(new BlockchainIdentityData(participantInfoData.getPubKey()), participantInfoData.getNetworkAddress(), ParticipantNodeState.CONSENSUSED); | |||
txTpl.states().update(new BlockchainIdentityData(participantInfoData.getPubKey()), participantInfoData.getNetworkAddress(), ParticipantNodeState.ACTIVED); | |||
// 签名; | |||
PreparedTransaction ptx = txTpl.prepare(); | |||
@@ -220,7 +220,7 @@ public class IntegrationBase { | |||
return keyPairResponse; | |||
} | |||
public static void validKeyPair(IntegrationBase.KeyPairResponse keyPairResponse, LedgerRepository ledgerRepository, | |||
public static void validKeyPair(IntegrationBase.KeyPairResponse keyPairResponse, LedgerQuery ledgerRepository, | |||
KeyPairType keyPairType) { | |||
TransactionResponse txResp = keyPairResponse.txResp; | |||
HashDigest transactionHash = keyPairResponse.txHash; | |||
@@ -245,7 +245,7 @@ public class IntegrationBase { | |||
System.out.printf("validKeyPair end %s \r\n", index); | |||
} | |||
public static void validKeyPair(IntegrationBase.KeyPairResponse keyPairResponse, LedgerRepository ledgerRepository, | |||
public static void validKeyPair(IntegrationBase.KeyPairResponse keyPairResponse, LedgerQuery ledgerRepository, | |||
KeyPairType keyPairType, CountDownLatch countDownLatch) { | |||
TransactionResponse txResp = keyPairResponse.txResp; | |||
@@ -269,7 +269,7 @@ public class IntegrationBase { | |||
countDownLatch.countDown(); | |||
} | |||
public static void validKvWrite(IntegrationBase.KvResponse kvResponse, LedgerRepository ledgerRepository, | |||
public static void validKvWrite(IntegrationBase.KvResponse kvResponse, LedgerQuery ledgerRepository, | |||
BlockchainService blockchainService) { | |||
// 先验证应答 | |||
TransactionResponse txResp = kvResponse.getTxResp(); | |||
@@ -294,10 +294,10 @@ public class IntegrationBase { | |||
} | |||
} | |||
public static LedgerRepository[] buildLedgers(LedgerBindingConfig[] bindingConfigs, | |||
public static LedgerQuery[] buildLedgers(LedgerBindingConfig[] bindingConfigs, | |||
DbConnectionFactory[] dbConnectionFactories) { | |||
int[] ids = { 0, 1, 2, 3 }; | |||
LedgerRepository[] ledgers = new LedgerRepository[ids.length]; | |||
LedgerQuery[] ledgers = new LedgerQuery[ids.length]; | |||
LedgerManager[] ledgerManagers = new LedgerManager[ids.length]; | |||
for (int i = 0; i < ids.length; i++) { | |||
ledgerManagers[i] = new LedgerManager(); | |||
@@ -309,11 +309,11 @@ public class IntegrationBase { | |||
return ledgers; | |||
} | |||
public static void testConsistencyAmongNodes(LedgerRepository[] ledgers) { | |||
LedgerRepository ledger0 = ledgers[0]; | |||
public static void testConsistencyAmongNodes(LedgerQuery[] ledgers) { | |||
LedgerQuery ledger0 = ledgers[0]; | |||
LedgerBlock latestBlock0 = ledger0.retrieveLatestBlock(); | |||
for (int i = 1; i < ledgers.length; i++) { | |||
LedgerRepository otherLedger = ledgers[i]; | |||
LedgerQuery otherLedger = ledgers[i]; | |||
LedgerBlock otherLatestBlock = otherLedger.retrieveLatestBlock(); | |||
assertEquals(ledger0.getHash(), otherLedger.getHash()); | |||
assertEquals(ledger0.getLatestBlockHeight(), otherLedger.getLatestBlockHeight()); | |||
@@ -501,7 +501,7 @@ public class IntegrationBase { | |||
static HashDigest txContentHash; | |||
public static LedgerBlock testSDK_Contract(AsymmetricKeypair adminKey, HashDigest ledgerHash, | |||
BlockchainService blockchainService, LedgerRepository ledgerRepository) { | |||
BlockchainService blockchainService, LedgerQuery ledgerRepository) { | |||
KeyPairResponse keyPairResponse = testSDK_RegisterDataAccount(adminKey,ledgerHash,blockchainService); | |||
System.out.println("adminKey=" + AddressEncoding.generateAddress(adminKey.getPubKey())); | |||
@@ -19,7 +19,7 @@ import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.gateway.GatewayConfigProperties.KeyPairConfig; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.tools.initializer.DBConnectionConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerBindingConfig; | |||
import com.jd.blockchain.tools.initializer.Prompter; | |||
@@ -92,16 +92,16 @@ public class IntegrationBaseTest { | |||
public void testConsistencyAmongNodes(IntegratedContext context) { | |||
int[] ids = context.getNodeIds(); | |||
Node[] nodes = new Node[ids.length]; | |||
LedgerRepository[] ledgers = new LedgerRepository[ids.length]; | |||
LedgerQuery[] ledgers = new LedgerQuery[ids.length]; | |||
for (int i = 0; i < nodes.length; i++) { | |||
nodes[i] = context.getNode(ids[i]); | |||
HashDigest ledgerHash = nodes[i].getLedgerManager().getLedgerHashs()[0]; | |||
ledgers[i] = nodes[i].getLedgerManager().getLedger(ledgerHash); | |||
} | |||
LedgerRepository ledger0 = ledgers[0]; | |||
LedgerQuery ledger0 = ledgers[0]; | |||
LedgerBlock latestBlock0 = ledger0.retrieveLatestBlock(); | |||
for (int i = 1; i < ledgers.length; i++) { | |||
LedgerRepository otherLedger = ledgers[i]; | |||
LedgerQuery otherLedger = ledgers[i]; | |||
LedgerBlock otherLatestBlock = otherLedger.retrieveLatestBlock(); | |||
assertEquals(ledger0.getHash(), otherLedger.getHash()); | |||
assertEquals(ledger0.getLatestBlockHeight(), otherLedger.getLatestBlockHeight()); | |||
@@ -187,10 +187,10 @@ public class IntegrationBaseTest { | |||
assertEquals(ledgerHash0, ledgerHash2); | |||
assertEquals(ledgerHash0, ledgerHash3); | |||
LedgerRepository ledger0 = nodeCtx0.registLedger(ledgerHash0); | |||
LedgerRepository ledger1 = nodeCtx1.registLedger(ledgerHash1); | |||
LedgerRepository ledger2 = nodeCtx2.registLedger(ledgerHash2); | |||
LedgerRepository ledger3 = nodeCtx3.registLedger(ledgerHash3); | |||
LedgerQuery ledger0 = nodeCtx0.registLedger(ledgerHash0); | |||
LedgerQuery ledger1 = nodeCtx1.registLedger(ledgerHash1); | |||
LedgerQuery ledger2 = nodeCtx2.registLedger(ledgerHash2); | |||
LedgerQuery ledger3 = nodeCtx3.registLedger(ledgerHash3); | |||
assertNotNull(ledger0); | |||
assertNotNull(ledger1); | |||
@@ -29,7 +29,7 @@ import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.PreparedTransaction; | |||
import com.jd.blockchain.ledger.TransactionResponse; | |||
import com.jd.blockchain.ledger.TransactionTemplate; | |||
import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.sdk.BlockchainService; | |||
import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||
import com.jd.blockchain.tools.initializer.DBConnectionConfig; | |||
@@ -117,16 +117,16 @@ public class IntegrationTest2 { | |||
private void testConsistencyAmongNodes(IntegratedContext context) { | |||
int[] ids = context.getNodeIds(); | |||
Node[] nodes = new Node[ids.length]; | |||
LedgerRepository[] ledgers = new LedgerRepository[ids.length]; | |||
LedgerQuery[] ledgers = new LedgerQuery[ids.length]; | |||
for (int i = 0; i < nodes.length; i++) { | |||
nodes[i] = context.getNode(ids[i]); | |||
HashDigest ledgerHash = nodes[i].getLedgerManager().getLedgerHashs()[0]; | |||
ledgers[i] = nodes[i].getLedgerManager().getLedger(ledgerHash); | |||
} | |||
LedgerRepository ledger0 = ledgers[0]; | |||
LedgerQuery ledger0 = ledgers[0]; | |||
LedgerBlock latestBlock0 = ledger0.retrieveLatestBlock(); | |||
for (int i = 1; i < ledgers.length; i++) { | |||
LedgerRepository otherLedger = ledgers[i]; | |||
LedgerQuery otherLedger = ledgers[i]; | |||
LedgerBlock otherLatestBlock = otherLedger.retrieveLatestBlock(); | |||
assertEquals(ledger0.getHash(), otherLedger.getHash()); | |||
assertEquals(ledger0.getLatestBlockHeight(), otherLedger.getLatestBlockHeight()); | |||
@@ -225,10 +225,10 @@ public class IntegrationTest2 { | |||
assertEquals(ledgerHash0, ledgerHash2); | |||
assertEquals(ledgerHash0, ledgerHash3); | |||
LedgerRepository ledger0 = nodeCtx0.registLedger(ledgerHash0); | |||
LedgerRepository ledger1 = nodeCtx1.registLedger(ledgerHash1); | |||
LedgerRepository ledger2 = nodeCtx2.registLedger(ledgerHash2); | |||
LedgerRepository ledger3 = nodeCtx3.registLedger(ledgerHash3); | |||
LedgerQuery ledger0 = nodeCtx0.registLedger(ledgerHash0); | |||
LedgerQuery ledger1 = nodeCtx1.registLedger(ledgerHash1); | |||
LedgerQuery ledger2 = nodeCtx2.registLedger(ledgerHash2); | |||
LedgerQuery ledger3 = nodeCtx3.registLedger(ledgerHash3); | |||
assertNotNull(ledger0); | |||
assertNotNull(ledger1); | |||
@@ -12,7 +12,7 @@ import com.jd.blockchain.ledger.BlockchainKeypair; | |||
import com.jd.blockchain.ledger.ParticipantNodeState; | |||
import com.jd.blockchain.ledger.ParticipantStateUpdateInfo; | |||
import com.jd.blockchain.ledger.ParticipantStateUpdateInfoData; | |||
import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.sdk.BlockchainService; | |||
import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||
import com.jd.blockchain.storage.service.DbConnectionFactory; | |||
@@ -90,7 +90,7 @@ public class IntegrationTest4Bftsmart { | |||
gwStarting.waitReturn(); | |||
// 执行测试用例之前,校验每个节点的一致性; | |||
LedgerRepository[] ledgers = buildLedgers(new LedgerBindingConfig[]{ | |||
LedgerQuery[] ledgers = buildLedgers(new LedgerBindingConfig[]{ | |||
peerNodes[0].getLedgerBindingConfig(), | |||
peerNodes[1].getLedgerBindingConfig(), | |||
peerNodes[2].getLedgerBindingConfig(), | |||
@@ -104,7 +104,7 @@ public class IntegrationTest4Bftsmart { | |||
IntegrationBase.testConsistencyAmongNodes(ledgers); | |||
LedgerRepository ledgerRepository = ledgers[0]; | |||
LedgerQuery ledgerRepository = ledgers[0]; | |||
GatewayServiceFactory gwsrvFact = GatewayServiceFactory.connect(gateway.getServiceAddress()); | |||
@@ -7,7 +7,7 @@ import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.gateway.GatewayConfigProperties; | |||
import com.jd.blockchain.ledger.BlockchainKeypair; | |||
import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.sdk.BlockchainService; | |||
import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||
import com.jd.blockchain.storage.service.DbConnectionFactory; | |||
@@ -60,7 +60,7 @@ public class IntegrationTest4Contract { | |||
gwStarting.waitReturn(); | |||
// 执行测试用例之前,校验每个节点的一致性; | |||
LedgerRepository[] ledgers = buildLedgers(new LedgerBindingConfig[]{ | |||
LedgerQuery[] ledgers = buildLedgers(new LedgerBindingConfig[]{ | |||
peerNodes[0].getLedgerBindingConfig(), | |||
peerNodes[1].getLedgerBindingConfig(), | |||
peerNodes[2].getLedgerBindingConfig(), | |||
@@ -74,7 +74,7 @@ public class IntegrationTest4Contract { | |||
IntegrationBase.testConsistencyAmongNodes(ledgers); | |||
LedgerRepository ledgerRepository = ledgers[0]; | |||
LedgerQuery ledgerRepository = ledgers[0]; | |||
GatewayServiceFactory gwsrvFact = GatewayServiceFactory.connect(gateway.getServiceAddress()); | |||
@@ -98,7 +98,7 @@ public class IntegrationTest4MQ { | |||
gwStarting.waitReturn(); | |||
// 执行测试用例之前,校验每个节点的一致性; | |||
LedgerRepository[] ledgers = buildLedgers(new LedgerBindingConfig[]{ | |||
LedgerQuery[] ledgers = buildLedgers(new LedgerBindingConfig[]{ | |||
peerNodes[0].getLedgerBindingConfig(), | |||
peerNodes[1].getLedgerBindingConfig(), | |||
peerNodes[2].getLedgerBindingConfig(), | |||
@@ -112,7 +112,7 @@ public class IntegrationTest4MQ { | |||
IntegrationBase.testConsistencyAmongNodes(ledgers); | |||
LedgerRepository ledgerRepository = ledgers[0]; | |||
LedgerQuery ledgerRepository = ledgers[0]; | |||
GatewayServiceFactory gwsrvFact = GatewayServiceFactory.connect(gateway.getServiceAddress()); | |||
@@ -7,7 +7,7 @@ import com.jd.blockchain.ledger.core.DataAccount; | |||
import com.jd.blockchain.ledger.core.DataAccountQuery; | |||
import com.jd.blockchain.ledger.core.LedgerManage; | |||
import com.jd.blockchain.ledger.core.LedgerManager; | |||
import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.sdk.BlockchainService; | |||
import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||
import com.jd.blockchain.storage.service.DbConnection; | |||
@@ -109,7 +109,7 @@ public class IntegrationTestAll4Redis { | |||
gwStarting0.waitReturn(); | |||
// 执行测试用例之前,校验每个节点的一致性; | |||
LedgerRepository[] ledgers = buildLedgers( | |||
LedgerQuery[] ledgers = buildLedgers( | |||
new LedgerBindingConfig[] { bindingConfig0, bindingConfig1, bindingConfig2, bindingConfig3 }, | |||
new DbConnectionFactory[] { dbConnectionFactory0, dbConnectionFactory1, dbConnectionFactory2, | |||
dbConnectionFactory3 }); | |||
@@ -144,10 +144,10 @@ public class IntegrationTestAll4Redis { | |||
} | |||
} | |||
private LedgerRepository[] buildLedgers(LedgerBindingConfig[] bindingConfigs, | |||
private LedgerQuery[] buildLedgers(LedgerBindingConfig[] bindingConfigs, | |||
DbConnectionFactory[] dbConnectionFactories) { | |||
int[] ids = { 0, 1, 2, 3 }; | |||
LedgerRepository[] ledgers = new LedgerRepository[ids.length]; | |||
LedgerQuery[] ledgers = new LedgerQuery[ids.length]; | |||
LedgerManager[] ledgerManagers = new LedgerManager[ids.length]; | |||
for (int i = 0; i < ids.length; i++) { | |||
ledgerManagers[i] = new LedgerManager(); | |||
@@ -160,11 +160,11 @@ public class IntegrationTestAll4Redis { | |||
return ledgers; | |||
} | |||
private void testConsistencyAmongNodes(LedgerRepository[] ledgers) { | |||
LedgerRepository ledger0 = ledgers[0]; | |||
private void testConsistencyAmongNodes(LedgerQuery[] ledgers) { | |||
LedgerQuery ledger0 = ledgers[0]; | |||
LedgerBlock latestBlock0 = ledger0.retrieveLatestBlock(); | |||
for (int i = 1; i < ledgers.length; i++) { | |||
LedgerRepository otherLedger = ledgers[i]; | |||
LedgerQuery otherLedger = ledgers[i]; | |||
LedgerBlock otherLatestBlock = otherLedger.retrieveLatestBlock(); | |||
assertEquals(ledger0.getHash(), otherLedger.getHash()); | |||
assertEquals(ledger0.getLatestBlockHeight(), otherLedger.getLatestBlockHeight()); | |||
@@ -183,7 +183,7 @@ public class IntegrationTestAll4Redis { | |||
// 测试一个区块包含多个交易的写入情况,并验证写入结果; | |||
private void testWriteBatchTransactions(GatewayTestRunner gateway, AsymmetricKeypair adminKey, | |||
LedgerRepository ledgerRepository) { | |||
LedgerQuery ledgerRepository) { | |||
// 连接网关; | |||
GatewayServiceFactory gwsrvFact = GatewayServiceFactory.connect(gateway.getServiceAddress()); | |||
BlockchainService blockchainService = gwsrvFact.getBlockchainService(); | |||
@@ -233,7 +233,7 @@ public class IntegrationTestAll4Redis { | |||
return; | |||
} | |||
private void testSDK(GatewayTestRunner gateway, AsymmetricKeypair adminKey, LedgerRepository ledgerRepository) { | |||
private void testSDK(GatewayTestRunner gateway, AsymmetricKeypair adminKey, LedgerQuery ledgerRepository) { | |||
// 连接网关; | |||
GatewayServiceFactory gwsrvFact = GatewayServiceFactory.connect(gateway.getServiceAddress()); | |||
BlockchainService bcsrv = gwsrvFact.getBlockchainService(); | |||
@@ -248,7 +248,7 @@ public class IntegrationTestAll4Redis { | |||
} | |||
private void testSDK_InsertData(AsymmetricKeypair adminKey, HashDigest ledgerHash, | |||
BlockchainService blockchainService, Bytes dataAccountAddress, LedgerRepository ledgerRepository) { | |||
BlockchainService blockchainService, Bytes dataAccountAddress, LedgerQuery ledgerRepository) { | |||
// 在本地定义注册账号的 TX; | |||
TransactionTemplate txTemp = blockchainService.newTransaction(ledgerHash); | |||
@@ -292,7 +292,7 @@ public class IntegrationTestAll4Redis { | |||
} | |||
private BlockchainKeypair testSDK_RegisterDataAccount(AsymmetricKeypair adminKey, HashDigest ledgerHash, | |||
BlockchainService blockchainService, LedgerRepository ledgerRepository) { | |||
BlockchainService blockchainService, LedgerQuery ledgerRepository) { | |||
// 注册数据账户,并验证最终写入; | |||
BlockchainKeypair dataAccount = BlockchainKeyGenerator.getInstance().generate(); | |||
@@ -327,7 +327,7 @@ public class IntegrationTestAll4Redis { | |||
} | |||
private BlockchainKeypair testSDK_RegisterUser(AsymmetricKeypair adminKey, HashDigest ledgerHash, | |||
BlockchainService blockchainService, LedgerRepository ledgerRepository) { | |||
BlockchainService blockchainService, LedgerQuery ledgerRepository) { | |||
// 注册用户,并验证最终写入; | |||
BlockchainKeypair user = BlockchainKeyGenerator.getInstance().generate(); | |||
@@ -367,7 +367,7 @@ public class IntegrationTestAll4Redis { | |||
} | |||
private LedgerBlock testSDK_Contract(AsymmetricKeypair adminKey, HashDigest ledgerHash, | |||
BlockchainService blockchainService, LedgerRepository ledgerRepository) { | |||
BlockchainService blockchainService, LedgerQuery ledgerRepository) { | |||
System.out.println("adminKey=" + AddressEncoding.generateAddress(adminKey.getPubKey())); | |||
BlockchainKeypair userKey = BlockchainKeyGenerator.getInstance().generate(); | |||
System.out.println("userKey=" + userKey.getAddress()); | |||
@@ -418,7 +418,7 @@ public class IntegrationTestAll4Redis { | |||
} | |||
private void testContractExe(AsymmetricKeypair adminKey, HashDigest ledgerHash, BlockchainKeypair userKey, | |||
BlockchainService blockchainService, LedgerRepository ledgerRepository) { | |||
BlockchainService blockchainService, LedgerQuery ledgerRepository) { | |||
LedgerInfo ledgerInfo = blockchainService.getLedger(ledgerHash); | |||
LedgerBlock previousBlock = blockchainService.getBlock(ledgerHash, ledgerInfo.getLatestBlockHeight() - 1); | |||
@@ -463,7 +463,7 @@ public class IntegrationTestAll4Redis { | |||
} | |||
private void prepareContractData(AsymmetricKeypair adminKey, HashDigest ledgerHash, | |||
BlockchainService blockchainService, LedgerRepository ledgerRepository) { | |||
BlockchainService blockchainService, LedgerQuery ledgerRepository) { | |||
// 定义交易; | |||
TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash); | |||
@@ -31,7 +31,7 @@ import com.jd.blockchain.ledger.TransactionResponse; | |||
import com.jd.blockchain.ledger.TransactionTemplate; | |||
import com.jd.blockchain.ledger.core.DataAccountQuery; | |||
import com.jd.blockchain.ledger.core.LedgerManager; | |||
import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.sdk.BlockchainService; | |||
import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||
import com.jd.blockchain.storage.service.DbConnection; | |||
@@ -185,7 +185,7 @@ public class IntegrationTestDataAccount { | |||
DbConnection memoryBasedDb = context.getNode(0).getStorageDB() | |||
.connect(LedgerInitConsensusConfig.memConnectionStrings[0]); | |||
LedgerRepository ledgerRepository = ledgerManager.register(ledgerHashs[0], memoryBasedDb.getStorageService()); | |||
LedgerQuery ledgerRepository = ledgerManager.register(ledgerHashs[0], memoryBasedDb.getStorageService()); | |||
DataAccountQuery dataAccountSet = ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock()); | |||
@@ -227,16 +227,16 @@ public class IntegrationTestDataAccount { | |||
public void testConsistencyAmongNodes(IntegratedContext context) { | |||
int[] ids = context.getNodeIds(); | |||
Node[] nodes = new Node[ids.length]; | |||
LedgerRepository[] ledgers = new LedgerRepository[ids.length]; | |||
LedgerQuery[] ledgers = new LedgerQuery[ids.length]; | |||
for (int i = 0; i < nodes.length; i++) { | |||
nodes[i] = context.getNode(ids[i]); | |||
HashDigest ledgerHash = nodes[i].getLedgerManager().getLedgerHashs()[0]; | |||
ledgers[i] = nodes[i].getLedgerManager().getLedger(ledgerHash); | |||
} | |||
LedgerRepository ledger0 = ledgers[0]; | |||
LedgerQuery ledger0 = ledgers[0]; | |||
LedgerBlock latestBlock0 = ledger0.retrieveLatestBlock(); | |||
for (int i = 1; i < ledgers.length; i++) { | |||
LedgerRepository otherLedger = ledgers[i]; | |||
LedgerQuery otherLedger = ledgers[i]; | |||
LedgerBlock otherLatestBlock = otherLedger.retrieveLatestBlock(); | |||
assertEquals(ledger0.getHash(), otherLedger.getHash()); | |||
assertEquals(ledger0.getLatestBlockHeight(), otherLedger.getLatestBlockHeight()); | |||
@@ -322,10 +322,10 @@ public class IntegrationTestDataAccount { | |||
assertEquals(ledgerHash0, ledgerHash2); | |||
assertEquals(ledgerHash0, ledgerHash3); | |||
LedgerRepository ledger0 = nodeCtx0.registLedger(ledgerHash0); | |||
LedgerRepository ledger1 = nodeCtx1.registLedger(ledgerHash1); | |||
LedgerRepository ledger2 = nodeCtx2.registLedger(ledgerHash2); | |||
LedgerRepository ledger3 = nodeCtx3.registLedger(ledgerHash3); | |||
LedgerQuery ledger0 = nodeCtx0.registLedger(ledgerHash0); | |||
LedgerQuery ledger1 = nodeCtx1.registLedger(ledgerHash1); | |||
LedgerQuery ledger2 = nodeCtx2.registLedger(ledgerHash2); | |||
LedgerQuery ledger3 = nodeCtx3.registLedger(ledgerHash3); | |||
assertNotNull(ledger0); | |||
assertNotNull(ledger1); | |||
@@ -15,7 +15,7 @@ import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.gateway.GatewayConfigProperties; | |||
import com.jd.blockchain.ledger.BlockchainKeypair; | |||
import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.peer.PeerServerBooter; | |||
import com.jd.blockchain.sdk.BlockchainService; | |||
import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||
@@ -93,7 +93,7 @@ public class BftsmartLedgerInit { | |||
localConf4NodesLoad(); | |||
PeerTestRunner[] peerNodes = startNodes(4); | |||
// 检查账本一致性 | |||
LedgerRepository[] ledgers = checkNodes(peerNodes); | |||
LedgerQuery[] ledgers = checkNodes(peerNodes); | |||
txRequestTest(peerNodes, ledgers); | |||
} | |||
@@ -110,7 +110,7 @@ public class BftsmartLedgerInit { | |||
localConf8NodesLoad(); | |||
PeerTestRunner[] peerNodes = startNodes(8); | |||
// 检查账本一致性 | |||
LedgerRepository[] ledgers = checkNodes(peerNodes); | |||
LedgerQuery[] ledgers = checkNodes(peerNodes); | |||
txRequestTest(peerNodes, ledgers); | |||
} | |||
@@ -127,7 +127,7 @@ public class BftsmartLedgerInit { | |||
localConf16NodesLoad(); | |||
PeerTestRunner[] peerNodes = startNodes(16); | |||
// 检查账本一致性 | |||
LedgerRepository[] ledgers = checkNodes(peerNodes); | |||
LedgerQuery[] ledgers = checkNodes(peerNodes); | |||
txRequestTest(peerNodes, ledgers); | |||
} | |||
@@ -145,7 +145,7 @@ public class BftsmartLedgerInit { | |||
// ledgerInitPools.shutdown(); | |||
PeerTestRunner[] peerNodes = startNodes(32); | |||
// 检查账本一致性 | |||
LedgerRepository[] ledgers = checkNodes(peerNodes); | |||
LedgerQuery[] ledgers = checkNodes(peerNodes); | |||
txRequestTest(peerNodes, ledgers); | |||
} | |||
@@ -162,16 +162,16 @@ public class BftsmartLedgerInit { | |||
localConf64NodesLoad(); | |||
PeerTestRunner[] peerNodes = startNodes(64); | |||
// 检查账本一致性 | |||
LedgerRepository[] ledgers = checkNodes(peerNodes); | |||
LedgerQuery[] ledgers = checkNodes(peerNodes); | |||
txRequestTest(peerNodes, ledgers); | |||
} | |||
public void txRequestTest(PeerTestRunner[] peerNodes, LedgerRepository[] ledgers) { | |||
public void txRequestTest(PeerTestRunner[] peerNodes, LedgerQuery[] ledgers) { | |||
// 测试K-V | |||
GatewayTestRunner gateway = initGateWay(peerNodes[0]); | |||
LedgerRepository ledgerRepository = ledgers[0]; | |||
LedgerQuery ledgerRepository = ledgers[0]; | |||
HashDigest ledgerHash = ledgerRepository.getHash(); | |||
@@ -249,7 +249,7 @@ public class BftsmartLedgerInit { | |||
return gateway; | |||
} | |||
public LedgerRepository[] checkNodes(PeerTestRunner[] peerNodes) { | |||
public LedgerQuery[] checkNodes(PeerTestRunner[] peerNodes) { | |||
int size = peerNodes.length; | |||
LedgerBindingConfig[] ledgerBindingConfigs = new LedgerBindingConfig[size]; | |||
DbConnectionFactory[] connectionFactories = new DbConnectionFactory[size]; | |||
@@ -259,7 +259,7 @@ public class BftsmartLedgerInit { | |||
} | |||
// 执行测试用例之前,校验每个节点的一致性; | |||
LedgerRepository[] ledgers = buildLedgers(ledgerBindingConfigs, connectionFactories); | |||
LedgerQuery[] ledgers = buildLedgers(ledgerBindingConfigs, connectionFactories); | |||
IntegrationBase.testConsistencyAmongNodes(ledgers); | |||
return ledgers; | |||
} | |||
@@ -34,7 +34,7 @@ import com.jd.blockchain.ledger.core.CryptoConfig; | |||
import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
import com.jd.blockchain.ledger.core.LedgerManager; | |||
import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.ledger.core.UserAccount; | |||
import com.jd.blockchain.ledger.core.UserAccountQuery; | |||
import com.jd.blockchain.storage.service.utils.MemoryDBConnFactory; | |||
@@ -133,10 +133,10 @@ public class LedgerInitializeTest { | |||
assertEquals(ledgerHash0, ledgerHash2); | |||
assertEquals(ledgerHash0, ledgerHash3); | |||
LedgerRepository ledger0 = node0.registLedger(ledgerHash0, dbConnections[0]); | |||
LedgerRepository ledger1 = node1.registLedger(ledgerHash1, dbConnections[1]); | |||
LedgerRepository ledger2 = node2.registLedger(ledgerHash2, dbConnections[2]); | |||
LedgerRepository ledger3 = node3.registLedger(ledgerHash3, dbConnections[3]); | |||
LedgerQuery ledger0 = node0.registLedger(ledgerHash0, dbConnections[0]); | |||
LedgerQuery ledger1 = node1.registLedger(ledgerHash1, dbConnections[1]); | |||
LedgerQuery ledger2 = node2.registLedger(ledgerHash2, dbConnections[2]); | |||
LedgerQuery ledger3 = node3.registLedger(ledgerHash3, dbConnections[3]); | |||
assertNotNull(ledger0); | |||
assertNotNull(ledger1); | |||
@@ -277,7 +277,7 @@ public class LedgerInitializeTest { | |||
return invoker.start(); | |||
} | |||
public LedgerRepository registLedger(HashDigest ledgerHash, String memConn) { | |||
public LedgerQuery registLedger(HashDigest ledgerHash, String memConn) { | |||
return ledgerManager.register(ledgerHash, storageDb.connect(memConn).getStorageService()); | |||
} | |||
} | |||
@@ -139,10 +139,10 @@ public class LedgerInitializeWeb4Nodes { | |||
assertEquals(ledgerHash0, ledgerHash2); | |||
assertEquals(ledgerHash0, ledgerHash3); | |||
LedgerRepository ledger0 = node0.registLedger(ledgerHash0); | |||
LedgerRepository ledger1 = node1.registLedger(ledgerHash1); | |||
LedgerRepository ledger2 = node2.registLedger(ledgerHash2); | |||
LedgerRepository ledger3 = node3.registLedger(ledgerHash3); | |||
LedgerQuery ledger0 = node0.registLedger(ledgerHash0); | |||
LedgerQuery ledger1 = node1.registLedger(ledgerHash1); | |||
LedgerQuery ledger2 = node2.registLedger(ledgerHash2); | |||
LedgerQuery ledger3 = node3.registLedger(ledgerHash3); | |||
assertNotNull(ledger0); | |||
assertNotNull(ledger1); | |||
@@ -240,9 +240,9 @@ public class LedgerInitializeWeb4Nodes { | |||
this.serverAddress = serverAddress; | |||
} | |||
public LedgerRepository registLedger(HashDigest ledgerHash) { | |||
public LedgerQuery registLedger(HashDigest ledgerHash) { | |||
DbConnection conn = db.connect(dbConnConfig.getUri()); | |||
LedgerRepository ledgerRepo = ledgerManager.register(ledgerHash, conn.getStorageService()); | |||
LedgerQuery ledgerRepo = ledgerManager.register(ledgerHash, conn.getStorageService()); | |||
return ledgerRepo; | |||
} | |||
@@ -30,7 +30,7 @@ import com.jd.blockchain.ledger.UserRegisterOperation; | |||
import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
import com.jd.blockchain.ledger.core.LedgerManager; | |||
import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.storage.service.DbConnection; | |||
import com.jd.blockchain.storage.service.impl.composite.CompositeConnectionFactory; | |||
import com.jd.blockchain.tools.initializer.DBConnectionConfig; | |||
@@ -326,7 +326,7 @@ public class LedgerInitializeWeb4SingleStepsTest { | |||
this.serverAddress = serverAddress; | |||
} | |||
public LedgerRepository registLedger(HashDigest ledgerHash) { | |||
public LedgerQuery registLedger(HashDigest ledgerHash) { | |||
// LedgerManage ledgerManager = ctx.getBean(LedgerManage.class); | |||
// | |||
// DbConnectionFactory dbConnFactory = ctx.getBean(DbConnectionFactory.class); | |||
@@ -336,7 +336,7 @@ public class LedgerInitializeWeb4SingleStepsTest { | |||
// DbConnection conn = db.connect(dbConnConfig.getUri(), | |||
// dbConnConfig.getPassword()); | |||
DbConnection conn = db.connect(dbConnConfig.getUri()); | |||
LedgerRepository ledgerRepo = ledgerManager.register(ledgerHash, conn.getStorageService()); | |||
LedgerQuery ledgerRepo = ledgerManager.register(ledgerHash, conn.getStorageService()); | |||
return ledgerRepo; | |||
} | |||
@@ -83,8 +83,7 @@ public class LedgerBlockGeneratingTest { | |||
LedgerEditor newEditor = ledger.createNextBlock(); | |||
TransactionBatchProcessor txProc = new TransactionBatchProcessor( | |||
LedgerPerformanceTest.DEFAULT_SECURITY_MANAGER, newEditor, previousDataSet, opHandler, | |||
ledgerManager); | |||
LedgerPerformanceTest.DEFAULT_SECURITY_MANAGER, newEditor, ledger, opHandler); | |||
testTxExec(txList, i * batchSize, batchSize, txProc); | |||
@@ -7,9 +7,14 @@ | |||
<artifactId>test</artifactId> | |||
<version>1.1.0-SNAPSHOT</version> | |||
</parent> | |||
<artifactId>test-ledger-core</artifactId> | |||
<artifactId>test-ledger</artifactId> | |||
<dependencies> | |||
<dependency> | |||
<groupId>com.jd.blockchain</groupId> | |||
<artifactId>tools-initializer</artifactId> | |||
<version>${project.version}</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.jd.blockchain</groupId> | |||
<artifactId>ledger-core</artifactId> |
@@ -1,4 +1,4 @@ | |||
package test.perf.com.jd.blockchain.ledger.core; | |||
package test.perf.com.jd.blockchain.ledger; | |||
import java.io.IOException; | |||
import java.util.Random; |
@@ -0,0 +1,267 @@ | |||
package test.com.jd.blockchain.test.ledger; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertNotNull; | |||
import static org.junit.Assert.assertTrue; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.util.Arrays; | |||
import java.util.HashSet; | |||
import java.util.Set; | |||
import org.junit.Test; | |||
import org.springframework.core.io.ClassPathResource; | |||
import com.jd.blockchain.binaryproto.DataContractRegistry; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.ledger.BlockchainKeyGenerator; | |||
import com.jd.blockchain.ledger.BlockchainKeypair; | |||
import com.jd.blockchain.ledger.DataAccountRegisterOperation; | |||
import com.jd.blockchain.ledger.DigitalSignature; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
import com.jd.blockchain.ledger.LedgerInitOperation; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.LedgerPermission; | |||
import com.jd.blockchain.ledger.RolePrivilegeSettings; | |||
import com.jd.blockchain.ledger.RolePrivileges; | |||
import com.jd.blockchain.ledger.RolesConfigureOperation; | |||
import com.jd.blockchain.ledger.RolesPolicy; | |||
import com.jd.blockchain.ledger.TransactionBuilder; | |||
import com.jd.blockchain.ledger.TransactionPermission; | |||
import com.jd.blockchain.ledger.TransactionRequest; | |||
import com.jd.blockchain.ledger.TransactionRequestBuilder; | |||
import com.jd.blockchain.ledger.UserAuthorizeOperation; | |||
import com.jd.blockchain.ledger.UserRegisterOperation; | |||
import com.jd.blockchain.ledger.UserRoles; | |||
import com.jd.blockchain.ledger.core.DefaultOperationHandleRegisteration; | |||
import com.jd.blockchain.ledger.core.LedgerInitializer; | |||
import com.jd.blockchain.ledger.core.LedgerManager; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.ledger.core.OperationHandleRegisteration; | |||
import com.jd.blockchain.ledger.core.TransactionBatchProcessor; | |||
import com.jd.blockchain.service.TransactionBatchResult; | |||
import com.jd.blockchain.service.TransactionBatchResultHandle; | |||
import com.jd.blockchain.storage.service.KVStorageService; | |||
import com.jd.blockchain.storage.service.utils.MemoryKVStorage; | |||
import com.jd.blockchain.tools.initializer.web.LedgerInitConfiguration; | |||
import com.jd.blockchain.transaction.TxBuilder; | |||
import com.jd.blockchain.utils.Bytes; | |||
import com.jd.blockchain.utils.io.RuntimeIOException; | |||
public class RolesAuthorizationTest { | |||
private static final OperationHandleRegisteration HANDLE_REG = new DefaultOperationHandleRegisteration(); | |||
public static final String PASSWORD = "abc"; | |||
public static final String[] PUB_KEYS = { "3snPdw7i7PjVKiTH2VnXZu5H8QmNaSXpnk4ei533jFpuifyjS5zzH9", | |||
"3snPdw7i7PajLB35tEau1kmixc6ZrjLXgxwKbkv5bHhP7nT5dhD9eX", | |||
"3snPdw7i7PZi6TStiyc6mzjprnNhgs2atSGNS8wPYzhbKaUWGFJt7x", | |||
"3snPdw7i7PifPuRX7fu3jBjsb3rJRfDe9GtbDfvFJaJ4V4hHXQfhwk" }; | |||
public static final String[] PRIV_KEYS = { | |||
"177gjzHTznYdPgWqZrH43W3yp37onm74wYXT4v9FukpCHBrhRysBBZh7Pzdo5AMRyQGJD7x", | |||
"177gju9p5zrNdHJVEQnEEKF4ZjDDYmAXyfG84V5RPGVc5xFfmtwnHA7j51nyNLUFffzz5UT", | |||
"177gjtwLgmSx5v1hFb46ijh7L9kdbKUpJYqdKVf9afiEmAuLgo8Rck9yu5UuUcHknWJuWaF", | |||
"177gk1pudweTq5zgJTh8y3ENCTwtSFsKyX7YnpuKPo7rKgCkCBXVXh5z2syaTCPEMbuWRns" }; | |||
public static final BlockchainKeypair[] KEYS; | |||
private static final BlockchainKeypair ADMIN_USER; | |||
private static final BlockchainKeypair MANAGER_USER; | |||
private static final BlockchainKeypair DEFAULT_USER; | |||
private static final BlockchainKeypair GUEST_USER; | |||
// 预置的数据账户; | |||
private static final BlockchainIdentity DATA_ACCOUNT_ID = BlockchainKeyGenerator.getInstance().generate() | |||
.getIdentity(); | |||
static { | |||
KEYS = new BlockchainKeypair[PRIV_KEYS.length]; | |||
for (int i = 0; i < PRIV_KEYS.length; i++) { | |||
PrivKey privKey = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[i], PASSWORD); | |||
PubKey pubKey = KeyGenUtils.decodePubKey(PUB_KEYS[i]); | |||
KEYS[i] = new BlockchainKeypair(pubKey, privKey); | |||
} | |||
ADMIN_USER = KEYS[0]; | |||
MANAGER_USER = KEYS[1]; | |||
DEFAULT_USER = KEYS[2]; | |||
GUEST_USER = KEYS[3]; | |||
// ---------- | |||
DataContractRegistry.register(LedgerInitOperation.class); | |||
DataContractRegistry.register(UserRegisterOperation.class); | |||
DataContractRegistry.register(DataAccountRegisterOperation.class); | |||
DataContractRegistry.register(RolesConfigureOperation.class); | |||
DataContractRegistry.register(UserAuthorizeOperation.class); | |||
} | |||
@Test | |||
public void test() { | |||
MemoryKVStorage storage = new MemoryKVStorage(); | |||
LedgerBlock genesisBlock = initLedger(storage); | |||
LedgerManager ledgerManager = new LedgerManager(); | |||
LedgerRepository ledger = ledgerManager.register(genesisBlock.getHash(), storage); | |||
// 验证角色和用户的权限配置; | |||
assertUserRolesPermissions(ledger); | |||
// 预置数据; | |||
TransactionRequest tx = buildRequest(ledger.getHash(), ADMIN_USER, ADMIN_USER, new TransactionDefiner() { | |||
@Override | |||
public void define(TransactionBuilder txBuilder) { | |||
txBuilder.dataAccounts().register(DATA_ACCOUNT_ID); | |||
} | |||
}); | |||
TransactionBatchResult procResult = executeTransactions(ledger, tx); | |||
assertEquals(1, procResult.getBlock().getHeight()); | |||
} | |||
private TransactionBatchResult executeTransactions(LedgerRepository ledger, TransactionRequest... transactions) { | |||
TransactionBatchProcessor txProcessor = new TransactionBatchProcessor(ledger, HANDLE_REG); | |||
for (TransactionRequest request : transactions) { | |||
txProcessor.schedule(request); | |||
} | |||
TransactionBatchResultHandle procResult = txProcessor.prepare(); | |||
procResult.commit(); | |||
return procResult; | |||
} | |||
private TransactionRequest buildRequest(HashDigest ledgerHash, BlockchainKeypair endpoint, BlockchainKeypair node, | |||
TransactionDefiner definer) { | |||
TransactionBuilder txBuilder = new TxBuilder(ledgerHash); | |||
definer.define(txBuilder); | |||
TransactionRequestBuilder reqBuilder = txBuilder.prepareRequest(); | |||
reqBuilder.signAsEndpoint(endpoint); | |||
if (node != null) { | |||
reqBuilder.signAsNode(node); | |||
} | |||
return reqBuilder.buildRequest(); | |||
} | |||
private void assertUserRolesPermissions(LedgerQuery ledger) { | |||
// 验证角色-权限; | |||
assertRolePermissions(ledger, "DEFAULT", | |||
new LedgerPermission[] { LedgerPermission.REGISTER_USER, LedgerPermission.REGISTER_DATA_ACCOUNT }, | |||
new TransactionPermission[] { TransactionPermission.DIRECT_OPERATION, | |||
TransactionPermission.CONTRACT_OPERATION }); | |||
assertRolePermissions(ledger, "ADMIN", | |||
new LedgerPermission[] { LedgerPermission.CONFIGURE_ROLES, LedgerPermission.AUTHORIZE_USER_ROLES, | |||
LedgerPermission.SET_CONSENSUS, LedgerPermission.SET_CRYPTO, | |||
LedgerPermission.REGISTER_PARTICIPANT, LedgerPermission.REGISTER_USER }, | |||
new TransactionPermission[] { TransactionPermission.DIRECT_OPERATION }); | |||
assertRolePermissions(ledger, "MANAGER", | |||
new LedgerPermission[] { LedgerPermission.CONFIGURE_ROLES, LedgerPermission.AUTHORIZE_USER_ROLES, | |||
LedgerPermission.REGISTER_USER, LedgerPermission.REGISTER_DATA_ACCOUNT, | |||
LedgerPermission.REGISTER_CONTRACT, LedgerPermission.UPGRADE_CONTRACT, | |||
LedgerPermission.SET_USER_ATTRIBUTES, LedgerPermission.WRITE_DATA_ACCOUNT, | |||
LedgerPermission.APPROVE_TX }, | |||
new TransactionPermission[] { TransactionPermission.DIRECT_OPERATION, | |||
TransactionPermission.CONTRACT_OPERATION }); | |||
assertRolePermissions(ledger, "GUEST", new LedgerPermission[] {}, | |||
new TransactionPermission[] { TransactionPermission.CONTRACT_OPERATION }); | |||
// 验证用户-角色; | |||
assertUserRoles(ledger, ADMIN_USER, RolesPolicy.UNION, "ADMIN", "MANAGER"); | |||
assertUserRoles(ledger, MANAGER_USER, RolesPolicy.UNION, "MANAGER"); | |||
assertUserRoles(ledger, DEFAULT_USER, RolesPolicy.UNION); | |||
assertUserRoles(ledger, DEFAULT_USER, RolesPolicy.UNION); | |||
} | |||
private void assertUserRoles(LedgerQuery ledger, BlockchainKeypair userKey, RolesPolicy policy, String... roles) { | |||
assertUserRoles(ledger, userKey.getAddress(), policy, roles); | |||
} | |||
private void assertUserRoles(LedgerQuery ledger, Bytes address, RolesPolicy policy, String[] roles) { | |||
if (roles == null) { | |||
roles = new String[0]; | |||
} | |||
UserRoles userRoles = ledger.getAdminInfo().getUserRoles().getUserRoles(address); | |||
assertNotNull(userRoles); | |||
assertEquals(policy, userRoles.getPolicy()); | |||
Set<String> expectedRoles = new HashSet<String>(Arrays.asList(roles)); | |||
Set<String> actualRoles = userRoles.getRoleSet(); | |||
assertEquals(expectedRoles.size(), actualRoles.size()); | |||
for (String r : actualRoles) { | |||
assertTrue(expectedRoles.contains(r)); | |||
} | |||
} | |||
private void assertRolePermissions(LedgerQuery ledger, String roleName, LedgerPermission[] ledgerPermissions, | |||
TransactionPermission[] txPermissions) { | |||
RolePrivilegeSettings roles = ledger.getAdminInfo().getRolePrivileges(); | |||
assertTrue(roles.contains(roleName)); | |||
RolePrivileges privileges = roles.getRolePrivilege(roleName); | |||
assertEquals(ledgerPermissions.length, privileges.getLedgerPrivilege().getPermissionCount()); | |||
assertEquals(txPermissions.length, privileges.getTransactionPrivilege().getPermissionCount()); | |||
Set<LedgerPermission> expectedLedgerPermissions = new HashSet<LedgerPermission>( | |||
Arrays.asList(ledgerPermissions)); | |||
for (LedgerPermission p : LedgerPermission.values()) { | |||
if (expectedLedgerPermissions.contains(p)) { | |||
assertTrue(privileges.getLedgerPrivilege().isEnable(p)); | |||
} else { | |||
assertFalse(privileges.getLedgerPrivilege().isEnable(p)); | |||
} | |||
} | |||
Set<TransactionPermission> expectedTxPermissions = new HashSet<TransactionPermission>( | |||
Arrays.asList(txPermissions)); | |||
for (TransactionPermission p : TransactionPermission.values()) { | |||
if (expectedTxPermissions.contains(p)) { | |||
assertTrue(privileges.getTransactionPrivilege().isEnable(p)); | |||
} else { | |||
assertFalse(privileges.getTransactionPrivilege().isEnable(p)); | |||
} | |||
} | |||
} | |||
private LedgerBlock initLedger(KVStorageService storage) { | |||
LedgerInitProperties initProps = loadInitProperties(); | |||
LedgerInitConfiguration initConfig = LedgerInitConfiguration.create(initProps); | |||
LedgerInitializer initializer = LedgerInitializer.create(initConfig.getLedgerSettings(), | |||
initConfig.getSecuritySettings()); | |||
DigitalSignature sign0 = initializer.signTransaction(KEYS[0]); | |||
DigitalSignature sign1 = initializer.signTransaction(KEYS[1]); | |||
DigitalSignature sign2 = initializer.signTransaction(KEYS[2]); | |||
DigitalSignature sign3 = initializer.signTransaction(KEYS[3]); | |||
LedgerBlock genesisBlock = initializer.prepareLedger(storage, sign0, sign1, sign2, sign3); | |||
initializer.commit(); | |||
return genesisBlock; | |||
} | |||
private LedgerInitProperties loadInitProperties() { | |||
try { | |||
ClassPathResource ledgerInitSettingResource = new ClassPathResource("ledger.init"); | |||
InputStream in = ledgerInitSettingResource.getInputStream(); | |||
return LedgerInitProperties.resolve(in); | |||
} catch (IOException e) { | |||
throw new RuntimeIOException(e.getMessage(), e); | |||
} | |||
} | |||
private static interface TransactionDefiner { | |||
void define(TransactionBuilder txBuilder); | |||
} | |||
} |
@@ -0,0 +1,144 @@ | |||
# Copyright (c) 2007-2013 Alysson Bessani, Eduardo Alchieri, Paulo Sousa, and the authors indicated in the @author tags | |||
# | |||
# Licensed under the Apache License, Version 2.0 (the "License"); | |||
# you may not use this file except in compliance with the License. | |||
# You may obtain a copy of the License at | |||
# | |||
# http://www.apache.org/licenses/LICENSE-2.0 | |||
# | |||
# Unless required by applicable law or agreed to in writing, software | |||
# distributed under the License is distributed on an "AS IS" BASIS, | |||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
# See the License for the specific language governing permissions and | |||
# limitations under the License. | |||
############################################ | |||
####### Communication Configurations ####### | |||
############################################ | |||
#HMAC algorithm used to authenticate messages between processes (HmacMD5 is the default value) | |||
#This parameter is not currently being used being used | |||
#system.authentication.hmacAlgorithm = HmacSHA1 | |||
#Specify if the communication system should use a thread to send data (true or false) | |||
system.communication.useSenderThread = true | |||
#Force all processes to use the same public/private keys pair and secret key. This is useful when deploying experiments | |||
#and benchmarks, but must not be used in production systems. | |||
system.communication.defaultkeys = true | |||
############################################ | |||
### Replication Algorithm Configurations ### | |||
############################################ | |||
#Timeout to asking for a client request | |||
system.totalordermulticast.timeout = 2000 | |||
#Maximum batch size (in number of messages) | |||
system.totalordermulticast.maxbatchsize = 400 | |||
#Number of nonces (for non-determinism actions) generated | |||
system.totalordermulticast.nonces = 10 | |||
#if verification of leader-generated timestamps are increasing | |||
#it can only be used on systems in which the network clocks | |||
#are synchronized | |||
system.totalordermulticast.verifyTimestamps = false | |||
#Quantity of messages that can be stored in the receive queue of the communication system | |||
system.communication.inQueueSize = 500000 | |||
# Quantity of messages that can be stored in the send queue of each replica | |||
system.communication.outQueueSize = 500000 | |||
#Set to 1 if SMaRt should use signatures, set to 0 if otherwise | |||
system.communication.useSignatures = 0 | |||
#Set to 1 if SMaRt should use MAC's, set to 0 if otherwise | |||
system.communication.useMACs = 1 | |||
#Set to 1 if SMaRt should use the standard output to display debug messages, set to 0 if otherwise | |||
system.debug = 0 | |||
#Print information about the replica when it is shutdown | |||
system.shutdownhook = true | |||
############################################ | |||
###### State Transfer Configurations ####### | |||
############################################ | |||
#Activate the state transfer protocol ('true' to activate, 'false' to de-activate) | |||
system.totalordermulticast.state_transfer = true | |||
#Maximum ahead-of-time message not discarded | |||
system.totalordermulticast.highMark = 10000 | |||
#Maximum ahead-of-time message not discarded when the replica is still on EID 0 (after which the state transfer is triggered) | |||
system.totalordermulticast.revival_highMark = 10 | |||
#Number of ahead-of-time messages necessary to trigger the state transfer after a request timeout occurs | |||
system.totalordermulticast.timeout_highMark = 200 | |||
############################################ | |||
###### Log and Checkpoint Configurations ### | |||
############################################ | |||
system.totalordermulticast.log = true | |||
system.totalordermulticast.log_parallel = false | |||
system.totalordermulticast.log_to_disk = false | |||
system.totalordermulticast.sync_log = false | |||
#Period at which BFT-SMaRt requests the state to the application (for the state transfer state protocol) | |||
system.totalordermulticast.checkpoint_period = 1000 | |||
system.totalordermulticast.global_checkpoint_period = 120000 | |||
system.totalordermulticast.checkpoint_to_disk = false | |||
system.totalordermulticast.sync_ckp = false | |||
############################################ | |||
###### Reconfiguration Configurations ###### | |||
############################################ | |||
#The ID of the trust third party (TTP) | |||
system.ttp.id = 7002 | |||
#This sets if the system will function in Byzantine or crash-only mode. Set to "true" to support Byzantine faults | |||
system.bft = true | |||
#Custom View Storage; | |||
#view.storage.handler=bftsmart.reconfiguration.views.DefaultViewStorage | |||
#Number of servers in the group | |||
system.servers.num = 4 | |||
#Maximum number of faulty replicas | |||
system.servers.f = 1 | |||
#Replicas ID for the initial view, separated by a comma. | |||
# The number of replicas in this parameter should be equal to that specified in 'system.servers.num' | |||
system.initial.view = 0,1,2,3 | |||
#Configuration of all node servers; | |||
#PubKey of node server with specified ID, with base58 encoding. | |||
system.server.0.pubkey= | |||
system.server.0.network.host=127.0.0.1 | |||
system.server.0.network.port=8900 | |||
system.server.0.network.secure=false | |||
system.server.1.pubkey= | |||
system.server.1.network.host=127.0.0.1 | |||
system.server.1.network.port=8910 | |||
system.server.1.network.secure=false | |||
system.server.2.pubkey= | |||
system.server.2.network.host=127.0.0.1 | |||
system.server.2.network.port=8920 | |||
system.server.2.network.secure=false | |||
system.server.3.pubkey= | |||
system.server.3.network.host=127.0.0.1 | |||
system.server.3.network.port=8920 | |||
system.server.3.network.secure=false |
@@ -0,0 +1 @@ | |||
3snPdw7i7PZi6TStiyc6mzjprnNhgs2atSGNS8wPYzhbKaUWGFJt7x |
@@ -0,0 +1,165 @@ | |||
#账本的种子;一段16进制字符,最长可以包含64个字符;可以用字符“-”分隔,以便更容易读取; | |||
ledger.seed=932dfe23-fe23232f-283f32fa-dd32aa76-8322ca2f-56236cda-7136b322-cb323ffe | |||
#账本的描述名称;此属性不参与共识,仅仅在当前参与方的本地节点用于描述用途; | |||
ledger.name=test | |||
#声明账本的创建时间;格式为 “yyyy-MM-dd HH:mm:ss.SSSZ”,表示”年-月-日 时:分:秒:毫秒时区“;例如:“2019-08-01 14:26:58.069+0800”,其中,+0800 表示时区是东8区 | |||
created-time=2019-08-01 14:26:58.069+0800 | |||
#----------------------------------------------- | |||
# 初始的角色名称列表;可选项; | |||
# 角色名称不区分大小写,最长不超过20个字符;多个角色名称之间用半角的逗点“,”分隔; | |||
# 系统会预置一个默认角色“DEFAULT”,所有未指定角色的用户都以赋予该角色的权限;若初始化时未配置默认角色的权限,则为默认角色分配所有权限; | |||
# | |||
# 注:如果声明了角色,但未声明角色对应的权限清单,这会忽略该角色的初始化; | |||
# | |||
security.roles=DEFAULT, ADMIN, MANAGER, GUEST | |||
# 赋予角色的账本权限清单;可选项; | |||
# 可选的权限如下; | |||
# AUTHORIZE_ROLES, SET_CONSENSUS, SET_CRYPTO, REGISTER_PARTICIPANT, | |||
# REGISTER_USER, REGISTER_DATA_ACCOUNT, REGISTER_CONTRACT, UPGRADE_CONTRACT, | |||
# SET_USER_ATTRIBUTES, WRITE_DATA_ACCOUNT, | |||
# APPROVE_TX, CONSENSUS_TX | |||
# 多项权限之间用逗点“,”分隔; | |||
# | |||
security.role.DEFAULT.ledger-privileges=REGISTER_USER, REGISTER_DATA_ACCOUNT | |||
# 赋予角色的交易权限清单;可选项; | |||
# 可选的权限如下; | |||
# DIRECT_OPERATION, CONTRACT_OPERATION | |||
# 多项权限之间用逗点“,”分隔; | |||
# | |||
security.role.DEFAULT.tx-privileges=DIRECT_OPERATION, CONTRACT_OPERATION | |||
# 其它角色的配置示例; | |||
# 系统管理员角色:只能操作全局性的参数配置和用户注册,只能执行直接操作指令; | |||
security.role.ADMIN.ledger-privileges=CONFIGURE_ROLES, AUTHORIZE_USER_ROLES, SET_CONSENSUS, SET_CRYPTO, REGISTER_PARTICIPANT, REGISTER_USER | |||
security.role.ADMIN.tx-privileges=DIRECT_OPERATION | |||
# 业务主管角色:只能够执行账本数据相关的操作,包括注册用户、注册数据账户、注册合约、升级合约、写入数据等;能够执行直接操作指令和调用合约; | |||
security.role.MANAGER.ledger-privileges=CONFIGURE_ROLES, AUTHORIZE_USER_ROLES, REGISTER_USER, REGISTER_DATA_ACCOUNT, \ | |||
REGISTER_CONTRACT, UPGRADE_CONTRACT, SET_USER_ATTRIBUTES, WRITE_DATA_ACCOUNT, APPROVE_TX | |||
security.role.MANAGER.tx-privileges=DIRECT_OPERATION, CONTRACT_OPERATION | |||
# 访客角色:不具备任何的账本权限,只有数据读取的操作;也只能够通过调用合约来读取数据; | |||
security.role.GUEST.ledger-privileges= | |||
security.role.GUEST.tx-privileges=CONTRACT_OPERATION | |||
#----------------------------------------------- | |||
#共识服务提供者;必须; | |||
consensus.service-provider=com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider | |||
#共识服务的参数配置;必须; | |||
consensus.conf=classpath:bftsmart.config | |||
#密码服务提供者列表,以英文逗点“,”分隔;必须; | |||
crypto.service-providers=com.jd.blockchain.crypto.service.classic.ClassicCryptoService, \ | |||
com.jd.blockchain.crypto.service.sm.SMCryptoService | |||
#从存储中加载账本数据时,是否校验哈希;可选; | |||
crypto.verify-hash=true | |||
#哈希算法; | |||
crypto.hash-algorithm=SHA256 | |||
#参与方的个数,后续以 cons_parti.id 分别标识每一个参与方的配置; | |||
cons_parti.count=4 | |||
#第0个参与方的名称; | |||
cons_parti.0.name=jd.com | |||
#第0个参与方的公钥文件路径; | |||
cons_parti.0.pubkey-path=keys/jd-com.pub | |||
#第0个参与方的公钥内容(由keygen工具生成);此参数优先于 pubkey-path 参数; | |||
cons_parti.0.pubkey=3snPdw7i7PjVKiTH2VnXZu5H8QmNaSXpnk4ei533jFpuifyjS5zzH9 | |||
#第0个参与方的角色清单;可选项; | |||
cons_parti.0.roles=ADMIN, MANAGER | |||
#第0个参与方的角色权限策略,可选值有:UNION(并集),INTERSECT(交集);可选项; | |||
cons_parti.0.roles-policy=UNION | |||
#第0个参与方的共识服务的主机地址; | |||
cons_parti.0.consensus.host=127.0.0.1 | |||
#第0个参与方的共识服务的端口; | |||
cons_parti.0.consensus.port=8900 | |||
#第0个参与方的共识服务是否开启安全连接; | |||
cons_parti.0.consensus.secure=true | |||
#第0个参与方的账本初始服务的主机; | |||
cons_parti.0.initializer.host=127.0.0.1 | |||
#第0个参与方的账本初始服务的端口; | |||
cons_parti.0.initializer.port=8800 | |||
#第0个参与方的账本初始服务是否开启安全连接; | |||
cons_parti.0.initializer.secure=true | |||
#第1个参与方的名称; | |||
cons_parti.1.name=at.com | |||
#第1个参与方的公钥文件路径; | |||
cons_parti.1.pubkey-path=keys/at-com.pub | |||
#第1个参与方的公钥内容(由keygen工具生成);此参数优先于 pubkey-path 参数; | |||
cons_parti.1.pubkey=3snPdw7i7PajLB35tEau1kmixc6ZrjLXgxwKbkv5bHhP7nT5dhD9eX | |||
#第1个参与方的角色清单;可选项; | |||
cons_parti.1.roles=MANAGER | |||
#第1个参与方的角色权限策略,可选值有:UNION(并集),INTERSECT(交集);可选项; | |||
cons_parti.1.roles-policy=UNION | |||
#第1个参与方的共识服务的主机地址; | |||
cons_parti.1.consensus.host=127.0.0.1 | |||
#第1个参与方的共识服务的端口; | |||
cons_parti.1.consensus.port=8910 | |||
#第1个参与方的共识服务是否开启安全连接; | |||
cons_parti.1.consensus.secure=false | |||
#第1个参与方的账本初始服务的主机; | |||
cons_parti.1.initializer.host=127.0.0.1 | |||
#第1个参与方的账本初始服务的端口; | |||
cons_parti.1.initializer.port=8810 | |||
#第1个参与方的账本初始服务是否开启安全连接; | |||
cons_parti.1.initializer.secure=false | |||
#第2个参与方的名称; | |||
cons_parti.2.name=bt.com | |||
#第2个参与方的公钥文件路径; | |||
cons_parti.2.pubkey-path=classpath:keys/parti2.pub | |||
#第2个参与方的公钥内容(由keygen工具生成);此参数优先于 pubkey-path 参数; | |||
cons_parti.2.pubkey= | |||
#第2个参与方的角色清单;可选项; | |||
cons_parti.2.roles= | |||
#第2个参与方的角色权限策略,可选值有:UNION(并集),INTERSECT(交集);可选项; | |||
cons_parti.2.roles-policy= | |||
#第2个参与方的共识服务的主机地址; | |||
cons_parti.2.consensus.host=127.0.0.1 | |||
#第2个参与方的共识服务的端口; | |||
cons_parti.2.consensus.port=8920 | |||
#第2个参与方的共识服务是否开启安全连接; | |||
cons_parti.2.consensus.secure=false | |||
#第2个参与方的账本初始服务的主机; | |||
cons_parti.2.initializer.host=127.0.0.1 | |||
#第2个参与方的账本初始服务的端口; | |||
cons_parti.2.initializer.port=8820 | |||
#第2个参与方的账本初始服务是否开启安全连接; | |||
cons_parti.2.initializer.secure=true | |||
#第3个参与方的名称; | |||
cons_parti.3.name=xt.com | |||
#第3个参与方的公钥文件路径; | |||
cons_parti.3.pubkey-path=keys/xt-com.pub | |||
#第3个参与方的公钥内容(由keygen工具生成);此参数优先于 pubkey-path 参数; | |||
cons_parti.3.pubkey=3snPdw7i7PifPuRX7fu3jBjsb3rJRfDe9GtbDfvFJaJ4V4hHXQfhwk | |||
#第3个参与方的角色清单;可选项; | |||
cons_parti.3.roles=GUEST | |||
#第3个参与方的角色权限策略,可选值有:UNION(并集),INTERSECT(交集);可选项; | |||
cons_parti.3.roles-policy=INTERSECT | |||
#第3个参与方的共识服务的主机地址; | |||
cons_parti.3.consensus.host=127.0.0.1 | |||
#第3个参与方的共识服务的端口; | |||
cons_parti.3.consensus.port=8930 | |||
#第3个参与方的共识服务是否开启安全连接; | |||
cons_parti.3.consensus.secure=false | |||
#第3个参与方的账本初始服务的主机; | |||
cons_parti.3.initializer.host=127.0.0.1 | |||
#第3个参与方的账本初始服务的端口; | |||
cons_parti.3.initializer.port=8830 | |||
#第3个参与方的账本初始服务是否开启安全连接; | |||
cons_parti.3.initializer.secure=false |
@@ -0,0 +1,6 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<configuration> | |||
<include resource="org/springframework/boot/logging/logback/base.xml" /> | |||
<!-- 日志级别设置为 ERROR --> | |||
<root level="ERROR" /> | |||
</configuration> |
@@ -21,7 +21,6 @@ import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.LedgerInitProperties.CryptoProperties; | |||
import com.jd.blockchain.ledger.LedgerInitProperties.ParticipantProperties; | |||
import com.jd.blockchain.ledger.LedgerPermission; | |||
import com.jd.blockchain.ledger.ParticipantNode; | |||
import com.jd.blockchain.ledger.SecurityInitData; | |||
import com.jd.blockchain.ledger.TransactionPermission; | |||
import com.jd.blockchain.ledger.core.CryptoConfig; | |||
@@ -184,6 +183,8 @@ public class LedgerInitConfiguration { | |||
partiProps.getId(), partiProps.getName())); | |||
} | |||
} | |||
//去掉对默认角色的授权; | |||
securityInitData.addUserAuthencation(partiProps.getAddress(), roles, partiProps.getRolesPolicy()); | |||
} | |||
@@ -166,7 +166,7 @@ public class MockerNodeContext implements BlockchainQueryService { | |||
ledgerRepository = registerLedger(ledgerHash, dbConnectionConfig); | |||
queryService = new LedgerQueryService(ledgerManager); | |||
queryService = new LedgerQueryService(ledgerRepository); | |||
contractExeHandle.initLedger(ledgerManager, ledgerHash); | |||
@@ -442,7 +442,7 @@ public class MockerNodeContext implements BlockchainQueryService { | |||
LedgerBlock latestBlock = ledgerRepository.getLatestBlock(); | |||
LedgerDataQuery previousDataSet = ledgerRepository.getDataSet(latestBlock); | |||
TransactionBatchProcessor txProc = new TransactionBatchProcessor(getSecurityManager(), newEditor, | |||
previousDataSet, opHandler, ledgerManager); | |||
ledgerRepository, opHandler); | |||
TransactionResponse txResp = txProc.schedule(txRequest); | |||
TransactionBatchResultHandle handle = txProc.prepare(); | |||
handle.commit(); | |||
@@ -16,11 +16,10 @@ import com.jd.blockchain.ledger.BytesValueList; | |||
import com.jd.blockchain.ledger.ContractEventSendOperation; | |||
import com.jd.blockchain.ledger.Operation; | |||
import com.jd.blockchain.ledger.TransactionRequest; | |||
import com.jd.blockchain.ledger.core.LedgerDataQuery; | |||
import com.jd.blockchain.ledger.core.LedgerDataset; | |||
import com.jd.blockchain.ledger.core.LedgerManager; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.ledger.core.LedgerQueryService; | |||
import com.jd.blockchain.ledger.core.LedgerService; | |||
import com.jd.blockchain.ledger.core.OperationHandle; | |||
import com.jd.blockchain.ledger.core.OperationHandleContext; | |||
import com.jd.blockchain.ledger.core.TransactionRequestExtension; | |||
@@ -37,7 +36,7 @@ public class MockerContractExeHandle implements OperationHandle { | |||
@Override | |||
public BytesValue process(Operation op, LedgerDataset dataset, TransactionRequestExtension request, | |||
LedgerDataQuery previousBlockDataset, OperationHandleContext opHandleContext, LedgerService ledgerService) { | |||
LedgerQuery ledger, OperationHandleContext opHandleContext) { | |||
ContractEventSendOperation contractOP = (ContractEventSendOperation) op; | |||
HashDigest txHash = request.getTransactionContent().getHash(); | |||
@@ -46,7 +45,7 @@ public class MockerContractExeHandle implements OperationHandle { | |||
Object result = null; | |||
if (executorProxy != null) { | |||
LedgerQueryService queryService = new LedgerQueryService(ledgerManager); | |||
LedgerQueryService queryService = new LedgerQueryService(ledger); | |||
ContractLedgerContext ledgerContext = new ContractLedgerContext(queryService, opHandleContext); | |||
MockerContractEventContext contractEventContext = new MockerContractEventContext(ledgerHash, | |||
@@ -7,7 +7,7 @@ import com.jd.blockchain.ledger.TransactionContent; | |||
import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
import com.jd.blockchain.ledger.core.LedgerManager; | |||
import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.ledger.core.LedgerQuery; | |||
import com.jd.blockchain.mocker.config.LedgerInitWebConfiguration; | |||
import com.jd.blockchain.storage.service.DbConnection; | |||
import com.jd.blockchain.storage.service.impl.composite.CompositeConnectionFactory; | |||
@@ -61,9 +61,9 @@ public class NodeWebContext { | |||
this.serverAddress = serverAddress; | |||
} | |||
public LedgerRepository registLedger(HashDigest ledgerHash) { | |||
public LedgerQuery registLedger(HashDigest ledgerHash) { | |||
DbConnection conn = db.connect(dbConnConfig.getUri()); | |||
LedgerRepository ledgerRepo = ledgerManager.register(ledgerHash, conn.getStorageService()); | |||
LedgerQuery ledgerRepo = ledgerManager.register(ledgerHash, conn.getStorageService()); | |||
return ledgerRepo; | |||
} | |||
@@ -0,0 +1,8 @@ | |||
package com.jd.blockchain.utils; | |||
public interface Int8Code { | |||
byte getCode(); | |||
} |
@@ -4,7 +4,6 @@ import java.io.ByteArrayInputStream; | |||
import java.io.ByteArrayOutputStream; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.io.ObjectInputStream; | |||
import java.io.ObjectOutputStream; | |||
import java.io.OutputStream; | |||
@@ -46,9 +45,10 @@ public class BinarySerializeUtils { | |||
@SuppressWarnings("unchecked") | |||
public static <T> T deserialize(InputStream in) { | |||
try { | |||
ObjectInputStream objIn = new ObjectInputStream(in); | |||
Object obj = objIn.readObject(); | |||
return (T) obj; | |||
try(FilteredObjectInputStream objIn = new FilteredObjectInputStream(in)){ | |||
Object obj = objIn.readObject(); | |||
return (T) obj; | |||
} | |||
} catch (IOException e) { | |||
throw new RuntimeIOException(e.getMessage(), e); | |||
} catch (ClassNotFoundException e) { | |||
@@ -0,0 +1,35 @@ | |||
package com.jd.blockchain.utils.serialize.binary; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.io.ObjectInputStream; | |||
import java.io.ObjectStreamClass; | |||
import java.util.HashSet; | |||
import java.util.Set; | |||
public class FilteredObjectInputStream extends ObjectInputStream { | |||
private static final Set<String> classBlacklist = new HashSet<String>(); | |||
/** | |||
* 把指定类型加入禁止反序列化的类型黑名单; | |||
* | |||
* @param className | |||
*/ | |||
public static void addBlackList(String className) { | |||
classBlacklist.add(className); | |||
} | |||
public FilteredObjectInputStream(InputStream in) throws IOException { | |||
super(in); | |||
} | |||
@Override | |||
protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { | |||
if (classBlacklist.contains(desc.getName())) { | |||
throw new SecurityException("Class["+desc.getName()+"] is forbidden to deserialize because it is in the blacklist!"); | |||
} | |||
return super.resolveClass(desc); | |||
} | |||
} |