Browse Source

the second revision of the code merger

tags/1.1.0
zhangshuang 5 years ago
parent
commit
299a5b3b52
17 changed files with 112 additions and 51 deletions
  1. +4
    -12
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/handles/ParticipantRegisterOperationHandle.java
  2. +2
    -2
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/handles/ParticipantStateUpdateOperationHandle.java
  3. +1
    -0
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/ParticipantInfoData.java
  4. +9
    -2
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/ParticipantRegisterOperation.java
  5. +12
    -2
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/ParticipantStateUpdateOperation.java
  6. +6
    -4
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/BlockchainOperationFactory.java
  7. +1
    -1
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ClientOperator.java
  8. +7
    -0
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ParticipantOperator.java
  9. +22
    -5
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ParticipantRegisterOpTemplate.java
  10. +4
    -1
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ParticipantRegisterOperationBuilder.java
  11. +5
    -2
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ParticipantRegisterOperationBuilderImpl.java
  12. +24
    -6
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ParticipantStateUpdateOpTemplate.java
  13. +4
    -1
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ParticipantStateUpdateOperationBuilder.java
  14. +5
    -2
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ParticipantStateUpdateOperationBuilderImpl.java
  15. +1
    -3
      source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_Participant_Regist_Test_.java
  16. +3
    -2
      source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_Participant_State_Update_Test_.java
  17. +2
    -6
      source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationBase.java

+ 4
- 12
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/handles/ParticipantRegisterOperationHandle.java View File

@@ -1,11 +1,10 @@
package com.jd.blockchain.ledger.core.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.transaction.UserRegisterOpTemplate;
import com.jd.blockchain.utils.Bytes;


@@ -27,22 +26,15 @@ public class ParticipantRegisterOperationHandle extends AbstractLedgerOperationH

LedgerAdminDataset adminAccountDataSet = newBlockDataset.getAdminDataset();

ParticipantInfo participantInfo = participantRegOp.getParticipantInfo();
ParticipantInfo participantInfo = new ParticipantInfoData(participantRegOp.getParticipantName(), participantRegOp.getParticipantIdentity().getPubKey(), participantRegOp.getNetworkAddress());

ParticipantNode participantNode = new PartNode((int)(adminAccountDataSet.getParticipantCount()), participantInfo.getName(), participantInfo.getPubKey(), ParticipantNodeState.REGISTED);

PubKey pubKey = participantNode.getPubKey();

BlockchainIdentityData identityData = new BlockchainIdentityData(pubKey);

// //reg participant as user
// dataset.getUserAccountSet().register(identityData.getAddress(), pubKey);

//add new participant as consensus node
adminAccountDataSet.addParticipant(participantNode);

// Build UserRegisterOperation;
UserRegisterOperation userRegOp = null;//
// Build UserRegisterOperation, reg participant as user
UserRegisterOperation userRegOp = new UserRegisterOpTemplate(participantRegOp.getParticipantIdentity());
handleContext.handle(userRegOp);
}



+ 2
- 2
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/handles/ParticipantStateUpdateOperationHandle.java View File

@@ -34,14 +34,14 @@ public class ParticipantStateUpdateOperationHandle extends AbstractLedgerOperati
ParticipantNode participantNode = null;

