Add struct and convenience methods to track stake activation status (#20392)

* Add struct and convenience methods to track stake activation status

* fix nits

* rename
This commit is contained in:
Justin Starry
2021-10-04 18:59:11 -04:00
committed by GitHub
parent 2b967202f3
commit 0ddb34a0b4
7 changed files with 139 additions and 98 deletions

View File

@@ -15,6 +15,42 @@ pub struct StakeHistoryEntry {
pub deactivating: u64, // requested to be cooled down, not fully deactivated yet
}
impl StakeHistoryEntry {
pub fn with_effective(effective: u64) -> Self {
Self {
effective,
..Self::default()
}
}
pub fn with_effective_and_activating(effective: u64, activating: u64) -> Self {
Self {
effective,
activating,
..Self::default()
}
}
pub fn with_deactivating(deactivating: u64) -> Self {
Self {
effective: deactivating,
deactivating,
..Self::default()
}
}
}
impl std::ops::Add for StakeHistoryEntry {
type Output = StakeHistoryEntry;
fn add(self, rhs: StakeHistoryEntry) -> Self::Output {
Self {
effective: self.effective.saturating_add(rhs.effective),
activating: self.activating.saturating_add(rhs.activating),
deactivating: self.deactivating.saturating_add(rhs.deactivating),
}
}
}
#[repr(C)]
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Default, Clone, AbiExample)]
pub struct StakeHistory(Vec<(Epoch, StakeHistoryEntry)>);