Skip to content

Commit 2ce385a

Browse files
authored
Update proof_of_work.py
1 parent b4419b7 commit 2ce385a

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

blockchain/proof_of_work.py

+18-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from datetime import datetime, timezone
66
import hashlib
77

8-
98
class Block:
109
def __init__(self, index: int, previous_hash: str, data: str, timestamp: str):
1110
self.index = index
@@ -17,19 +16,28 @@ def calculate_hash(self) -> str:
1716
value = f"{self.index}{self.previous_hash}{self.data}{self.timestamp}"
1817
return hashlib.sha256(value.encode("utf-8")).hexdigest()
1918

20-
def mine_block(self) -> None:
19+
def mine_block(self, difficulty: int) -> None:
2120
"""
2221
Mines a block by finding a nonce that produces a hash
2322
"""
24-
# Implementation of mining logic goes here
23+
pass # Implement mining logic here
2524

26-
@staticmethod
27-
def create_genesis_block() -> "Block":
25+
def get_block(self) -> str:
2826
"""
29-
Creates the genesis block
27+
Returns a formatted string of the block
3028
"""
31-
return Block(0, "0", "Genesis Block", datetime.now(timezone.utc).isoformat())
29+
return f"Block {self.index}:\nHash: {self.calculate_hash()}\nData: {self.data}\n"
30+
31+
def create_genesis_block() -> Block:
32+
"""
33+
Creates the first block in the blockchain
34+
"""
35+
return Block(0, "0", "Genesis Block", datetime.now(timezone.utc).isoformat())
36+
37+
def get_latest_block() -> Block:
38+
"""
39+
Returns the latest block in the blockchain
40+
"""
41+
pass # Implement logic to return the latest block
3242

33-
def get_latest_block(self) -> "Block":
34-
# Logic to get the latest block
35-
pass
43+
# Further implementation here...

0 commit comments

Comments
 (0)