/// Verifies the rule is not violated by the given list of transactions
///
/// # Arguments
///
/// * `txn_info` - The list of transactions (reduced to only relevant info) to validate
/// * `local_signer_key` - The key used for validating the `Local` rule
/// * `final_validation` - If `true`, the `XatY` and `Local` rules will fail when there is no
///   transactions at the required position
Verifies the rule is not violated by the given list of transactions
Verifies the rule is not violated by the given list of transactions
pub fn validate<'a, I: IntoIterator<Item = &'a TxnInfo>>(
        &self,
        txn_info: I,
        local_signer_key: &[u8],
        final_validation: bool,
    ) -> bool {
        match self {
            Self::NofX { family_name, limit } => {
                let count = txn_info
                    .into_iter()
                    .filter(|info| &info.family_name == family_name)
                    .count();
                if count > *limit {
                    debug!(
                        "Found {} transactions of type {}; only {} are allowed",
                        count, family_name, limit
                    );
                    false
                } else {
                    true
                }
            }
            Self::XatY {
                family_name,
                position,
            } => {
                let txn_family_name = match txn_info.into_iter().nth(*position) {
                    Some(info) => &info.family_name,
                    None if final_validation => {
                        debug!(
                            "Transaction at position {} is required by XatY rule",
                            position
                        );
                        return false;
                    }
                    None => return true, // Haven't gotten txn at position Y yet
                };
                if txn_family_name != family_name {
                    debug!(
                        "Transaction at position {} is not of the correct type; expected {}, \
                         found {}",
                        position, family_name, txn_family_name
                    );
                    false
                } else {
                    true
                }
            }
            Self::Local { indices } => {
                let mut txn_info = txn_info.into_iter();
                for index in indices {
                    let signer_key = match txn_info.by_ref().nth(*index) {
                        Some(info) => info.signer_public_key.as_slice(),
                        None if final_validation => {
                            debug!("Transaction at index {} is required by local rule", index);
                            return false;
                        }
                        None => return true, // Haven't gotten txn at this index yet
                    };
                    if signer_key != local_signer_key {
                        debug!(
                            "Transaction at position {} is not signed by the local key {}",
                            index,
                            hex::encode(local_signer_key)
                        );
                        return false;
                    }
                }
                true
            }
        }
    }
pub fn validate < ' a , I : IntoIterator < Item = & ' a TxnInfo > > ( & self , txn_info : I , local_signer_key : & [ u8 ] , final_validation : bool , ) -> bool { match self { Self :: NofX { family_name , limit } => { let count = txn_info . into_iter ( ) . filter ( | info | & info . family_name == family_name ) . count ( ) ; if count > * limit { debug ! ( " " count family_name limit ) ; false } else { true } } Self :: XatY { family_name , position , } => { let txn_family_name = match txn_info . into_iter ( ) . nth ( * position ) { Some ( info ) => & info . family_name , None if final_validation => { debug ! ( " " position ) ; return false ; } None => return true , // Haven't gotten txn at position Y yet } ; if txn_family_name != family_name { debug ! ( " \
 " position family_name txn_family_name ) ; false } else { true } } Self :: Local { indices } => { let mut txn_info = txn_info . into_iter ( ) ; for index in indices { let signer_key = match txn_info . by_ref ( ) . nth ( * index ) { Some ( info ) => info . signer_public_key . as_slice ( ) , None if final_validation => { debug ! ( " " index ) ; return false ; } None => return true , // Haven't gotten txn at this index yet } ; if signer_key != local_signer_key { debug ! ( " " index hex encode ( local_signer_key ) ) ; return false ; } } true } } }
Verifies the rule is not violated by the given list of transactions
Verifies the rule is not violated by the given list of transactions
&self
txn_info
I
local_signer_key
&[u8]
final_validation
bool