import json
import hashlib
from datetime import datetime
class Block():
def real_time(self):
return datetime.fromtimestamp(self.timestamp).strftime('%Y-%m-%d %H:%M:%S')
def __init__(self, index, timestamp, data, previous_hash):
super().__init__()
self.index = index
self.timestamp = timestamp
self.data = data
self.previous_hash = previous_hash
self.hash = self.calculate_hash()
# Function to calculate hash values usinf SHA256 algorithm
def calculate_hash(self):
string_to_be_hashed = str(
self.index) + str(self.timestamp) + self.previous_hash + json.dumps(self.data)
byte_string = string_to_be_hashed.encode()
return hashlib.sha256(byte_string).hexdigest()
# Instanciating the object of Block class
block = Block(1, 77, "89", "0")
ans = block.calculate_hash()
print(ans)
print(block.real_time())
the argument passed in block for timestamp is having value 77 but the output I'm getting when calling real_time method is : 1970-01-01 05:31:17