Search in sources :

Example 1 with ParticipantNode

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());
    }
}
Also used : ParticipantNode(com.jd.blockchain.ledger.ParticipantNode) Bytes(utils.Bytes) HashMap(java.util.HashMap)

Example 2 with ParticipantNode

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;
}
Also used : LedgerAdminInfo(com.jd.blockchain.ledger.LedgerAdminInfo) ParticipantNode(com.jd.blockchain.ledger.ParticipantNode) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) ParticipantCertData(com.jd.blockchain.ledger.core.ParticipantCertData) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ParticipantNode

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());
}
Also used : LedgerAdminInfo(com.jd.blockchain.ledger.LedgerAdminInfo) ParticipantNode(com.jd.blockchain.ledger.ParticipantNode) HashDigest(com.jd.blockchain.crypto.HashDigest) LedgerRepository(com.jd.blockchain.ledger.core.LedgerRepository)

Example 4 with ParticipantNode

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;
}
Also used : PubKey(com.jd.blockchain.crypto.PubKey) Bytes(utils.Bytes) ParticipantNode(com.jd.blockchain.ledger.ParticipantNode) ParticipantCertData(com.jd.blockchain.ledger.core.ParticipantCertData) Test(org.junit.Test)

Example 5 with ParticipantNode

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()]);
}
Also used : PubKey(com.jd.blockchain.crypto.PubKey) ParticipantNode(com.jd.blockchain.ledger.ParticipantNode) SignatureDigest(com.jd.blockchain.crypto.SignatureDigest) DigitalSignatureBlob(com.jd.blockchain.transaction.DigitalSignatureBlob) ArrayList(java.util.ArrayList) DigitalSignature(com.jd.blockchain.ledger.DigitalSignature)

Aggregations

ParticipantNode (com.jd.blockchain.ledger.ParticipantNode)9 PubKey (com.jd.blockchain.crypto.PubKey)4 SignatureDigest (com.jd.blockchain.crypto.SignatureDigest)2 LedgerAdminInfo (com.jd.blockchain.ledger.LedgerAdminInfo)2 LedgerInitException (com.jd.blockchain.ledger.LedgerInitException)2 ParticipantCertData (com.jd.blockchain.ledger.core.ParticipantCertData)2 ArrayList (java.util.ArrayList)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Bytes (utils.Bytes)2 HashDigest (com.jd.blockchain.crypto.HashDigest)1 SignatureFunction (com.jd.blockchain.crypto.SignatureFunction)1 DigitalSignature (com.jd.blockchain.ledger.DigitalSignature)1 LedgerInitProposal (com.jd.blockchain.ledger.core.LedgerInitProposal)1 LedgerQuery (com.jd.blockchain.ledger.core.LedgerQuery)1 LedgerRepository (com.jd.blockchain.ledger.core.LedgerRepository)1 DigitalSignatureBlob (com.jd.blockchain.transaction.DigitalSignatureBlob)1 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1 InvocationResult (utils.concurrent.InvocationResult)1