From 6d2bc5e1e562a64760d9f0e0e53e4188e85a443a Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Sat, 9 Nov 2024 12:12:42 +0700 Subject: [PATCH] Simplify code Signed-off-by: Gabriel-Trintinalia --- .../core/encoding/registry/RlpProvider.java | 69 +++++++------------ 1 file changed, 23 insertions(+), 46 deletions(-) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpProvider.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpProvider.java index 9de4ac44f2..4210512736 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpProvider.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpProvider.java @@ -25,72 +25,49 @@ public class RlpProvider { private RlpProvider() {} public static TransactionHandler transaction() { - return new TransactionHandler(); + return new TransactionHandler( + RlpRegistry.getInstance().getTransactionDecoder(), + RlpRegistry.getInstance().getTransactionEncoder()); } - public static PooledTransactionHandler pooledTransaction() { - return new PooledTransactionHandler(); + public static TransactionHandler pooledTransaction() { + return new TransactionHandler( + RlpRegistry.getInstance().getPooledTransactionDecoder(), + RlpRegistry.getInstance().getPooledTransactionEncoder()); } - public static class TransactionHandler { + public static class TransactionHandler implements TransactionEncoder, TransactionDecoder { + private final TransactionDecoder decoder; + private final TransactionEncoder encoder; - public Transaction readFrom(final RLPInput rlpInput) { - return getDecoder().readFrom(rlpInput); - } - - public Transaction readFrom(final Bytes bytes) { - return getDecoder().readFrom(bytes); - } - - public Transaction decodeOpaqueBytes(final Bytes bytes) { - return getDecoder().decodeOpaqueBytes(bytes); - } - - public void writeTo(final Transaction transaction, final RLPOutput output) { - getEncoder().writeTo(transaction, output); + public TransactionHandler(final TransactionDecoder decoder, final TransactionEncoder encoder) { + this.decoder = decoder; + this.encoder = encoder; } - public Bytes encodeOpaqueBytes(final Transaction transaction) { - return getEncoder().encodeOpaqueBytes(transaction); - } - - private TransactionDecoder getDecoder() { - return RlpRegistry.getInstance().getTransactionDecoder(); - } - - private TransactionEncoder getEncoder() { - return RlpRegistry.getInstance().getTransactionEncoder(); - } - } - - public static class PooledTransactionHandler { - + @Override public Transaction readFrom(final RLPInput rlpInput) { - return getDecoder().readFrom(rlpInput); + return decoder.readFrom(rlpInput); } + @Override public Transaction readFrom(final Bytes bytes) { - return getDecoder().readFrom(bytes); + return decoder.readFrom(bytes); } + @Override public Transaction decodeOpaqueBytes(final Bytes bytes) { - return getDecoder().decodeOpaqueBytes(bytes); + return decoder.decodeOpaqueBytes(bytes); } + @Override public void writeTo(final Transaction transaction, final RLPOutput output) { - getEncoder().writeTo(transaction, output); + encoder.writeTo(transaction, output); } + @Override public Bytes encodeOpaqueBytes(final Transaction transaction) { - return getEncoder().encodeOpaqueBytes(transaction); - } - - private TransactionDecoder getDecoder() { - return RlpRegistry.getInstance().getPooledTransactionDecoder(); - } - - private TransactionEncoder getEncoder() { - return RlpRegistry.getInstance().getPooledTransactionEncoder(); + return encoder.encodeOpaqueBytes(transaction); } } }