use of org.hyperledger.besu.ethereum.rlp.RLPInput in project besu by hyperledger.
the class NewBlockHashesMessageTest method blockHeadersRoundTrip.
@Test
public void blockHeadersRoundTrip() throws IOException {
final List<NewBlockHashesMessage.NewBlockHash> hashes = new ArrayList<>();
final ByteBuffer buffer = ByteBuffer.wrap(Resources.toByteArray(this.getClass().getResource("/50.blocks")));
for (int i = 0; i < 50; ++i) {
final int blockSize = RLP.calculateSize(Bytes.wrapByteBuffer(buffer));
final byte[] block = new byte[blockSize];
buffer.get(block);
buffer.compact().position(0);
final RLPInput oneBlock = new BytesValueRLPInput(Bytes.wrap(block), false);
oneBlock.enterList();
final BlockHeader header = BlockHeader.readFrom(oneBlock, new MainnetBlockHeaderFunctions());
hashes.add(new NewBlockHashesMessage.NewBlockHash(header.getHash(), header.getNumber()));
// We don't care about the bodies, just the header hashes
oneBlock.skipNext();
oneBlock.skipNext();
}
final MessageData initialMessage = NewBlockHashesMessage.create(hashes);
final MessageData raw = new RawMessage(EthPV62.NEW_BLOCK_HASHES, initialMessage.getData());
final NewBlockHashesMessage message = NewBlockHashesMessage.readFrom(raw);
final Iterator<NewBlockHashesMessage.NewBlockHash> readHeaders = message.getNewHashes();
for (int i = 0; i < 50; ++i) {
Assertions.assertThat(readHeaders.next()).isEqualTo(hashes.get(i));
}
}
use of org.hyperledger.besu.ethereum.rlp.RLPInput in project besu by hyperledger.
the class GetTrieNodes method paths.
public TrieNodesPaths paths(final boolean withRequestId) {
final RLPInput input = new BytesValueRLPInput(data, false);
input.enterList();
if (withRequestId)
input.skipNext();
final ImmutableTrieNodesPaths.Builder paths = ImmutableTrieNodesPaths.builder().worldStateRootHash(Hash.wrap(Bytes32.wrap(input.readBytes32()))).paths(input.readList(rlpInput -> rlpInput.readList(RLPInput::readBytes))).responseBytes(input.readBigIntegerScalar());
input.leaveList();
return paths.build();
}
use of org.hyperledger.besu.ethereum.rlp.RLPInput in project besu by hyperledger.
the class TrieNodes method nodes.
public ArrayDeque<Bytes> nodes(final boolean withRequestId) {
final ArrayDeque<Bytes> trieNodes = new ArrayDeque<>();
final RLPInput input = new BytesValueRLPInput(data, false);
input.enterList();
if (withRequestId)
input.skipNext();
input.enterList();
while (!input.isEndOfCurrentList()) {
trieNodes.add(input.readBytes());
}
input.leaveList();
input.leaveList();
return trieNodes;
}
Aggregations