Created
August 18, 2018 07:15
-
-
Save fwping/316bc0151f2f51cc5d355ddefd7cc862 to your computer and use it in GitHub Desktop.
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 time | |
import hashlib | |
class Block: | |
def __init__(self, data, prevBlockHash): | |
self.timestamp = int(time.time()) | |
self.data = data | |
self.prevBlockHash = prevBlockHash | |
self.setHash() | |
def setHash(self): | |
timestamp = bytes(str(self.timestamp), "ascii") | |
print(timestamp) | |
header = bytes().join([self.prevBlockHash, bytes(self.data, "ascii"), timestamp]) | |
print(header) | |
self.hash = bytes(hashlib.sha256(header).hexdigest(), "ascii") | |
print(self.hash) | |
if __name__ == '__main__': | |
block = Block("Genesis Block", bytes()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment