-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBlock.py
More file actions
22 lines (18 loc) · 753 Bytes
/
Block.py
File metadata and controls
22 lines (18 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from HashGenerator import HashGenerator
from datetime import datetime
import json
class Block:
def __init__(self, created, transaction, previousHash=""):
self.created = created
self.transactions = transaction
self.previousHash = previousHash
self.temp = 0
self.currentHash = self.createHash()
def createHash(self):
transactionsToJsonString = json.dumps(
[t.__dict__ for t in self.transactions])
return HashGenerator(self.created + transactionsToJsonString + self.previousHash + str(self.temp))
def mineBlock(self, difficulty):
while (self.currentHash[0:difficulty] != "0"*difficulty):
self.temp += 1
self.currentHash = self.createHash()