pub fn assert_is_valid_voter_weight(
    voter_weight_record: &VoterWeightRecord,
    weight_action: VoterWeightAction,
    weight_action_target: &Pubkey,
) -> Result<(), ProgramError> {
    // Assert the weight is not stale
    if let Some(voter_weight_expiry) = voter_weight_record.voter_weight_expiry {
        let slot = Clock::get()?.slot;

        if slot > voter_weight_expiry {
            return Err(GovernanceError::VoterWeightRecordExpired.into());
        }
    }

    // Assert the weight is for the action specified by the addin
    if let Some(voter_weight_action) = &voter_weight_record.weight_action {
        if voter_weight_action != &weight_action {
            return Err(GovernanceError::VoterWeightRecordInvalidAction.into());
        }
    }

    // Assert the weight is for the action target specified by the addin
    if let Some(voter_weight_action_target) = &voter_weight_record.weight_action_target {
        if voter_weight_action_target != weight_action_target {
            return Err(GovernanceError::VoterWeightRecordInvalidActionTarget.into());
        }
    }

    Ok(())
}
/// Asserts the VoterWeightRecord hasn't expired and matches the given action and target if specified
Asserts the VoterWeightRecord hasn't expired and matches the given action and target if specified
Asserts the VoterWeightRecord hasn ' t expired and matches the given action and target if specified
pub fn assert_is_valid_voter_weight(
    voter_weight_record: &VoterWeightRecord,
    weight_action: VoterWeightAction,
    weight_action_target: &Pubkey,
) -> Result<(), ProgramError> {
    // Assert the weight is not stale
    if let Some(voter_weight_expiry) = voter_weight_record.voter_weight_expiry {
        let slot = Clock::get()?.slot;
        if slot > voter_weight_expiry {
            return Err(GovernanceError::VoterWeightRecordExpired.into());
        }
    }
    // Assert the weight is for the action specified by the addin
    if let Some(voter_weight_action) = &voter_weight_record.weight_action {
        if voter_weight_action != &weight_action {
            return Err(GovernanceError::VoterWeightRecordInvalidAction.into());
        }
    }
    // Assert the weight is for the action target specified by the addin
    if let Some(voter_weight_action_target) = &voter_weight_record.weight_action_target {
        if voter_weight_action_target != weight_action_target {
            return Err(GovernanceError::VoterWeightRecordInvalidActionTarget.into());
        }
    }
    Ok(())
}
pub fn assert_is_valid_voter_weight ( voter_weight_record : & VoterWeightRecord , weight_action : VoterWeightAction , weight_action_target : & Pubkey , ) -> Result < ( ) , ProgramError > { // Assert the weight is not stale if let Some ( voter_weight_expiry ) = voter_weight_record . voter_weight_expiry { let slot = Clock :: get ( ) ? . slot ; if slot > voter_weight_expiry { return Err ( GovernanceError :: VoterWeightRecordExpired . into ( ) ) ; } } // Assert the weight is for the action specified by the addin if let Some ( voter_weight_action ) = & voter_weight_record . weight_action { if voter_weight_action != & weight_action { return Err ( GovernanceError :: VoterWeightRecordInvalidAction . into ( ) ) ; } } // Assert the weight is for the action target specified by the addin if let Some ( voter_weight_action_target ) = & voter_weight_record . weight_action_target { if voter_weight_action_target != weight_action_target { return Err ( GovernanceError :: VoterWeightRecordInvalidActionTarget . into ( ) ) ; } } Ok ( ( ) ) }
Asserts the VoterWeightRecord hasn't expired and matches the given action and target if specified
Asserts the VoterWeightRecord hasn ' t expired and matches the given action and target if specified
voter_weight_record
&VoterWeightRecord
weight_action
VoterWeightAction
weight_action_target
&Pubkey
voter_weight_record
&VoterWeightRecord
weight_action
VoterWeightAction
weight_action_target
&Pubkey