use of com.jd.blockchain.ledger.core.ParticipantCertData in project jdchain-core by blockchain-jd-com.
the class LedgerInitOperationTest method test_LedgerInitOperation_ParticipantCertData.
@Test
public void test_LedgerInitOperation_ParticipantCertData() {
ParticipantCertData[] parties = new ParticipantCertData[4];
BlockchainKeypair[] keys = new BlockchainKeypair[parties.length];
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.CONSENSUS);
}
ParticipantCertData[] parties1 = Arrays.copyOf(parties, 4);
ledgerInitSettingData.setConsensusParticipants(parties1);
ledgerInitSettingData.setIdentityMode(IdentityMode.KEYPAIR);
ledgerInitSettingData.setLedgerDataStructure(LedgerDataStructure.MERKLE_TREE);
LedgerInitOpTemplate template = new LedgerInitOpTemplate(ledgerInitSettingData);
byte[] encode = BinaryProtocol.encode(template, LedgerInitOperation.class);
LedgerInitOperation decode = BinaryProtocol.decode(encode);
for (int i = 0; i < template.getInitSetting().getConsensusParticipants().length; i++) {
assertEquals(template.getInitSetting().getConsensusParticipants()[i].getAddress(), decode.getInitSetting().getConsensusParticipants()[i].getAddress());
assertEquals(template.getInitSetting().getConsensusParticipants()[i].getName(), decode.getInitSetting().getConsensusParticipants()[i].getName());
assertEquals(template.getInitSetting().getConsensusParticipants()[i].getPubKey(), decode.getInitSetting().getConsensusParticipants()[i].getPubKey());
}
assertArrayEquals(template.getInitSetting().getLedgerSeed(), decode.getInitSetting().getLedgerSeed());
assertArrayEquals(template.getInitSetting().getConsensusSettings().toBytes(), decode.getInitSetting().getConsensusSettings().toBytes());
assertEquals(template.getInitSetting().getCryptoSetting().getHashAlgorithm(), decode.getInitSetting().getCryptoSetting().getHashAlgorithm());
assertEquals(template.getInitSetting().getCryptoSetting().getAutoVerifyHash(), decode.getInitSetting().getCryptoSetting().getAutoVerifyHash());
assertEquals(template.getInitSetting().getConsensusProvider(), decode.getInitSetting().getConsensusProvider());
}
use of com.jd.blockchain.ledger.core.ParticipantCertData in project jdchain-core by blockchain-jd-com.
the class LedgerInitSettingSerializeTest method test_ledgerinitsetting_ParticipantCertData.
// @Test
// public void test_ledgerinitsetting_ConsensusParticipantConfig() {
// }
@Test
public void test_ledgerinitsetting_ParticipantCertData() {
ParticipantCertData[] parties = new ParticipantCertData[4];
BlockchainKeypair[] keys = new BlockchainKeypair[parties.length];
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.CONSENSUS);
}
ParticipantCertData[] parties1 = Arrays.copyOf(parties, 4);
ledgerInitSettingData.setConsensusParticipants(parties1);
ledgerInitSettingData.setLedgerDataStructure(LedgerDataStructure.MERKLE_TREE);
ledgerInitSettingData.setIdentityMode(IdentityMode.KEYPAIR);
byte[] encode = BinaryProtocol.encode(ledgerInitSettingData, LedgerInitSetting.class);
LedgerInitSetting decode = BinaryProtocol.decode(encode);
for (int i = 0; i < ledgerInitSettingData.getConsensusParticipants().length; i++) {
assertEquals(ledgerInitSettingData.getConsensusParticipants()[i].getAddress(), decode.getConsensusParticipants()[i].getAddress());
assertEquals(ledgerInitSettingData.getConsensusParticipants()[i].getName(), decode.getConsensusParticipants()[i].getName());
assertEquals(ledgerInitSettingData.getConsensusParticipants()[i].getPubKey(), decode.getConsensusParticipants()[i].getPubKey());
}
assertArrayEquals(ledgerInitSettingData.getLedgerSeed(), decode.getLedgerSeed());
assertArrayEquals(ledgerInitSettingData.getConsensusSettings().toBytes(), decode.getConsensusSettings().toBytes());
assertEquals(ledgerInitSettingData.getCryptoSetting().getHashAlgorithm(), decode.getCryptoSetting().getHashAlgorithm());
assertEquals(ledgerInitSettingData.getCryptoSetting().getAutoVerifyHash(), decode.getCryptoSetting().getAutoVerifyHash());
assertEquals(ledgerInitSettingData.getConsensusProvider(), decode.getConsensusProvider());
}
use of com.jd.blockchain.ledger.core.ParticipantCertData in project jdchain-core by blockchain-jd-com.
the class LedgerQueryController method getConsensusParticipants.
@RequestMapping(method = RequestMethod.GET, path = GET_CONSENSUS_PARTICIPANTS)
@Override
public ParticipantNode[] getConsensusParticipants(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerAdminInfo ledgerAdministration = ledger.getAdminInfo();
long participantCount = ledgerAdministration.getParticipantCount();
if (participantCount <= 0) {
return null;
}
ParticipantNode[] participantNodes = ledgerAdministration.getParticipants();
// 重新封装,处理Proxy的问题
if (participantNodes != null && participantNodes.length > 0) {
ParticipantNode[] convertNodes = new ParticipantNode[participantNodes.length];
for (int i = 0, length = participantNodes.length; i < length; i++) {
convertNodes[i] = new ParticipantCertData(participantNodes[i]);
}
return convertNodes;
}
return null;
}
use of com.jd.blockchain.ledger.core.ParticipantCertData in project jdchain-core by blockchain-jd-com.
the class LedgerMetaDataTest method testSerialize_ParticipantCert.
@Test
public void testSerialize_ParticipantCert() {
// LedgerCodes.METADATA_PARTICIPANT_CERT
// prepare work
int id = 1;
// String address = "xxxxxxxxxxxxxx";
PubKey pubKey = Crypto.getSignatureFunction(ClassicAlgorithm.ED25519).generateKeypair().getPubKey();
// ParticipantInfo info = new ParticipantCertData.ParticipantInfoData(1, "yyy");
// SignatureDigest signature = new SignatureDigest(CryptoAlgorithm.SM2,
// rawDigestBytes);
String name = "John";
// NetworkAddress consensusAddress = new NetworkAddress("192.168.1.1", 9001,
// false);
Bytes address = AddressEncoding.generateAddress(pubKey);
ParticipantCertData participantCertData = new ParticipantCertData(address, name, pubKey, ParticipantNodeState.CONSENSUS);
// encode and decode
byte[] encodeBytes = BinaryProtocol.encode(participantCertData, ParticipantNode.class);
ParticipantNode deParticipantInfoData = BinaryProtocol.decode(encodeBytes);
// verify start
assertEquals(participantCertData.getAddress(), deParticipantInfoData.getAddress());
assertEquals(participantCertData.getPubKey(), deParticipantInfoData.getPubKey());
assertEquals(participantCertData.getName(), deParticipantInfoData.getName());
return;
}
Aggregations