-
Notifications
You must be signed in to change notification settings - Fork 0
/
block.py
23 lines (19 loc) · 801 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
import datetime
from hashlib import sha256
#changed data to transactions
class Block:
def __init__(self, transactions, previous_hash):
self.time_stamp = datetime.datetime.now()
self.transactions = transactions
self.previous_hash = previous_hash
self.nonce = 0
self.hash = self.generate_hash()
def generate_hash(self):
block_header = str(self.time_stamp) + str(self.transactions) +str(self.previous_hash) + str(self.nonce)
block_hash = sha256(block_header.encode())
return block_hash.hexdigest()
def print_contents(self):
print("timestamp:", self.time_stamp)
print("transactions:", self.transactions)
print("current hash:", self.generate_hash())
print("previous hash:", self.previous_hash)