txpool: added a helper to filter pending txns by predicate (#12204)

This commit is contained in:
Darshan Kathiriya
2024-11-01 07:10:55 -04:00
committed by GitHub
parent 249c600dd9
commit 2758a560c0
5 changed files with 36 additions and 0 deletions

View File

@ -496,6 +496,13 @@ where
self.pool.get_transactions_by_sender(sender)
}
fn get_pending_transactions_with_predicate(
&self,
predicate: impl FnMut(&ValidPoolTransaction<Self::Transaction>) -> bool,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
self.pool.pending_transactions_with_predicate(predicate)
}
fn get_pending_transactions_by_sender(
&self,
sender: Address,

View File

@ -213,6 +213,13 @@ impl TransactionPool for NoopTransactionPool {
vec![]
}
fn get_pending_transactions_with_predicate(
&self,
_predicate: impl FnMut(&ValidPoolTransaction<Self::Transaction>) -> bool,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
vec![]
}
fn get_pending_transactions_by_sender(
&self,
_sender: Address,

View File

@ -787,6 +787,14 @@ where
self.get_pool_data().pending_txs_by_sender(sender_id)
}
/// Returns all pending transactions filtered by predicate
pub(crate) fn pending_transactions_with_predicate(
&self,
predicate: impl FnMut(&ValidPoolTransaction<T::Transaction>) -> bool,
) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
self.get_pool_data().pending_transactions_with_predicate(predicate)
}
/// Returns all pending transactions of the address by sender
pub(crate) fn get_pending_transactions_by_sender(
&self,

View File

@ -364,6 +364,14 @@ impl<T: TransactionOrdering> TxPool<T> {
self.pending_pool.all()
}
/// Returns all pending transactions filtered by predicate
pub(crate) fn pending_transactions_with_predicate(
&self,
mut predicate: impl FnMut(&ValidPoolTransaction<T::Transaction>) -> bool,
) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
self.pending_transactions_iter().filter(|tx| predicate(tx)).collect()
}
/// Returns all pending transactions for the specified sender
pub(crate) fn pending_txs_by_sender(
&self,

View File

@ -342,6 +342,12 @@ pub trait TransactionPool: Send + Sync + Clone {
sender: Address,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>>;
/// Returns all pending transactions filtered by predicate
fn get_pending_transactions_with_predicate(
&self,
predicate: impl FnMut(&ValidPoolTransaction<Self::Transaction>) -> bool,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>>;
/// Returns all pending transactions sent by a given user
fn get_pending_transactions_by_sender(
&self,