Created
December 16, 2021 12:37
-
-
Save celsoagra/fc19579158f6ef3aaaec4491efe70c0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A simple Blockchain in Python | |
""" | |
import hashlib | |
class GeekCoinBlock: | |
def __init__(self, previous_block_hash, transaction_list): | |
self.previous_block_hash = previous_block_hash | |
self.transaction_list = transaction_list | |
self.block_data = f"{' - '.join(transaction_list)} - {previous_block_hash}" | |
self.block_hash = hashlib.sha256(self.block_data.encode()).hexdigest() | |
t1 = "Noah sends 5 GC to Mark" | |
t2 = "Mark sends 3.2 GC to James" | |
t3 = "James sends 4.2 GC to Alisson" | |
t4 = "Alisson sends 1.1 GC to Noah" | |
block1 = GeekCoinBlock('firstblock', [t1, t2]) | |
print(f"Block 1 data: {block1.block_data}") | |
print(f"Block 1 hash: {block1.block_hash}") | |
block2 = GeekCoinBlock(block1.block_hash, [t3, t4]) | |
print(f"Block 2 data: {block2.block_data}") | |
print(f"Block 2 hash: {block2.block_hash}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment