fn resolve_final_vote_state(
        &mut self,
        max_vote_weight: u64,
        config: &GovernanceConfig,
    ) -> Result<ProposalState, ProgramError> {
        // Get the min vote weight required for options to pass
        let min_vote_threshold_weight =
            get_min_vote_threshold_weight(&config.vote_threshold_percentage, max_vote_weight)
                .unwrap();

        // If the proposal has a reject option then any other option must beat it regardless of the configured min_vote_threshold_weight
        let deny_vote_weight = self.deny_vote_weight.unwrap_or(0);

        let mut best_succeeded_option_weight = 0;
        let mut best_succeeded_option_count = 0u16;

        for option in self.options.iter_mut() {
            // Any positive vote (Yes) must be equal or above the required min_vote_threshold_weight and higher than the reject option vote (No)
            // The same number of positive (Yes) and rejecting (No) votes is a tie and resolved as Defeated
            // In other words  +1 vote as a tie breaker is required to succeed for the positive option vote
            if option.vote_weight >= min_vote_threshold_weight
                && option.vote_weight > deny_vote_weight
            {
                option.vote_result = OptionVoteResult::Succeeded;

                match option.vote_weight.cmp(&best_succeeded_option_weight) {
                    Ordering::Greater => {
                        best_succeeded_option_weight = option.vote_weight;
                        best_succeeded_option_count = 1;
                    }
                    Ordering::Equal => {
                        best_succeeded_option_count =
                            best_succeeded_option_count.checked_add(1).unwrap()
                    }
                    Ordering::Less => {}
                }
            } else {
                option.vote_result = OptionVoteResult::Defeated;
            }
        }

        let mut final_state = if best_succeeded_option_count == 0 {
            // If none of the individual options succeeded then the proposal as a whole is defeated
            ProposalState::Defeated
        } else {
            match self.vote_type {
                VoteType::SingleChoice => {
                    let proposal_state = if best_succeeded_option_count > 1 {
                        // If there is more than one winning option then the single choice proposal is considered as defeated
                        best_succeeded_option_weight = u64::MAX; // no winning option
                        ProposalState::Defeated
                    } else {
                        ProposalState::Succeeded
                    };

                    // Coerce options vote results based on the winning score (best_succeeded_vote_weight)
                    for option in self.options.iter_mut() {
                        option.vote_result = if option.vote_weight == best_succeeded_option_weight {
                            OptionVoteResult::Succeeded
                        } else {
                            OptionVoteResult::Defeated
                        };
                    }

                    proposal_state
                }
                VoteType::MultiChoice {
                    max_voter_options: _n,
                    max_winning_options: _m,
                } => {
                    // If any option succeeded for multi choice then the proposal as a whole succeeded as well
                    ProposalState::Succeeded
                }
            }
        };

        // None executable proposal is just a survey and is considered Completed once the vote ends and no more actions are available
        // There is no overall Success or Failure status for the Proposal however individual options still have their own status
        if self.deny_vote_weight.is_none() {
            final_state = ProposalState::Completed;
        }

        Ok(final_state)
    }
/// Resolves final proposal state after vote ends
/// It inspects all proposals options and resolves their final vote results
Resolves final proposal state after vote ends
It inspects all proposals options and resolves their final vote results
Resolves final proposal state after vote ends It inspects all proposals options and resolves their final vote results
fn resolve_final_vote_state(
        &mut self,
        max_vote_weight: u64,
        config: &GovernanceConfig,
    ) -> Result<ProposalState, ProgramError> {
        // Get the min vote weight required for options to pass
        let min_vote_threshold_weight =
            get_min_vote_threshold_weight(&config.vote_threshold_percentage, max_vote_weight)
                .unwrap();
        // If the proposal has a reject option then any other option must beat it regardless of the configured min_vote_threshold_weight
        let deny_vote_weight = self.deny_vote_weight.unwrap_or(0);
        let mut best_succeeded_option_weight = 0;
        let mut best_succeeded_option_count = 0u16;
        for option in self.options.iter_mut() {
            // Any positive vote (Yes) must be equal or above the required min_vote_threshold_weight and higher than the reject option vote (No)
            // The same number of positive (Yes) and rejecting (No) votes is a tie and resolved as Defeated
            // In other words  +1 vote as a tie breaker is required to succeed for the positive option vote
            if option.vote_weight >= min_vote_threshold_weight
                && option.vote_weight > deny_vote_weight
            {
                option.vote_result = OptionVoteResult::Succeeded;
                match option.vote_weight.cmp(&best_succeeded_option_weight) {
                    Ordering::Greater => {
                        best_succeeded_option_weight = option.vote_weight;
                        best_succeeded_option_count = 1;
                    }
                    Ordering::Equal => {
                        best_succeeded_option_count =
                            best_succeeded_option_count.checked_add(1).unwrap()
                    }
                    Ordering::Less => {}
                }
            } else {
                option.vote_result = OptionVoteResult::Defeated;
            }
        }
        let mut final_state = if best_succeeded_option_count == 0 {
            // If none of the individual options succeeded then the proposal as a whole is defeated
            ProposalState::Defeated
        } else {
            match self.vote_type {
                VoteType::SingleChoice => {
                    let proposal_state = if best_succeeded_option_count > 1 {
                        // If there is more than one winning option then the single choice proposal is considered as defeated
                        best_succeeded_option_weight = u64::MAX; // no winning option
                        ProposalState::Defeated
                    } else {
                        ProposalState::Succeeded
                    };
                    // Coerce options vote results based on the winning score (best_succeeded_vote_weight)
                    for option in self.options.iter_mut() {
                        option.vote_result = if option.vote_weight == best_succeeded_option_weight {
                            OptionVoteResult::Succeeded
                        } else {
                            OptionVoteResult::Defeated
                        };
                    }
                    proposal_state
                }
                VoteType::MultiChoice {
                    max_voter_options: _n,
                    max_winning_options: _m,
                } => {
                    // If any option succeeded for multi choice then the proposal as a whole succeeded as well
                    ProposalState::Succeeded
                }
            }
        };
        // None executable proposal is just a survey and is considered Completed once the vote ends and no more actions are available
        // There is no overall Success or Failure status for the Proposal however individual options still have their own status
        if self.deny_vote_weight.is_none() {
            final_state = ProposalState::Completed;
        }
        Ok(final_state)
    }
