Files
brk/_src/structs/epoch.rs
2025-02-23 01:25:15 +01:00

21 lines
427 B
Rust

use super::{Height, MapKey};
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct Epoch(pub u16);
impl Epoch {
pub const BLOCKS_PER_EPOCH: usize = 210_000;
}
impl From<Height> for Epoch {
fn from(height: Height) -> Self {
Self::from(&height)
}
}
impl From<&Height> for Epoch {
fn from(height: &Height) -> Self {
Self(((height.to_usize() / Self::BLOCKS_PER_EPOCH) + 1) as u16)
}
}