use crate::simplex::types::{Notarization, Nullification, View}; use commonware_cryptography::{Digest, Signature}; use futures::{channel::mpsc, SinkExt}; pub enum Message { Fetch { notarizations: Vec, nullifications: Vec, }, Notarized { notarization: Notarization, }, Nullified { nullification: Nullification, }, Finalized { // Used to indicate when to prune old notarizations/nullifications. view: View, }, } #[derive(Clone)] pub struct Mailbox { sender: mpsc::Sender>, } impl Mailbox { pub fn new(sender: mpsc::Sender>) -> Self { Self { sender } } pub async fn fetch(&mut self, notarizations: Vec, nullifications: Vec) { self.sender .send(Message::Fetch { notarizations, nullifications, }) .await .expect("Failed to send notarizations"); } pub async fn notarized(&mut self, notarization: Notarization) { self.sender .send(Message::Notarized { notarization }) .await .expect("Failed to send notarization"); } pub async fn nullified(&mut self, nullification: Nullification) { self.sender .send(Message::Nullified { nullification }) .await .expect("Failed to send nullification"); } pub async fn finalized(&mut self, view: View) { self.sender .send(Message::Finalized { view }) .await .expect("Failed to send finalized view"); } }