def valid_proof(transactions, last_hash, proof): guess = (str(transactions) + str(last_hash) + str(proof)).encode() # Hash the string. guess_hash = hash_string_256(guess) print(guess_hash) # Define the conditions for a new valid hash. return guess_hash[0:2] == "00"
def valid_proof(transactions, last_block_hash, proof): # guess_str = str(transactions) + str(last_block_hash) + str(proof) guess_str = generate_guess_string(transactions, last_block_hash, proof) guess_str_encoded = guess_str.encode() # guess_hash = hashlib.sha256(guess_str_encoded).hexdigest() guess_hash = hash_utils.hash_string_256(guess_str_encoded) # print(f"[debug]: guess_str ({guess_str}) and guess_hash ({guess_hash})", end="\r") print(f"[debug]: guess_hash ({guess_hash})", end="\r") return guess_hash[0:POW_DIGITS] == POW_PATTERN
def valid_proof(transactions, last_hash, proof): """Validate a proof. Arguments: transactions: Transaction of the block last_hash: The stored previous_hash. proof: The proof we are testing. """ guess = (str([tx.to_ordered_dict() for tx in transactions]) + str(last_hash) + str(proof)).encode() # Hash the string. guess_hash = hash_string_256(guess) print(guess_hash) # Define the conditions for a new valid hash. return guess_hash[0:2] == "00"
def is_valid_proof(transactions, last_block_hash, proof): guess = (str(transactions) + str(last_block_hash) + str(proof)).encode() guess_hash = hash_string_256(guess) print(guess_hash) return guess_hash[0:2] == '00'