fn resolve_final_vote_state ( & mut self , max_vote_weight : u64 , config : & GovernanceConfig , ) -> Result < ProposalState , ProgramError > { // Get the min vote weight required for options to pass let min_vote_threshold_weight = get_min_vote_threshold_weight ( & config . vote_threshold_percentage , max_vote_weight ) . unwrap ( ) ; // If the proposal has a reject option then any other option must beat it regardless of the configured min_vote_threshold_weight let deny_vote_weight = self . deny_vote_weight . unwrap_or ( 0 ) ; let mut best_succeeded_option_weight = 0 ; let mut best_succeeded_option_count = 0u16 ; for option in self . options . iter_mut ( ) { // Any positive vote (Yes) must be equal or above the required min_vote_threshold_weight and higher than the reject option vote (No) // The same number of positive (Yes) and rejecting (No) votes is a tie and resolved as Defeated // In other words  +1 vote as a tie breaker is required to succeed for the positive option vote if option . vote_weight >= min_vote_threshold_weight && option . vote_weight > deny_vote_weight { option . vote_result = OptionVoteResult :: Succeeded ; match option . vote_weight . cmp ( & best_succeeded_option_weight ) { Ordering :: Greater => { best_succeeded_option_weight = option . vote_weight ; best_succeeded_option_count = 1 ; } Ordering :: Equal => { best_succeeded_option_count = best_succeeded_option_count . checked_add ( 1 ) . unwrap ( ) } Ordering :: Less => { } } } else { option . vote_result = OptionVoteResult :: Defeated ; } } let mut final_state = if best_succeeded_option_count == 0 { // If none of the individual options succeeded then the proposal as a whole is defeated ProposalState :: Defeated } else { match self . vote_type { VoteType :: SingleChoice => { let proposal_state = if best_succeeded_option_count > 1 { // If there is more than one winning option then the single choice proposal is considered as defeated best_succeeded_option_weight = u64 :: MAX ; // no winning option ProposalState :: Defeated } else { ProposalState :: Succeeded } ; // Coerce options vote results based on the winning score (best_succeeded_vote_weight) for option in self . options . iter_mut ( ) { option . vote_result = if option . vote_weight == best_succeeded_option_weight { OptionVoteResult :: Succeeded } else { OptionVoteResult :: Defeated } ; } proposal_state } VoteType :: MultiChoice { max_voter_options : _n , max_winning_options : _m , } => { // If any option succeeded for multi choice then the proposal as a whole succeeded as well ProposalState :: Succeeded } } } ; // None executable proposal is just a survey and is considered Completed once the vote ends and no more actions are available // There is no overall Success or Failure status for the Proposal however individual options still have their own status if self . deny_vote_weight . is_none ( ) { final_state = ProposalState :: Completed ; } Ok ( final_state ) }
Resolves final proposal state after vote ends
It inspects all proposals options and resolves their final vote results
Resolves final proposal state after vote ends It inspects all proposals options and resolves their final vote results
&mut self
max_vote_weight
u64
config
&GovernanceConfig
&mut self
max_vote_weight
u64
config
&GovernanceConfig