use crate::simplex::types::{Certificate, Proposal}; use commonware_cryptography::{certificate::Scheme, Digest}; use commonware_utils::channels::fallible::AsyncFallibleExt; use futures::channel::mpsc; /// Messages sent to the [super::actor::Actor]. pub enum Message { /// Leader's proposal from batcher. Proposal(Proposal), /// Certificate from batcher or resolver. /// /// The boolean indicates if the certificate came from the resolver. /// When true, the voter will not send it back to the resolver (to avoid "boomerang"). Verified(Certificate, bool), } #[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 a leader's proposal. pub async fn proposal(&mut self, proposal: Proposal) { self.sender.send_lossy(Message::Proposal(proposal)).await; } /// Send a recovered certificate. pub async fn recovered(&mut self, certificate: Certificate) { self.sender .send_lossy(Message::Verified(certificate, false)) .await; } /// Send a resolved certificate. pub async fn resolved(&mut self, certificate: Certificate) { self.sender .send_lossy(Message::Verified(certificate, true)) .await; } }