cbe_program/vote/state/
vote_state_versions.rs1use 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 authorized_withdrawer: state.authorized_withdrawer,
25
26 commission: state.commission,
29
30 votes: state.votes.clone(),
31
32 root_slot: state.root_slot,
33
34 authorized_voters,
36
37 prior_voters: CircBuf::default(),
41
42 epoch_credits: state.epoch_credits.clone(),
45
46 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}