(block_number, transactions, previous_hash, prefix_zeros)
| 16 | |
| 17 | |
| 18 | def mine(block_number, transactions, previous_hash, prefix_zeros): |
| 19 | prefix_str = "0" * prefix_zeros |
| 20 | for nonce in range(MAX_NONCE): |
| 21 | text = str(block_number) + transactions + previous_hash + str(nonce) |
| 22 | new_hash = SHA256(text) |
| 23 | if new_hash.startswith(prefix_str): |
| 24 | print(f"Yay! Successfully mined bitcoins with nonce value:{nonce}") |
| 25 | return new_hash |
| 26 | |
| 27 | raise BaseException(f"Couldn't find correct has after trying {MAX_NONCE} times") |
| 28 | |
| 29 | |
| 30 | if __name__ == "__main__": |