From fe0bbb467b0b354d1f6285e26cf79fb1b75bfa0f Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 10 Oct 2024 03:08:03 +0200 Subject: [PATCH 1/2] feat: add logs_bloom --- crates/primitives/src/log/mod.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/primitives/src/log/mod.rs b/crates/primitives/src/log/mod.rs index a9eacaeeb..92d4e8f27 100644 --- a/crates/primitives/src/log/mod.rs +++ b/crates/primitives/src/log/mod.rs @@ -1,9 +1,21 @@ -use crate::{Address, Bytes, B256}; +use crate::{Address, Bloom, Bytes, B256}; use alloc::vec::Vec; #[cfg(feature = "serde")] mod serde; +/// Compute the logs bloom filter for the given logs. +pub fn logs_bloom<'a>(logs: impl IntoIterator) -> Bloom { + let mut bloom = Bloom::ZERO; + for log in logs { + bloom.m3_2048(log.address.as_slice()); + for topic in log.topics() { + bloom.m3_2048(topic.as_slice()); + } + } + bloom +} + /// An Ethereum event log object. #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))] From eecbc4c2adbbbce8507012d8d18648eeb00e1480 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 10 Oct 2024 20:46:45 +0200 Subject: [PATCH 2/2] accrue_log --- crates/primitives/src/lib.rs | 2 +- crates/primitives/src/log/mod.rs | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index b46e1eaee..c7f2f4335 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -42,7 +42,7 @@ mod common; pub use common::TxKind; mod log; -pub use log::{IntoLogData, Log, LogData}; +pub use log::{logs_bloom, IntoLogData, Log, LogData}; #[cfg(feature = "map")] pub mod map; diff --git a/crates/primitives/src/log/mod.rs b/crates/primitives/src/log/mod.rs index 92d4e8f27..712e1ca91 100644 --- a/crates/primitives/src/log/mod.rs +++ b/crates/primitives/src/log/mod.rs @@ -8,10 +8,7 @@ mod serde; pub fn logs_bloom<'a>(logs: impl IntoIterator) -> Bloom { let mut bloom = Bloom::ZERO; for log in logs { - bloom.m3_2048(log.address.as_slice()); - for topic in log.topics() { - bloom.m3_2048(topic.as_slice()); - } + bloom.accrue_log(log); } bloom }