-
Notifications
You must be signed in to change notification settings - Fork 0
/
Block.py
28 lines (23 loc) · 811 Bytes
/
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
import time
import copy
class Block():
def __init__(self, transactions, lastHash, forger, blockCount):
self.transactions = transactions
self.lastHash = lastHash
self.forger = forger
self.blockCount = blockCount
self.timestamp = time.time()
self.signature = ''
def sign(self, signature):
self.signature = signature
def toJson(self):
data = copy.deepcopy(self.__dict__)
jsonTransactions = []
for transaction in self.transactions:
jsonTransactions.append(transaction.toJson())
data['transactions'] = jsonTransactions
return data
def payload(self):
jsonRepresentation = copy.deepcopy(self.toJson())
jsonRepresentation['signature'] = ''
return jsonRepresentation