Skip to content

Commit 75a0ffb

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent f17414a commit 75a0ffb

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

blockchain/proof_of_work.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
from datetime import datetime
88
import hashlib
99

10+
1011
class Block:
11-
def __init__(self, index: int, previous_hash: str, data: str, timestamp: str) -> None:
12+
def __init__(
13+
self, index: int, previous_hash: str, data: str, timestamp: str
14+
) -> None:
1215
self.index = index
1316
self.previous_hash = previous_hash
1417
self.data = data
@@ -24,8 +27,14 @@ def calculate_hash(self) -> str:
2427
>>> block.calculate_hash()
2528
'...' # Expected hash value here
2629
"""
27-
value = str(self.index) + self.previous_hash + str(self.data) + str(self.timestamp) + str(self.nonce)
28-
return hashlib.sha256(value.encode('utf-8')).hexdigest()
30+
value = (
31+
str(self.index)
32+
+ self.previous_hash
33+
+ str(self.data)
34+
+ str(self.timestamp)
35+
+ str(self.nonce)
36+
)
37+
return hashlib.sha256(value.encode("utf-8")).hexdigest()
2938

3039
def mine_block(self, difficulty: int) -> None:
3140
"""
@@ -38,6 +47,7 @@ def mine_block(self, difficulty: int) -> None:
3847
# Implementation of mining logic
3948
print(f"Block mined: {self.hash}")
4049

50+
4151
class Blockchain:
4252
def __init__(self) -> None:
4353
self.chain = [self.create_genesis_block()]

0 commit comments

Comments
 (0)