-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsortium_Blockchain.py
48 lines (37 loc) · 1016 Bytes
/
Consortium_Blockchain.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
46
47
48
from Block import Block
import copy
class Consortium_Blockchain:
def __init__(self):
self.chain = []
self.tmpchain = []
self.tmpdata = []
def return_chain_structure(self):
return self.chain
def return_chain_length(self):
return len(self.chain)
def return_last_block(self):
if len(self.chain) > 0:
return self.chain[-1]
else:
# blockchain doesn't even have its genesis block
return None
def return_last_block_pow_proof(self):
if len(self.chain) > 0:
return self.return_last_block().compute_hash(hash_entire_block=True)
else:
return None
def replace_chain(self, chain):
self.chain = copy.copy(chain)
def append_block(self, block):
self.chain.append(copy.copy(block))
def new_local_block(self, block, cdata = None):
self.tmpchain.append(block)
if cdata is not None:
self.tmpdata.append(cdata)
def return_local_chain(self):
return self.tmpchain
def return_last_cdata(self):
if len(self.tmpdata) > 0:
return self.tmpdata[-1]
else:
return None