for(int i = 0; i < participants.length; i++) {
if (stateUpdateOperation.getStateUpdateInfo().getPubKey().equals(participants[i].getPubKey())) {
if (stateUpdateOperation.getParticipantIdentity().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());
ParticipantInfo participantInfo = new ParticipantInfoData(participantNode.getName(), participantNode.getPubKey(), stateUpdateOperation.getNetworkAddress());

Bytes newConsensusSettings = provider.getSettingsFactory().getConsensusSettingsBuilder().updateSettings(adminAccountDataSet.getSettings().getConsensusSetting(), participantInfo);



+ 1
- 0
source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/ParticipantInfoData.java View File

@@ -2,6 +2,7 @@ package com.jd.blockchain.ledger;

import com.jd.blockchain.crypto.PubKey;
import com.jd.blockchain.utils.net.NetworkAddress;
import org.omg.CORBA.PUBLIC_MEMBER;

/**
* 即将要注册的参与方的信息


+ 9
- 2
source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/ParticipantRegisterOperation.java View File

@@ -2,12 +2,19 @@ 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.utils.net.NetworkAddress;

@DataContract(code= DataCodes.TX_OP_PARTICIPANT_REG)
public interface ParticipantRegisterOperation extends Operation {

@DataField(order=1, refContract = true)
ParticipantInfo getParticipantInfo();
@DataField(order = 0, primitiveType=PrimitiveType.TEXT)
String getParticipantName();

@DataField(order = 1, refContract = true)
BlockchainIdentity getParticipantIdentity();

@DataField(order = 2, primitiveType = PrimitiveType.BYTES)
NetworkAddress getNetworkAddress();
}

+ 12
- 2
source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/ParticipantStateUpdateOperation.java View File

@@ -2,10 +2,20 @@ package com.jd.blockchain.ledger;

import com.jd.blockchain.binaryproto.DataContract;
import com.jd.blockchain.binaryproto.DataField;
import com.jd.blockchain.binaryproto.PrimitiveType;
import com.jd.blockchain.consts.DataCodes;
import com.jd.blockchain.utils.net.NetworkAddress;

@DataContract(code= DataCodes.TX_OP_PARTICIPANT_STATE_UPDATE)
public interface ParticipantStateUpdateOperation extends Operation {
@DataField(order=1, refContract = true)
ParticipantStateUpdateInfo getStateUpdateInfo();

@DataField(order = 0, refContract = true)
BlockchainIdentity getParticipantIdentity();

@DataField(order = 1, primitiveType = PrimitiveType.BYTES)
NetworkAddress getNetworkAddress();

@DataField(order = 2, refEnum = true)
ParticipantNodeState getState();

}

+ 6
- 4
source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/BlockchainOperationFactory.java View File

@@ -4,8 +4,10 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.jd.blockchain.crypto.PubKey;
import com.jd.blockchain.ledger.*;
import com.jd.blockchain.utils.Bytes;
import com.jd.blockchain.utils.net.NetworkAddress;
/**
* @author huanghaiquan
@@ -288,8 +290,8 @@ public class BlockchainOperationFactory implements ClientOperator, LedgerInitOpe
private class ParticipantRegisterOperationBuilderFilter implements ParticipantRegisterOperationBuilder {
@Override
public ParticipantRegisterOperation register(ParticipantInfo participantInfo) {
ParticipantRegisterOperation op = PARTICIPANT_REG_OP_BUILDER.register(participantInfo);
public ParticipantRegisterOperation register(String participantName, BlockchainIdentity participantIdentity, NetworkAddress networkAddress) {
ParticipantRegisterOperation op = PARTICIPANT_REG_OP_BUILDER.register(participantName, participantIdentity, networkAddress);
operationList.add(op);
return op;
}
@@ -297,8 +299,8 @@ 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);
public ParticipantStateUpdateOperation update(BlockchainIdentity blockchainIdentity, NetworkAddress networkAddress, ParticipantNodeState participantNodeState) {
ParticipantStateUpdateOperation op = PARTICIPANT_STATE_UPDATE_OP_BUILDER.update(blockchainIdentity, networkAddress, participantNodeState);
operationList.add(op);
return op;
}


+ 1
- 1
source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ClientOperator.java View File

@@ -7,6 +7,6 @@ package com.jd.blockchain.transaction;
*
*/
public interface ClientOperator
extends SecurityOperator, UserOperator, DataAccountOperator, ContractOperator, EventOperator, ParticipantOperator, ParticipantStateOperator {
extends SecurityOperator, UserOperator, DataAccountOperator, ContractOperator, EventOperator, ParticipantOperator {

}

+ 7
- 0
source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ParticipantOperator.java View File

@@ -8,4 +8,11 @@ public interface ParticipantOperator {
* @return
*/
ParticipantRegisterOperationBuilder participants();

/**
* 参与方状态更新操作;
*
* @return
*/
ParticipantStateUpdateOperationBuilder states();
}

+ 22
- 5
source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ParticipantRegisterOpTemplate.java View File

@@ -1,8 +1,11 @@
package com.jd.blockchain.transaction;

import com.jd.blockchain.binaryproto.DataContractRegistry;
import com.jd.blockchain.crypto.PubKey;
import com.jd.blockchain.ledger.BlockchainIdentity;
import com.jd.blockchain.ledger.ParticipantInfo;
import com.jd.blockchain.ledger.ParticipantRegisterOperation;
import com.jd.blockchain.utils.net.NetworkAddress;

public class ParticipantRegisterOpTemplate implements ParticipantRegisterOperation {

@@ -10,15 +13,29 @@ public class ParticipantRegisterOpTemplate implements ParticipantRegisterOperati
DataContractRegistry.register(ParticipantRegisterOperation.class);
}

private ParticipantInfo participantInfo;
private String participantName;
private BlockchainIdentity participantPubKey;
private NetworkAddress networkAddress;

public ParticipantRegisterOpTemplate(ParticipantInfo participantInfo) {
public ParticipantRegisterOpTemplate(String participantName, BlockchainIdentity participantPubKey, NetworkAddress networkAddress) {
this.participantName = participantName;
this.participantPubKey = participantPubKey;
this.networkAddress = networkAddress;

this.participantInfo = participantInfo;
}

@Override
public ParticipantInfo getParticipantInfo() {
return participantInfo;
public String getParticipantName() {
return participantName;
}

@Override
public BlockchainIdentity getParticipantIdentity() {
return participantPubKey;
}

@Override
public NetworkAddress getNetworkAddress() {
return networkAddress;
}
}

+ 4
- 1
source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ParticipantRegisterOperationBuilder.java View File

@@ -1,7 +1,10 @@
package com.jd.blockchain.transaction;

import com.jd.blockchain.crypto.PubKey;
import com.jd.blockchain.ledger.BlockchainIdentity;
import com.jd.blockchain.ledger.ParticipantInfo;
import com.jd.blockchain.ledger.ParticipantRegisterOperation;
import com.jd.blockchain.utils.net.NetworkAddress;

public interface ParticipantRegisterOperationBuilder {

@@ -14,7 +17,7 @@ public interface ParticipantRegisterOperationBuilder {
*
* @return
*/
ParticipantRegisterOperation register(ParticipantInfo participantInfo);
ParticipantRegisterOperation register(String participantName, BlockchainIdentity participantPubKey, NetworkAddress networkAddress);


}

+ 5
- 2
source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ParticipantRegisterOperationBuilderImpl.java View File

@@ -1,11 +1,14 @@
package com.jd.blockchain.transaction;

import com.jd.blockchain.crypto.PubKey;
import com.jd.blockchain.ledger.BlockchainIdentity;
import com.jd.blockchain.ledger.ParticipantInfo;
import com.jd.blockchain.ledger.ParticipantRegisterOperation;
import com.jd.blockchain.utils.net.NetworkAddress;

public class ParticipantRegisterOperationBuilderImpl implements ParticipantRegisterOperationBuilder {
@Override
public ParticipantRegisterOperation register(ParticipantInfo participantNode) {
return new ParticipantRegisterOpTemplate(participantNode);
public ParticipantRegisterOperation register(String participantName, BlockchainIdentity participantPubKey, NetworkAddress networkAddress) {
return new ParticipantRegisterOpTemplate(participantName, participantPubKey, networkAddress);
}
}

+ 24
- 6
source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ParticipantStateUpdateOpTemplate.java View File

@@ -1,8 +1,10 @@
package com.jd.blockchain.transaction;

import com.jd.blockchain.binaryproto.DataContractRegistry;
import com.jd.blockchain.ledger.ParticipantStateUpdateInfo;
import com.jd.blockchain.ledger.BlockchainIdentity;
import com.jd.blockchain.ledger.ParticipantNodeState;
import com.jd.blockchain.ledger.ParticipantStateUpdateOperation;
import com.jd.blockchain.utils.net.NetworkAddress;

public class ParticipantStateUpdateOpTemplate implements ParticipantStateUpdateOperation {

@@ -10,14 +12,30 @@ public class ParticipantStateUpdateOpTemplate implements ParticipantStateUpdateO
DataContractRegistry.register(ParticipantStateUpdateOperation.class);
}

private ParticipantStateUpdateInfo stateUpdateInfo;
private BlockchainIdentity blockchainIdentity;
private NetworkAddress networkAddress;
private ParticipantNodeState participantNodeState;

public ParticipantStateUpdateOpTemplate(ParticipantStateUpdateInfo stateUpdateInfo) {
this.stateUpdateInfo = stateUpdateInfo;
public ParticipantStateUpdateOpTemplate(BlockchainIdentity blockchainIdentity, NetworkAddress networkAddress, ParticipantNodeState participantNodeState) {

this.blockchainIdentity = blockchainIdentity;
this.networkAddress = networkAddress;
this.participantNodeState = participantNodeState;
}


@Override
public BlockchainIdentity getParticipantIdentity() {
return blockchainIdentity;
}

@Override
public NetworkAddress getNetworkAddress() {
return networkAddress;
}

@Override
public ParticipantStateUpdateInfo getStateUpdateInfo() {
return stateUpdateInfo;
public ParticipantNodeState getState() {
return participantNodeState;
}
}

+ 4
- 1
source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ParticipantStateUpdateOperationBuilder.java View File

@@ -1,7 +1,10 @@
package com.jd.blockchain.transaction;

import com.jd.blockchain.ledger.BlockchainIdentity;
import com.jd.blockchain.ledger.ParticipantNodeState;
import com.jd.blockchain.ledger.ParticipantStateUpdateInfo;
import com.jd.blockchain.ledger.ParticipantStateUpdateOperation;
import com.jd.blockchain.utils.net.NetworkAddress;

public interface ParticipantStateUpdateOperationBuilder {

@@ -14,5 +17,5 @@ public interface ParticipantStateUpdateOperationBuilder {
*
* @return
*/
ParticipantStateUpdateOperation update(ParticipantStateUpdateInfo stateUpdateInfo);
ParticipantStateUpdateOperation update(BlockchainIdentity blockchainIdentity, NetworkAddress networkAddress, ParticipantNodeState participantNodeState);
}

+ 5
- 2
source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ParticipantStateUpdateOperationBuilderImpl.java View File

@@ -1,12 +1,15 @@
package com.jd.blockchain.transaction;

import com.jd.blockchain.ledger.BlockchainIdentity;
import com.jd.blockchain.ledger.ParticipantNodeState;
import com.jd.blockchain.ledger.ParticipantStateUpdateInfo;
import com.jd.blockchain.ledger.ParticipantStateUpdateOperation;
import com.jd.blockchain.utils.net.NetworkAddress;

public class ParticipantStateUpdateOperationBuilderImpl implements ParticipantStateUpdateOperationBuilder {

@Override
public ParticipantStateUpdateOperation update(ParticipantStateUpdateInfo stateUpdateInfo) {
return new ParticipantStateUpdateOpTemplate(stateUpdateInfo);
public ParticipantStateUpdateOperation update(BlockchainIdentity blockchainIdentity, NetworkAddress networkAddress, ParticipantNodeState participantNodeState) {
return new ParticipantStateUpdateOpTemplate(blockchainIdentity, networkAddress, participantNodeState);
}
}

+ 1
- 3
source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_Participant_Regist_Test_.java View File

@@ -82,10 +82,8 @@ public class SDK_GateWay_Participant_Regist_Test_ {

NetworkAddress networkAddress = new NetworkAddress("127.0.0.1", 20000);

ParticipantInfo participantInfo = new ParticipantInfoData("Peer4", user.getPubKey(), networkAddress);

// 注册参与方
txTemp.participants().register(participantInfo);
txTemp.participants().register("Peer4", user.getIdentity(), networkAddress);

// TX 准备就绪;
PreparedTransaction prepTx = txTemp.prepare();


+ 3
- 2
source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_Participant_State_Update_Test_.java View File

@@ -77,10 +77,11 @@ public class SDK_GateWay_Participant_State_Update_Test_ {

System.out.println("Address = "+AddressEncoding.generateAddress(pubKey));

BlockchainKeypair user = new BlockchainKeypair(pubKey, privKey);

NetworkAddress networkAddress = new NetworkAddress("127.0.0.1", 20000);

ParticipantStateUpdateInfo stateUpdateInfo = new ParticipantStateUpdateInfoData(pubKey, ParticipantNodeState.CONSENSUSED, networkAddress);
txTemp.states().update(stateUpdateInfo);
txTemp.states().update(user.getIdentity(),networkAddress, ParticipantNodeState.CONSENSUSED);

// TX 准备就绪;
PreparedTransaction prepTx = txTemp.prepare();


+ 2
- 6
source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationBase.java View File

@@ -175,9 +175,7 @@ public class IntegrationBase {
// 定义交易;
TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash);

ParticipantInfoData participantInfoData = new ParticipantInfoData("peer4", participant.getPubKey(), new NetworkAddress("127.0.0.1", 20000));

txTpl.participants().register(participantInfoData);
txTpl.participants().register("peer4", new BlockchainIdentityData(participant.getPubKey()), new NetworkAddress("127.0.0.1", 20000));

// 签名;
PreparedTransaction ptx = txTpl.prepare();
@@ -203,9 +201,7 @@ public class IntegrationBase {

ParticipantInfoData participantInfoData = new ParticipantInfoData("peer4", participantKeyPair.getPubKey(), new NetworkAddress("127.0.0.1", 20000));

ParticipantStateUpdateInfo stateUpdateInfo = new ParticipantStateUpdateInfoData(participantKeyPair.getPubKey(), ParticipantNodeState.CONSENSUSED, participantInfoData.getNetworkAddress());

txTpl.states().update(stateUpdateInfo);
txTpl.states().update(new BlockchainIdentityData(participantInfoData.getPubKey()), participantInfoData.getNetworkAddress(), ParticipantNodeState.CONSENSUSED);

// 签名;
PreparedTransaction ptx = txTpl.prepare();


Loading…
Cancel
Save