cbe_program/vote/state/
vote_state_versions.rs

1use super::{vote_state_0_23_5::VoteState0_23_5, *};
2
3#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
4pub enum VoteStateVersions {
5    V0_23_5(Box<VoteState0_23_5>),
6    Current(Box<VoteState>),
7}
8
9impl VoteStateVersions {
10    pub fn new_current(vote_state: VoteState) -> Self {
11        Self::Current(Box::new(vote_state))
12    }
13
14    pub fn convert_to_current(self) -> VoteState {
15        match self {
16            VoteStateVersions::V0_23_5(state) => {
17                let authorized_voters =
18                    AuthorizedVoters::new(state.authorized_voter_epoch, state.authorized_voter);
19
20                VoteState {
21                    node_pubkey: state.node_pubkey,
22
23                    /// the signer for withdrawals
24                    authorized_withdrawer: state.authorized_withdrawer,
25
26                    /// percentage (0-100) that represents what part of a rewards
27                    ///  payout should be given to this VoteAccount
28                    commission: state.commission,
29
30                    votes: state.votes.clone(),
31
32                    root_slot: state.root_slot,
33
34                    /// the signer for vote transactions
35                    authorized_voters,
36
37                    /// history of prior authorized voters and the epochs for which
38                    /// they were set, the bottom end of the range is inclusive,
39                    /// the top of the range is exclusive
40                    prior_voters: CircBuf::default(),
41
42                    /// history of how many credits earned by the end of each epoch
43                    ///  each tuple is (Epoch, credits, prev_credits)
44                    epoch_credits: state.epoch_credits.clone(),
45
46                    /// most recent timestamp submitted with a vote
47                    last_timestamp: state.last_timestamp.clone(),
48                }
49            }
50            VoteStateVersions::Current(state) => *state,
51        }
52    }
53
54    pub fn is_uninitialized(&self) -> bool {
55        match self {
56            VoteStateVersions::V0_23_5(vote_state) => {
57                vote_state.authorized_voter == Pubkey::default()
58            }
59
60            VoteStateVersions::Current(vote_state) => vote_state.authorized_voters.is_empty(),
61        }
62    }
63}