File tree 1 file changed +2
-5
lines changed
1 file changed +2
-5
lines changed Original file line number Diff line number Diff line change 1
1
import hashlib
2
- import time
3
2
4
3
5
4
def proof_of_work (difficulty : int ) -> int :
6
5
"""
7
6
Simulates a Proof of Work mining process.
8
7
9
- The miner must find a nonce such that the hash of the nonce starts
8
+ The miner must find a nonce such that the hash of the nonce starts
10
9
with a specific number of leading zeros (difficulty).
11
10
12
11
Args:
@@ -20,13 +19,11 @@ def proof_of_work(difficulty: int) -> int:
20
19
>>> isinstance(result, int)
21
20
True
22
21
"""
23
- prefix = "0" * difficulty
22
+ prefix = '0' * difficulty
24
23
nonce = 0
25
- start = time .time () # Timing starts
26
24
27
25
while True :
28
26
hash_result = hashlib .sha256 (f"{ nonce } " .encode ()).hexdigest ()
29
27
if hash_result .startswith (prefix ):
30
- end = time .time () # Timing ends
31
28
return nonce
32
29
nonce += 1
You can’t perform that action at this time.
0 commit comments