Skip to content

Commit

Permalink
chore: add AllTransactionsEvents::new (#7192)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Mar 18, 2024
1 parent 56d688b commit 273f3c7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/transaction-pool/src/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl TransactionPool for NoopTransactionPool {
}

fn all_transactions_event_listener(&self) -> AllTransactionsEvents<Self::Transaction> {
AllTransactionsEvents { events: mpsc::channel(1).1 }
AllTransactionsEvents::new(mpsc::channel(1).1)
}

fn pending_transactions_listener_for(
Expand Down
9 changes: 8 additions & 1 deletion crates/transaction-pool/src/pool/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ pub struct AllTransactionsEvents<T: PoolTransaction> {
pub(crate) events: Receiver<FullTransactionEvent<T>>,
}

impl<T: PoolTransaction> AllTransactionsEvents<T> {
/// Create a new instance of this stream.
pub const fn new(events: Receiver<FullTransactionEvent<T>>) -> Self {
Self { events }
}
}

impl<T: PoolTransaction> Stream for AllTransactionsEvents<T> {
type Item = FullTransactionEvent<T>;

Expand Down Expand Up @@ -122,7 +129,7 @@ impl<T: PoolTransaction> PoolEventBroadcast<T> {
pub(crate) fn subscribe_all(&mut self) -> AllTransactionsEvents<T> {
let (tx, rx) = tokio::sync::mpsc::channel(TX_POOL_EVENT_CHANNEL_SIZE);
self.all_events_broadcaster.senders.push(tx);
AllTransactionsEvents { events: rx }
AllTransactionsEvents::new(rx)
}

/// Notify listeners about a transaction that was added to the pending queue.
Expand Down

0 comments on commit 273f3c7

Please sign in to comment.