jito_programs_vote_state/
lib.rs

1use anchor_lang::{
2    error::ErrorCode::{AccountDidNotDeserialize, ConstraintOwner},
3    prelude::{AccountInfo, Pubkey, Result},
4};
5use bincode::deserialize;
6
7pub struct VoteState;
8
9impl VoteState {
10    pub fn deserialize_node_pubkey(account_info: &AccountInfo) -> Result<Pubkey> {
11        if Pubkey::from(account_info.owner.to_bytes())
12            != Pubkey::from(solana_sdk_ids::vote::id().to_bytes())
13        {
14            return Err(ConstraintOwner.into());
15        }
16
17        // The first 4 bytes are the enumeration type and the next 32 bytes of the vote state are the node pubkey.
18        let data = account_info.data.borrow();
19        deserialize::<Pubkey>(&data[4..36]).map_err(|_| AccountDidNotDeserialize.into())
20    }
21}