use of org.hyperledger.besu.ethereum.rlp.RLPOutput in project besu by hyperledger.
the class TrieLogLayer method writeTo.
void writeTo(final RLPOutput output) {
freeze();
final Set<Address> addresses = new TreeSet<>();
addresses.addAll(accounts.keySet());
addresses.addAll(code.keySet());
addresses.addAll(storage.keySet());
// container
output.startList();
output.writeBytes(blockHash);
for (final Address address : addresses) {
// this change
output.startList();
output.writeBytes(address);
final BonsaiValue<StateTrieAccountValue> accountChange = accounts.get(address);
if (accountChange == null || accountChange.isUnchanged()) {
output.writeNull();
} else {
accountChange.writeRlp(output, (o, sta) -> sta.writeTo(o));
}
final BonsaiValue<Bytes> codeChange = code.get(address);
if (codeChange == null || codeChange.isUnchanged()) {
output.writeNull();
} else {
codeChange.writeRlp(output, RLPOutput::writeBytes);
}
final Map<Hash, BonsaiValue<UInt256>> storageChanges = storage.get(address);
if (storageChanges == null) {
output.writeNull();
} else {
output.startList();
for (final Map.Entry<Hash, BonsaiValue<UInt256>> storageChangeEntry : storageChanges.entrySet()) {
output.startList();
output.writeBytes(storageChangeEntry.getKey());
storageChangeEntry.getValue().writeInnerRlp(output, RLPOutput::writeUInt256Scalar);
output.endList();
}
output.endList();
}
// TODO write trie nodes
// this change
output.endList();
}
// container
output.endList();
}
use of org.hyperledger.besu.ethereum.rlp.RLPOutput in project besu by hyperledger.
the class PingPacketDataTest method handleSourcePortNullHost.
@Test
public void handleSourcePortNullHost() {
final Endpoint to = new Endpoint("127.0.0.2", 30303, Optional.empty());
final BytesValueRLPOutput out = new BytesValueRLPOutput();
final UInt64 enrSeq = UInt64.MAX_VALUE;
final long time = System.currentTimeMillis();
out.startList();
out.writeIntScalar(4);
((RLPOutput) out).startList();
out.writeNull();
out.writeIntScalar(30303);
out.writeNull();
((RLPOutput) out).endList();
to.encodeStandalone(out);
out.writeLongScalar(time);
out.writeBigIntegerScalar(enrSeq.toBigInteger());
out.endList();
final Bytes serialized = out.encoded();
final PingPacketData deserialized = PingPacketData.readFrom(RLP.input(serialized));
assertThat(deserialized.getFrom()).isPresent();
assertThat(deserialized.getFrom().get().getUdpPort()).isEqualTo(30303);
assertThat(deserialized.getFrom().get().getHost().isEmpty()).isTrue();
assertThat(deserialized.getFrom().get().getTcpPort().isEmpty()).isTrue();
assertThat(deserialized.getTo()).isEqualTo(to);
assertThat(deserialized.getExpiration()).isEqualTo(time);
assertThat(deserialized.getEnrSeq().isPresent()).isTrue();
assertThat(deserialized.getEnrSeq().get()).isEqualTo(enrSeq);
}
Aggregations