-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock.py
26 lines (22 loc) · 819 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:
# block constructor
# to this example simple as is possible nonce is allways zero
def __init__(self, previous_hash, timestamp, current_height, data, nonce=0):
self.previous_block_hash = previous_hash
self.timestamp = timestamp
self.current_height = current_height
self.data = data
self.nonce = nonce
self.hash = self.calculate_hash()
# func for calculate hash of block
# hash func SHA256
def calculate_hash(self):
block_string = (
str(self.previous_block_hash)
+ str(self.timestamp)
+ str(self.current_height)
+ str(self.data)
+ str(self.nonce)
)
return hashlib.sha256(block_string.encode("utf-8")).hexdigest()