(block_number, transactions, previous_hash, prefix_zeros)
| 5 | return sha256(text.encode("ascii")).hexdigest() |
| 6 | |
| 7 | def mine(block_number, transactions, previous_hash, prefix_zeros): |
| 8 | prefix_str = '0'*prefix_zeros |
| 9 | for nonce in range(MAX_NONCE): |
| 10 | text = str(block_number) + transactions + previous_hash + str(nonce) |
| 11 | new_hash = SHA256(text) |
| 12 | if new_hash.startswith(prefix_str): |
| 13 | print(f"Yay! Successfully mined bitcoins with nonce value:{nonce}") |
| 14 | return new_hash |
| 15 | |
| 16 | raise BaseException(f"Couldn't find correct has after trying {MAX_NONCE} times") |
| 17 | |
| 18 | if __name__=='__main__': |
| 19 | transactions=''' |
no test coverage detected