@@ -50,6 +50,7 @@ public interface DataCodes { | |||||
public static final int TX_OP_CONTRACT_EVENT_SEND = 0x340; | public static final int TX_OP_CONTRACT_EVENT_SEND = 0x340; | ||||
public static final int TX_OP_PARTICIPANT_REG = 0x350; | public static final int TX_OP_PARTICIPANT_REG = 0x350; | ||||
public static final int TX_OP_PARTICIPANT_STATE_UPDATE = 0x351; | |||||
public static final int TX_RESPONSE = 0x360; | public static final int TX_RESPONSE = 0x360; | ||||
@@ -71,7 +72,9 @@ public interface DataCodes { | |||||
public static final int METADATA_CONSENSUS_SETTING = 0x631; | public static final int METADATA_CONSENSUS_SETTING = 0x631; | ||||
public static final int METADATA_PARTICIPANT_INFO = 0x640; | |||||
public static final int METADATA_PARTICIPANT_INFO = 0x640; | |||||
public static final int METADATA_PARTICIPANT_STATE_INFO = 0x641; | |||||
public static final int METADATA_CRYPTO_SETTING = 0x642; | public static final int METADATA_CRYPTO_SETTING = 0x642; | ||||
@@ -249,6 +249,15 @@ public class LedgerAdminAccount implements Transactional, LedgerAdministration { | |||||
participants.addConsensusParticipant(participant); | participants.addConsensusParticipant(participant); | ||||
} | } | ||||
/** | |||||
* 更新参与方的状态参数; | |||||
* | |||||
* @param participant | |||||
*/ | |||||
public void updateParticipant(ParticipantNode participant) { | |||||
participants.updateConsensusParticipant(participant); | |||||
} | |||||
@Override | @Override | ||||
public boolean isUpdated() { | public boolean isUpdated() { | ||||
return updated || participants.isUpdated(); | return updated || participants.isUpdated(); | ||||
@@ -73,6 +73,25 @@ public class ParticipantDataSet implements Transactional, MerkleProvable { | |||||
} | } | ||||
} | } | ||||
/** | |||||
* 更新共识参与方的状态信息; <br> | |||||
* | |||||
* @param participant | |||||
*/ | |||||
public void updateConsensusParticipant(ParticipantNode participant) { | |||||
Bytes key = encodeKey(participant.getAddress()); | |||||
byte[] participantBytes = BinaryProtocol.encode(participant, ParticipantNode.class); | |||||
long version = dataset.getVersion(key); | |||||
if (version < 0) { | |||||
throw new LedgerException("Participant not exist, update failed!"); | |||||
} | |||||
long nv = dataset.setValue(key, participantBytes, version); | |||||
if (nv < 0) { | |||||
throw new LedgerException("Participant update failed!"); | |||||
} | |||||
} | |||||
private Bytes encodeKey(String address) { | private Bytes encodeKey(String address) { | ||||
// return id + ""; | // return id + ""; | ||||
return Bytes.fromString(address); | return Bytes.fromString(address); | ||||
@@ -28,6 +28,7 @@ public class DefaultOperationHandleRegisteration implements OperationHandleRegis | |||||
opHandles.add(new ParticipantRegisterOperationHandle()); | opHandles.add(new ParticipantRegisterOperationHandle()); | ||||
opHandles.add(new ContractCodeDeployOperationHandle()); | opHandles.add(new ContractCodeDeployOperationHandle()); | ||||
opHandles.add(new JVMContractEventSendOperationHandle()); | opHandles.add(new JVMContractEventSendOperationHandle()); | ||||
opHandles.add(new ParticipantStateUpdateOperationHandle()); | |||||
} | } | ||||
/** | /** | ||||
@@ -0,0 +1,84 @@ | |||||
package com.jd.blockchain.ledger.core.impl.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.core.impl.OperationHandleContext; | |||||
public class ParticipantStateUpdateOperationHandle implements OperationHandle { | |||||
@Override | |||||
public boolean support(Class<?> operationType) { | |||||
return ParticipantStateUpdateOperation.class.isAssignableFrom(operationType); | |||||
} | |||||
@Override | |||||
public BytesValue process(Operation op, LedgerDataSet newBlockDataset, TransactionRequestContext requestContext, LedgerDataSet previousBlockDataset, OperationHandleContext handleContext, LedgerService ledgerService) { | |||||
ParticipantStateUpdateOperation stateUpdateOperation = (ParticipantStateUpdateOperation) op; | |||||
LedgerAdminAccount adminAccount = newBlockDataset.getAdminAccount(); | |||||
ParticipantNode[] participants = adminAccount.getParticipants(); | |||||
ParticipantNode participantNode = null; | |||||
for(int i = 0; i < participants.length; i++) { | |||||
if (stateUpdateOperation.getStateUpdateInfo().getPubKey().equals(participants[i].getPubKey())) { | |||||
participantNode = new PartNode(participants[i].getId(), participants[i].getName(), participants[i].getPubKey(), ParticipantNodeState.CONSENSUSED); | |||||
} | |||||
} | |||||
adminAccount.updateParticipant(participantNode); | |||||
return null; | |||||
} | |||||
private static class PartNode implements ParticipantNode { | |||||
private int id; | |||||
private String address; | |||||
private String name; | |||||
private PubKey pubKey; | |||||
private ParticipantNodeState participantNodeState; | |||||
public PartNode(int id, String name, PubKey pubKey, ParticipantNodeState participantNodeState) { | |||||
this.id = id; | |||||
this.name = name; | |||||
this.pubKey = pubKey; | |||||
this.address = AddressEncoding.generateAddress(pubKey).toBase58(); | |||||
this.participantNodeState = participantNodeState; | |||||
} | |||||
@Override | |||||
public int getId() { | |||||
return id; | |||||
} | |||||
@Override | |||||
public String getAddress() { | |||||
return address; | |||||
} | |||||
@Override | |||||
public String getName() { | |||||
return name; | |||||
} | |||||
@Override | |||||
public PubKey getPubKey() { | |||||
return pubKey; | |||||
} | |||||
@Override | |||||
public ParticipantNodeState getParticipantNodeState() { | |||||
return participantNodeState; | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,31 @@ | |||||
package com.jd.blockchain.ledger; | |||||
import com.jd.blockchain.binaryproto.DataContract; | |||||
import com.jd.blockchain.binaryproto.DataField; | |||||
import com.jd.blockchain.binaryproto.PrimitiveType; | |||||
import com.jd.blockchain.consts.DataCodes; | |||||
import com.jd.blockchain.crypto.PubKey; | |||||
/** | |||||
* 参与方状态更新信息; | |||||
* | |||||
* | |||||
*/ | |||||
@DataContract(code = DataCodes.METADATA_PARTICIPANT_STATE_INFO) | |||||
public interface ParticipantStateUpdateInfo { | |||||
/** | |||||
* 公钥; | |||||
* | |||||
* @return | |||||
*/ | |||||
@DataField(order = 1, primitiveType = PrimitiveType.BYTES) | |||||
PubKey getPubKey(); | |||||
/** | |||||
* 参与方状态; | |||||
* | |||||
* @return | |||||
*/ | |||||
@DataField(order = 2, refEnum = true) | |||||
ParticipantNodeState getState(); | |||||
} |
@@ -0,0 +1,31 @@ | |||||
package com.jd.blockchain.ledger; | |||||
import com.jd.blockchain.crypto.PubKey; | |||||
public class ParticipantStateUpdateInfoData implements ParticipantStateUpdateInfo { | |||||
private PubKey pubKey; | |||||
private ParticipantNodeState state; | |||||
public ParticipantStateUpdateInfoData(PubKey pubKey, ParticipantNodeState state) { | |||||
this.pubKey = pubKey; | |||||
this.state = state; | |||||
} | |||||
public void setPubKey(PubKey pubKey) { | |||||
this.pubKey = pubKey; | |||||
} | |||||
@Override | |||||
public PubKey getPubKey() { | |||||
return pubKey; | |||||
} | |||||
public void setState(ParticipantNodeState state) { | |||||
this.state = state; | |||||
} | |||||
@Override | |||||
public ParticipantNodeState getState() { | |||||
return state; | |||||
} | |||||
} |
@@ -0,0 +1,11 @@ | |||||
package com.jd.blockchain.ledger; | |||||
import com.jd.blockchain.binaryproto.DataContract; | |||||
import com.jd.blockchain.binaryproto.DataField; | |||||
import com.jd.blockchain.consts.DataCodes; | |||||
@DataContract(code= DataCodes.TX_OP_PARTICIPANT_STATE_UPDATE) | |||||
public interface ParticipantStateUpdateOperation extends Operation { | |||||
@DataField(order=1, refContract = true) | |||||
ParticipantStateUpdateInfo getStateUpdateInfo(); | |||||
} |
@@ -25,6 +25,8 @@ public class BlockchainOperationFactory implements ClientOperator, LedgerInitOpe | |||||
private static final ParticipantRegisterOperationBuilderImpl PARTICIPANT_REG_OP_BUILDER = new ParticipantRegisterOperationBuilderImpl(); | private static final ParticipantRegisterOperationBuilderImpl PARTICIPANT_REG_OP_BUILDER = new ParticipantRegisterOperationBuilderImpl(); | ||||
private static final ParticipantStateUpdateOperationBuilderImpl PARTICIPANT_STATE_UPDATE_OP_BUILDER = new ParticipantStateUpdateOperationBuilderImpl(); | |||||
private LedgerInitOperationBuilder ledgerInitOpBuilder = new LedgerInitOperationBuilderFilter(); | private LedgerInitOperationBuilder ledgerInitOpBuilder = new LedgerInitOperationBuilderFilter(); | ||||
private UserRegisterOperationBuilder userRegOpBuilder = new UserRegisterOperationBuilderFilter(); | private UserRegisterOperationBuilder userRegOpBuilder = new UserRegisterOperationBuilderFilter(); | ||||
@@ -39,6 +41,8 @@ public class BlockchainOperationFactory implements ClientOperator, LedgerInitOpe | |||||
private ParticipantRegisterOperationBuilder participantRegOpBuilder = new ParticipantRegisterOperationBuilderFilter(); | private ParticipantRegisterOperationBuilder participantRegOpBuilder = new ParticipantRegisterOperationBuilderFilter(); | ||||
private ParticipantStateUpdateOperationBuilder participantStateModifyOpBuilder = new ParticipantStateUpdateOperationBuilderFilter(); | |||||
// TODO: 暂时只支持单线程情形,未考虑多线程; | // TODO: 暂时只支持单线程情形,未考虑多线程; | ||||
private List<Operation> operationList = new ArrayList<>(); | private List<Operation> operationList = new ArrayList<>(); | ||||
@@ -80,6 +84,9 @@ public class BlockchainOperationFactory implements ClientOperator, LedgerInitOpe | |||||
public ParticipantRegisterOperationBuilder participants() {return participantRegOpBuilder;} | public ParticipantRegisterOperationBuilder participants() {return participantRegOpBuilder;} | ||||
@Override | @Override | ||||
public ParticipantStateUpdateOperationBuilder states() {return participantStateModifyOpBuilder;} | |||||
@Override | |||||
public <T> T contract(String address, Class<T> contractIntf) { | public <T> T contract(String address, Class<T> contractIntf) { | ||||
return contractInvoProxyBuilder.create(address, contractIntf, contractEventSendOpBuilder); | return contractInvoProxyBuilder.create(address, contractIntf, contractEventSendOpBuilder); | ||||
} | } | ||||
@@ -262,6 +269,15 @@ public class BlockchainOperationFactory implements ClientOperator, LedgerInitOpe | |||||
} | } | ||||
} | } | ||||
private class ParticipantStateUpdateOperationBuilderFilter implements ParticipantStateUpdateOperationBuilder { | |||||
@Override | |||||
public ParticipantStateUpdateOperation update(ParticipantStateUpdateInfo stateUpdateInfo) { | |||||
ParticipantStateUpdateOperation op = PARTICIPANT_STATE_UPDATE_OP_BUILDER.update(stateUpdateInfo); | |||||
operationList.add(op); | |||||
return op; | |||||
} | |||||
} | |||||
private class ContractEventSendOperationBuilderFilter implements ContractEventSendOperationBuilder { | private class ContractEventSendOperationBuilderFilter implements ContractEventSendOperationBuilder { | ||||
@Override | @Override | ||||
@@ -6,6 +6,6 @@ package com.jd.blockchain.transaction; | |||||
* @author huanghaiquan | * @author huanghaiquan | ||||
* | * | ||||
*/ | */ | ||||
public interface ClientOperator extends UserOperator, DataAccountOperator, ContractOperator, EventOperator, ParticipantOperator { | |||||
public interface ClientOperator extends UserOperator, DataAccountOperator, ContractOperator, EventOperator, ParticipantOperator, ParticipantStateOperator{ | |||||
} | } |
@@ -0,0 +1,10 @@ | |||||
package com.jd.blockchain.transaction; | |||||
public interface ParticipantStateOperator { | |||||
/** | |||||
* 参与方状态更新操作; | |||||
* | |||||
* @return | |||||
*/ | |||||
ParticipantStateUpdateOperationBuilder states(); | |||||
} |
@@ -0,0 +1,23 @@ | |||||
package com.jd.blockchain.transaction; | |||||
import com.jd.blockchain.binaryproto.DataContractRegistry; | |||||
import com.jd.blockchain.ledger.ParticipantStateUpdateInfo; | |||||
import com.jd.blockchain.ledger.ParticipantStateUpdateOperation; | |||||
public class ParticipantStateUpdateOpTemplate implements ParticipantStateUpdateOperation { | |||||
static { | |||||
DataContractRegistry.register(ParticipantStateUpdateOperation.class); | |||||
} | |||||
private ParticipantStateUpdateInfo stateUpdateInfo; | |||||
public ParticipantStateUpdateOpTemplate(ParticipantStateUpdateInfo stateUpdateInfo) { | |||||
this.stateUpdateInfo = stateUpdateInfo; | |||||
} | |||||
@Override | |||||
public ParticipantStateUpdateInfo getStateUpdateInfo() { | |||||
return stateUpdateInfo; | |||||
} | |||||
} |
@@ -0,0 +1,18 @@ | |||||
package com.jd.blockchain.transaction; | |||||
import com.jd.blockchain.ledger.ParticipantStateUpdateInfo; | |||||
import com.jd.blockchain.ledger.ParticipantStateUpdateOperation; | |||||
public interface ParticipantStateUpdateOperationBuilder { | |||||
/** | |||||
* 更新参与方状态,已注册->参与共识; | |||||
* | |||||
* @param | |||||
* | |||||
* @param | |||||
* | |||||
* @return | |||||
*/ | |||||
ParticipantStateUpdateOperation update(ParticipantStateUpdateInfo stateUpdateInfo); | |||||
} |
@@ -0,0 +1,12 @@ | |||||
package com.jd.blockchain.transaction; | |||||
import com.jd.blockchain.ledger.ParticipantStateUpdateInfo; | |||||
import com.jd.blockchain.ledger.ParticipantStateUpdateOperation; | |||||
public class ParticipantStateUpdateOperationBuilderImpl implements ParticipantStateUpdateOperationBuilder { | |||||
@Override | |||||
public ParticipantStateUpdateOperation update(ParticipantStateUpdateInfo stateUpdateInfo) { | |||||
return new ParticipantStateUpdateOpTemplate(stateUpdateInfo); | |||||
} | |||||
} |
@@ -114,6 +114,9 @@ public class TxBuilder implements TransactionBuilder { | |||||
public ParticipantRegisterOperationBuilder participants() {return opFactory.participants(); } | public ParticipantRegisterOperationBuilder participants() {return opFactory.participants(); } | ||||
@Override | @Override | ||||
public ParticipantStateUpdateOperationBuilder states() {return opFactory.states(); } | |||||
@Override | |||||
public <T> T contract(Bytes address, Class<T> contractIntf) { | public <T> T contract(Bytes address, Class<T> contractIntf) { | ||||
return opFactory.contract(address, contractIntf); | return opFactory.contract(address, contractIntf); | ||||
} | } | ||||
@@ -72,6 +72,12 @@ public class TxTemplate implements TransactionTemplate { | |||||
} | } | ||||
@Override | @Override | ||||
public ParticipantStateUpdateOperationBuilder states() { | |||||
stateManager.operate(); | |||||
return txBuilder.states(); | |||||
} | |||||
@Override | |||||
public <T> T contract(Bytes address, Class<T> contractIntf) { | public <T> T contract(Bytes address, Class<T> contractIntf) { | ||||
stateManager.operate(); | stateManager.operate(); | ||||
return txBuilder.contract(address, contractIntf); | return txBuilder.contract(address, contractIntf); | ||||
@@ -20,7 +20,7 @@ import static org.junit.Assert.assertTrue; | |||||
* @since 1.0.0 | * @since 1.0.0 | ||||
*/ | */ | ||||
public class SDK_GateWay_Participant_Test_ { | |||||
public class SDK_GateWay_Participant_Regist_Test_ { | |||||
private PrivKey privKey; | private PrivKey privKey; | ||||
private PubKey pubKey; | private PubKey pubKey; |
@@ -0,0 +1,91 @@ | |||||
package test.com.jd.blockchain.sdk.test; | |||||
import com.jd.blockchain.binaryproto.DataContractRegistry; | |||||
import com.jd.blockchain.crypto.*; | |||||
import com.jd.blockchain.ledger.*; | |||||
import com.jd.blockchain.sdk.BlockchainService; | |||||
import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||||
import com.jd.blockchain.sdk.samples.SDKDemo_Constant; | |||||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||||
import org.junit.Before; | |||||
import org.junit.Test; | |||||
import static org.junit.Assert.assertTrue; | |||||
/** | |||||
* 参与方状态更新测试 | |||||
* @author zhangshuang | |||||
* @create 2019/7/18 | |||||
* @since 1.0.0 | |||||
*/ | |||||
public class SDK_GateWay_Participant_State_Update_Test_ { | |||||
private PrivKey privKey; | |||||
private PubKey pubKey; | |||||
private BlockchainKeypair CLIENT_CERT = null; | |||||
private String GATEWAY_IPADDR = null; | |||||
private int GATEWAY_PORT; | |||||
private boolean SECURE; | |||||
private BlockchainService service; | |||||
//根据密码工具产生的公私钥 | |||||
static String PUB = "3snPdw7i7PkdgqiGX7GbZuFSi1cwZn7vtjw4vifb1YoXgr9k6Kfmis"; | |||||
String PRIV = "177gjtZu8w1phqHFVNiFhA35cfimXmP6VuqrBFhfbXBWK8s4TRwro2tnpffwP1Emwr6SMN6"; | |||||
@Before | |||||
public void init() { | |||||
privKey = SDK_GateWay_KeyPair_Para.privkey1; | |||||
pubKey = SDK_GateWay_KeyPair_Para.pubKey1; | |||||
CLIENT_CERT = new BlockchainKeypair(SDK_GateWay_KeyPair_Para.pubKey0, SDK_GateWay_KeyPair_Para.privkey0); | |||||
GATEWAY_IPADDR = "127.0.0.1"; | |||||
GATEWAY_PORT = 11000; | |||||
SECURE = false; | |||||
GatewayServiceFactory serviceFactory = GatewayServiceFactory.connect(GATEWAY_IPADDR, GATEWAY_PORT, SECURE, | |||||
CLIENT_CERT); | |||||
service = serviceFactory.getBlockchainService(); | |||||
DataContractRegistry.register(TransactionContent.class); | |||||
DataContractRegistry.register(TransactionContentBody.class); | |||||
DataContractRegistry.register(TransactionRequest.class); | |||||
DataContractRegistry.register(NodeRequest.class); | |||||
DataContractRegistry.register(EndpointRequest.class); | |||||
DataContractRegistry.register(TransactionResponse.class); | |||||
} | |||||
@Test | |||||
public void updateParticipantState_Test() { | |||||
HashDigest[] ledgerHashs = service.getLedgerHashs(); | |||||
// 在本地定义注册账号的 TX; | |||||
TransactionTemplate txTemp = service.newTransaction(ledgerHashs[0]); | |||||
//existed signer | |||||
AsymmetricKeypair keyPair = new BlockchainKeypair(pubKey, privKey); | |||||
PrivKey privKey = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV, SDKDemo_Constant.PASSWORD); | |||||
PubKey pubKey = KeyGenCommand.decodePubKey(PUB); | |||||
System.out.println("Address = "+AddressEncoding.generateAddress(pubKey)); | |||||
ParticipantStateUpdateInfo stateUpdateInfo = new ParticipantStateUpdateInfoData(pubKey, ParticipantNodeState.CONSENSUSED); | |||||
txTemp.states().update(stateUpdateInfo); | |||||
// TX 准备就绪; | |||||
PreparedTransaction prepTx = txTemp.prepare(); | |||||
// 使用私钥进行签名; | |||||
prepTx.sign(keyPair); | |||||
// 提交交易; | |||||
TransactionResponse transactionResponse = prepTx.commit(); | |||||
assertTrue(transactionResponse.isSuccess()); | |||||
} | |||||
} |
@@ -25,6 +25,7 @@ import java.util.Random; | |||||
import java.util.concurrent.CountDownLatch; | import java.util.concurrent.CountDownLatch; | ||||
import java.util.concurrent.atomic.AtomicLong; | import java.util.concurrent.atomic.AtomicLong; | ||||
import com.jd.blockchain.crypto.PubKey; | |||||
import com.jd.blockchain.ledger.*; | import com.jd.blockchain.ledger.*; | ||||
import org.apache.commons.io.FileUtils; | import org.apache.commons.io.FileUtils; | ||||
import org.springframework.core.io.ClassPathResource; | import org.springframework.core.io.ClassPathResource; | ||||
@@ -195,6 +196,32 @@ public class IntegrationBase { | |||||
return keyPairResponse; | return keyPairResponse; | ||||
} | } | ||||
public static KeyPairResponse testSDK_UpdateParticipantState(AsymmetricKeypair adminKey, BlockchainKeypair participantKeyPair, HashDigest ledgerHash, | |||||
BlockchainService blockchainService) { | |||||
// 定义交易; | |||||
TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash); | |||||
ParticipantStateUpdateInfo stateUpdateInfo = new ParticipantStateUpdateInfoData(participantKeyPair.getPubKey(), ParticipantNodeState.CONSENSUSED); | |||||
txTpl.states().update(stateUpdateInfo); | |||||
// 签名; | |||||
PreparedTransaction ptx = txTpl.prepare(); | |||||
HashDigest transactionHash = ptx.getHash(); | |||||
ptx.sign(adminKey); | |||||
// 提交并等待共识返回; | |||||
TransactionResponse txResp = ptx.commit(); | |||||
KeyPairResponse keyPairResponse = new KeyPairResponse(); | |||||
keyPairResponse.keyPair = participantKeyPair; | |||||
keyPairResponse.txResp = txResp; | |||||
keyPairResponse.txHash = transactionHash; | |||||
return keyPairResponse; | |||||
} | |||||
public static void validKeyPair(IntegrationBase.KeyPairResponse keyPairResponse, LedgerRepository ledgerRepository, | public static void validKeyPair(IntegrationBase.KeyPairResponse keyPairResponse, LedgerRepository ledgerRepository, | ||||
KeyPairType keyPairType) { | KeyPairType keyPairType) { | ||||
TransactionResponse txResp = keyPairResponse.txResp; | TransactionResponse txResp = keyPairResponse.txResp; | ||||
@@ -6,6 +6,9 @@ import com.jd.blockchain.crypto.PrivKey; | |||||
import com.jd.blockchain.crypto.PubKey; | import com.jd.blockchain.crypto.PubKey; | ||||
import com.jd.blockchain.gateway.GatewayConfigProperties; | import com.jd.blockchain.gateway.GatewayConfigProperties; | ||||
import com.jd.blockchain.ledger.BlockchainKeypair; | 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.LedgerRepository; | ||||
import com.jd.blockchain.sdk.BlockchainService; | import com.jd.blockchain.sdk.BlockchainService; | ||||
import com.jd.blockchain.sdk.client.GatewayServiceFactory; | import com.jd.blockchain.sdk.client.GatewayServiceFactory; | ||||
@@ -32,6 +35,8 @@ public class IntegrationTest4Bftsmart { | |||||
private static final boolean isRegisterParticipant = true; | private static final boolean isRegisterParticipant = true; | ||||
private static final boolean isParticipantStateUpdate = true; | |||||
private static final boolean isWriteKv = true; | private static final boolean isWriteKv = true; | ||||
private static final String DB_TYPE_MEM = "mem"; | private static final String DB_TYPE_MEM = "mem"; | ||||
@@ -148,8 +153,9 @@ public class IntegrationTest4Bftsmart { | |||||
System.out.printf("before add participant: participantCount = %d, userCount = %d\r\n", (int)participantCount, (int)userCount); | System.out.printf("before add participant: participantCount = %d, userCount = %d\r\n", (int)participantCount, (int)userCount); | ||||
IntegrationBase.KeyPairResponse participantResponse; | |||||
if (isRegisterParticipant) { | if (isRegisterParticipant) { | ||||
IntegrationBase.KeyPairResponse participantResponse = IntegrationBase.testSDK_RegisterParticipant(adminKey, ledgerHash, blockchainService); | |||||
participantResponse = IntegrationBase.testSDK_RegisterParticipant(adminKey, ledgerHash, blockchainService); | |||||
} | } | ||||
participantCount = ledgerRepository.getAdminAccount(ledgerRepository.retrieveLatestBlock()).getParticipantCount(); | participantCount = ledgerRepository.getAdminAccount(ledgerRepository.retrieveLatestBlock()).getParticipantCount(); | ||||
@@ -158,6 +164,21 @@ public class IntegrationTest4Bftsmart { | |||||
System.out.printf("after add participant: participantCount = %d, userCount = %d\r\n", (int)participantCount, (int)userCount); | System.out.printf("after add participant: participantCount = %d, userCount = %d\r\n", (int)participantCount, (int)userCount); | ||||
System.out.println("update participant state before \r\n"); | |||||
for (int i = 0; i < participantCount; i++) { | |||||
System.out.printf("part%d state = %d\r\n",i, ledgerRepository.getAdminAccount(ledgerRepository.retrieveLatestBlock()).getParticipants()[i].getParticipantNodeState().CODE); | |||||
} | |||||
if (isParticipantStateUpdate) { | |||||
IntegrationBase.testSDK_UpdateParticipantState(adminKey, new BlockchainKeypair(participantResponse.getKeyPair().getPubKey(), participantResponse.getKeyPair().getPrivKey()), ledgerHash, blockchainService); | |||||
} | |||||
System.out.println("update participant state after\r\n"); | |||||
for (int i = 0; i < participantCount; i++) { | |||||
System.out.printf("part%d state = %d\r\n",i, ledgerRepository.getAdminAccount(ledgerRepository.retrieveLatestBlock()).getParticipants()[i].getParticipantNodeState().CODE); | |||||
} | |||||
try { | try { | ||||
System.out.println("----------------- Init Completed -----------------"); | System.out.println("----------------- Init Completed -----------------"); | ||||
@@ -32,6 +32,8 @@ public class IntegrationTest4MQ { | |||||
private static final boolean isRegisterParticipant = true; | private static final boolean isRegisterParticipant = true; | ||||
private static final boolean isParticipantStateUpdate = true; | |||||
private static final boolean isWriteKv = true; | private static final boolean isWriteKv = true; | ||||
private static final boolean isContract = false; | private static final boolean isContract = false; | ||||
@@ -146,8 +148,9 @@ public class IntegrationTest4MQ { | |||||
System.out.printf("before add participant: participantCount = %d, userCount = %d\r\n", (int)participantCount, (int)userCount); | System.out.printf("before add participant: participantCount = %d, userCount = %d\r\n", (int)participantCount, (int)userCount); | ||||
IntegrationBase.KeyPairResponse participantResponse; | |||||
if (isRegisterParticipant) { | if (isRegisterParticipant) { | ||||
IntegrationBase.KeyPairResponse participantResponse = IntegrationBase.testSDK_RegisterParticipant(adminKey, ledgerHash, blockchainService); | |||||
participantResponse = IntegrationBase.testSDK_RegisterParticipant(adminKey, ledgerHash, blockchainService); | |||||
} | } | ||||
participantCount = ledgerRepository.getAdminAccount(ledgerRepository.retrieveLatestBlock()).getParticipantCount(); | participantCount = ledgerRepository.getAdminAccount(ledgerRepository.retrieveLatestBlock()).getParticipantCount(); | ||||
@@ -156,6 +159,24 @@ public class IntegrationTest4MQ { | |||||
System.out.printf("after add participant: participantCount = %d, userCount = %d\r\n", (int)participantCount, (int)userCount); | System.out.printf("after add participant: participantCount = %d, userCount = %d\r\n", (int)participantCount, (int)userCount); | ||||
System.out.printf("after add participant: participantCount = %d, userCount = %d\r\n", (int)participantCount, (int)userCount); | |||||
System.out.println("update participant state before \r\n"); | |||||
for (int i = 0; i < participantCount; i++) { | |||||
System.out.printf("part%d state = %d\r\n",i, ledgerRepository.getAdminAccount(ledgerRepository.retrieveLatestBlock()).getParticipants()[i].getParticipantNodeState().CODE); | |||||
} | |||||
if (isParticipantStateUpdate) { | |||||
IntegrationBase.testSDK_UpdateParticipantState(adminKey, new BlockchainKeypair(participantResponse.getKeyPair().getPubKey(), participantResponse.getKeyPair().getPrivKey()), ledgerHash, blockchainService); | |||||
} | |||||
System.out.println("update participant state after\r\n"); | |||||
for (int i = 0; i < participantCount; i++) { | |||||
System.out.printf("part%d state = %d\r\n",i, ledgerRepository.getAdminAccount(ledgerRepository.retrieveLatestBlock()).getParticipants()[i].getParticipantNodeState().CODE); | |||||
} | |||||
IntegrationBase.testConsistencyAmongNodes(ledgers); | IntegrationBase.testConsistencyAmongNodes(ledgers); | ||||
if(isOnline){ | if(isOnline){ | ||||