use serde::{Deserialize, Serialize};
#[doc(hidden)]
pub const STR_002_MODULE_PRESENT: () = ();
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum EpochPhase {
BlockProduction,
Checkpoint,
Finalization,
Complete,
}
impl EpochPhase {
pub fn index(&self) -> usize {
match self {
Self::BlockProduction => 0,
Self::Checkpoint => 1,
Self::Finalization => 2,
Self::Complete => 3,
}
}
pub fn next(&self) -> Option<EpochPhase> {
match self {
Self::BlockProduction => Some(Self::Checkpoint),
Self::Checkpoint => Some(Self::Finalization),
Self::Finalization => Some(Self::Complete),
Self::Complete => None,
}
}
pub fn previous(&self) -> Option<EpochPhase> {
match self {
Self::Complete => Some(Self::Finalization),
Self::Finalization => Some(Self::Checkpoint),
Self::Checkpoint => Some(Self::BlockProduction),
Self::BlockProduction => None,
}
}
pub fn name(&self) -> &'static str {
match self {
Self::BlockProduction => "BlockProduction",
Self::Checkpoint => "Checkpoint",
Self::Finalization => "Finalization",
Self::Complete => "Complete",
}
}
pub fn allows_block_production(&self) -> bool {
matches!(self, Self::BlockProduction)
}
pub fn allows_checkpoint_submission(&self) -> bool {
matches!(self, Self::Checkpoint)
}
pub fn allows_finalization(&self) -> bool {
matches!(self, Self::Finalization)
}
}
impl std::fmt::Display for EpochPhase {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.name())
}
}
#[derive(Debug, Clone)]
pub struct PhaseTransition {
pub epoch: u64,
pub from: EpochPhase,
pub to: EpochPhase,
pub l1_height: u32,
}