Skip to content

Instantly share code, notes, and snippets.

@edenau
Last active December 27, 2019 16:40
Show Gist options
  • Save edenau/ef9f235e6c5f6267079cd06062ae1270 to your computer and use it in GitHub Desktop.
Save edenau/ef9f235e6c5f6267079cd06062ae1270 to your computer and use it in GitHub Desktop.
MinimalBlock object in minimal blockchain
import hashlib
class MinimalBlock():
def __init__(self, index, timestamp, data, previous_hash):
self.index = index
self.timestamp = timestamp
self.data = data
self.previous_hash = previous_hash
self.hash = self.hashing()
def hashing(self):
key = hashlib.sha256()
key.update(str(self.index).encode('utf-8'))
key.update(str(self.timestamp).encode('utf-8'))
key.update(str(self.data).encode('utf-8'))
key.update(str(self.previous_hash).encode('utf-8'))
return key.hexdigest()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment