use commonware_consensus::types::Epoch;
use commonware_cryptography::bls12381::{
dkg::Output,
primitives::{group::Share, variant::Variant},
};
use std::{future::Future, pin::Pin};
#[allow(dead_code)]
pub enum Update<V: Variant, P> {
Failure { epoch: Epoch },
Success {
epoch: Epoch,
output: Output<V, P>,
share: Option<Share>,
},
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum PostUpdate {
Continue,
Stop,
}
pub trait UpdateCallBack<V: Variant, P>: Send {
fn on_update(
&mut self,
update: Update<V, P>,
) -> Pin<Box<dyn Future<Output = PostUpdate> + Send>>;
}
pub struct ContinueOnUpdate;
impl ContinueOnUpdate {
pub fn boxed() -> Box<Self> {
Box::new(Self)
}
}
impl<V: Variant, P> UpdateCallBack<V, P> for ContinueOnUpdate {
fn on_update(
&mut self,
_update: Update<V, P>,
) -> Pin<Box<dyn Future<Output = PostUpdate> + Send>> {
Box::pin(async { PostUpdate::Continue })
}
}