Retrieve the validation rules stored in state and check that the
    given batches do not violate any of those rules. These rules include:

        NofX: Only N of transaction type X may be included in a block.
        XatY: A transaction of type X must be in the list at position Y.
        local: A transaction must be signed by the given public key

    If any setting stored in state does not match the required format for
    that rule, the rule will be ignored.

    Args:
        settings_view (:obj:SettingsView): the settings view to find the
            current rule values
        expected_signer (str): the public key used to use for local signing
        batches (:list:Batch): the list of batches to validate

def enforce_validation_rules(settings_view, expected_signer, batches):
    """
    Retrieve the validation rules stored in state and check that the
    given batches do not violate any of those rules. These rules include:

        NofX: Only N of transaction type X may be included in a block.
        XatY: A transaction of type X must be in the list at position Y.
        local: A transaction must be signed by the given public key

    If any setting stored in state does not match the required format for
    that rule, the rule will be ignored.

    Args:
        settings_view (:obj:SettingsView): the settings view to find the
            current rule values
        expected_signer (str): the public key used to use for local signing
        batches (:list:Batch): the list of batches to validate

    """
    rules = settings_view.get_setting(
        "sawtooth.validator.block_validation_rules")

    if rules is None:
        return True

    transactions = []
    for batch in batches:
        transactions += batch.transactions

    rules = rules.split(";")
    valid = True
    for rule in rules:
        try:
            rule_type, arguments = rule.split(":")
        except ValueError:
            LOGGER.warning("Validation Rule Ignored, not in the correct "
                           "format: %s",
                           rule)
            continue

        rule_type = rule_type.strip()
        # NofX: Only N of transaction type X may be included in a block.
        if rule_type == "NofX":
            valid = _do_nofx(transactions, arguments)

        # XatY: A transaction of type X must be in the block at position Y.
        elif rule_type == "XatY":
            valid = _do_xaty(transactions, arguments)

        # local: A transaction must be signed by the same key as the block.
        elif rule_type == "local":
            valid = _do_local(
                transactions, expected_signer, arguments)

        if not valid:
            return False

    return valid