#[doc(hidden)]
pub const STR_002_MODULE_PRESENT: () = ();
use chia_protocol::Bytes32;
use chia_sha2::Sha256;
use serde::{Deserialize, Serialize};
use crate::error::EpochError;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EpochBlockLink {
pub parent_hash: Bytes32,
pub block_hash: Bytes32,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct EpochCheckpointData {
pub network_id: Bytes32,
pub epoch: u64,
pub block_root: Bytes32,
pub state_root: Bytes32,
pub withdrawals_root: Bytes32,
pub checkpoint_hash: Bytes32,
}
impl EpochCheckpointData {
pub fn signing_digest(&self) -> Bytes32 {
let mut h = Sha256::new();
h.update(self.network_id.as_ref());
h.update(self.epoch.to_le_bytes());
h.update(self.block_root.as_ref());
h.update(self.state_root.as_ref());
h.update(self.withdrawals_root.as_ref());
h.update(self.checkpoint_hash.as_ref());
Bytes32::new(h.finalize())
}
pub fn to_bytes(&self) -> Vec<u8> {
bincode::serialize(self).expect("EpochCheckpointData serialization should never fail")
}
pub fn from_bytes(bytes: &[u8]) -> Result<Self, EpochError> {
bincode::deserialize(bytes).map_err(|e| EpochError::InvalidData(e.to_string()))
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct EpochCheckpointSignMaterial {
pub checkpoint: EpochCheckpointData,
pub score: u64,
pub signing_digest: Bytes32,
}