view personal transactions and changed counters
This commit is contained in:
parent
a15cdce0c0
commit
2d60686f38
@ -37,11 +37,12 @@ class MenuHelper:
|
|||||||
|
|
||||||
self.user_blockchain_menu[0] = "Back"
|
self.user_blockchain_menu[0] = "Back"
|
||||||
self.user_blockchain_menu[1] = "Explore the Blockchain"
|
self.user_blockchain_menu[1] = "Explore the Blockchain"
|
||||||
self.user_blockchain_menu[2] = "Transfer coins"
|
self.user_blockchain_menu[2] = "View personal transactions"
|
||||||
self.user_blockchain_menu[3] = "Cancel transaction"
|
self.user_blockchain_menu[3] = "Transfer coins"
|
||||||
self.user_blockchain_menu[4] = "Check balance"
|
self.user_blockchain_menu[4] = "Cancel transaction"
|
||||||
self.user_blockchain_menu[5] = "Check the pool"
|
self.user_blockchain_menu[5] = "Check balance"
|
||||||
self.user_blockchain_menu[6] = "Mine a block"
|
self.user_blockchain_menu[6] = "Check the pool"
|
||||||
|
self.user_blockchain_menu[7] = "Mine a block"
|
||||||
|
|
||||||
self.user_settings_menu[0] = "Back"
|
self.user_settings_menu[0] = "Back"
|
||||||
self.user_settings_menu[1] = "View account info"
|
self.user_settings_menu[1] = "View account info"
|
||||||
@ -141,6 +142,9 @@ class MenuHelper:
|
|||||||
case "Explore the Blockchain":
|
case "Explore the Blockchain":
|
||||||
taskHelper.exploreBlocks(self)
|
taskHelper.exploreBlocks(self)
|
||||||
|
|
||||||
|
case "View personal transactions":
|
||||||
|
taskHelper.getPersonalTransactions(self)
|
||||||
|
|
||||||
case "Transfer coins":
|
case "Transfer coins":
|
||||||
new_tx = taskHelper.transaction(self)
|
new_tx = taskHelper.transaction(self)
|
||||||
if new_tx != False and new_tx.is_valid():
|
if new_tx != False and new_tx.is_valid():
|
||||||
@ -207,6 +211,11 @@ class MenuHelper:
|
|||||||
utilityHelper.clearScreen()
|
utilityHelper.clearScreen()
|
||||||
print("Wrong input, try again")
|
print("Wrong input, try again")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
if choice > len(menu):
|
||||||
|
utilityHelper.clearScreen()
|
||||||
|
print("Wrong input, try again")
|
||||||
|
return None
|
||||||
utilityHelper.clearScreen()
|
utilityHelper.clearScreen()
|
||||||
|
|
||||||
return choice
|
return choice
|
@ -132,10 +132,12 @@ def createBlock(self):
|
|||||||
def exploreBlocks(self):
|
def exploreBlocks(self):
|
||||||
blocks = utilityHelper.loadFile("../data/ledger.dat")
|
blocks = utilityHelper.loadFile("../data/ledger.dat")
|
||||||
x = 0
|
x = 0
|
||||||
|
total_transactions = 0
|
||||||
for block in blocks:
|
for block in blocks:
|
||||||
|
x += 1
|
||||||
|
total_transactions += len(block.data)
|
||||||
print(f"---------------------------------------{x}-------------------------------------------")
|
print(f"---------------------------------------{x}-------------------------------------------")
|
||||||
print(f"Block created: {block.date}")
|
print(f"Block created: {block.date}")
|
||||||
x += 1
|
|
||||||
print("---------------------------------------END-------------------------------------------")
|
print("---------------------------------------END-------------------------------------------")
|
||||||
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(">>: ")
|
||||||
@ -143,30 +145,31 @@ def exploreBlocks(self):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user_input = int(user_input)
|
user_input = int(user_input) -1
|
||||||
except:
|
except:
|
||||||
utilityHelper.clearScreen()
|
utilityHelper.clearScreen()
|
||||||
print("Wrong input, try again")
|
print("Wrong input, try again")
|
||||||
return
|
return
|
||||||
|
|
||||||
if user_input > len(blocks):
|
if user_input > len(blocks) - 1 or user_input < 0:
|
||||||
utilityHelper.clearScreen()
|
utilityHelper.clearScreen()
|
||||||
print("Wrong input, try again")
|
print("Wrong input, try again")
|
||||||
return
|
return
|
||||||
|
|
||||||
# print all info of the block
|
# print all info of the block
|
||||||
utilityHelper.clearScreen()
|
utilityHelper.clearScreen()
|
||||||
print(f"---------------------------------------{user_input}-------------------------------------------")
|
print(f"---------------------------------------{user_input +1}-------------------------------------------")
|
||||||
print(f"Block created: {blocks[user_input].date}")
|
print(f"Block created: {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}")
|
||||||
# print(f"Block transactions: {blocks[user_input].transactions}")
|
print(f"Block transactions: {len(blocks[user_input].data)}")
|
||||||
print(f"Block previous hash: {blocks[user_input].previousHash}")
|
print(f"Block previous hash: {blocks[user_input].previousHash}")
|
||||||
print("---------------------------------------------------------------------------------------")
|
print("---------------------------------------------------------------------------------------")
|
||||||
print("0 -- go back")
|
print("0 -- Go back")
|
||||||
print("1 -- View transactions of current block")
|
print("1 -- Validate block")
|
||||||
print("2 -- View another block")
|
print("2 -- View transactions of current block")
|
||||||
|
print("3 -- View another block")
|
||||||
choice = input(">>: ")
|
choice = input(">>: ")
|
||||||
|
|
||||||
match choice:
|
match choice:
|
||||||
@ -174,18 +177,20 @@ def exploreBlocks(self):
|
|||||||
utilityHelper.clearScreen()
|
utilityHelper.clearScreen()
|
||||||
return
|
return
|
||||||
case "1":
|
case "1":
|
||||||
|
print("Validating block... TODO")
|
||||||
|
case "2":
|
||||||
utilityHelper.clearScreen()
|
utilityHelper.clearScreen()
|
||||||
x = 0
|
x = 0
|
||||||
for transaction in blocks[user_input].data:
|
for transaction in blocks[user_input].data:
|
||||||
|
x += 1
|
||||||
print(f"---------------------------------------{x}-------------------------------------------")
|
print(f"---------------------------------------{x}-------------------------------------------")
|
||||||
print(f"Transaction input: {transaction.inputs[0][1]}")
|
print(f"Transaction input: {transaction.inputs[0][1]}")
|
||||||
print(f"Transaction output: {transaction.outputs[0][1]}")
|
print(f"Transaction output: {transaction.outputs[0][1]}")
|
||||||
print(f"Transaction fees: {transaction.inputs[0][1] - transaction.outputs[0][1]}")
|
print(f"Transaction fees: {transaction.inputs[0][1] - transaction.outputs[0][1]}")
|
||||||
print(f"Transaction sender: \n{transaction.inputs[0][0]}")
|
print(f"Transaction sender: \n{transaction.inputs[0][0]}")
|
||||||
print(f"Transaction recipient: \n{transaction.outputs[0][0]}")
|
print(f"Transaction recipient: \n{transaction.outputs[0][0]}")
|
||||||
x += 1
|
|
||||||
print("-----------------------------------------------------------------------------------")
|
print("-----------------------------------------------------------------------------------")
|
||||||
case "2":
|
case "3":
|
||||||
utilityHelper.clearScreen()
|
utilityHelper.clearScreen()
|
||||||
exploreBlocks(self)
|
exploreBlocks(self)
|
||||||
case _:
|
case _:
|
||||||
@ -202,4 +207,32 @@ def getBalance(self):
|
|||||||
balance += transaction.outputs[0][1]
|
balance += transaction.outputs[0][1]
|
||||||
elif transaction.inputs[0][0] == self.user.public_ser:
|
elif transaction.inputs[0][0] == self.user.public_ser:
|
||||||
balance -= transaction.inputs[0][1]
|
balance -= transaction.inputs[0][1]
|
||||||
return balance
|
return balance
|
||||||
|
|
||||||
|
def getPersonalTransactions(self):
|
||||||
|
blocks = utilityHelper.loadFile("../data/ledger.dat")
|
||||||
|
total = 0
|
||||||
|
total_input = 0
|
||||||
|
total_output = 0
|
||||||
|
for block in blocks:
|
||||||
|
for transaction in block.data:
|
||||||
|
if transaction.outputs[0][0] == self.user.public_ser or transaction.inputs[0][0] == self.user.public_ser:
|
||||||
|
total += 1
|
||||||
|
print(f"---------------------------------------{total}-------------------------------------------")
|
||||||
|
print(f"Transaction input: {transaction.inputs[0][1]}")
|
||||||
|
print(f"Transaction output: {transaction.outputs[0][1]}")
|
||||||
|
print(f"Transaction fees: {transaction.inputs[0][1] - transaction.outputs[0][1]}")
|
||||||
|
print(f"Transaction sender: \n{transaction.inputs[0][0]}")
|
||||||
|
print(f"Transaction recipient: \n{transaction.outputs[0][0]}")
|
||||||
|
|
||||||
|
if transaction.outputs[0][0] == self.user.public_ser:
|
||||||
|
total_output += transaction.outputs[0][1]
|
||||||
|
elif transaction.inputs[0][0] == self.user.public_ser:
|
||||||
|
total_input += transaction.inputs[0][1]
|
||||||
|
print("-----------------------------------------------------------------------------------")
|
||||||
|
print(f"Total transactions: {total}")
|
||||||
|
print(f"Total spent: {total_input}")
|
||||||
|
print(f"Total received: {total_output}")
|
||||||
|
print(f"Total balance: {total_output - total_input}")
|
||||||
|
print("-----------------------------------------------------------------------------------")
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user