From 3e808b3381a820848b2ac2164822748b6ec3f76e Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Fri, 22 Nov 2024 21:22:47 +0400 Subject: [PATCH] fixes --- crates/consensus-any/src/receipt/envelope.rs | 2 +- crates/consensus/src/receipt/envelope.rs | 13 +++++++------ crates/consensus/src/receipt/mod.rs | 2 +- crates/consensus/src/receipt/receipts.rs | 17 ++++++++++------- crates/rpc-types-any/Cargo.toml | 1 + crates/rpc-types-any/src/transaction/receipt.rs | 5 ++++- crates/rpc-types-eth/src/log.rs | 8 ++++++++ crates/rpc-types-eth/src/transaction/receipt.rs | 2 +- 8 files changed, 33 insertions(+), 17 deletions(-) diff --git a/crates/consensus-any/src/receipt/envelope.rs b/crates/consensus-any/src/receipt/envelope.rs index 731893f0b53..a26f6fe2a44 100644 --- a/crates/consensus-any/src/receipt/envelope.rs +++ b/crates/consensus-any/src/receipt/envelope.rs @@ -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}; diff --git a/crates/consensus/src/receipt/envelope.rs b/crates/consensus/src/receipt/envelope.rs index ebf9b3f7391..698b0854093 100644 --- a/crates/consensus/src/receipt/envelope.rs +++ b/crates/consensus/src/receipt/envelope.rs @@ -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]. /// @@ -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. @@ -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) @@ -141,7 +140,7 @@ where /// Return the receipt logs. fn logs(&self) -> &[Self::Log] { - &self.as_receipt().unwrap().logs() + self.as_receipt().unwrap().logs() } } @@ -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: super::Receipt { status: super::Eip658Value::PostState(b256!( "284d35bf53b82ef480ab4208527325477439c64fb90ef518450f05ee151c8e10" @@ -260,7 +261,7 @@ mod test { println!("Serialized {}", json); - let receipt: super::ReceiptWithBloom<()> = serde_json::from_str(&json).unwrap(); + let receipt: super::ReceiptWithBloom> = serde_json::from_str(&json).unwrap(); assert_eq!( receipt.receipt.status, diff --git a/crates/consensus/src/receipt/mod.rs b/crates/consensus/src/receipt/mod.rs index 5695c3d9915..6a117a57d91 100644 --- a/crates/consensus/src/receipt/mod.rs +++ b/crates/consensus/src/receipt/mod.rs @@ -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 diff --git a/crates/consensus/src/receipt/receipts.rs b/crates/consensus/src/receipt/receipts.rs index 932397b2b3f..2aeb9852300 100644 --- a/crates/consensus/src/receipt/receipts.rs +++ b/crates/consensus/src/receipt/receipts.rs @@ -36,7 +36,7 @@ where /// Calculates the bloom filter for the receipt and returns the [ReceiptWithBloom] container /// type. - pub fn with_bloom(self) -> ReceiptWithBloom> { + pub fn with_bloom(self) -> ReceiptWithBloom { self.into() } } @@ -68,9 +68,9 @@ where } } -impl From>> for Receipt { +impl From> for Receipt { /// Consume the structure, returning only the receipt - fn from(receipt_with_bloom: ReceiptWithBloom>) -> Self { + fn from(receipt_with_bloom: ReceiptWithBloom) -> Self { receipt_with_bloom.receipt } } @@ -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 { @@ -159,7 +162,7 @@ where } fn logs(&self) -> &[Self::Log] { - &self.receipt.logs() + self.receipt.logs() } } @@ -260,12 +263,12 @@ impl Decodable for ReceiptWithBloom> { } #[cfg(any(test, feature = "arbitrary"))] -impl<'a, T> arbitrary::Arbitrary<'a> for ReceiptWithBloom> +impl<'a, T> arbitrary::Arbitrary<'a> for ReceiptWithBloom where T: arbitrary::Arbitrary<'a>, { fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { - Ok(Self { receipt: Receipt::::arbitrary(u)?, logs_bloom: Bloom::arbitrary(u)? }) + Ok(Self { receipt: T::arbitrary(u)?, logs_bloom: Bloom::arbitrary(u)? }) } } diff --git a/crates/rpc-types-any/Cargo.toml b/crates/rpc-types-any/Cargo.toml index 560ef541358..16a2d8dc234 100644 --- a/crates/rpc-types-any/Cargo.toml +++ b/crates/rpc-types-any/Cargo.toml @@ -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 diff --git a/crates/rpc-types-any/src/transaction/receipt.rs b/crates/rpc-types-any/src/transaction/receipt.rs index aa81e91693e..21ff8d7fc64 100644 --- a/crates/rpc-types-any/src/transaction/receipt.rs +++ b/crates/rpc-types-any/src/transaction/receipt.rs @@ -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>>; + WithOtherFields>>>; #[cfg(test)] mod test { diff --git a/crates/rpc-types-eth/src/log.rs b/crates/rpc-types-eth/src/log.rs index c9e8f2def6c..5d73929fac4 100644 --- a/crates/rpc-types-eth/src/log.rs +++ b/crates/rpc-types-eth/src/log.rs @@ -1,3 +1,5 @@ +use core::borrow::Borrow; + use alloy_primitives::{Address, BlockHash, LogData, TxHash, B256}; /// Ethereum Log emitted by a transaction @@ -151,6 +153,12 @@ impl AsMut for Log { } } +impl Borrow> for Log { + fn borrow(&self) -> &alloy_primitives::Log { + &self.inner + } +} + #[cfg(test)] mod tests { use alloy_primitives::{Address, Bytes}; diff --git a/crates/rpc-types-eth/src/transaction/receipt.rs b/crates/rpc-types-eth/src/transaction/receipt.rs index aeaee6aed46..144936e3958 100644 --- a/crates/rpc-types-eth/src/transaction/receipt.rs +++ b/crates/rpc-types-eth/src/transaction/receipt.rs @@ -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};