calculate stake from activated amount (#4630)

This commit is contained in:
Rob Walker
2019-06-10 16:17:29 -07:00
committed by GitHub
parent a77e576cd9
commit d1d53c3fb6
2 changed files with 44 additions and 13 deletions

View File

@ -51,12 +51,27 @@ impl StakeState {
Self::from(account).and_then(|state: Self| state.voter_pubkey())
}
// utility function, used by Stakes, tests
pub fn voter_pubkey_and_stake_from(account: &Account) -> Option<(Pubkey, u64)> {
Self::from(account).and_then(|state: Self| state.voter_pubkey_and_stake())
}
pub fn voter_pubkey(&self) -> Option<Pubkey> {
match self {
StakeState::Stake { voter_pubkey, .. } => Some(*voter_pubkey),
_ => None,
}
}
pub fn voter_pubkey_and_stake(&self) -> Option<(Pubkey, u64)> {
match self {
StakeState::Stake {
voter_pubkey,
stake,
..
} => Some((*voter_pubkey, *stake)),
_ => None,
}
}
pub fn calculate_rewards(
credits_observed: u64,