use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class BlockHeadersMessage method parse.
private void parse() {
RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);
blockHeaders = new ArrayList<>();
for (int i = 0; i < paramsList.size(); ++i) {
RLPList rlpData = ((RLPList) paramsList.get(i));
blockHeaders.add(new BlockHeader(rlpData, true));
}
parsed = true;
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class BlockHeadersMessage method toString.
@Override
public String toString() {
if (!parsed) {
parse();
}
StringBuilder payload = new StringBuilder();
payload.append("count( ").append(blockHeaders.size()).append(" )");
if (logger.isDebugEnabled()) {
payload.append(" ");
for (BlockHeader header : blockHeaders) {
payload.append(Hex.toHexString(header.getHash().getBytes()).substring(0, 6)).append(" ").append(header.getNumber()).append(" | ");
}
if (!blockHeaders.isEmpty()) {
payload.delete(payload.length() - 3, payload.length());
}
}
return "[" + getCommand().name() + " " + payload + "]";
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class BlockHeadersByHashMessageTest method createMessage.
@Test
public void createMessage() {
List<BlockHeader> blocks = new ArrayList<>();
BlockGenerator blockGenerator = new BlockGenerator();
Block block = blockGenerator.getGenesisBlock();
for (int k = 1; k <= 4; k++) {
Block b = blockGenerator.createChildBlock(block);
blocks.add(b.getHeader());
}
BlockHeadersResponseMessage message = new BlockHeadersResponseMessage(1, blocks);
Assert.assertEquals(1, message.getId());
List<BlockHeader> mblocks = message.getBlockHeaders();
Assert.assertEquals(mblocks.size(), blocks.size());
for (int i = 0; i < blocks.size(); i++) Assert.assertEquals(blocks.get(1).getHash(), mblocks.get(1).getHash());
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class BlockHeadersMessageTest method getBlockHeaders.
@Test
public void getBlockHeaders() {
List<BlockHeader> blocks = new ArrayList<>();
BlockGenerator blockGenerator = new BlockGenerator();
for (int k = 0; k < 5; k++) {
Block b = blockGenerator.getBlock(k);
blocks.add(b.getHeader());
}
BlockHeadersMessage message = new BlockHeadersMessage(blocks);
List<BlockHeader> mblocks = message.getBlockHeaders();
Assert.assertEquals(mblocks.size(), blocks.size());
for (int i = 0; i < blocks.size(); i++) {
Assert.assertEquals(blocks.get(1).getHash(), mblocks.get(1).getHash());
}
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class FamilyUtilsTest method getUnclesHeaders.
@Test
public void getUnclesHeaders() {
BlockStore store = createBlockStore();
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block block1 = blockGenerator.createChildBlock(genesis);
Block uncle11 = blockGenerator.createChildBlock(genesis);
Block uncle111 = blockGenerator.createChildBlock(uncle11);
Block uncle12 = blockGenerator.createChildBlock(genesis);
Block uncle121 = blockGenerator.createChildBlock(uncle12);
Block block2 = blockGenerator.createChildBlock(block1);
Block uncle21 = blockGenerator.createChildBlock(block1);
Block uncle22 = blockGenerator.createChildBlock(block1);
Block block3 = blockGenerator.createChildBlock(block2);
Block uncle31 = blockGenerator.createChildBlock(block2);
Block uncle32 = blockGenerator.createChildBlock(block2);
store.saveBlock(genesis, TEST_DIFFICULTY, true);
store.saveBlock(block1, TEST_DIFFICULTY, true);
store.saveBlock(uncle11, TEST_DIFFICULTY, false);
store.saveBlock(uncle12, TEST_DIFFICULTY, false);
store.saveBlock(uncle111, TEST_DIFFICULTY, false);
store.saveBlock(uncle121, TEST_DIFFICULTY, false);
store.saveBlock(block2, TEST_DIFFICULTY, true);
store.saveBlock(uncle21, TEST_DIFFICULTY, false);
store.saveBlock(uncle22, TEST_DIFFICULTY, false);
store.saveBlock(block3, TEST_DIFFICULTY, true);
store.saveBlock(uncle31, TEST_DIFFICULTY, false);
store.saveBlock(uncle32, TEST_DIFFICULTY, false);
List<BlockHeader> list = FamilyUtils.getUnclesHeaders(store, block3, 3);
Assert.assertNotNull(list);
Assert.assertFalse(list.isEmpty());
Assert.assertEquals(4, list.size());
Assert.assertTrue(containsHash(uncle11.getHash(), list));
Assert.assertTrue(containsHash(uncle12.getHash(), list));
Assert.assertTrue(containsHash(uncle21.getHash(), list));
Assert.assertTrue(containsHash(uncle22.getHash(), list));
}
Aggregations