diff --git a/crates/consensus/src/receipt/envelope.rs b/crates/consensus/src/receipt/envelope.rs index f7f548a9f..3f1d6ddf6 100644 --- a/crates/consensus/src/receipt/envelope.rs +++ b/crates/consensus/src/receipt/envelope.rs @@ -123,6 +123,11 @@ impl OpReceiptEnvelope { &self.as_receipt().unwrap().logs } + /// Consumes the type and returns the logs. + pub fn into_logs(self) -> Vec { + self.into_receipt().logs + } + /// Return the receipt's bloom. pub const fn logs_bloom(&self) -> &Bloom { match self { @@ -160,6 +165,14 @@ impl OpReceiptEnvelope { } } + /// Consumes the type and returns the underlying [`Receipt`]. + pub fn into_receipt(self) -> Receipt { + match self { + Self::Legacy(t) | Self::Eip2930(t) | Self::Eip1559(t) | Self::Eip7702(t) => t.receipt, + Self::Deposit(t) => t.receipt.into_inner(), + } + } + /// Return the inner receipt. Currently this is infallible, however, future /// receipt types may be added. pub const fn as_receipt(&self) -> Option<&Receipt> { @@ -306,6 +319,12 @@ impl Decodable2718 for OpReceiptEnvelope { } } +impl From> for Receipt { + fn from(receipt: OpReceiptEnvelope) -> Self { + receipt.into_receipt() + } +} + #[cfg(all(test, feature = "arbitrary"))] impl<'a, T> arbitrary::Arbitrary<'a> for OpReceiptEnvelope where diff --git a/crates/consensus/src/receipt/receipts.rs b/crates/consensus/src/receipt/receipts.rs index bcb7c6f96..b09d5aa5a 100644 --- a/crates/consensus/src/receipt/receipts.rs +++ b/crates/consensus/src/receipt/receipts.rs @@ -7,6 +7,14 @@ use alloy_consensus::{ use alloy_primitives::{Bloom, Log}; use alloy_rlp::{Buf, BufMut, Decodable, Encodable, Header}; +/// [`OpDepositReceipt`] with calculated bloom filter, modified for the OP Stack. +/// +/// This convenience type allows us to lazily calculate the bloom filter for a +/// receipt, similar to [`Sealed`]. +/// +/// [`Sealed`]: alloy_consensus::Sealed +pub type OpDepositReceiptWithBloom = ReceiptWithBloom>; + /// Receipt containing result of transaction execution. #[derive(Clone, Debug, PartialEq, Eq, Default)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -55,6 +63,13 @@ impl OpDepositReceipt { } } +impl OpDepositReceipt { + /// Consumes the type and returns the inner [`Receipt`]. + pub fn into_inner(self) -> Receipt { + self.inner + } +} + impl OpDepositReceipt { /// Returns length of RLP-encoded receipt fields with the given [`Bloom`] without an RLP header. pub fn rlp_encoded_fields_length_with_bloom(&self, bloom: &Bloom) -> usize { @@ -108,6 +123,12 @@ impl AsRef> for OpDepositReceipt { } } +impl From> for Receipt { + fn from(value: OpDepositReceipt) -> Self { + value.into_inner() + } +} + impl TxReceipt for OpDepositReceipt where T: AsRef + Clone + core::fmt::Debug + PartialEq + Eq + Send + Sync, @@ -182,14 +203,6 @@ impl OpTxReceipt for OpDepositReceipt { } } -/// [`OpDepositReceipt`] with calculated bloom filter, modified for the OP Stack. -/// -/// This convenience type allows us to lazily calculate the bloom filter for a -/// receipt, similar to [`Sealed`]. -/// -/// [`Sealed`]: alloy_consensus::Sealed -pub type OpDepositReceiptWithBloom = ReceiptWithBloom>; - #[cfg(feature = "arbitrary")] impl<'a, T> arbitrary::Arbitrary<'a> for OpDepositReceipt where