Skip to content

Commit bb3b23d

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

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

blockchain/simple_blockchain.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ def compute_hash(self, nonce: int) -> str:
4444
Returns:
4545
str: Hexadecimal hash string.
4646
"""
47-
block_string = f"{self.index}{self.timestamp}{self.data}{self.previous_hash}{nonce}"
47+
block_string = (
48+
f"{self.index}{self.timestamp}{self.data}{self.previous_hash}{nonce}"
49+
)
4850
return hashlib.sha256(block_string.encode()).hexdigest()
4951

5052
def mine_block(self, difficulty: int) -> Tuple[int, str]:
@@ -64,7 +66,7 @@ def mine_block(self, difficulty: int) -> Tuple[int, str]:
6466
if difficulty < 1:
6567
raise ValueError("Difficulty must be at least 1")
6668
nonce = 0
67-
target = '0' * difficulty
69+
target = "0" * difficulty
6870
while True:
6971
hash_result = self.compute_hash(nonce)
7072
if hash_result.startswith(target):
@@ -152,7 +154,7 @@ def is_valid(self) -> bool:
152154
prev = self.chain[i - 1]
153155
if current.previous_hash != prev.hash:
154156
return False
155-
if not current.hash.startswith('0' * self.difficulty):
157+
if not current.hash.startswith("0" * self.difficulty):
156158
return False
157159
if current.hash != current.compute_hash(current.nonce):
158160
return False

0 commit comments

Comments
 (0)