Example #1
0
def valid_proof(transactions, last_hash, proof):
    guess = (str(transaction.to_ordered_dict()
                 for transaction in transactions) + str(last_hash) +
             str(proof)).encode()
    guess_hash = hash_string_256(guess)
    # print(guess_hash)
    return guess_hash[0:2] == "00"
Example #2
0
def valid_proof(transactions, last_hash, proof):
    guess = (str(transactions) + str(last_hash) + str(proof)).encode()
    print(guess)
    guess_hash = hash_string_256(guess)
    print(guess_hash)
    #returning only first and the second element
    return guess_hash[0:2] == '00'
def valid_proof(transactions, last_hash, proof):
    guess = (str(transactions) + str(last_hash) + str(proof)).encode()

    guess_hash = hash_string_256(guess)
    print(guess_hash)

    return guess_hash[0:2] == '00'
Example #4
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_util.hash_string_256(guess)
     return guess_hash[
         0:
         2] == '00'  # If generated hash has two leading 0's, it is valid. The condition can be changed.
Example #5
0
 def valid_proof(self, 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()
     #Hash the string
     guess_hash = hash_string_256(guess)
     return guess_hash[0:2] == '00'
Example #6
0
def valid_proof(transactions, last_hash, proof):
    guess = (str([tx.to_ordered_dict() for tx in transactions]) +
             str(last_hash) + str(proof)).encode()
    # print(guess)
    guess_hash = hash_string_256(guess)
    # print(guess_hash)
    #returning only first and the second element
    return guess_hash[0:2] == '00'
def valid_proof(transactions, last_hash, proof):
    """Check: Only a hash with "00" is valid"""
    #concertinate all of it together as string and encode in order to get a proper UTF8 string
    guess = (str(transactions) + str(last_hash) + str(proof)).encode()
    #hash that guess
    guess_hash = hash_string_256(guess)
    print(guess_hash)
    #check that the hash starts with two zeros
    return guess_hash[0:2] == "00"
Example #8
0
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()

    #Hash the string
    # This is NOT the same hash as will be stored in the previous_hash
    guess_hash = hash_string_256(guess)
    print(guess_hash)
    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()
     # Hash the string
     # IMPORTANT: This is NOT the same hash that will be stored in the previous_hash
     guess_hash = hash_string_256(guess)
     # Only a hash (which is based on the above inputs) which starts with two zeroes will be accepted
     # This condition is of course defined by you. You could also require 10 leading zeroes in hash
     return guess_hash[0:2] == '00'
Example #10
0
def valid_proof(transactions, last_hash, proof):
    """Validate a proof of work number and see if it solves the puzzle algorithm (two leading 0s)

    Arguments:
        :transactions: The transactions of the block for which the proof is created.
        :last_hash: The previous block's hash which will be stored in the current block.
        :proof: The proof number we're testing.
    """
    # Create a string with all the hash inputs
    guess = (str(transactions) + str(last_hash) + str(proof)).encode()
    # Hash the string
    # IMPORTANT: This is NOT the same hash as will be stored in the previous_hash. It's a not a block's hash. It's only used for the proof-of-work algorithm.
    guess_hash = hash_string_256(guess)
    # Only a hash (which is based on the above inputs) which starts with two 0s is treated as valid
    # This condition is of course defined by you. You could also require 10 leading 0s - this would take significantly longer (and this allows you to control the speed at which new blocks can be added)
    return guess_hash[0:2] == '00'
def valid_proof(transactions, last_hash, proof):
    """Validate a proof of work number and see if it solves the puzzle algorithm

    Arguments:
        :transactions: The transactions of the block for which the proof is calculated.
        :last_hash: The previous block's hash which will be stored.
        :proof: The proof number we're testing.
    """
    # Create a string with all the hash inputs
    guess = (str(transactions) + str(last_hash) + str(proof)).encode()
    # Hash the string
    # IMPORTANT: This is NOT the the same hash as will be stored int the previous block
    guess_hash = hash_string_256(guess)
    # Only a hash which starts with two zeros will return True.
    # This condition is of course defined by you.
    return guess_hash[0:2] == '00'
def valid_proof(transactions, last_hash, proof):
    """validate a proof of work numberand see if it solves a puzzle algorithm (two leading 0's)

	Arguements:
		:transactions: the transactions of block where proof is created
		:last_hash: previous hash will be stored in current block
		:proof: the proof number we are testing
	"""
    #create a string with all hash inputs
    guess = (str(transactions) + str(last_hash) + str(proof)).encode()
    #hash the string
    #this is not same as previous hash its  only used for proof of work algo
    guess_hash = hash_string_256(guess)
    print(guess_hash)
    # Only a hash (which is based on the above inputs) which starts with two 0s is treated as valid
    # This condition is of course defined by you.
    # You could also require 10 leading 0s - this would take significantly longer
    #  (and this allows you to control the speed at which new blocks can be added)
    return guess_hash[0:2] == '00'
def validTarget(transactions, last_hash, proof):
    guess = (str(transactions) + str(last_hash) + str(proof)).encode()
    guess_hash = hash_string_256(guess)
    return guess_hash
def validProof(transactions):
    guess = (str(transactions)).encode()
    guess_hash = hash_string_256(guess)
    return guess_hash
Example #15
0
def valid_proof(transactions, last_hash, proof_number):
    guess = (str(transactions) + str(last_hash) + str(proof_number)).encode()
    guess_hash = hash_string_256(guess)
    return guess_hash[0:2] == "00"
Example #16
0
def valid_proof(transactions, last_hash, proof):
    guess = (str(transactions) + str(last_hash) + str(proof)).encode()
    # This hashing is used for Proof of work Algo
    guess_hash = hash_string_256(guess)
    # Only a hash (which is based on the above inputs) which starts with two 0s is treated as valid
    return guess_hash[0:2] == '00'
Example #17
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)
     return guess_hash[0:2] == '00'
Example #18
0
def valid_proof(transactions, last_hash, proof):
    '''  confirms proof: small enough number from the hashing function '''
    guess = (str(transactions) + str(last_hash) + str(proof)).encode()
    guess_hash = hash_string_256(guess) # this is not the hash of the last block! This is the pow # attempting to solve the puzzle!
    print(guess_hash)  # typically prints out loads of hashes
    return guess_hash[0:2] == '00'  # truth condition for a valid hash
Example #19
0
 def valid_proof(transactions,last_hash,proof):
     # be carefull while passing the arguments make sure hashing will cause issue for the same item (list or string matters!!str([tx....])) 
     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)
     return guess_hash[0:2]=='00'