Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Nov 22, 2024
1 parent 2a2390b commit 3e808b3
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion crates/consensus-any/src/receipt/envelope.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy_consensus::{Eip658Value, ReceiptWithBloom, TxReceipt, Receipt};
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};
Expand Down
13 changes: 7 additions & 6 deletions crates/consensus/src/receipt/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::{Eip658Value, Receipt, ReceiptWithBloom, TxReceipt, TxType};
use alloy_eips::eip2718::{Decodable2718, Eip2718Error, Eip2718Result, Encodable2718};
use alloy_primitives::{Bloom, Log};
use alloy_rlp::{BufMut, Decodable, Encodable};
use core::fmt;

/// Receipt envelope, as defined in [EIP-2718].
///
Expand Down Expand Up @@ -78,7 +77,7 @@ where

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

/// Return the receipt's bloom.
Expand All @@ -101,7 +100,7 @@ where
/// Return the inner receipt. Currently this is infallible, however, future
/// receipt types may be added.
pub const fn as_receipt(&self) -> Option<&T> {
match self {
match self {
Self::Legacy(t)
| Self::Eip2930(t)
| Self::Eip1559(t)
Expand Down Expand Up @@ -141,7 +140,7 @@ where

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

Expand Down Expand Up @@ -245,7 +244,9 @@ mod test {
fn deser_pre658_receipt_envelope() {
use alloy_primitives::b256;

let receipt = super::ReceiptWithBloom::<()> {
use crate::Receipt;

let receipt = super::ReceiptWithBloom::<Receipt<()>> {
receipt: super::Receipt {
status: super::Eip658Value::PostState(b256!(
"284d35bf53b82ef480ab4208527325477439c64fb90ef518450f05ee151c8e10"
Expand All @@ -260,7 +261,7 @@ mod test {

println!("Serialized {}", json);

let receipt: super::ReceiptWithBloom<()> = serde_json::from_str(&json).unwrap();
let receipt: super::ReceiptWithBloom<Receipt<()>> = serde_json::from_str(&json).unwrap();

assert_eq!(
receipt.receipt.status,
Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/src/receipt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub trait TxReceipt: Clone + fmt::Debug + PartialEq + Eq + Send + Sync {
mod tests {
use super::*;
use alloy_eips::eip2718::Encodable2718;
use alloy_primitives::{address, b256, bytes, hex, LogData};
use alloy_primitives::{address, b256, bytes, hex, Log, LogData};
use alloy_rlp::{Decodable, Encodable};

// Test vector from: https://eips.ethereum.org/EIPS/eip-2481
Expand Down
17 changes: 10 additions & 7 deletions crates/consensus/src/receipt/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ where

/// Calculates the bloom filter for the receipt and returns the [ReceiptWithBloom] container
/// type.
pub fn with_bloom(self) -> ReceiptWithBloom<Receipt<T>> {
pub fn with_bloom(self) -> ReceiptWithBloom<Self> {
self.into()
}
}
Expand Down Expand Up @@ -68,9 +68,9 @@ where
}
}

impl<T> From<ReceiptWithBloom<Receipt<T>>> for Receipt<T> {
impl<T> From<ReceiptWithBloom<Self>> for Receipt<T> {
/// Consume the structure, returning only the receipt
fn from(receipt_with_bloom: ReceiptWithBloom<Receipt<T>>) -> Self {
fn from(receipt_with_bloom: ReceiptWithBloom<Self>) -> Self {
receipt_with_bloom.receipt
}
}
Expand Down Expand Up @@ -143,7 +143,10 @@ where
}

fn status(&self) -> bool {
matches!(self.receipt.status_or_post_state(), Eip658Value::Eip658(true) | Eip658Value::PostState(_))
matches!(
self.receipt.status_or_post_state(),
Eip658Value::Eip658(true) | Eip658Value::PostState(_)
)
}

fn bloom(&self) -> Bloom {
Expand All @@ -159,7 +162,7 @@ where
}

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

Expand Down Expand Up @@ -260,12 +263,12 @@ impl<T: Decodable> Decodable for ReceiptWithBloom<Receipt<T>> {
}

#[cfg(any(test, feature = "arbitrary"))]
impl<'a, T> arbitrary::Arbitrary<'a> for ReceiptWithBloom<Receipt<T>>
impl<'a, T> arbitrary::Arbitrary<'a> for ReceiptWithBloom<T>
where
T: arbitrary::Arbitrary<'a>,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
Ok(Self { receipt: Receipt::<T>::arbitrary(u)?, logs_bloom: Bloom::arbitrary(u)? })
Ok(Self { receipt: T::arbitrary(u)?, logs_bloom: Bloom::arbitrary(u)? })
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-any/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 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
5 changes: 4 additions & 1 deletion crates/rpc-types-any/src/transaction/receipt.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
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 =
alloy_serde::WithOtherFields<TransactionReceipt<alloy_consensus_any::AnyReceiptEnvelope<Log>>>;
WithOtherFields<TransactionReceipt<AnyReceiptEnvelope<Receipt<Log>>>>;

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

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

/// Ethereum Log emitted by a transaction
Expand Down Expand Up @@ -151,6 +153,12 @@ 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
2 changes: 1 addition & 1 deletion crates/rpc-types-eth/src/transaction/receipt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::Log;
use alloc::vec::Vec;
use alloy_consensus::{ReceiptEnvelope, TxReceipt, TxType, Receipt};
use alloy_consensus::{Receipt, ReceiptEnvelope, TxReceipt, TxType};
use alloy_eips::eip7702::SignedAuthorization;
use alloy_network_primitives::ReceiptResponse;
use alloy_primitives::{Address, BlockHash, TxHash, B256};
Expand Down

0 comments on commit 3e808b3

Please sign in to comment.