2023-04-14 00:35:55 +00:00
|
|
|
use std::collections::VecDeque;
|
2023-04-12 00:24:27 +00:00
|
|
|
|
|
|
|
use crate::{TransactionKind, Transaction};
|
|
|
|
|
|
|
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
|
|
pub struct ProvidedTransactions<T: Transaction> {
|
2023-04-14 00:35:55 +00:00
|
|
|
pub(crate) transactions: VecDeque<T>,
|
2023-04-12 00:24:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Transaction> Default for ProvidedTransactions<T> {
|
|
|
|
fn default() -> Self {
|
2023-04-14 00:35:55 +00:00
|
|
|
ProvidedTransactions { transactions: VecDeque::new() }
|
2023-04-12 00:24:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Transaction> ProvidedTransactions<T> {
|
2023-04-14 00:35:55 +00:00
|
|
|
pub(crate) fn new() -> Self {
|
2023-04-12 00:24:27 +00:00
|
|
|
ProvidedTransactions::default()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Provide a transaction for inclusion in a block.
|
2023-04-14 00:35:55 +00:00
|
|
|
pub(crate) fn provide(&mut self, tx: T) {
|
|
|
|
// TODO: Make an error out of this
|
2023-04-12 00:24:27 +00:00
|
|
|
assert_eq!(tx.kind(), TransactionKind::Provided, "provided a non-provided transaction");
|
2023-04-14 00:35:55 +00:00
|
|
|
self.transactions.push_back(tx);
|
2023-04-12 00:24:27 +00:00
|
|
|
}
|
|
|
|
|
2023-04-14 00:35:55 +00:00
|
|
|
/// Complete a provided transaction, no longer proposing it nor voting for its validity.
|
|
|
|
pub(crate) fn complete(&mut self, tx: [u8; 32]) {
|
|
|
|
assert_eq!(self.transactions.pop_front().unwrap().hash(), tx);
|
2023-04-12 00:24:27 +00:00
|
|
|
}
|
|
|
|
}
|