Skip to content

rheona2000/simple-blockchain-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

simple-blockchain-

from hashlib import sha256 import time

class block: def init (self, timestamp, data, previousHash = ' '): self.timestamp = timestamp self.data = data self.previousHash = previousHash self.hash = self.calculateHash()

def calculateHash(self):
	return sha256((str(self.timestamp) + str(self.data) + str(self.previousHash)).encode()).hexdigest()

class blockchain: def init(self): self.chain = [self.createGenesis()]

def createGenesis(self):
	return block(time.ctime(), "genesisBlock", "00000")

def mineBlock(self, data):
	node = block(time.ctime(), data, self.chain[-1].hash)
	# mining a new block to the blockchain
	self.chain.append(node)

def printBlockchain(self):
	for i in range(len(self.chain)):
		print("\n-----Block ", i ,"---------\n timestamp = "\
			       , self.chain[i].timestamp,"\n data = ", \
			       		self.chain[i].data, "\n previousHash = ",\
			       		 self.chain[i].previousHash,"\n hash = ", \
			       		    self.chain[i].hash)

RIO = blockchain()

data = input()

sending data to get mined

print("\n\n ----> Mining New Block -->") RIO.mineBlock(data)

print("\n\n ----> New Block mined successfully --> ")

RIO.printBlockchain()

About

simple blockchain for beginners

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages