Skip to content

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

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

## Blockchain
* [Diophantine Equation](blockchain/diophantine_equation.py)
* [Proof Of Work](blockchain/proof_of_work.py)

## Boolean Algebra
* [And Gate](boolean_algebra/and_gate.py)
Expand Down
43 changes: 43 additions & 0 deletions blockchain/proof_of_work.py
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:

Check failure on line 8 in blockchain/proof_of_work.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

blockchain/proof_of_work.py:5:1: I001 Import block is un-sorted or un-formatted
def __init__(self, index: int, previous_hash: str, data: str, timestamp: str):

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:

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:

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:

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:

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:

self.index = index
self.previous_hash = previous_hash
self.data = data
self.timestamp = timestamp

def calculate_hash(self) -> str:

Choose a reason for hiding this comment

The 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 blockchain/proof_of_work.py, please provide doctest for the function calculate_hash

Choose a reason for hiding this comment

The 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 blockchain/proof_of_work.py, please provide doctest for the function calculate_hash

Choose a reason for hiding this comment

The 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 blockchain/proof_of_work.py, please provide doctest for the function calculate_hash

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:

Choose a reason for hiding this comment

The 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 blockchain/proof_of_work.py, please provide doctest for the function mine_block

Choose a reason for hiding this comment

The 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 blockchain/proof_of_work.py, please provide doctest for the function mine_block

Choose a reason for hiding this comment

The 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 blockchain/proof_of_work.py, please provide doctest for the function mine_block

Choose a reason for hiding this comment

The 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 blockchain/proof_of_work.py, please provide doctest for the function mine_block

"""
Mines a block by finding a nonce that produces a hash
"""
pass # Implement mining logic here

Check failure on line 23 in blockchain/proof_of_work.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (PIE790)

blockchain/proof_of_work.py:23:9: PIE790 Unnecessary `pass` statement

def get_block(self) -> str:

Choose a reason for hiding this comment

The 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 blockchain/proof_of_work.py, please provide doctest for the function get_block

"""
Returns a formatted string of the block
"""
return f"Block {self.index}:\nHash: {self.calculate_hash()}\nData: {self.data}\n"

Check failure on line 29 in blockchain/proof_of_work.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

blockchain/proof_of_work.py:29:89: E501 Line too long (89 > 88)

def create_genesis_block() -> Block:

Choose a reason for hiding this comment

The 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 blockchain/proof_of_work.py, please provide doctest for the function create_genesis_block

"""
Creates the first block in the blockchain
"""
return Block(0, "0", "Genesis Block", datetime.now(timezone.utc).isoformat())

Check failure on line 35 in blockchain/proof_of_work.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (UP017)

blockchain/proof_of_work.py:35:56: UP017 Use `datetime.UTC` alias

def get_latest_block() -> Block:

Choose a reason for hiding this comment

The 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 blockchain/proof_of_work.py, please provide doctest for the function get_latest_block

"""
Returns the latest block in the blockchain
"""
pass # Implement logic to return the latest block

Check failure on line 41 in blockchain/proof_of_work.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (PIE790)

blockchain/proof_of_work.py:41:5: PIE790 Unnecessary `pass` statement

# Further implementation here...
Loading