From 6520cc19e620690b96fd391310571348e3271cc2 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 21 Nov 2023 12:55:18 +0100 Subject: [PATCH] feat: add getters for tx by origin --- crates/transaction-pool/src/lib.rs | 7 +++++++ crates/transaction-pool/src/noop.rs | 7 +++++++ crates/transaction-pool/src/pool/mod.rs | 8 ++++++++ crates/transaction-pool/src/traits.rs | 21 +++++++++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/crates/transaction-pool/src/lib.rs b/crates/transaction-pool/src/lib.rs index de60ab7c5fff..84c9e15ecf9d 100644 --- a/crates/transaction-pool/src/lib.rs +++ b/crates/transaction-pool/src/lib.rs @@ -473,6 +473,13 @@ where self.pool.get_transactions_by_sender(sender) } + fn get_transactions_by_origin( + &self, + origin: TransactionOrigin, + ) -> Vec>> { + self.pool.get_transactions_by_origin(origin) + } + fn unique_senders(&self) -> HashSet
{ self.pool.unique_senders() } diff --git a/crates/transaction-pool/src/noop.rs b/crates/transaction-pool/src/noop.rs index 6e6be8f2b8f4..a1cadb5f6597 100644 --- a/crates/transaction-pool/src/noop.rs +++ b/crates/transaction-pool/src/noop.rs @@ -216,6 +216,13 @@ impl TransactionPool for NoopTransactionPool { } Err(BlobStoreError::MissingSidecar(tx_hashes[0])) } + + fn get_transactions_by_origin( + &self, + _origin: TransactionOrigin, + ) -> Vec>> { + vec![] + } } /// A [`TransactionValidator`] that does nothing. diff --git a/crates/transaction-pool/src/pool/mod.rs b/crates/transaction-pool/src/pool/mod.rs index 7242099c1588..cc60955470b4 100644 --- a/crates/transaction-pool/src/pool/mod.rs +++ b/crates/transaction-pool/src/pool/mod.rs @@ -695,6 +695,14 @@ where self.pool.read().get_transactions_by_sender(sender_id) } + /// Returns all transactions that where submitted with the given [TransactionOrigin] + pub(crate) fn get_transactions_by_origin( + &self, + origin: TransactionOrigin, + ) -> Vec>> { + self.pool.read().all().transactions_iter().filter(|tx| tx.origin == origin).collect() + } + /// Returns all the transactions belonging to the hashes. /// /// If no transaction exists, it is skipped. diff --git a/crates/transaction-pool/src/traits.rs b/crates/transaction-pool/src/traits.rs index 91455df3d866..3888b1078666 100644 --- a/crates/transaction-pool/src/traits.rs +++ b/crates/transaction-pool/src/traits.rs @@ -306,6 +306,27 @@ pub trait TransactionPool: Send + Sync + Clone { sender: Address, ) -> Vec>>; + /// Returns all transactions that where submitted with the given [TransactionOrigin] + fn get_transactions_by_origin( + &self, + origin: TransactionOrigin, + ) -> Vec>>; + + /// Returns all transactions that where submitted as [TransactionOrigin::Local] + fn get_local_transactions(&self) -> Vec>> { + self.get_transactions_by_origin(TransactionOrigin::Local) + } + + /// Returns all transactions that where submitted as [TransactionOrigin::Private] + fn get_private_transactions(&self) -> Vec>> { + self.get_transactions_by_origin(TransactionOrigin::Private) + } + + /// Returns all transactions that where submitted as [TransactionOrigin::External] + fn get_external_transactions(&self) -> Vec>> { + self.get_transactions_by_origin(TransactionOrigin::External) + } + /// Returns a set of all senders of transactions in the pool fn unique_senders(&self) -> HashSet
;