Search in sources :

Example 1 with ParticipantCertData

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());
}
Also used : ParticipantCertData(com.jd.blockchain.ledger.core.ParticipantCertData) LedgerInitOpTemplate(com.jd.blockchain.transaction.LedgerInitOpTemplate) Test(org.junit.Test)

Example 2 with ParticipantCertData

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());
}
Also used : ParticipantCertData(com.jd.blockchain.ledger.core.ParticipantCertData) LedgerInitSetting(com.jd.blockchain.ledger.LedgerInitSetting) BlockchainKeypair(com.jd.blockchain.ledger.BlockchainKeypair) Test(org.junit.Test)

Example 3 with ParticipantCertData

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;
}
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 4 with ParticipantCertData

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;
}
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)

Aggregations

ParticipantCertData (com.jd.blockchain.ledger.core.ParticipantCertData)4 Test (org.junit.Test)3 ParticipantNode (com.jd.blockchain.ledger.ParticipantNode)2 PubKey (com.jd.blockchain.crypto.PubKey)1 BlockchainKeypair (com.jd.blockchain.ledger.BlockchainKeypair)1 LedgerAdminInfo (com.jd.blockchain.ledger.LedgerAdminInfo)1 LedgerInitSetting (com.jd.blockchain.ledger.LedgerInitSetting)1 LedgerQuery (com.jd.blockchain.ledger.core.LedgerQuery)1 LedgerInitOpTemplate (com.jd.blockchain.transaction.LedgerInitOpTemplate)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 Bytes (utils.Bytes)1