use codec::{Decode, Encode, MaxEncodedLen};
use core::fmt;
use jam_types::{HeaderHash, Slot, StateRootHash};
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encode, Decode, MaxEncodedLen,
)]
pub struct GrandpaTarget {
pub hash: HeaderHash,
pub state_root: StateRootHash,
}
impl GrandpaTarget {
pub fn new(hash: HeaderHash, state_root: StateRootHash) -> Self {
GrandpaTarget { hash, state_root }
}
}
impl fmt::Display for GrandpaTarget {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} (state root {})", self.hash, self.state_root)
}
}
pub type GrandpaSetId = u32;
pub type GrandpaRoundNumber = u64;
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, MaxEncodedLen)]
pub enum GrandpaMessage {
#[codec(index = 0)]
Prevote(GrandpaTarget, Slot),
#[codec(index = 1)]
Precommit(GrandpaTarget, Slot),
#[codec(index = 2)]
PrimaryPropose(GrandpaTarget, Slot),
}