From 810d04aa69a17260d2ea8bf3d92c046d63c3fc07 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 14 Nov 2024 18:28:32 +0100 Subject: [PATCH] feat: add rlp for txtype --- crates/consensus/src/transaction/envelope.rs | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/crates/consensus/src/transaction/envelope.rs b/crates/consensus/src/transaction/envelope.rs index 902356fbea9..bb4b230753c 100644 --- a/crates/consensus/src/transaction/envelope.rs +++ b/crates/consensus/src/transaction/envelope.rs @@ -61,6 +61,12 @@ impl PartialEq for TxType { } } +impl PartialEq for u8 { + fn eq(&self, other: &TxType) -> bool { + *self == *other as Self + } +} + #[cfg(any(test, feature = "arbitrary"))] impl arbitrary::Arbitrary<'_> for TxType { fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result { @@ -83,6 +89,23 @@ impl TryFrom for TxType { } } +impl Encodable for TxType { + fn encode(&self, out: &mut dyn alloy_rlp::BufMut) { + (*self as u8).encode(out); + } + + fn length(&self) -> usize { + 1 + } +} + +impl Decodable for TxType { + fn decode(buf: &mut &[u8]) -> alloy_rlp::Result { + let ty = u8::decode(buf)?; + Self::try_from(ty).map_err(|_| alloy_rlp::Error::Custom("invalid transaction type")) + } +} + /// The Ethereum [EIP-2718] Transaction Envelope. /// /// # Note: