Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions crates/consensus/src/receipt/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ impl<T> OpReceiptEnvelope<T> {
&self.as_receipt().unwrap().logs
}

/// Consumes the type and returns the logs.
pub fn into_logs(self) -> Vec<T> {
self.into_receipt().logs
}

/// Return the receipt's bloom.
pub const fn logs_bloom(&self) -> &Bloom {
match self {
Expand Down Expand Up @@ -160,6 +165,14 @@ impl<T> OpReceiptEnvelope<T> {
}
}

/// Consumes the type and returns the underlying [`Receipt`].
pub fn into_receipt(self) -> Receipt<T> {
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<T>> {
Expand Down Expand Up @@ -306,6 +319,12 @@ impl Decodable2718 for OpReceiptEnvelope {
}
}

impl<T> From<OpReceiptEnvelope<T>> for Receipt<T> {
fn from(receipt: OpReceiptEnvelope<T>) -> Self {
receipt.into_receipt()
}
}

#[cfg(all(test, feature = "arbitrary"))]
impl<'a, T> arbitrary::Arbitrary<'a> for OpReceiptEnvelope<T>
where
Expand Down
29 changes: 21 additions & 8 deletions crates/consensus/src/receipt/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T = Log> = ReceiptWithBloom<OpDepositReceipt<T>>;

/// Receipt containing result of transaction execution.
#[derive(Clone, Debug, PartialEq, Eq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand Down Expand Up @@ -55,6 +63,13 @@ impl OpDepositReceipt {
}
}

impl<T> OpDepositReceipt<T> {
/// Consumes the type and returns the inner [`Receipt`].
pub fn into_inner(self) -> Receipt<T> {
self.inner
}
}

impl<T: Encodable> OpDepositReceipt<T> {
/// 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 {
Expand Down Expand Up @@ -108,6 +123,12 @@ impl<T> AsRef<Receipt<T>> for OpDepositReceipt<T> {
}
}

impl<T> From<OpDepositReceipt<T>> for Receipt<T> {
fn from(value: OpDepositReceipt<T>) -> Self {
value.into_inner()
}
}

impl<T> TxReceipt for OpDepositReceipt<T>
where
T: AsRef<Log> + Clone + core::fmt::Debug + PartialEq + Eq + Send + Sync,
Expand Down Expand Up @@ -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<T = Log> = ReceiptWithBloom<OpDepositReceipt<T>>;

#[cfg(feature = "arbitrary")]
impl<'a, T> arbitrary::Arbitrary<'a> for OpDepositReceipt<T>
where
Expand Down