Last active
December 27, 2019 16:40
-
-
Save edenau/ef9f235e6c5f6267079cd06062ae1270 to your computer and use it in GitHub Desktop.
MinimalBlock object in minimal blockchain
This file contains 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
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