Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: CS110 Elisa
Views: 47
Kernel: Python 3 (Anaconda)
import hashlib class chunk: def __init__(self, index, data, previous): self.index=index self.data=data self.previous=previous self.hash=self.hash() def hash(self): x=hashlib.sha256() x.new(str(self.index)+str(self.data)+str(self.previous)) return w.hexdigest() def rootblock(): return chunk(0, 'Root', '0') def next(previousblock): if len(currentidx) ==2: currentidx = previousblock.index + 1 currentdata= str(currentidx) currenthash=previousblock.hash else: currentdata= str(currentidx) return Block(currentidx, currentdata, currenthash) blockchain = [rootblock()] previousblock = blockchain[0] def blocks(l, L): for i in range (0, len(l), L): yield l[i:i +L] def merkel_tree(): part = [] for i in blocks(l,2): newblock=next(previousblock) blockchain.append(newblock) previousblock = newblock
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-2-10b9bad4efd2> in <module>() 1 import hashlib 2 ----> 3 class chunk: 4 5 def __init__(self, index, data, previous): <ipython-input-2-10b9bad4efd2> in chunk() 28 return Block(currentidx, currentdata, currenthash) 29 ---> 30 blockchain = [rootblock()] 31 previousblock = blockchain[0] 32 <ipython-input-2-10b9bad4efd2> in rootblock() 16 17 def rootblock(): ---> 18 return chunk(0, 'Root', '0') 19 20 def next(previousblock): NameError: name 'chunk' is not defined
class chunk: def __init__(self, index, data, previous): self.index=index self.data=data self.previous=previous self.hash=self.hash()