added balance check
This commit is contained in:
parent
711f7b1c63
commit
a15cdce0c0
@ -153,7 +153,8 @@ class MenuHelper:
|
|||||||
print("TODO")
|
print("TODO")
|
||||||
|
|
||||||
case "Check balance":
|
case "Check balance":
|
||||||
taskHelper.getBalance(self)
|
print(f"Your balance is: {taskHelper.getBalance(self)}")
|
||||||
|
|
||||||
|
|
||||||
case "Check the pool":
|
case "Check the pool":
|
||||||
transactions = utilityHelper.loadFile("../data/transaction_pool.dat")
|
transactions = utilityHelper.loadFile("../data/transaction_pool.dat")
|
||||||
|
@ -22,7 +22,7 @@ def transaction(self):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
amount = int(amount)
|
amount = float(amount)
|
||||||
except:
|
except:
|
||||||
print("Wrong input, try again")
|
print("Wrong input, try again")
|
||||||
return False
|
return False
|
||||||
@ -32,11 +32,19 @@ def transaction(self):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fee = int(fee)
|
fee = float(fee)
|
||||||
except:
|
except:
|
||||||
print("Wrong input, try again")
|
print("Wrong input, try again")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
utilityHelper.clearScreen()
|
||||||
|
|
||||||
|
print(f"Processing transaction of {amount + fee} coins, {receiver} will receive {amount} coins")
|
||||||
|
|
||||||
|
if amount + fee > getBalance(self):
|
||||||
|
print("You dont have enough money")
|
||||||
|
return False
|
||||||
|
|
||||||
new_tx = Tx()
|
new_tx = Tx()
|
||||||
new_tx.createTransaction(self.user.public_ser, self.user.private_ser, amount, fee, receiver_data[1])
|
new_tx.createTransaction(self.user.public_ser, self.user.private_ser, amount, fee, receiver_data[1])
|
||||||
return new_tx
|
return new_tx
|
||||||
@ -194,5 +202,4 @@ 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]
|
||||||
print(f"Your balance is: {balance}")
|
|
||||||
return balance
|
return balance
|
Loading…
x
Reference in New Issue
Block a user