use of com.jd.blockchain.transaction.ConsensusParticipantData in project jdchain-core by blockchain-jd-com.
the class LedgerAdminDatasetTest method verifyReadonlyState.
/**
* 验证指定账户是否只读;
*
* @param readonlyAccount
*/
private void verifyReadonlyState(LedgerAdminDataSetEditor readonlyAccount) {
ConsensusParticipantData newParti = new ConsensusParticipantData();
newParti.setId((int) readonlyAccount.getParticipantCount());
newParti.setHostAddress(new NetworkAddress("192.168.10." + (10 + newParti.getId()), 10010 + 10 * newParti.getId()));
newParti.setName("Participant[" + newParti.getAddress() + "]");
BlockchainKeypair newKey = BlockchainKeyGenerator.getInstance().generate();
newParti.setPubKey(newKey.getPubKey());
newParti.setParticipantState(ParticipantNodeState.CONSENSUS);
Throwable ex = null;
try {
readonlyAccount.addParticipant(newParti);
} catch (Exception e) {
ex = e;
}
assertNotNull(ex);
ex = null;
try {
LedgerConfiguration newLedgerSetting = new LedgerConfiguration(readonlyAccount.getSettings());
readonlyAccount.setLedgerSetting(newLedgerSetting);
} catch (Exception e) {
ex = e;
}
assertNotNull(ex);
}
use of com.jd.blockchain.transaction.ConsensusParticipantData in project jdchain-core by blockchain-jd-com.
the class LedgerInitOperationTest method test_LedgerInitOperation_ConsensusParticipantData.
@Test
public void test_LedgerInitOperation_ConsensusParticipantData() {
ConsensusParticipantData[] parties = new ConsensusParticipantData[4];
BlockchainKeypair[] keys = new BlockchainKeypair[parties.length];
for (int i = 0; i < parties.length; i++) {
keys[i] = BlockchainKeyGenerator.getInstance().generate();
parties[i] = new ConsensusParticipantData();
// parties[i].setId(i);
parties[i].setAddress(AddressEncoding.generateAddress(keys[i].getPubKey()));
parties[i].setHostAddress(new NetworkAddress("192.168.10." + (10 + i), 10010 + 10 * i));
parties[i].setName("Participant[" + i + "]");
parties[i].setPubKey(keys[i].getPubKey());
parties[i].setParticipantState(ParticipantNodeState.CONSENSUS);
}
ConsensusParticipantData[] 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.transaction.ConsensusParticipantData in project jdchain-core by blockchain-jd-com.
the class LedgerManagerTest method createLedgerInitSetting.
private LedgerInitSetting createLedgerInitSetting() {
CryptoProvider[] supportedProviders = new CryptoProvider[SUPPORTED_PROVIDERS.length];
for (int i = 0; i < SUPPORTED_PROVIDERS.length; i++) {
supportedProviders[i] = Crypto.getProvider(SUPPORTED_PROVIDERS[i]);
}
CryptoConfig defCryptoSetting = new CryptoConfig();
defCryptoSetting.setSupportedProviders(supportedProviders);
defCryptoSetting.setAutoVerifyHash(true);
defCryptoSetting.setHashAlgorithm(ClassicAlgorithm.SHA256);
LedgerInitData initSetting = new LedgerInitData();
initSetting.setLedgerSeed(BytesUtils.toBytes("A Test Ledger seed!", "UTF-8"));
initSetting.setCryptoSetting(defCryptoSetting);
ConsensusParticipantData[] parties = new ConsensusParticipantData[4];
parties[0] = new ConsensusParticipantData();
parties[0].setId(0);
parties[0].setName("John");
AsymmetricKeypair kp0 = signatureFunction.generateKeypair();
parties[0].setPubKey(kp0.getPubKey());
parties[0].setAddress(AddressEncoding.generateAddress(kp0.getPubKey()));
parties[0].setHostAddress(new NetworkAddress("127.0.0.1", 9000));
parties[0].setParticipantState(ParticipantNodeState.CONSENSUS);
parties[1] = new ConsensusParticipantData();
parties[1].setId(1);
parties[1].setName("Mary");
AsymmetricKeypair kp1 = signatureFunction.generateKeypair();
parties[1].setPubKey(kp1.getPubKey());
parties[1].setAddress(AddressEncoding.generateAddress(kp1.getPubKey()));
parties[1].setHostAddress(new NetworkAddress("127.0.0.1", 9010));
parties[1].setParticipantState(ParticipantNodeState.CONSENSUS);
parties[2] = new ConsensusParticipantData();
parties[2].setId(2);
parties[2].setName("Jerry");
AsymmetricKeypair kp2 = signatureFunction.generateKeypair();
parties[2].setPubKey(kp2.getPubKey());
parties[2].setAddress(AddressEncoding.generateAddress(kp2.getPubKey()));
parties[2].setHostAddress(new NetworkAddress("127.0.0.1", 9020));
parties[2].setParticipantState(ParticipantNodeState.CONSENSUS);
parties[3] = new ConsensusParticipantData();
parties[3].setId(3);
parties[3].setName("Tom");
AsymmetricKeypair kp3 = signatureFunction.generateKeypair();
parties[3].setPubKey(kp3.getPubKey());
parties[3].setAddress(AddressEncoding.generateAddress(kp3.getPubKey()));
parties[3].setHostAddress(new NetworkAddress("127.0.0.1", 9030));
parties[3].setParticipantState(ParticipantNodeState.CONSENSUS);
initSetting.setConsensusParticipants(parties);
initSetting.setLedgerDataStructure(LedgerDataStructure.MERKLE_TREE);
initSetting.setIdentityMode(IdentityMode.KEYPAIR);
return initSetting;
}
use of com.jd.blockchain.transaction.ConsensusParticipantData in project jdchain-core by blockchain-jd-com.
the class LedgerInitSettingSerializeTest method test_ledgerinitsetting_ConsensusParticipantData.
@Test
public void test_ledgerinitsetting_ConsensusParticipantData() {
ConsensusParticipantData[] parties = new ConsensusParticipantData[4];
BlockchainKeypair[] keys = new BlockchainKeypair[parties.length];
for (int i = 0; i < parties.length; i++) {
keys[i] = BlockchainKeyGenerator.getInstance().generate();
parties[i] = new ConsensusParticipantData();
// parties[i].setId(i);
parties[i].setAddress(AddressEncoding.generateAddress(keys[i].getPubKey()));
parties[i].setHostAddress(new NetworkAddress("192.168.10." + (10 + i), 10010 + 10 * i));
parties[i].setName("Participant[" + i + "]");
parties[i].setPubKey(keys[i].getPubKey());
parties[i].setParticipantState(ParticipantNodeState.CONSENSUS);
}
ConsensusParticipantData[] 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.transaction.ConsensusParticipantData in project jdchain-core by blockchain-jd-com.
the class LedgerTestUtils method createLedgerInitSetting.
public static LedgerInitSetting createLedgerInitSetting(CryptoSetting cryptoSetting, BlockchainKeypair[] partiKeys) {
LedgerInitData initSetting = new LedgerInitData();
initSetting.setLedgerSeed(BytesUtils.toBytes("A Test Ledger seed!", "UTF-8"));
initSetting.setCryptoSetting(cryptoSetting);
initSetting.setIdentityMode(IdentityMode.KEYPAIR);
ConsensusParticipantData[] parties = new ConsensusParticipantData[partiKeys.length];
for (int i = 0; i < parties.length; i++) {
parties[i] = new ConsensusParticipantData();
parties[i].setId(0);
parties[i].setName("Parti-" + i);
parties[i].setPubKey(partiKeys[i].getPubKey());
parties[i].setAddress(AddressEncoding.generateAddress(partiKeys[i].getPubKey()));
parties[i].setHostAddress(new NetworkAddress("192.168.1." + (10 + i), 9000));
parties[i].setParticipantState(ParticipantNodeState.CONSENSUS);
}
initSetting.setConsensusParticipants(parties);
return initSetting;
}
Aggregations