From 5b84295aa651a341d0d9944ff444d8c94b0b8e50 Mon Sep 17 00:00:00 2001 From: Shoham Chakraborty Date: Thu, 15 Jun 2023 13:17:41 +0800 Subject: [PATCH 1/2] Make filters order dependent --- lib/ain-evm/src/log.rs | 11 ++++++++--- lib/ain-grpc/src/transaction_log.rs | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/ain-evm/src/log.rs b/lib/ain-evm/src/log.rs index 2db8484bfad..d786bab315c 100644 --- a/lib/ain-evm/src/log.rs +++ b/lib/ain-evm/src/log.rs @@ -66,7 +66,7 @@ impl LogHandler { pub fn get_logs( &self, address: Option>, - topics: Option>, + topics: Option>>, block_number: U256, ) -> Vec { debug!("Getting logs for block {:#x?}", block_number); @@ -89,8 +89,13 @@ impl LogHandler { Some(topics) => logs .into_iter() .filter(|log| { - let set: HashSet<_> = log.topics.iter().copied().collect(); - topics.iter().any(|item| set.contains(item)) + topics + .iter() // for all topic filters + .zip(&log.topics) // construct tuple with corresponding log topics + .all(|(filter_item, log_item)| { + // check if topic filter at index matches log topic + filter_item.as_ref().map_or(true, |item| item == log_item) + }) }) .collect(), } diff --git a/lib/ain-grpc/src/transaction_log.rs b/lib/ain-grpc/src/transaction_log.rs index f10392e18eb..7e953c1ecb8 100644 --- a/lib/ain-grpc/src/transaction_log.rs +++ b/lib/ain-grpc/src/transaction_log.rs @@ -40,5 +40,5 @@ pub struct GetLogsRequest { pub block_hash: Option, pub from_block: Option, pub to_block: Option, - pub topics: Option>, + pub topics: Option>>, } From 96fd3f4a867d05c86c59d3dadc06c11b872249dc Mon Sep 17 00:00:00 2001 From: Shoham Chakraborty Date: Thu, 15 Jun 2023 13:34:23 +0800 Subject: [PATCH 2/2] Remove unused import --- lib/ain-evm/src/log.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ain-evm/src/log.rs b/lib/ain-evm/src/log.rs index d786bab315c..305329d2afb 100644 --- a/lib/ain-evm/src/log.rs +++ b/lib/ain-evm/src/log.rs @@ -5,7 +5,7 @@ use ethereum::ReceiptV3; use log::debug; use primitive_types::{H160, H256, U256}; use serde::{Deserialize, Serialize}; -use std::collections::{HashMap, HashSet}; +use std::collections::HashMap; use std::sync::Arc; #[derive(Serialize, Deserialize, Clone, Debug)]