1use entropa_core::Transaction;
4
5#[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 pub fn submit(&mut self, tx: Transaction) {
18 self.pending.push(tx);
19 }
20
21 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}