-
Notifications
You must be signed in to change notification settings - Fork 1
/
block.py
45 lines (41 loc) · 1.35 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 transaction import Transaction
class Block:
def __init__(self,
difficulty,
minerId=-1,
index=0,
previous_hash=None,
timestamp=1618473245.5043766,
nonce=0):
self.index = index
self.previous_hash = previous_hash
self.timestamp = timestamp
self.transactions = []
self.nonce = nonce
self.minerId = minerId
self.minedAt = timestamp
self.difficulty = difficulty
# Get block datagithub
def get_block_data(self):
data = {
'index': self.index,
'previous_hash': self.previous_hash,
'timestamp': self.timestamp,
'transactions': self.transactions,
'nonce': self.nonce,
'minerId': self.minerId,
'difficulty': self.difficulty
}
return data
def printIt(self):
print('index : ', self.index)
print('miner id : ', self.minerId)
print('diificulty : ', self.difficulty)
if self.previous_hash != None:
print('previous_hash : ', self.previous_hash[-50:])
print('timestamp : ', self.timestamp)
print('transactions : ')
for t in self.transactions:
Transaction.printIt(t)
print('nonce : ', self.nonce)
print()