use derive_where::derive_where;
use malachitebft_core_types::{Context, NilOrVal, Round, Timeout, TimeoutKind, ValueId};
#[derive_where(Clone, Debug, PartialEq, Eq)]
pub enum Output<Ctx>
where
Ctx: Context,
{
NewRound(Round),
Proposal(Ctx::Proposal),
Vote(Ctx::Vote),
ScheduleTimeout(Timeout),
GetValueAndScheduleTimeout(Ctx::Height, Round, Timeout),
Decision(Round, Ctx::Proposal),
}
impl<Ctx: Context> Output<Ctx> {
pub fn proposal(
ctx: &Ctx,
height: Ctx::Height,
round: Round,
value: Ctx::Value,
pol_round: Round,
address: Ctx::Address,
) -> Self {
Output::Proposal(ctx.new_proposal(height, round, value, pol_round, address))
}
pub fn prevote(
ctx: &Ctx,
height: Ctx::Height,
round: Round,
value_id: NilOrVal<ValueId<Ctx>>,
address: Ctx::Address,
) -> Self {
Output::Vote(ctx.new_prevote(height, round, value_id, address))
}
pub fn precommit(
ctx: &Ctx,
height: Ctx::Height,
round: Round,
value_id: NilOrVal<ValueId<Ctx>>,
address: Ctx::Address,
) -> Self {
Output::Vote(ctx.new_precommit(height, round, value_id, address))
}
pub fn schedule_timeout(round: Round, step: TimeoutKind) -> Self {
Output::ScheduleTimeout(Timeout { round, kind: step })
}
pub fn get_value_and_schedule_timeout(
height: Ctx::Height,
round: Round,
step: TimeoutKind,
) -> Self {
Output::GetValueAndScheduleTimeout(height, round, Timeout { round, kind: step })
}
pub fn decision(round: Round, proposal: Ctx::Proposal) -> Self {
Output::Decision(round, proposal)
}
}