Skip to content

Instantly share code, notes, and snippets.

@fwping
Created August 18, 2018 07:15
Show Gist options
  • Save fwping/316bc0151f2f51cc5d355ddefd7cc862 to your computer and use it in GitHub Desktop.
Save fwping/316bc0151f2f51cc5d355ddefd7cc862 to your computer and use it in GitHub Desktop.
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