I'm trying to follow the blockchain tutorial which is in JS but I'm trying it on Python.
I've got this far and when I'm trying to test run it, I get this syntax error which is confusing me since it seems legit.
Any thoughts?
import hashlib
class block:
def __init__(self, index, timestamp, data, previous= ''):
self.index = index
self.timestamp = timestamp
self.data= data
self.previous = previous
self.hash = ''
def calculateHash(self):
return hashlib.sha256(self.index + self.previous + self.timestamp+ (self.data).__str__()
class blockchain:
#btw this it where it says the error is: "class"
def __init__(self):
self.chain= [self.createGenesisBlock()]
def createGenesisBlock(self):
return block(0, "01/01/2017", "Genesis Block", "0")
def getLatestBlock(self):
return self.chain[len(self.chain)-1]
def addBlock(self, newBlock):
newBlock.previous = self.getLatestBlock().hash
newBlock.hash= newBlock.calculateHash()
self.chain.push(newBlock)
korCoin = blockchain()
korCoin.addBlock(block(1, "10/07/2017", 4))
korCoin.addBlock(block(2, "12/07/2017", 40))
if __name__ = "__main__":
print(korCoin)