Skip to content

Commit 9403de6

Browse files
authored
Update proof_of_work.py
1 parent 5d87a84 commit 9403de6

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

blockchain/proof_of_work.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import hashlib
2-
import time
32

43

54
def proof_of_work(difficulty: int) -> int:
65
"""
76
Simulates a Proof of Work mining process.
87
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
109
with a specific number of leading zeros (difficulty).
1110
1211
Args:
@@ -20,13 +19,11 @@ def proof_of_work(difficulty: int) -> int:
2019
>>> isinstance(result, int)
2120
True
2221
"""
23-
prefix = "0" * difficulty
22+
prefix = '0' * difficulty
2423
nonce = 0
25-
start = time.time() # Timing starts
2624

2725
while True:
2826
hash_result = hashlib.sha256(f"{nonce}".encode()).hexdigest()
2927
if hash_result.startswith(prefix):
30-
end = time.time() # Timing ends
3128
return nonce
3229
nonce += 1

0 commit comments

Comments
 (0)