Skip to content
Open
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
52 changes: 26 additions & 26 deletions crates/consensus/src/receipt/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,17 @@ impl<T> ReceiptEnvelope<T> {

/// Returns the success status of the receipt's transaction.
pub const fn status(&self) -> bool {
self.as_receipt().unwrap().status.coerce_status()
self.as_receipt().status.coerce_status()
}

/// Returns the cumulative gas used at this receipt.
pub const fn cumulative_gas_used(&self) -> u64 {
self.as_receipt().unwrap().cumulative_gas_used
self.as_receipt().cumulative_gas_used
}

/// Return the receipt logs.
pub fn logs(&self) -> &[T] {
&self.as_receipt().unwrap().logs
&self.as_receipt().logs
}

/// Consumes the type and returns the logs.
Expand All @@ -130,34 +130,32 @@ impl<T> ReceiptEnvelope<T> {

/// Return the receipt's bloom.
pub const fn logs_bloom(&self) -> &Bloom {
&self.as_receipt_with_bloom().unwrap().logs_bloom
&self.as_receipt_with_bloom().logs_bloom
}

/// Return the inner receipt with bloom. Currently this is infallible,
/// however, future receipt types may be added.
pub const fn as_receipt_with_bloom(&self) -> Option<&ReceiptWithBloom<Receipt<T>>> {
/// Returns a reference to the bloom.
pub const fn as_receipt_with_bloom(&self) -> &ReceiptWithBloom<Receipt<T>> {
match self {
Self::Legacy(t)
| Self::Eip2930(t)
| Self::Eip1559(t)
| Self::Eip4844(t)
| Self::Eip7702(t) => Some(t),
| Self::Eip7702(t) => t,
}
}

/// Return the mutable inner receipt with bloom. Currently this is
/// infallible, however, future receipt types may be added.
pub const fn as_receipt_with_bloom_mut(&mut self) -> Option<&mut ReceiptWithBloom<Receipt<T>>> {
/// Returns a mutable reference to the bloom.
pub const fn as_receipt_with_bloom_mut(&mut self) -> &mut ReceiptWithBloom<Receipt<T>> {
match self {
Self::Legacy(t)
| Self::Eip2930(t)
| Self::Eip1559(t)
| Self::Eip4844(t)
| Self::Eip7702(t) => Some(t),
| Self::Eip7702(t) => t,
}
}

/// Consumes the type and returns the underlying [`Receipt`].
/// Consumes the type and returns the underlying Receipt.
pub fn into_receipt(self) -> Receipt<T> {
match self {
Self::Legacy(t)
Expand All @@ -168,15 +166,17 @@ impl<T> ReceiptEnvelope<T> {
}
}

/// Return the inner receipt. Currently this is infallible, however, future
/// receipt types may be added.
pub const fn as_receipt(&self) -> Option<&Receipt<T>> {
/// Returns a reference to the inner receipt.
///
/// This method is infallible because all enum variants contain a
/// `ReceiptWithBloom<Receipt<T>>`.
pub const fn as_receipt(&self) -> &Receipt<T> {
match self {
Self::Legacy(t)
| Self::Eip2930(t)
| Self::Eip1559(t)
| Self::Eip4844(t)
| Self::Eip7702(t) => Some(&t.receipt),
| Self::Eip7702(t) => &t.receipt,
}
}
}
Expand All @@ -188,16 +188,16 @@ where
type Log = T;

fn status_or_post_state(&self) -> Eip658Value {
self.as_receipt().unwrap().status
self.as_receipt().status
}

fn status(&self) -> bool {
self.as_receipt().unwrap().status.coerce_status()
self.as_receipt().status.coerce_status()
}

/// Return the receipt's bloom.
fn bloom(&self) -> Bloom {
self.as_receipt_with_bloom().unwrap().logs_bloom
self.as_receipt_with_bloom().logs_bloom
}

fn bloom_cheap(&self) -> Option<Bloom> {
Expand All @@ -206,12 +206,12 @@ where

/// Returns the cumulative gas used at this receipt.
fn cumulative_gas_used(&self) -> u64 {
self.as_receipt().unwrap().cumulative_gas_used
self.as_receipt().cumulative_gas_used
}

/// Return the receipt logs.
fn logs(&self) -> &[T] {
&self.as_receipt().unwrap().logs
&self.as_receipt().logs
}

fn into_logs(self) -> Vec<Self::Log>
Expand All @@ -225,12 +225,12 @@ where
impl ReceiptEnvelope {
/// Get the length of the inner receipt in the 2718 encoding.
pub fn inner_length(&self) -> usize {
self.as_receipt_with_bloom().unwrap().length()
self.as_receipt_with_bloom().length()
}

/// Calculate the length of the rlp payload of the network encoded receipt.
pub fn rlp_payload_length(&self) -> usize {
let length = self.as_receipt_with_bloom().unwrap().length();
let length = self.as_receipt_with_bloom().length();
match self {
Self::Legacy(_) => length,
_ => length + 1,
Expand Down Expand Up @@ -283,7 +283,7 @@ impl Encodable2718 for ReceiptEnvelope {
None => {}
Some(ty) => out.put_u8(ty),
}
self.as_receipt_with_bloom().unwrap().encode(out);
self.as_receipt_with_bloom().encode(out);
}
}

Expand Down Expand Up @@ -449,7 +449,7 @@ pub(crate) mod serde_bincode_compat {
};

// ensure we have proper roundtrip data
data.transaction.as_receipt_with_bloom_mut().unwrap().receipt.status = true.into();
data.transaction.as_receipt_with_bloom_mut().receipt.status = true.into();

let encoded = bincode::serde::encode_to_vec(&data, config::legacy()).unwrap();
let (decoded, _) =
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc-types-eth/src/transaction/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ mod test {
})
));

let log = receipt.inner.as_receipt().unwrap().logs.first().unwrap();
let log = receipt.inner.as_receipt().logs.first().unwrap();
assert_eq!(log.address(), address!("dac17f958d2ee523a2206206994597c13d831ec7"));
assert_eq!(log.log_index, Some(0x118));
assert_eq!(
Expand All @@ -384,7 +384,7 @@ mod test {
"transactionHash": "0xea1093d492a1dcb1bef708f771a99a96ff05dcab81ca76c31940300177fcf49f",
"blockHash": "0x8e38b4dbf6b11fcc3b9dee84fb7986e29ca0a02cecd8977c161ff7333329681e",
"blockNumber": "0xf4240",
"logsBloom": "0x00000000000000000000000000000000000800000000000000000000000800000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000",
"logsBloom": "0x000000000000000000000000000000000008000000000000000000000008000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000",
"gasUsed": "0x723c",
"root": "0x284d35bf53b82ef480ab4208527325477439c64fb90ef518450f05ee151c8e10",
"contractAddress": null,
Expand Down
Loading