use of com.jd.blockchain.ledger.ParticipantNode in project jdchain-core by blockchain-jd-com.
the class LedgerAdminDatasetTest method verifyRealoadingParities.
private void verifyRealoadingParities(LedgerAdminInfo actualAccount, ParticipantNode[] expectedParties) {
assertEquals(expectedParties.length, actualAccount.getParticipantCount());
ParticipantNode[] actualPaticipants = actualAccount.getParticipants();
assertEquals(expectedParties.length, actualPaticipants.length);
Map<Bytes, ParticipantNode> partisMap = new HashMap<Bytes, ParticipantNode>();
for (int i = 0; i < actualPaticipants.length; i++) {
ParticipantNode parti = actualPaticipants[i];
partisMap.put(parti.getAddress(), parti);
}
for (int i = 0; i < expectedParties.length; i++) {
ParticipantNode parti = partisMap.get(expectedParties[i].getAddress());
assertNotNull(parti);
assertEquals(expectedParties[i].getAddress(), parti.getAddress());
assertEquals(expectedParties[i].getName(), parti.getName());
assertEquals(expectedParties[i].getParticipantNodeState(), parti.getParticipantNodeState());
assertEquals(expectedParties[i].getPubKey(), parti.getPubKey());
}
}
use of com.jd.blockchain.ledger.ParticipantNode 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.ParticipantNode in project jdchain-core by blockchain-jd-com.
the class QueryParticipantsNodeRequestProcessor method processRequest.
@Override
protected void processRequest(QueryParticipantsNodeRequest request, RpcResponseClosure done) {
HashDigest hashDigest = Crypto.resolveAsHashDigest(Base58Utils.decode(request.getLedgerHash()));
LedgerRepository ledgerRepository = LedgerManageUtils.getLedgerRepository(hashDigest);
LedgerAdminInfo adminInfo = ledgerRepository.getAdminInfo(ledgerRepository.retrieveLatestBlock());
ParticipantNode[] participants = adminInfo.getParticipants();
done.setResponse(RpcResponse.success(BinaryProtocol.encode(participants)));
done.run(Status.OK());
}
use of com.jd.blockchain.ledger.ParticipantNode 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;
}
use of com.jd.blockchain.ledger.ParticipantNode in project jdchain-core by blockchain-jd-com.
the class LedgerInitializeWebController method getNodesSignatures.
private DigitalSignature[] getNodesSignatures() {
ParticipantNode[] parties = this.ledgerInitConfig.getParticipants();
List<DigitalSignature> signatures = new ArrayList<>();
for (int i = 0; i < parties.length; i++) {
if (parties[i].getParticipantNodeState() != ParticipantNodeState.CONSENSUS) {
continue;
}
PubKey pubKey = parties[i].getPubKey();
SignatureDigest signDigest = this.permissions[i].getTransactionSignature();
signatures.add(new DigitalSignatureBlob(pubKey, signDigest));
}
return signatures.toArray(new DigitalSignature[signatures.size()]);
}
Aggregations