added time to block

This commit is contained in:
Ryan Bakkes 2023-11-09 09:56:16 +01:00
parent 2d60686f38
commit 20361590ff

View File

@ -121,8 +121,7 @@ def createBlock(self):
# add block to blockchain # add block to blockchain
block.time = elapsed block.time = elapsed
block.nonce = nonce block.nonce = nonce
# TODO ADD DATE block.date = time.time()
block.date = None
utilityHelper.saveFile("../data/ledger.dat", block) utilityHelper.saveFile("../data/ledger.dat", block)
# TODO remove transactions from transaction pool # TODO remove transactions from transaction pool
@ -137,8 +136,11 @@ def exploreBlocks(self):
x += 1 x += 1
total_transactions += len(block.data) total_transactions += len(block.data)
print(f"---------------------------------------{x}-------------------------------------------") print(f"---------------------------------------{x}-------------------------------------------")
print(f"Block created: {block.date}") print(f"Block created: {time.strftime('%Y-%m-%d', time.localtime(block.date))}")
print("---------------------------------------END-------------------------------------------") print("---------------------------------------END-------------------------------------------")
print(f"Total blocks: {x}")
print(f"Total transactions: {total_transactions}")
print("-----------------------------------------------------------------------------------")
print("Select a number to view the block, keep empty to return.") print("Select a number to view the block, keep empty to return.")
user_input = input(">>: ") user_input = input(">>: ")
if user_input == "": if user_input == "":
@ -159,7 +161,7 @@ def exploreBlocks(self):
# print all info of the block # print all info of the block
utilityHelper.clearScreen() utilityHelper.clearScreen()
print(f"---------------------------------------{user_input +1}-------------------------------------------") print(f"---------------------------------------{user_input +1}-------------------------------------------")
print(f"Block created: {blocks[user_input].date}") print(f"Block created: {time.strftime('%Y-%m-%d', time.localtime(blocks[user_input].date))}")
print(f"Block hash: {blocks[user_input].blockHash}") print(f"Block hash: {blocks[user_input].blockHash}")
print(f"Block nonce: {blocks[user_input].nonce}") print(f"Block nonce: {blocks[user_input].nonce}")
print(f"Block mined time: {blocks[user_input].time}") print(f"Block mined time: {blocks[user_input].time}")