Skip to main content

entropa_node/
mempool.rs

1//! The mempool — pending transactions awaiting inclusion in a block.
2
3use entropa_core::Transaction;
4
5/// A FIFO pool of pending transactions.
6#[derive(Debug, Default, Clone)]
7pub struct Mempool {
8    pending: Vec<Transaction>,
9}
10
11impl Mempool {
12    pub fn new() -> Self {
13        Self::default()
14    }
15
16    /// Submit a transaction into the pool.
17    pub fn submit(&mut self, tx: Transaction) {
18        self.pending.push(tx);
19    }
20
21    /// Remove and return up to `max` transactions, oldest first.
22    pub fn drain(&mut self, max: usize) -> Vec<Transaction> {
23        let n = max.min(self.pending.len());
24        self.pending.drain(..n).collect()
25    }
26
27    pub fn pending(&self) -> &[Transaction] {
28        &self.pending
29    }
30
31    pub fn len(&self) -> usize {
32        self.pending.len()
33    }
34
35    pub fn is_empty(&self) -> bool {
36        self.pending.is_empty()
37    }
38}