feat: add BestTransactions::filter_transactions (#12041)

This commit is contained in:
Matthias Seitz
2024-10-24 15:28:25 +02:00
committed by GitHub
parent 53c5476637
commit e74f185d95
3 changed files with 25 additions and 0 deletions

View File

@ -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>

View File

@ -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());
}

View File

@ -9,4 +9,6 @@ mod listeners;
#[cfg(feature = "test-utils")]
mod pending;
mod best;
const fn main() {}