use crate::{ simplex::types::Vote, types::{Participant, View}, }; use commonware_cryptography::{certificate::Scheme, Digest}; use commonware_utils::channels::fallible::AsyncFallibleExt; use futures::channel::{mpsc, oneshot}; /// Messages sent to the [super::actor::Actor]. pub enum Message { /// View update with leader info. Update { current: View, leader: Participant, finalized: View, active: oneshot::Sender, }, /// A constructed vote (needed for quorum). Constructed(Vote), } #[derive(Clone)] pub struct Mailbox { sender: mpsc::Sender>, } impl Mailbox { /// Create a new mailbox. pub const fn new(sender: mpsc::Sender>) -> Self { Self { sender } } /// Send an update message. pub async fn update(&mut self, current: View, leader: Participant, finalized: View) -> bool { self.sender .request_or( |active| Message::Update { current, leader, finalized, active, }, true, ) .await } /// Send a constructed vote. pub async fn constructed(&mut self, message: Vote) { self.sender.send_lossy(Message::Constructed(message)).await; } }