From 7b3446f4a0077ba3dadd4bb209792347cd4e0ee2 Mon Sep 17 00:00:00 2001 From: Ayelet Zilber Date: Tue, 4 Jun 2024 14:33:54 +0300 Subject: [PATCH] feat: add address priority queue. will be used in mempool, multiple txs per account --- crates/mempool/src/priority_queue.rs | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/crates/mempool/src/priority_queue.rs b/crates/mempool/src/priority_queue.rs index f4b9254b..92c0409e 100644 --- a/crates/mempool/src/priority_queue.rs +++ b/crates/mempool/src/priority_queue.rs @@ -58,3 +58,32 @@ impl PartialOrd for PrioritizedTransaction { Some(self.cmp(other)) } } + +// TODO: remove when is used. +#[allow(dead_code)] +// Assumption: there are no gaps, and the transactions are received in order. +pub struct AddressPriorityQueue(pub Vec); + +// TODO: remove when is used. +#[allow(dead_code)] +impl AddressPriorityQueue { + pub fn push(&mut self, tx: ThinTransaction) { + self.0.push(tx); + } + + pub fn top(&self) -> Option<&ThinTransaction> { + self.0.first() + } + + pub fn pop(&mut self) -> Option { + Some(self.0.remove(0)) + } + + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } + + pub fn contains(&self, tx: &ThinTransaction) -> bool { + self.0.contains(tx) + } +}