We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 374cbc2 commit bd89e97Copy full SHA for bd89e97
blockchain/proof_of_work.py
@@ -1,11 +1,12 @@
1
import hashlib
2
import time
3
4
+
5
def proof_of_work(difficulty: int) -> int:
6
"""
7
Simulates a Proof of Work mining process.
8
- The miner must find a nonce such that the hash of the nonce starts
9
+ The miner must find a nonce such that the hash of the nonce starts
10
with a specific number of leading zeros (difficulty).
11
12
Args:
@@ -19,10 +20,10 @@ def proof_of_work(difficulty: int) -> int:
19
20
>>> isinstance(result, int)
21
True
22
- prefix = '0' * difficulty
23
+ prefix = "0" * difficulty
24
nonce = 0
25
start = time.time()
-
26
27
while True:
28
hash_result = hashlib.sha256(f"{nonce}".encode()).hexdigest()
29
if hash_result.startswith(prefix):
0 commit comments