forked from Priyadarshan2000/TOI-LOST-VOTE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlock.py
26 lines (22 loc) · 832 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
import hashlib
class Block:
def __init__(self, index, candidate_id, timestamp, proof, previous_hash):
self.index = index
self.candidate_id = candidate_id
self.timestamp = timestamp
self.proof = proof
self.previous_hash = previous_hash
self.hash = self.generate_hash()
def generate_hash(self):
lst = [self.index, self.candidate_id, self.timestamp, self.proof, self.previous_hash]
s = str(lst).encode()
return hashlib.sha256(s).hexdigest()
def toDict(self):
return {
'index': self.index,
'candidate_id': self.candidate_id,
'timestamp': self.timestamp,
'proof': self.proof,
'previous_hash': self.previous_hash,
'hash': self.hash
}