miraland_program/vote/state/
vote_state_1_14_11.rs1use super::*;
2#[cfg(test)]
3use arbitrary::Arbitrary;
4
5const DEFAULT_PRIOR_VOTERS_OFFSET: usize = 82;
7
8#[frozen_abi(digest = "CZTgLymuevXjAx6tM8X8T5J3MCx9AkEsFSmu4FJrEpkG")]
9#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Eq, Clone, AbiExample)]
10#[cfg_attr(test, derive(Arbitrary))]
11pub struct VoteState1_14_11 {
12 pub node_pubkey: Pubkey,
14
15 pub authorized_withdrawer: Pubkey,
17 pub commission: u8,
20
21 pub votes: VecDeque<Lockout>,
22
23 pub root_slot: Option<Slot>,
26
27 pub authorized_voters: AuthorizedVoters,
29
30 pub prior_voters: CircBuf<(Pubkey, Epoch, Epoch)>,
34
35 pub epoch_credits: Vec<(Epoch, u64, u64)>,
38
39 pub last_timestamp: BlockTimestamp,
41}
42
43impl VoteState1_14_11 {
44 pub fn get_rent_exempt_reserve(rent: &Rent) -> u64 {
45 rent.minimum_balance(Self::size_of())
46 }
47
48 pub fn size_of() -> usize {
51 3731 }
53
54 pub fn is_correct_size_and_initialized(data: &[u8]) -> bool {
55 const VERSION_OFFSET: usize = 4;
56 const DEFAULT_PRIOR_VOTERS_END: usize = VERSION_OFFSET + DEFAULT_PRIOR_VOTERS_OFFSET;
57 data.len() == VoteState1_14_11::size_of()
58 && data[VERSION_OFFSET..DEFAULT_PRIOR_VOTERS_END] != [0; DEFAULT_PRIOR_VOTERS_OFFSET]
59 }
60}
61
62impl From<VoteState> for VoteState1_14_11 {
63 fn from(vote_state: VoteState) -> Self {
64 Self {
65 node_pubkey: vote_state.node_pubkey,
66 authorized_withdrawer: vote_state.authorized_withdrawer,
67 commission: vote_state.commission,
68 votes: vote_state
69 .votes
70 .into_iter()
71 .map(|landed_vote| landed_vote.into())
72 .collect(),
73 root_slot: vote_state.root_slot,
74 authorized_voters: vote_state.authorized_voters,
75 prior_voters: vote_state.prior_voters,
76 epoch_credits: vote_state.epoch_credits,
77 last_timestamp: vote_state.last_timestamp,
78 }
79 }
80}