From dbecd1e7ea43b6533b957f602e7f29af73bc7de3 Mon Sep 17 00:00:00 2001 From: Ayelet Zilber Date: Tue, 9 Jul 2024 13:55:20 +0300 Subject: [PATCH] feat(mempool): add from_iter func to TransactionQueue --- crates/mempool/src/transaction_queue.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/mempool/src/transaction_queue.rs b/crates/mempool/src/transaction_queue.rs index 9dc070f2..cf59f7fa 100644 --- a/crates/mempool/src/transaction_queue.rs +++ b/crates/mempool/src/transaction_queue.rs @@ -3,6 +3,7 @@ use std::collections::{BTreeSet, HashMap}; use starknet_api::core::{ContractAddress, Nonce}; use starknet_api::transaction::TransactionHash; +use starknet_mempool_types::mempool_types::ThinTransaction; use crate::mempool::TransactionReference; // Assumption: for the MVP only one transaction from the same contract class can be in the mempool @@ -50,6 +51,19 @@ impl TransactionQueue { } } +impl FromIterator for TransactionQueue { + fn from_iter(txs: I) -> Self + where + I: IntoIterator, + { + let mut queue = Self::default(); + for tx in txs { + queue.insert(TransactionReference::new(&tx)); + } + queue + } +} + #[derive(Clone, Debug, derive_more::Deref, derive_more::From)] struct QueuedTransaction(pub TransactionReference);