Skip to content

Instantly share code, notes, and snippets.

@perymerdeka
Last active November 8, 2021 22:48
Show Gist options
  • Save perymerdeka/54af33e9fb538e1fa62fc0801affb977 to your computer and use it in GitHub Desktop.
Save perymerdeka/54af33e9fb538e1fa62fc0801affb977 to your computer and use it in GitHub Desktop.
Class Blockchain
from hashlib import sha256
class Blockchain:
def __init__(self, prev_hash: str, transaction_list: list):
self.prev_hash = prev_hash
self.transaction_list = transaction_list
# block data and concate strings
self.block_data = " - ".join(transaction_list) + " - " + prev_hash
self.block_hash = sha256(self.block_data.encode()).hexdigest()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment