Make getStakeActivation response consistent for undelegated accounts (#16038)

This commit is contained in:
Tyera Eulberg 2021-03-19 14:54:56 -06:00 committed by GitHub
parent 64429104b1
commit 2ec24d438f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 3 deletions

View File

@ -1157,9 +1157,25 @@ impl JsonRpcRequestProcessor {
let stake_state: StakeState = stake_account let stake_state: StakeState = stake_account
.state() .state()
.map_err(|_| Error::invalid_params("Invalid param: not a stake account".to_string()))?; .map_err(|_| Error::invalid_params("Invalid param: not a stake account".to_string()))?;
let delegation = stake_state.delegation().ok_or_else(|| { let delegation = stake_state.delegation();
Error::invalid_params("Invalid param: stake account has not been delegated".to_string()) if delegation.is_none() {
})?; match stake_state.meta() {
None => {
return Err(Error::invalid_params(
"Invalid param: stake account not initialized".to_string(),
));
}
Some(meta) => {
let rent_exempt_reserve = meta.rent_exempt_reserve;
return Ok(RpcStakeActivation {
state: StakeActivationState::Inactive,
active: 0,
inactive: stake_account.lamports().saturating_sub(rent_exempt_reserve),
});
}
}
}
let delegation = delegation.unwrap();
let stake_history_account = bank let stake_history_account = bank
.get_account(&stake_history::id()) .get_account(&stake_history::id())