<commit_before>"""This file explains how we tell if a transaction is valid or not, it explains
how we update the system when new transactions are added to the blockchain."""
import blockchain
import custom
import copy
import tools


def addr(tx):
    return tools.make_address(tx['pubkeys'], len(tx['signatures']))


def spend_verify(tx, txs, DB):

    def sigs_match(sigs, pubs, msg):
        for sig in sigs:
            for pub in pubs:
                try:
                    if tools.verify(msg, sig, pub):
                        sigs.remove(sig)
                        pubs.remove(pub)
                except:
                    pass
        return len(sigs) == 0

    tx_copy = copy.deepcopy(tx)
    tx_copy_2 = copy.deepcopy(tx)
    tx_copy.pop('signatures')
    if len(tx['pubkeys']) == 0:
        return False
    if len(tx['signatures']) > len(tx['pubkeys']):
        return False
    msg = tools.det_hash(tx_copy)
    if not sigs_match(copy.deepcopy(tx['signatures']),
                      copy.deepcopy(tx['pubkeys']), msg):
        return False
    if tx['amount'] < custom.fee:
        return False
    address = addr(tx_copy_2)
    total_cost = 0<commit_msg>Re-write `sigs_match`.<commit_after>"""This file explains how we tell if a transaction is valid or not, it explains
how we update the system when new transactions are added to the blockchain."""
import blockchain
import custom
import copy
import tools


def addr(tx):
    return tools.make_address(tx['pubkeys'], len(tx['signatures']))


def spend_verify(tx, txs, DB):

    def sigs_match(sigs, pubs, msg):
        return all(tools.verify(msg, sig, pub) for sig in sigs for pub in pubs)

    tx_copy = copy.deepcopy(tx)
    tx_copy_2 = copy.deepcopy(tx)
    tx_copy.pop('signatures')
    if len(tx['pubkeys']) == 0:
        return False
    if len(tx['signatures']) > len(tx['pubkeys']):
        return False
    msg = tools.det_hash(tx_copy)
    if not sigs_match(copy.deepcopy(tx['signatures']),
                      copy.deepcopy(tx['pubkeys']), msg):
        return False
    if tx['amount'] < custom.fee:
        return False
    address = addr(tx_copy_2)
    total_cost = 0
{'fraction_non_alphanumeric': 0.1144048170449282, 'fraction_numerical': 0.0041685965724872626, 'mean_word_length': 2.5467980295566504, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6911038', 'n_tokens_mistral': 682, 'n_tokens_neox': 656, 'n_words': 196}