-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathBlock.py
More file actions
49 lines (40 loc) · 1.42 KB
/
Block.py
File metadata and controls
49 lines (40 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from config import *
from HashAlgo import *
import sys
class Block:
def __init__(self, prevBlockPtr, root, nonce, transactionList):
self.prevBlockPtr = prevBlockPtr
if(prevBlockPtr):
self.prevBlockHash = prevBlockPtr.hashVal
else:
self.prevBlockHash = ""
self.txnList = transactionList
self.noOfTxn = len(transactionList)
self.merkleTreeRoot = root
self.nonce = nonce
allHash = ""
# allHash += root.hashVal + self.prevBlockHash + str(nonce) + str(self.noOfTxn)
allHash += self.prevBlockHash + str(nonce) + str(self.noOfTxn) + self.merkleTreeRoot.hashVal
self.hashVal = generateHash(allHash)
def get_size(self):
totalSize = 0
totalSize += sys.getsizeof(self.prevBlockHash)
totalSize += sys.getsizeof(self.nonce)
totalSize += sys.getsizeof(self.hashVal)
for txn in self.txnList:
totalSize += txn.get_size()
noOfNodesinMerkleTree = 15
n = 15
while(n>1):
noOfNodesinMerkleTree += (n + arity - 1)//arity
n = (n+ arity - 1)//arity
totalSize += noOfNodesinMerkleTree * sys.getsizeof(self.merkleTreeRoot.hashVal)
return totalSize
# b = None
# # print(sys.getsizeof(b))
# b1 = Block(None, None, 879796, [])
# # print(sys.getsizeof(b1))
# b2 = Block(b1,b1, 3000, [])
# b1.get_size()
# b2.get_size()
# print((9+3)//4)