Skip to content

Commit

Permalink
feat: add BestTransactions::filter_transactions (#12041)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Oct 24, 2024
1 parent 53c5476 commit e74f185
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions crates/transaction-pool/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,19 @@ pub trait BestTransactions: Iterator + Send {
///
/// If set to true, no blob transactions will be returned.
fn set_skip_blobs(&mut self, skip_blobs: bool);

/// Creates an iterator which uses a closure to determine whether a transaction should be
/// returned by the iterator.
///
/// All items the closure returns false for are marked as invalid via [`Self::mark_invalid`] and
/// descendant transactions will be skipped.
fn filter_transactions<P>(self, predicate: P) -> BestTransactionFilter<Self, P>
where
P: FnMut(&Self::Item) -> bool,
Self: Sized,
{
BestTransactionFilter::new(self, predicate)
}
}

impl<T> BestTransactions for Box<T>
Expand Down
10 changes: 10 additions & 0 deletions crates/transaction-pool/tests/it/best.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//! Best transaction and filter testing
use reth_transaction_pool::{noop::NoopTransactionPool, BestTransactions, TransactionPool};

#[test]
fn test_best_transactions() {
let noop = NoopTransactionPool::default();
let mut best = noop.best_transactions().filter_transactions(|_| true);
assert!(best.next().is_none());
}
2 changes: 2 additions & 0 deletions crates/transaction-pool/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ mod listeners;
#[cfg(feature = "test-utils")]
mod pending;

mod best;

const fn main() {}

0 comments on commit e74f185

Please sign in to comment.