use super::*; #[derive(Copy, Clone, Debug, Display, FromStr, Ord, Eq, Serialize, PartialEq, PartialOrd)] pub(crate) struct Height(pub(crate) u32); impl Height { pub(crate) fn n(self) -> u32 { self.0 } pub(crate) fn subsidy(self) -> u64 { Epoch::from(self).subsidy() } pub(crate) fn starting_sat(self) -> Sat { let epoch = Epoch::from(self); let epoch_starting_sat = epoch.starting_sat(); let epoch_starting_height = epoch.starting_height(); epoch_starting_sat + u64::from(self.n() - epoch_starting_height.n()) * epoch.subsidy() } pub(crate) fn period_offset(self) -> u32 { self.0 % DIFFCHANGE_INTERVAL } } impl Add for Height { type Output = Self; fn add(self, other: u32) -> Height { Self(self.0 + other) } } impl Sub for Height { type Output = Self; fn sub(self, other: u32) -> Height { Self(self.0 - other) } } impl PartialEq for Height { fn eq(&self, other: &u32) -> bool { self.0 == *other } } #[cfg(test)] mod tests { use super::*;