pub fn assert_valid_vote(&self, vote: &Vote) -> Result<(), ProgramError> {
        match vote {
            Vote::Approve(choices) => {
                if self.options.len() != choices.len() {
                    return Err(GovernanceError::InvalidVote.into());
                }

                let mut choice_count = 0u16;

                for choice in choices {
                    if choice.rank > 0 {
                        return Err(GovernanceError::InvalidVote.into());
                    }

                    if choice.weight_percentage == 100 {
                        choice_count = choice_count.checked_add(1).unwrap();
                    } else if choice.weight_percentage != 0 {
                        return Err(GovernanceError::InvalidVote.into());
                    }
                }

                match self.vote_type {
                    VoteType::SingleChoice => {
                        if choice_count != 1 {
                            return Err(GovernanceError::InvalidVote.into());
                        }
                    }
                    VoteType::MultiChoice {
                        max_voter_options: _n,
                        max_winning_options: _m,
                    } => {
                        if choice_count == 0 {
                            return Err(GovernanceError::InvalidVote.into());
                        }
                    }
                }
            }
            Vote::Deny => {
                if self.deny_vote_weight.is_none() {
                    return Err(GovernanceError::InvalidVote.into());
                }
            }
            Vote::Abstain | Vote::Veto => {
                return Err(GovernanceError::NotSupportedVoteType.into());
            }
        }

        Ok(())
    }
/// Asserts the given vote is valid for the proposal
Asserts the given vote is valid for the proposal
Asserts the given vote is valid for the proposal
pub fn assert_valid_vote(&self, vote: &Vote) -> Result<(), ProgramError> {
        match vote {
            Vote::Approve(choices) => {
                if self.options.len() != choices.len() {
                    return Err(GovernanceError::InvalidVote.into());
                }
                let mut choice_count = 0u16;
                for choice in choices {
                    if choice.rank > 0 {
                        return Err(GovernanceError::InvalidVote.into());
                    }
                    if choice.weight_percentage == 100 {
                        choice_count = choice_count.checked_add(1).unwrap();
                    } else if choice.weight_percentage != 0 {
                        return Err(GovernanceError::InvalidVote.into());
                    }
                }
                match self.vote_type {
                    VoteType::SingleChoice => {
                        if choice_count != 1 {
                            return Err(GovernanceError::InvalidVote.into());
                        }
                    }
                    VoteType::MultiChoice {
                        max_voter_options: _n,
                        max_winning_options: _m,
                    } => {
                        if choice_count == 0 {
                            return Err(GovernanceError::InvalidVote.into());
                        }
                    }
                }
            }
            Vote::Deny => {
                if self.deny_vote_weight.is_none() {
                    return Err(GovernanceError::InvalidVote.into());
                }
            }
            Vote::Abstain | Vote::Veto => {
                return Err(GovernanceError::NotSupportedVoteType.into());
            }
        }
        Ok(())
    }
pub fn assert_valid_vote ( & self , vote : & Vote ) -> Result < ( ) , ProgramError > { match vote { Vote :: Approve ( choices ) => { if self . options . len ( ) != choices . len ( ) { return Err ( GovernanceError :: InvalidVote . into ( ) ) ; } let mut choice_count = 0u16 ; for choice in choices { if choice . rank > 0 { return Err ( GovernanceError :: InvalidVote . into ( ) ) ; } if choice . weight_percentage == 100 { choice_count = choice_count . checked_add ( 1 ) . unwrap ( ) ; } else if choice . weight_percentage != 0 { return Err ( GovernanceError :: InvalidVote . into ( ) ) ; } } match self . vote_type { VoteType :: SingleChoice => { if choice_count != 1 { return Err ( GovernanceError :: InvalidVote . into ( ) ) ; } } VoteType :: MultiChoice { max_voter_options : _n , max_winning_options : _m , } => { if choice_count == 0 { return Err ( GovernanceError :: InvalidVote . into ( ) ) ; } } } } Vote :: Deny => { if self . deny_vote_weight . is_none ( ) { return Err ( GovernanceError :: InvalidVote . into ( ) ) ; } } Vote :: Abstain | Vote :: Veto => { return Err ( GovernanceError :: NotSupportedVoteType . into ( ) ) ; } } Ok ( ( ) ) }
Asserts the given vote is valid for the proposal
Asserts the given vote is valid for the proposal
&self
vote
&Vote
&self
vote
&Vote