diff --git a/crates/consensus/src/receipt/envelope.rs b/crates/consensus/src/receipt/envelope.rs index b2ba2dd9c82..b00baf92b02 100644 --- a/crates/consensus/src/receipt/envelope.rs +++ b/crates/consensus/src/receipt/envelope.rs @@ -110,17 +110,17 @@ impl ReceiptEnvelope { /// 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. @@ -130,34 +130,32 @@ impl ReceiptEnvelope { /// 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>> { + /// Returns a reference to the bloom. + pub const fn as_receipt_with_bloom(&self) -> &ReceiptWithBloom> { 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>> { + /// Returns a mutable reference to the bloom. + pub const fn as_receipt_with_bloom_mut(&mut self) -> &mut ReceiptWithBloom> { 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 { match self { Self::Legacy(t) @@ -168,15 +166,17 @@ impl ReceiptEnvelope { } } - /// Return the inner receipt. Currently this is infallible, however, future - /// receipt types may be added. - pub const fn as_receipt(&self) -> Option<&Receipt> { + /// Returns a reference to the inner receipt. + /// + /// This method is infallible because all enum variants contain a + /// `ReceiptWithBloom>`. + pub const fn as_receipt(&self) -> &Receipt { 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, } } } @@ -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 { @@ -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 @@ -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, @@ -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); } } @@ -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, _) = diff --git a/crates/rpc-types-eth/src/transaction/receipt.rs b/crates/rpc-types-eth/src/transaction/receipt.rs index cb6c3ef541a..b4bab2cc146 100644 --- a/crates/rpc-types-eth/src/transaction/receipt.rs +++ b/crates/rpc-types-eth/src/transaction/receipt.rs @@ -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!( @@ -384,7 +384,7 @@ mod test { "transactionHash": "0xea1093d492a1dcb1bef708f771a99a96ff05dcab81ca76c31940300177fcf49f", "blockHash": "0x8e38b4dbf6b11fcc3b9dee84fb7986e29ca0a02cecd8977c161ff7333329681e", "blockNumber": "0xf4240", - "logsBloom": "0x00000000000000000000000000000000000800000000000000000000000800000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000", + "logsBloom": "0x000000000000000000000000000000000008000000000000000000000008000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000", "gasUsed": "0x723c", "root": "0x284d35bf53b82ef480ab4208527325477439c64fb90ef518450f05ee151c8e10", "contractAddress": null,