From ad1ebc71326a0281b5757ffeca3f9fbab14c113e Mon Sep 17 00:00:00 2001 From: Ayelet Zilber Date: Wed, 17 Apr 2024 13:37:53 +0300 Subject: [PATCH] feat: implement from for priority queue --- crates/mempool/src/priority_queue.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/mempool/src/priority_queue.rs b/crates/mempool/src/priority_queue.rs index bc02d6871..6264ab687 100644 --- a/crates/mempool/src/priority_queue.rs +++ b/crates/mempool/src/priority_queue.rs @@ -2,13 +2,11 @@ #[path = "priority_queue_test.rs"] pub mod priority_queue_test; -use std::{cmp::Ordering, collections::BTreeSet}; - use starknet_api::{ internal_transaction::InternalTransaction, transaction::{DeclareTransaction, DeployAccountTransaction, InvokeTransaction, Tip}, }; - +use std::{cmp::Ordering, collections::BTreeSet}; // Assumption: for the MVP only one transaction from the same contract class can be in the mempool // at a time. When this changes, saving the transactions themselves on the queu might no longer be // appropriate, because we'll also need to stores transactions without indexing them. For example, @@ -28,7 +26,15 @@ impl PriorityQueue { } } -#[derive(Clone, Debug, derive_more::Deref)] +impl From> for PriorityQueue { + fn from(transactions: Vec) -> Self { + PriorityQueue(BTreeSet::from_iter( + transactions.into_iter().map(PQTransaction), + )) + } +} + +#[derive(Clone, Debug, derive_more::Deref, derive_more::From)] pub struct PQTransaction(pub InternalTransaction); impl PQTransaction {