MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / mine

Function mine

projects/Bitcoin Mining/mine.py:18–27  ·  view source on GitHub ↗
(block_number, transactions, previous_hash, prefix_zeros)

Source from the content-addressed store, hash-verified

16
17
18def 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
30if __name__ == "__main__":

Callers 1

mine.pyFile · 0.70

Calls 1

SHA256Function · 0.70

Tested by

no test coverage detected