Skip to content

Commit

Permalink
fix: remove Borrow impl for RPC receipt (#1721)
Browse files Browse the repository at this point in the history
wip
  • Loading branch information
klkvr authored Dec 2, 2024
1 parent 9d66bd2 commit 7b4db9e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 34 deletions.
45 changes: 23 additions & 22 deletions crates/consensus-any/src/receipt/envelope.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use alloy_consensus::{Eip658Value, Receipt, ReceiptWithBloom, RlpEncodableReceipt, TxReceipt};
use alloy_consensus::{Eip658Value, Receipt, ReceiptWithBloom, TxReceipt};
use alloy_eips::eip2718::{Decodable2718, Eip2718Result, Encodable2718};
use alloy_primitives::{bytes::BufMut, Bloom, Log};
use alloy_rlp::{Decodable, Encodable};
use core::fmt;

/// Receipt envelope, as defined in [EIP-2718].
///
Expand All @@ -16,23 +17,23 @@ use alloy_rlp::{Decodable, Encodable};
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[doc(alias = "AnyTransactionReceiptEnvelope", alias = "AnyTxReceiptEnvelope")]
pub struct AnyReceiptEnvelope<T = Receipt<Log>> {
pub struct AnyReceiptEnvelope<T = Log> {
/// The receipt envelope.
#[cfg_attr(feature = "serde", serde(flatten))]
pub inner: ReceiptWithBloom<T>,
pub inner: ReceiptWithBloom<Receipt<T>>,
/// The transaction type.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub r#type: u8,
}

impl<R> AnyReceiptEnvelope<R> {
impl<T> AnyReceiptEnvelope<T> {
/// Returns whether this is a legacy receipt (type 0)
pub const fn is_legacy(&self) -> bool {
self.r#type == 0
}
}

impl<R: RlpEncodableReceipt> AnyReceiptEnvelope<R> {
impl<T: Encodable> AnyReceiptEnvelope<T> {
/// Calculate the length of the rlp payload of the network encoded receipt.
pub fn rlp_payload_length(&self) -> usize {
let length = self.inner.length();
Expand All @@ -44,7 +45,7 @@ impl<R: RlpEncodableReceipt> AnyReceiptEnvelope<R> {
}
}

impl<R: TxReceipt> AnyReceiptEnvelope<R> {
impl<T> AnyReceiptEnvelope<T> {
/// Return true if the transaction was successful.
///
/// ## Note
Expand All @@ -53,7 +54,7 @@ impl<R: TxReceipt> AnyReceiptEnvelope<R> {
/// for transactions before [EIP-658].
///
/// [EIP-658]: https://eips.ethereum.org/EIPS/eip-658
pub fn is_success(&self) -> bool {
pub const fn is_success(&self) -> bool {
self.status()
}

Expand All @@ -65,8 +66,8 @@ impl<R: TxReceipt> AnyReceiptEnvelope<R> {
/// for transactions before [EIP-658].
///
/// [EIP-658]: https://eips.ethereum.org/EIPS/eip-658
pub fn status(&self) -> bool {
self.inner.receipt.status()
pub const fn status(&self) -> bool {
self.inner.receipt.status.coerce_status()
}

/// Return the receipt's bloom.
Expand All @@ -75,40 +76,40 @@ impl<R: TxReceipt> AnyReceiptEnvelope<R> {
}

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

/// Return the receipt logs.
pub fn logs(&self) -> &[R::Log] {
self.inner.receipt.logs()
pub fn logs(&self) -> &[T] {
&self.inner.receipt.logs
}
}

impl<R> TxReceipt for AnyReceiptEnvelope<R>
impl<T> TxReceipt for AnyReceiptEnvelope<T>
where
R: TxReceipt,
T: Clone + fmt::Debug + PartialEq + Eq + Send + Sync,
{
type Log = R::Log;
type Log = T;

fn status_or_post_state(&self) -> Eip658Value {
self.inner.receipt.status_or_post_state()
self.inner.receipt.status
}

fn status(&self) -> bool {
self.inner.receipt.status()
self.status()
}

fn bloom(&self) -> Bloom {
self.inner.logs_bloom
self.bloom()
}

fn cumulative_gas_used(&self) -> u128 {
self.inner.receipt.cumulative_gas_used()
self.cumulative_gas_used()
}

fn logs(&self) -> &[Self::Log] {
self.inner.receipt.logs()
fn logs(&self) -> &[T] {
self.logs()
}
}

Expand Down
1 change: 0 additions & 1 deletion crates/rpc-types-any/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ rustdoc-args = ["--cfg", "docsrs"]
workspace = true

[dependencies]
alloy-consensus = { workspace = true, features = ["serde"] }
alloy-consensus-any = { workspace = true, features = ["serde"] }
alloy-rpc-types-eth.workspace = true
alloy-serde.workspace = true
Expand Down
4 changes: 1 addition & 3 deletions crates/rpc-types-any/src/transaction/receipt.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use alloy_consensus::Receipt;
use alloy_consensus_any::AnyReceiptEnvelope;
use alloy_rpc_types_eth::{Log, TransactionReceipt};
use alloy_serde::WithOtherFields;

/// Alias for a catch-all receipt type.
#[doc(alias = "AnyTxReceipt")]
pub type AnyTransactionReceipt =
WithOtherFields<TransactionReceipt<AnyReceiptEnvelope<Receipt<Log>>>>;
pub type AnyTransactionReceipt = WithOtherFields<TransactionReceipt<AnyReceiptEnvelope<Log>>>;

#[cfg(test)]
mod test {
Expand Down
8 changes: 0 additions & 8 deletions crates/rpc-types-eth/src/log.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use core::borrow::Borrow;

use alloy_primitives::{Address, BlockHash, LogData, TxHash, B256};

/// Ethereum Log emitted by a transaction
Expand Down Expand Up @@ -153,12 +151,6 @@ impl<T> AsMut<T> for Log<T> {
}
}

impl<T> Borrow<alloy_primitives::Log<T>> for Log<T> {
fn borrow(&self) -> &alloy_primitives::Log<T> {
&self.inner
}
}

#[cfg(test)]
mod tests {
use alloy_primitives::{Address, Bytes};
Expand Down

0 comments on commit 7b4db9e

Please sign in to comment.