model/network.py
def is_transaction_valid(self, transaction: dict, _type: object) -> bool:
        """Verfies if a transaction is valid or not"""

        required_keys = ["content", "receivers"]

        if Counter(transaction.keys()) != Counter(required_keys):
            # If, doesn't matter the order, the keys are not all
            # the same as the expected ones, return False

            print("Invalid transaction: Keys don't match")
            return False

        tr_content = transaction["content"]
        tr_receivers = transaction["receivers"]

        expected_obj_types = {
            "content": dict,
            "receivers": list
        }

        if any([not isinstance(value, expected_obj_types[key]) for key, value in transaction.items()]):
            # Returns false if any of the transaction values
            # have a different type other than the expected

            print(
                "Invalid transaction: Transaction has a different type than the expected")
            return False

        t = _type.import_dict(transaction["content"])
        if t is None or t.is_valid() is False:
            print("Invalid transaction")
            return False

        for userid in tr_receivers:
            try:
                if ID(**userid).is_valid() is False:
                    return False
            except TypeError as e:
                print(e)
                print("Invalid transaction: Invalid judge ID")
                return False

        return True
Verfies if a transaction is valid or not
Verfies if a transaction is valid or not
Verfies if a transaction is valid or not
def is_transaction_valid(self, transaction: dict, _type: object) -> bool:
        required_keys = ["content", "receivers"]
        if Counter(transaction.keys()) != Counter(required_keys):
            print("Invalid transaction: Keys don't match")
            return False
        tr_content = transaction["content"]
        tr_receivers = transaction["receivers"]
        expected_obj_types = {
            "content": dict,
            "receivers": list
        }
        if any([not isinstance(value, expected_obj_types[key]) for key, value in transaction.items()]):
            print(
                "Invalid transaction: Transaction has a different type than the expected")
            return False
        t = _type.import_dict(transaction["content"])
        if t is None or t.is_valid() is False:
            print("Invalid transaction")
            return False
        for userid in tr_receivers:
            try:
                if ID(**userid).is_valid() is False:
                    return False
            except TypeError as e:
                print(e)
                print("Invalid transaction: Invalid judge ID")
                return False
        return True
def is_transaction_valid ( self , transaction : dict , _type : object ) -> bool : required_keys = [ "content" , "receivers" ] if Counter ( transaction . keys ( ) ) != Counter ( required_keys ) : print ( "Invalid transaction: Keys don't match" ) return False tr_content = transaction [ "content" ] tr_receivers = transaction [ "receivers" ] expected_obj_types = { "content" : dict , "receivers" : list } if any ( [ not isinstance ( value , expected_obj_types [ key ] ) for key , value in transaction . items ( ) ] ) : print ( "Invalid transaction: Transaction has a different type than the expected" ) return False t = _type . import_dict ( transaction [ "content" ] ) if t is None or t . is_valid ( ) is False : print ( "Invalid transaction" ) return False for userid in tr_receivers : try : if ID ( ** userid ) . is_valid ( ) is False : return False except TypeError as e : print ( e ) print ( "Invalid transaction: Invalid judge ID" ) return False return True
Verfies if a transaction is valid or not
Verfies if a transaction is valid or not
"""Verfies if a transaction is valid or not""" # If, doesn't matter the order, the keys are not all # the same as the expected ones, return False # Returns false if any of the transaction values # have a different type other than the expected
self
transaction
dict
_type
object