diff --git a/crates/consensus/src/receipt/receipts.rs b/crates/consensus/src/receipt/receipts.rs index c6fc621cd7b..97fec2767ea 100644 --- a/crates/consensus/src/receipt/receipts.rs +++ b/crates/consensus/src/receipt/receipts.rs @@ -1,12 +1,12 @@ -use crate::receipt::{Eip658Value, RlpDecodableReceipt, RlpEncodableReceipt, TxReceipt}; +use crate::receipt::{ + Eip2718EncodableReceipt, Eip658Value, RlpDecodableReceipt, RlpEncodableReceipt, TxReceipt, +}; use alloc::{vec, vec::Vec}; use alloy_eips::eip2718::Encodable2718; use alloy_primitives::{Bloom, Log}; use alloy_rlp::{BufMut, Decodable, Encodable, Header}; use core::{borrow::Borrow, fmt}; -use derive_more::{DerefMut, From, IntoIterator}; - -use super::Eip2718EncodableReceipt; +use derive_more::{From, IntoIterator}; /// Receipt containing result of transaction execution. #[derive(Clone, Debug, Default, PartialEq, Eq)] @@ -148,9 +148,7 @@ impl From> for Receipt { } /// Receipt containing result of transaction execution. -#[derive( - Clone, Debug, PartialEq, Eq, Default, From, derive_more::Deref, DerefMut, IntoIterator, -)] +#[derive(Clone, Debug, PartialEq, Eq, Default, From, IntoIterator)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Receipts { /// A two-dimensional vector of [`Receipt`] instances. @@ -186,6 +184,22 @@ impl FromIterator> for Receipts { } } +impl Encodable for Receipts { + fn encode(&self, out: &mut dyn BufMut) { + self.receipt_vec.encode(out) + } + + fn length(&self) -> usize { + self.receipt_vec.length() + } +} + +impl Decodable for Receipts { + fn decode(buf: &mut &[u8]) -> alloy_rlp::Result { + Ok(Self { receipt_vec: Decodable::decode(buf)? }) + } +} + /// [`Receipt`] with calculated bloom filter. /// /// This convenience type allows us to lazily calculate the bloom filter for a @@ -302,6 +316,9 @@ where #[cfg(test)] mod test { + use super::*; + use crate::ReceiptEnvelope; + use alloy_rlp::{Decodable, Encodable}; #[cfg(feature = "serde")] #[test] @@ -344,4 +361,18 @@ mod test { )) ); } + + #[test] + fn rountrip_encodable_eip1559() { + let receipts = + Receipts { receipt_vec: vec![vec![ReceiptEnvelope::Eip1559(Default::default())]] }; + + let mut out = vec![]; + receipts.encode(&mut out); + + let mut out = out.as_slice(); + let decoded = Receipts::::decode(&mut out).unwrap(); + + assert_eq!(receipts, decoded); + } }