-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Added/blockchain basics in python #9465
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
Added/blockchain basics in python #9465
Conversation
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
timestamp = 0 | ||
|
||
# Default constructor for the Block class | ||
def __init__(self, transactions, previous_hash, nonce=0): |
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:
Please provide type hint for the parameter: transactions
Please provide type hint for the parameter: previous_hash
Please provide type hint for the parameter: nonce
# Create a Block class | ||
class Block: | ||
# Initialize the Block object with transactions and the previous block's hash | ||
def __init__(self, transactions, previous_hash): |
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:
Please provide type hint for the parameter: transactions
Please provide type hint for the parameter: previous_hash
self.hash = self.generate_hash() # Compute and store the block's hash | ||
|
||
# Generate a hash for the block | ||
def generate_hash(self): |
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.
As there is no test file in this pull request nor any test function or class in the file blockchain/Blockchain-basics/Consensus-algorithms/Proof-of-work/block.py
, please provide doctest for the function generate_hash
Please provide return type hint for the function: generate_hash
. If the function does not return a value, please provide the type hint as: def function() -> None:
return block_hash.hexdigest() # Return the hexadecimal representation of the hash | ||
|
||
# Print the contents of the block | ||
def print_contents(self): |
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.
As there is no test file in this pull request nor any test function or class in the file blockchain/Blockchain-basics/Consensus-algorithms/Proof-of-work/block.py
, please provide doctest for the function print_contents
Please provide return type hint for the function: print_contents
. If the function does not return a value, please provide the type hint as: def function() -> None:
# Create a Blockchain class | ||
class Blockchain: | ||
# Constructor to initialize the blockchain | ||
def __init__(self): |
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:
return self.chain | ||
|
||
# Function to print the contents of all blocks in the blockchain | ||
def print_blocks(self): |
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.
As there is no test file in this pull request nor any test function or class in the file blockchain/Blockchain-basics/Consensus-algorithms/Proof-of-work/proofOfWork.py
, please provide doctest for the function print_blocks
Please provide return type hint for the function: print_blocks
. If the function does not return a value, please provide the type hint as: def function() -> None:
def print_blocks(self): | ||
for i in range(len(self.chain)): | ||
current_block = self.chain[i] | ||
print("Block {} {}".format(i, current_block)) |
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.
As mentioned in the Contributing Guidelines, please do not use printf style formatting or str.format()
. Use f-string instead to be more readable and efficient.
current_block.print_contents() # Call the print_contents() method of the Block class to print block details | ||
|
||
# Function to add a new block to the blockchain | ||
def add_block(self, transactions): |
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.
As there is no test file in this pull request nor any test function or class in the file blockchain/Blockchain-basics/Consensus-algorithms/Proof-of-work/proofOfWork.py
, please provide doctest for the function add_block
Please provide return type hint for the function: add_block
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: transactions
self.chain.append(new_block) # Add the new block to the blockchain | ||
|
||
# Function to validate the integrity of the blockchain | ||
def validate_chain(self): |
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.
As there is no test file in this pull request nor any test function or class in the file blockchain/Blockchain-basics/Consensus-algorithms/Proof-of-work/proofOfWork.py
, please provide doctest for the function validate_chain
Please provide return type hint for the function: validate_chain
. If the function does not return a value, please provide the type hint as: def function() -> None:
return True | ||
|
||
# Function to perform proof of work (mining) | ||
def proof_of_work(self, block, difficulty=2): |
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.
As there is no test file in this pull request nor any test function or class in the file blockchain/Blockchain-basics/Consensus-algorithms/Proof-of-work/proofOfWork.py
, please provide doctest for the function proof_of_work
Please provide return type hint for the function: proof_of_work
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: block
Please provide type hint for the parameter: difficulty
for more information, see https://pre-commit.ci
No type hints. No doctests. All three checks are failing. Closing because we currently have more than 100 open pull requests. |
Describe your change:
Fixes #9051
Added a blockchain basis folder which contains the Python files for creating a block in blockchain and building a blockchain network and also added a consensus algorithm proof of work.
Checklist: