-
-
Notifications
You must be signed in to change notification settings - Fork 46.7k
proof_of_work.py #12003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proof_of_work.py #12003
Changes from 14 commits
b7d4872
f86061b
fe47ba4
f4223e8
0213607
c37e2f9
65a08c3
ef12e2b
d64c8ea
ead7845
f17414a
75a0ffb
b4419b7
2ce385a
87d42b7
f171519
bc0a150
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
Proof of Work Module | ||
""" | ||
|
||
from datetime import datetime, timezone | ||
import hashlib | ||
|
||
class Block: | ||
def __init__(self, index: int, previous_hash: str, data: str, timestamp: str): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: |
||
self.index = index | ||
self.previous_hash = previous_hash | ||
self.data = data | ||
self.timestamp = timestamp | ||
|
||
def calculate_hash(self) -> str: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file |
||
value = f"{self.index}{self.previous_hash}{self.data}{self.timestamp}" | ||
return hashlib.sha256(value.encode("utf-8")).hexdigest() | ||
|
||
def mine_block(self, difficulty: int) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file |
||
""" | ||
Mines a block by finding a nonce that produces a hash | ||
""" | ||
pass # Implement mining logic here | ||
|
||
def get_block(self) -> str: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file |
||
""" | ||
Returns a formatted string of the block | ||
""" | ||
return f"Block {self.index}:\nHash: {self.calculate_hash()}\nData: {self.data}\n" | ||
|
||
def create_genesis_block() -> Block: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file |
||
""" | ||
Creates the first block in the blockchain | ||
""" | ||
return Block(0, "0", "Genesis Block", datetime.now(timezone.utc).isoformat()) | ||
|
||
def get_latest_block() -> Block: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file |
||
""" | ||
Returns the latest block in the blockchain | ||
""" | ||
pass # Implement logic to return the latest block | ||
|
||
# Further implementation here... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function:
__init__
. If the function does not return a value, please provide the type hint as:def function() -> None: