Skip to content

Commit

Permalink
fix: trace_filter matches all transactions on empty addresses (#5279)
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipleblanc authored Nov 3, 2023
1 parent e2ce015 commit ddcd4d6
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions crates/rpc/rpc-types/src/eth/trace/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ 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 {
// If `from_addresses` and `to_addresses` are empty, then match all transactions.
if self.from_addresses.is_empty() && self.to_addresses.is_empty() {
return true;
}

match self.mode {
TraceFilterMode::Union => {
self.from_addresses.contains(&from) ||
Expand All @@ -87,4 +92,27 @@ mod tests {
assert_eq!(filter.from_block, Some(3));
assert_eq!(filter.to_block, Some(5));
}

#[test]
fn test_filter_matcher() {
let s = r#"{"fromBlock": "0x3","toBlock": "0x5"}"#;
let filter: TraceFilter = serde_json::from_str(s).unwrap();
let matcher = filter.matcher();
assert!(
matcher.matches("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045".parse().unwrap(), None)
);
assert!(
matcher.matches("0x160f5f00288e9e1cc8655b327e081566e580a71d".parse().unwrap(), None)
);

let s = r#"{"fromBlock": "0x3","toBlock": "0x5", "fromAddress": ["0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"]}"#;
let filter: TraceFilter = serde_json::from_str(s).unwrap();
let matcher = filter.matcher();
assert!(
matcher.matches("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045".parse().unwrap(), None)
);
assert!(
!matcher.matches("0x160f5f00288e9e1cc8655b327e081566e580a71d".parse().unwrap(), None)
);
}
}

0 comments on commit ddcd4d6

Please sign in to comment.