Skip to content

Commit 5f20830

Browse files
committed
feat: truncate_block_range
1 parent 427cdee commit 5f20830

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

crates/rpc-types-eth/src/filter.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,22 @@ impl Filter {
634634
}
635635
}
636636

637+
/// Bound the block range to the given range. If the filter is a range
638+
/// filter, this will modify the `from_block` and `to_block` values to be
639+
/// within the given range. If the filter is a block hash filter, this will
640+
/// do nothing.
641+
pub fn truncate_block_range(&mut self, min_from: u64, max_end: u64) {
642+
if let FilterBlockOption::Range { from_block, to_block } = &mut self.block_option {
643+
// bound to `from_block` to the greater of `from_block` and
644+
// `min_from`
645+
let from = from_block.get_or_insert(min_from);
646+
*from = from.max(*min_from);
647+
// bound to `to_block` to the lesser of `to_block` and `max_end`
648+
let to = to_block.get_or_insert(max_end);
649+
*to = to.min(*max_end);
650+
}
651+
}
652+
637653
/// Returns `true` if at least one topic is set
638654
pub fn has_topics(&self) -> bool {
639655
self.topics.iter().any(|t| !t.is_empty())

0 commit comments

Comments
 (0)