mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(txpool): add get_all function (#65)
This commit is contained in:
@ -212,6 +212,13 @@ where
|
||||
fn get(&self, tx_hash: &TxHash) -> Option<Arc<ValidPoolTransaction<Self::Transaction>>> {
|
||||
self.inner().get(tx_hash)
|
||||
}
|
||||
|
||||
fn get_all(
|
||||
&self,
|
||||
txs: impl IntoIterator<Item = TxHash>,
|
||||
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
|
||||
self.inner().get_all(txs)
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: TransactionValidator, O: TransactionOrdering> Clone for Pool<V, O> {
|
||||
|
||||
@ -283,6 +283,16 @@ where
|
||||
self.pool.read().get(tx_hash)
|
||||
}
|
||||
|
||||
/// Returns all the transactions belonging to the hashes.
|
||||
///
|
||||
/// If no transaction exists, it is skipped.
|
||||
pub(crate) fn get_all(
|
||||
&self,
|
||||
txs: impl IntoIterator<Item = TxHash>,
|
||||
) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
|
||||
self.pool.read().get_all(txs).collect()
|
||||
}
|
||||
|
||||
/// Number of transactions in the entire pool
|
||||
pub(crate) fn len(&self) -> usize {
|
||||
self.pool.read().len()
|
||||
|
||||
@ -123,6 +123,14 @@ impl<T: TransactionOrdering> TxPool<T> {
|
||||
self.all_transactions.by_hash.get(tx_hash).cloned()
|
||||
}
|
||||
|
||||
/// Returns all transaction for the hashes, if it exis.
|
||||
pub(crate) fn get_all<'a>(
|
||||
&'a self,
|
||||
txs: impl IntoIterator<Item = TxHash> + 'a,
|
||||
) -> impl Iterator<Item = Arc<ValidPoolTransaction<T::Transaction>>> + 'a {
|
||||
txs.into_iter().filter_map(|tx| self.get(&tx))
|
||||
}
|
||||
|
||||
/// Adds the transaction into the pool.
|
||||
///
|
||||
/// This pool consists of two three-pools: `Queued`, `Pending` and `BaseFee`.
|
||||
|
||||
@ -67,6 +67,16 @@ pub trait TransactionPool: Send + Sync {
|
||||
|
||||
/// Returns the transaction for the given hash.
|
||||
fn get(&self, tx_hash: &TxHash) -> Option<Arc<ValidPoolTransaction<Self::Transaction>>>;
|
||||
|
||||
/// Returns all transactions objects for the given hashes.
|
||||
///
|
||||
/// This adheres to the expected behavior of [`GetPooledTransactions`](https://github.com/ethereum/devp2p/blob/master/caps/eth.md#getpooledtransactions-0x09):
|
||||
/// The transactions must be in same order as in the request, but it is OK to skip transactions
|
||||
/// which are not available.
|
||||
fn get_all(
|
||||
&self,
|
||||
txs: impl IntoIterator<Item = TxHash>,
|
||||
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>>;
|
||||
}
|
||||
|
||||
/// Represents a new transaction
|
||||
|
||||
Reference in New Issue
Block a user