-
Notifications
You must be signed in to change notification settings - Fork 0
/
block.py
45 lines (34 loc) · 1.1 KB
/
block.py
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
from merkle_tree import MerkleTree
import utils
# Defination of Block
# ts: time stamp
class Block:
def __init__(self, idx, ver, pre_hash, ts, fee, tr_list, thresh, addr):
self.idx = idx
self.ver = ver
self.pre_hash = pre_hash
self.ts = ts
self.fee = fee
self.thresh = thresh
self.addr = addr
self.nonce = 0
self.tr_list = tr_list
mt = MerkleTree(self.tr_list)
if len(tr_list) > 0:
self.mt_root = mt.root_val
else:
self.mt_root = utils.get_hash(None)
def set_nonce(self, nonce):
self.nonce = nonce
def set_ts(self, ts):
self.ts = ts
def output(self):
print("Block:", self.idx, "ver: ", self.ver, "time_stamp: ", self.ts, "fee", self.fee, "thresh", self.thresh)
print("pre_hash: ", self.pre_hash[:8])
print("addr: ", self.addr[:8])
print("mr_root: ", self.mt_root[:8])
print("nonce: ", self.nonce)
print("hash: ", utils.get_hash(self)[:8])
print("Fin.")
if __name__ == "__main__":
pass