1
0
mirror of https://github.com/bitcoinbook/bitcoinbook synced 2024-11-22 08:08:11 +00:00

Merge pull request #531 from koshikraj/code-fix

fixed hashlib library error for python3
This commit is contained in:
Will Binns 2019-05-08 20:26:45 +00:00 committed by GitHub
commit ee6131abf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View File

@ -12,7 +12,7 @@ for nonce in range(20):
input_data = text + str(nonce) input_data = text + str(nonce)
# calculate the SHA-256 hash of the input (text+nonce) # calculate the SHA-256 hash of the input (text+nonce)
hash_data = hashlib.sha256(input_data).hexdigest() hash_data = hashlib.sha256(input_data.encode()).hexdigest()
# show the input and hash result # show the input and hash result
print(input_data, '=>', hash_data) print(input_data, '=>', hash_data)

View File

@ -19,7 +19,7 @@ def proof_of_work(header, difficulty_bits):
target = 2 ** (256 - difficulty_bits) target = 2 ** (256 - difficulty_bits)
for nonce in xrange(max_nonce): for nonce in xrange(max_nonce):
hash_result = hashlib.sha256(str(header) + str(nonce)).hexdigest() hash_result = hashlib.sha256((str(header) + str(nonce)).encode()).hexdigest()
# check if this is a valid result, below the target # check if this is a valid result, below the target
if long(hash_result, 16) < target: if long(hash_result, 16) < target: