-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.py
More file actions
42 lines (34 loc) · 1.13 KB
/
Block.py
File metadata and controls
42 lines (34 loc) · 1.13 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
import copy
import time
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 = ''
@staticmethod
def genesis():
genesisBlock = Block([], 'genesisHash', 'genesis', 0)
genesisBlock.timestamp = 0
return genesisBlock
def toJson(self):
data = {
'lastHash': self.lastHash,
'forger': self.forger,
'blockCount': self.blockCount,
'timestamp': self.timestamp,
'signature': self.signature
}
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
def sign(self, signature):
self.signature = signature