@@ -20,11 +20,11 @@ public class ParticipantRegisterOperationHandle implements OperationHandle { | |||
ParticipantInfo participantInfo = participantRegOp.getParticipantInfo(); | |||
ConsensusProvider provider = ConsensusProviders.getProvider(adminAccount.getSetting().getConsensusProvider()); | |||
// ConsensusProvider provider = ConsensusProviders.getProvider(adminAccount.getSetting().getConsensusProvider()); | |||
ParticipantNode participantNode = new PartNode((int)(adminAccount.getParticipantCount()), participantInfo.getName(), participantInfo.getPubKey(), ParticipantNodeState.REGISTED); | |||
LedgerAdminAccount.LedgerMetadataImpl metadata = (LedgerAdminAccount.LedgerMetadataImpl) adminAccount.getMetadata(); | |||
// LedgerAdminAccount.LedgerMetadataImpl metadata = (LedgerAdminAccount.LedgerMetadataImpl) adminAccount.getMetadata(); | |||
PubKey pubKey = participantNode.getPubKey(); | |||
@@ -32,12 +32,12 @@ public class ParticipantRegisterOperationHandle implements OperationHandle { | |||
BlockchainIdentityData identityData = new BlockchainIdentityData(pubKey); | |||
//update consensus setting | |||
Bytes newConsensusSettings = provider.getSettingsFactory().getConsensusSettingsBuilder().updateSettings(metadata.getSetting().getConsensusSetting(), participantInfo); | |||
// Bytes newConsensusSettings = provider.getSettingsFactory().getConsensusSettingsBuilder().updateSettings(metadata.getSetting().getConsensusSetting(), participantInfo); | |||
LedgerSetting ledgerSetting = new LedgerConfiguration(adminAccount.getSetting().getConsensusProvider(), | |||
newConsensusSettings, metadata.getSetting().getCryptoSetting()); | |||
// LedgerSetting ledgerSetting = new LedgerConfiguration(adminAccount.getSetting().getConsensusProvider(), | |||
// newConsensusSettings, metadata.getSetting().getCryptoSetting()); | |||
metadata.setSetting(ledgerSetting); | |||
// metadata.setSetting(ledgerSetting); | |||
// metadata.setViewId(metadata.getViewId() + 1); | |||
//reg participant as user | |||
@@ -1,10 +1,13 @@ | |||
package com.jd.blockchain.ledger.core.impl.handles; | |||
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.core.impl.OperationHandleContext; | |||
import com.jd.blockchain.utils.Bytes; | |||
public class ParticipantStateUpdateOperationHandle implements OperationHandle { | |||
@@ -20,6 +23,10 @@ public class ParticipantStateUpdateOperationHandle implements OperationHandle { | |||
LedgerAdminAccount adminAccount = newBlockDataset.getAdminAccount(); | |||
ConsensusProvider provider = ConsensusProviders.getProvider(adminAccount.getSetting().getConsensusProvider()); | |||
LedgerAdminAccount.LedgerMetadataImpl metadata = (LedgerAdminAccount.LedgerMetadataImpl) adminAccount.getMetadata(); | |||
ParticipantNode[] participants = adminAccount.getParticipants(); | |||
ParticipantNode participantNode = null; | |||
@@ -27,9 +34,20 @@ public class ParticipantStateUpdateOperationHandle implements OperationHandle { | |||
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); | |||
break; | |||
} | |||
} | |||
//update consensus setting | |||
ParticipantInfo participantInfo = new ParticipantInfoData("", participantNode.getName(), participantNode.getPubKey(), stateUpdateOperation.getStateUpdateInfo().getNetworkAddress()); | |||
Bytes newConsensusSettings = provider.getSettingsFactory().getConsensusSettingsBuilder().updateSettings(metadata.getSetting().getConsensusSetting(), participantInfo); | |||
LedgerSetting ledgerSetting = new LedgerConfiguration(adminAccount.getSetting().getConsensusProvider(), | |||
newConsensusSettings, metadata.getSetting().getCryptoSetting()); | |||
metadata.setSetting(ledgerSetting); | |||
adminAccount.updateParticipant(participantNode); | |||
return null; | |||
@@ -5,6 +5,7 @@ import com.jd.blockchain.binaryproto.DataField; | |||
import com.jd.blockchain.binaryproto.PrimitiveType; | |||
import com.jd.blockchain.consts.DataCodes; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.utils.net.NetworkAddress; | |||
/** | |||
* 参与方状态更新信息; | |||
@@ -13,6 +14,7 @@ import com.jd.blockchain.crypto.PubKey; | |||
*/ | |||
@DataContract(code = DataCodes.METADATA_PARTICIPANT_STATE_INFO) | |||
public interface ParticipantStateUpdateInfo { | |||
/** | |||
* 公钥; | |||
* | |||
@@ -22,10 +24,18 @@ public interface ParticipantStateUpdateInfo { | |||
PubKey getPubKey(); | |||
/** | |||
* 共识协议的网络地址; | |||
* | |||
* @return | |||
*/ | |||
@DataField(order = 2, primitiveType = PrimitiveType.BYTES) | |||
NetworkAddress getNetworkAddress(); | |||
/** | |||
* 参与方状态; | |||
* | |||
* @return | |||
*/ | |||
@DataField(order = 2, refEnum = true) | |||
@DataField(order = 3, refEnum = true) | |||
ParticipantNodeState getState(); | |||
} |
@@ -1,14 +1,17 @@ | |||
package com.jd.blockchain.ledger; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.utils.net.NetworkAddress; | |||
public class ParticipantStateUpdateInfoData implements ParticipantStateUpdateInfo { | |||
private PubKey pubKey; | |||
private ParticipantNodeState state; | |||
private NetworkAddress networkAddress; | |||
public ParticipantStateUpdateInfoData(PubKey pubKey, ParticipantNodeState state) { | |||
public ParticipantStateUpdateInfoData(PubKey pubKey, ParticipantNodeState state, NetworkAddress networkAddress) { | |||
this.pubKey = pubKey; | |||
this.state = state; | |||
this.networkAddress = networkAddress; | |||
} | |||
public void setPubKey(PubKey pubKey) { | |||
@@ -20,6 +23,15 @@ public class ParticipantStateUpdateInfoData implements ParticipantStateUpdateInf | |||
return pubKey; | |||
} | |||
public void setNetworkAddress(NetworkAddress networkAddress) { | |||
this.networkAddress = networkAddress; | |||
} | |||
@Override | |||
public NetworkAddress getNetworkAddress() { | |||
return networkAddress; | |||
} | |||
public void setState(ParticipantNodeState state) { | |||
this.state = state; | |||
} | |||
@@ -7,6 +7,7 @@ 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 com.jd.blockchain.utils.net.NetworkAddress; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
@@ -76,8 +77,9 @@ public class SDK_GateWay_Participant_State_Update_Test_ { | |||
System.out.println("Address = "+AddressEncoding.generateAddress(pubKey)); | |||
NetworkAddress networkAddress = new NetworkAddress("127.0.0.1", 20000); | |||
ParticipantStateUpdateInfo stateUpdateInfo = new ParticipantStateUpdateInfoData(pubKey, ParticipantNodeState.CONSENSUSED); | |||
ParticipantStateUpdateInfo stateUpdateInfo = new ParticipantStateUpdateInfoData(pubKey, ParticipantNodeState.CONSENSUSED, networkAddress); | |||
txTemp.states().update(stateUpdateInfo); | |||
// TX 准备就绪; | |||
@@ -201,7 +201,9 @@ public class IntegrationBase { | |||
// 定义交易; | |||
TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash); | |||
ParticipantStateUpdateInfo stateUpdateInfo = new ParticipantStateUpdateInfoData(participantKeyPair.getPubKey(), ParticipantNodeState.CONSENSUSED); | |||
ParticipantInfoData participantInfoData = new ParticipantInfoData("add", "peer4", participantKeyPair.getPubKey(), new NetworkAddress("127.0.0.1", 20000)); | |||
ParticipantStateUpdateInfo stateUpdateInfo = new ParticipantStateUpdateInfoData(participantKeyPair.getPubKey(), ParticipantNodeState.CONSENSUSED, participantInfoData.getNetworkAddress()); | |||
txTpl.states().update(stateUpdateInfo); | |||