pub fn assert_valid_proposal_options(
    options: &[String],
    vote_type: &VoteType,
) -> Result<(), ProgramError> {
    if options.is_empty() || options.len() > 10 {
        return Err(GovernanceError::InvalidProposalOptions.into());
    }

    if let VoteType::MultiChoice {
        max_voter_options,
        max_winning_options,
    } = *vote_type
    {
        if options.len() == 1
            || max_voter_options as usize != options.len()
            || max_winning_options as usize != options.len()
        {
            return Err(GovernanceError::InvalidProposalOptions.into());
        }
    }

    // TODO: Check for duplicated option labels
    // The options are identified by index so it's ok for now

    if options.iter().any(|o| o.is_empty()) {
        return Err(GovernanceError::InvalidProposalOptions.into());
    }

    Ok(())
}
/// Assert options to create proposal are valid for the Proposal vote_type
Assert options to create proposal are valid for the Proposal vote_type
Assert options to create proposal are valid for the Proposal vote_type
pub fn assert_valid_proposal_options(
    options: &[String],
    vote_type: &VoteType,
) -> Result<(), ProgramError> {
    if options.is_empty() || options.len() > 10 {
        return Err(GovernanceError::InvalidProposalOptions.into());
    }
    if let VoteType::MultiChoice {
        max_voter_options,
        max_winning_options,
    } = *vote_type
    {
        if options.len() == 1
            || max_voter_options as usize != options.len()
            || max_winning_options as usize != options.len()
        {
            return Err(GovernanceError::InvalidProposalOptions.into());
        }
    }
    // TODO: Check for duplicated option labels
    // The options are identified by index so it's ok for now
    if options.iter().any(|o| o.is_empty()) {
        return Err(GovernanceError::InvalidProposalOptions.into());
    }
    Ok(())
}
pub fn assert_valid_proposal_options ( options : & [ String ] , vote_type : & VoteType , ) -> Result < ( ) , ProgramError > { if options . is_empty ( ) || options . len ( ) > 10 { return Err ( GovernanceError :: InvalidProposalOptions . into ( ) ) ; } if let VoteType :: MultiChoice { max_voter_options , max_winning_options , } = * vote_type { if options . len ( ) == 1 || max_voter_options as usize != options . len ( ) || max_winning_options as usize != options . len ( ) { return Err ( GovernanceError :: InvalidProposalOptions . into ( ) ) ; } } // TODO: Check for duplicated option labels // The options are identified by index so it's ok for now if options . iter ( ) . any ( | o | o . is_empty ( ) ) { return Err ( GovernanceError :: InvalidProposalOptions . into ( ) ) ; } Ok ( ( ) ) }
Assert options to create proposal are valid for the Proposal vote_type
Assert options to create proposal are valid for the Proposal vote_type
options
&[String]
vote_type
&VoteType
options
&[String]
vote_type
&VoteType