Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chain/ethereum : refactor extend for BlockFilter
Browse files Browse the repository at this point in the history
incrypto32 committed Aug 17, 2023
1 parent fea4a5f commit b9c8e97
Showing 2 changed files with 13 additions and 26 deletions.
25 changes: 8 additions & 17 deletions chain/ethereum/src/adapter.rs
Original file line number Diff line number Diff line change
@@ -699,18 +699,8 @@ impl EthereumBlockFilter {
}

for (other_start_block, other_polling_interval) in &polling_intervals {
if self.polling_intervals.iter().any(
|(current_start_block, current_polling_interval)| {
*current_polling_interval == *other_polling_interval
&& *current_start_block == *other_start_block
},
) {
// Already exists, do nothing
} else {
// No conflict found, insert the polling interval
self.polling_intervals
.insert((*other_start_block, *other_polling_interval));
}
self.polling_intervals
.insert((*other_start_block, *other_polling_interval));
}
}

@@ -720,12 +710,13 @@ impl EthereumBlockFilter {

/// An empty filter is one that never matches.
pub fn is_empty(&self) -> bool {
let Self {
contract_addresses,
polling_intervals,
trigger_every_block,
} = self;
// If we are triggering every block, we are of course not empty
if self.trigger_every_block {
return false;
}

self.contract_addresses.is_empty() && self.polling_intervals.is_empty()
!*trigger_every_block && contract_addresses.is_empty() && polling_intervals.is_empty()
}

fn find_contract_address(&self, candidate: &Address) -> Option<(i32, Address)> {
14 changes: 5 additions & 9 deletions chain/ethereum/src/data_source.rs
Original file line number Diff line number Diff line change
@@ -270,17 +270,14 @@ impl blockchain::DataSource<Chain> for DataSource {

let has_non_filtered_block_handler = non_filtered_block_handler_count > 0;
// If there is a non-filtered block handler, we need to check if there are any
// filtered block handlers
// filtered block handlers except for the ones with call filter
// If there are, we do not allow that combination
let has_both_filtered_and_non_filtered = has_non_filtered_block_handler
&& (call_filtered_block_handler_count > 0
|| polling_filtered_block_handler_count > 0
|| initialization_handler_count > 0);
let has_restricted_filtered_and_non_filtered_combination = has_non_filtered_block_handler
&& (polling_filtered_block_handler_count > 0 || initialization_handler_count > 0);

if has_both_filtered_and_non_filtered {
if has_restricted_filtered_and_non_filtered_combination {
errors.push(anyhow!(
"data source has both filtered and non-filtered block handlers, \
this is not allowed"
"data source has a combination of filtered and non-filtered block handlers that is not allowed"
));
}

@@ -425,7 +422,6 @@ impl DataSource {
.iter()
.find(move |handler| match handler.filter {
Some(BlockHandlerFilter::Polling { every }) => {
// POLLING_TODO: Get creation block if start_block is zero
let start_block = self.start_block;
let should_trigger = (block - start_block) % every.get() as i32 == 0;
should_trigger

0 comments on commit b9c8e97

Please sign in to comment.