minor VoteAccount refactoring (#23686)
This commit is contained in:
committed by
GitHub
parent
cffc32af3e
commit
fa7926580a
@ -5,7 +5,7 @@ use {
|
|||||||
ser::{Serialize, Serializer},
|
ser::{Serialize, Serializer},
|
||||||
},
|
},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
account::{Account, AccountSharedData},
|
account::{Account, AccountSharedData, ReadableAccount},
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
},
|
},
|
||||||
@ -57,13 +57,13 @@ impl VoteAccount {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn lamports(&self) -> u64 {
|
pub(crate) fn lamports(&self) -> u64 {
|
||||||
self.account().lamports
|
self.account().lamports()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn vote_state(&self) -> RwLockReadGuard<Result<VoteState, InstructionError>> {
|
pub fn vote_state(&self) -> RwLockReadGuard<Result<VoteState, InstructionError>> {
|
||||||
let inner = &self.0;
|
let inner = &self.0;
|
||||||
inner.vote_state_once.call_once(|| {
|
inner.vote_state_once.call_once(|| {
|
||||||
let vote_state = VoteState::deserialize(&inner.account.data);
|
let vote_state = VoteState::deserialize(inner.account.data());
|
||||||
*inner.vote_state.write().unwrap() = vote_state;
|
*inner.vote_state.write().unwrap() = vote_state;
|
||||||
});
|
});
|
||||||
inner.vote_state.read().unwrap()
|
inner.vote_state.read().unwrap()
|
||||||
@ -405,7 +405,7 @@ mod tests {
|
|||||||
fn test_vote_account() {
|
fn test_vote_account() {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let (account, vote_state) = new_rand_vote_account(&mut rng, None);
|
let (account, vote_state) = new_rand_vote_account(&mut rng, None);
|
||||||
let lamports = account.lamports;
|
let lamports = account.lamports();
|
||||||
let vote_account = VoteAccount::from(account);
|
let vote_account = VoteAccount::from(account);
|
||||||
assert_eq!(lamports, vote_account.lamports());
|
assert_eq!(lamports, vote_account.lamports());
|
||||||
assert_eq!(vote_state, *vote_account.vote_state().as_ref().unwrap());
|
assert_eq!(vote_state, *vote_account.vote_state().as_ref().unwrap());
|
||||||
|
Reference in New Issue
Block a user