Exemplo n.º 1
0
 def valid_proof(transactions, last_hash, proof):
     guess = (str([tx.to_ordered_dict() for tx in transactions]) +
              str(last_hash) + str(proof)).encode()
     guess_hash = hash_string_256(guess)
     print(guess_hash)
     # check if the hash start with two zeros at the beginning to return true(valid)
     return guess_hash[0:2] == '00'
    def valid_proof(transactions, last_hash, proof):
        """ To check whether a given proof generates a valid hash or not for the given transactions 

        Arguments:
            :transactions: The list of transactions
            :last_hash: The hash of the previous block
            :proof: The number to check if it is a valid proof
        """

        guess = (str([tx.to_ordered_dict() for tx in transactions]) +
                 str(last_hash) + str(proof)).encode()
        guess_hash = hash_string_256(guess)

        return guess_hash[0:2] == '00'
Exemplo n.º 3
0
 def valid_proof(transactions, last_hash, proof):
     """
     Validates a proof of work number to check if it is valid to solve the hash algorithm.
     :param transactions: the transactions of the block for whick the proof is validated.
     :param last_hash: the previous block hash which will be store in the current guess for the hash.
     :param proof: the proof number we are testing.
     :return: if the generated hash is a valid hash based on the given condition.
     """
     # Creates a String containing all the hash inputs.
     guess = (str([transaction.to_ordered_dict() for transaction in transactions]) + str(last_hash) + str(
         proof)).encode()
     # Hashes the String.
     guess_hash = hash_util.hash_string_256(guess)
     # Only a hash based on the above inputs that starts with two 0s is valid for the algorithm.
     # This condition can be changed, but once adding more characters to validate, the more time consuming it is.
     return guess_hash[0:2] == '00'
 def valid_proof(transactions: list, last_hash: str, proof) -> bool:
     guess = (str([tx.to_ordered_dict() for tx in transactions]) +
              str(last_hash) + str(proof)).encode()
     guess_hash = hash_string_256(guess)
     return guess_hash[0:2] == '00'
Exemplo n.º 5
0
    def valid_proof(transactions, last_hash, proof):
        guess = str([tx.to_ordered_dict()
                     for tx in transactions]) + str(last_hash) + str(proof)
        guess_hash = hash_string_256(guess)

        return guess_hash[0:2] == '00'
 def valid_proof(transactions, last_hash, proof):
     # Create a string with all the hash inputs
     guess = (str([tx.to_ordered_dict() for tx in transactions]) +
              str(last_hash) + str(proof)).encode()
     guess_hash = hash_string_256(guess)
     return guess_hash[0:2] == '00'