Skip to content

Commit

Permalink
Just one match
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipleblanc committed Nov 4, 2023
1 parent 18ab2a9 commit 14f00c3
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions crates/rpc/rpc-types/src/eth/trace/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,19 @@ pub struct TraceFilterMatcher {
impl TraceFilterMatcher {
/// Returns `true` if the given `from` and `to` addresses match this filter.
pub fn matches(&self, from: Address, to: Option<Address>) -> bool {
let from_matches = self.from_addresses.contains(&from);
let to_matches = to.map_or(false, |to_addr| self.to_addresses.contains(&to_addr));

enum Match {
All,
From,
To,
Both(TraceFilterMode),
}

let match_type = match (self.from_addresses.is_empty(), self.to_addresses.is_empty()) {
(true, true) => Match::All,
(false, true) => Match::From,
(true, false) => Match::To,
(false, false) => Match::Both(self.mode),
};

match match_type {
Match::All => true,
Match::From => from_matches,
Match::To => to_matches,
Match::Both(mode) => match mode {
TraceFilterMode::Union => from_matches || to_matches,
TraceFilterMode::Intersection => from_matches && to_matches,
match (self.from_addresses.is_empty(), self.to_addresses.is_empty()) {
(true, true) => true,
(false, true) => self.from_addresses.contains(&from),
(true, false) => to.map_or(false, |to_addr| self.to_addresses.contains(&to_addr)),
(false, false) => match self.mode {
TraceFilterMode::Union => {
self.from_addresses.contains(&from) ||
to.map_or(false, |to_addr| self.to_addresses.contains(&to_addr))
}
TraceFilterMode::Intersection => {
self.from_addresses.contains(&from) &&
to.map_or(false, |to_addr| self.to_addresses.contains(&to_addr))
}
},
}
}
Expand Down

0 comments on commit 14f00c3

Please sign in to comment.