serai/coordinator/tributary/src/provided.rs

33 lines
967 B
Rust
Raw Normal View History

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> {
pub(crate) transactions: VecDeque<T>,
2023-04-12 00:24:27 +00:00
}
impl<T: Transaction> Default for ProvidedTransactions<T> {
fn default() -> Self {
ProvidedTransactions { transactions: VecDeque::new() }
2023-04-12 00:24:27 +00:00
}
}
impl<T: Transaction> ProvidedTransactions<T> {
pub(crate) fn new() -> Self {
2023-04-12 00:24:27 +00:00
ProvidedTransactions::default()
}
/// Provide a transaction for inclusion in a block.
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");
self.transactions.push_back(tx);
2023-04-12 00:24:27 +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
}
}