add stake warmup and cool down (#4711)

This commit is contained in:
Rob Walker
2019-06-17 19:34:21 -07:00
committed by GitHub
parent 9cafd1f85e
commit 0ff9c4cd8e
4 changed files with 236 additions and 128 deletions

View File

@ -21,16 +21,17 @@ pub struct Stakes {
impl Stakes {
// sum the stakes that point to the given voter_pubkey
fn calculate_stake(&self, voter: &Pubkey) -> u64 {
fn calculate_stake(&self, voter_pubkey: &Pubkey) -> u64 {
self.stake_accounts
.iter()
.map(|(_, stake_account)| match StakeState::from(stake_account) {
Some(StakeState::Stake {
voter_pubkey,
stake,
..
}) if *voter == voter_pubkey => stake,
_ => 0,
.map(|(_, stake_account)| {
StakeState::stake_from(stake_account).map_or(0, |stake| {
if stake.voter_pubkey == *voter_pubkey {
stake.stake
} else {
0
}
})
})
.sum()
}