Skip to content

Commit

Permalink
feat(mempool): add from_iter func to TransactionQueue
Browse files Browse the repository at this point in the history
  • Loading branch information
ayeletstarkware committed Jul 9, 2024
1 parent cbc4f67 commit dbecd1e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/mempool/src/transaction_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -50,6 +51,19 @@ impl TransactionQueue {
}
}

impl FromIterator<ThinTransaction> for TransactionQueue {
fn from_iter<I>(txs: I) -> Self
where
I: IntoIterator<Item = ThinTransaction>,
{
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);

Expand Down

0 comments on commit dbecd1e

Please sign in to comment.