use melstructs::{Transaction, TxHash};
#[derive(Default, Debug, Clone)]
pub struct TransactionSet {
inner: imbl::OrdMap<TxHash, Transaction>,
}
impl FromIterator<Transaction> for TransactionSet {
fn from_iter<T: IntoIterator<Item = Transaction>>(iter: T) -> Self {
Self {
inner: iter.into_iter().map(|tx| (tx.hash_nosigs(), tx)).collect(),
}
}
}
impl TransactionSet {
pub fn iter(&self) -> impl Iterator<Item = &Transaction> {
self.inner.values()
}
pub fn iter_hashes(&self) -> impl Iterator<Item = TxHash> + '_ {
self.inner.keys().copied()
}
pub fn is_empty(&self) -> bool {
self.inner.is_empty()
}
pub fn insert(&mut self, txn: Transaction) {
self.inner.insert(txn.hash_nosigs(), txn);
}
}