feat: add getters for tx by origin (#5516)

This commit is contained in:
Matthias Seitz
2023-11-21 15:00:53 +01:00
committed by GitHub
parent 3e0caae5b6
commit 6904194204
4 changed files with 43 additions and 0 deletions

View File

@@ -473,6 +473,13 @@ where
self.pool.get_transactions_by_sender(sender)
}
fn get_transactions_by_origin(
&self,
origin: TransactionOrigin,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
self.pool.get_transactions_by_origin(origin)
}
fn unique_senders(&self) -> HashSet<Address> {
self.pool.unique_senders()
}

View File

@@ -216,6 +216,13 @@ impl TransactionPool for NoopTransactionPool {
}
Err(BlobStoreError::MissingSidecar(tx_hashes[0]))
}
fn get_transactions_by_origin(
&self,
_origin: TransactionOrigin,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
vec![]
}
}
/// A [`TransactionValidator`] that does nothing.

View File

@@ -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<Arc<ValidPoolTransaction<T::Transaction>>> {
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.

View File

@@ -306,6 +306,27 @@ pub trait TransactionPool: Send + Sync + Clone {
sender: Address,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>>;
/// Returns all transactions that where submitted with the given [TransactionOrigin]
fn get_transactions_by_origin(
&self,
origin: TransactionOrigin,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>>;
/// Returns all transactions that where submitted as [TransactionOrigin::Local]
fn get_local_transactions(&self) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
self.get_transactions_by_origin(TransactionOrigin::Local)
}
/// Returns all transactions that where submitted as [TransactionOrigin::Private]
fn get_private_transactions(&self) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
self.get_transactions_by_origin(TransactionOrigin::Private)
}
/// Returns all transactions that where submitted as [TransactionOrigin::External]
fn get_external_transactions(&self) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
self.get_transactions_by_origin(TransactionOrigin::External)
}
/// Returns a set of all senders of transactions in the pool
fn unique_senders(&self) -> HashSet<Address>;