added change modify pending tx, fixed same user tx
This commit is contained in:
parent
30bb49de03
commit
2c41f960b9
@ -17,6 +17,11 @@ def transaction(self):
|
|||||||
print("Username not found")
|
print("Username not found")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if receiver_data[1] == self.user.public_ser:
|
||||||
|
utilityHelper.clearScreen()
|
||||||
|
print("You cant send money to yourself")
|
||||||
|
return False
|
||||||
|
|
||||||
amount = input("Enter the amount excluding fees:")
|
amount = input("Enter the amount excluding fees:")
|
||||||
if amount == "":
|
if amount == "":
|
||||||
return False
|
return False
|
||||||
@ -56,7 +61,6 @@ def createBlock(self):
|
|||||||
except:
|
except:
|
||||||
lastBlock = []
|
lastBlock = []
|
||||||
|
|
||||||
print(lastBlock)
|
|
||||||
if lastBlock != []:
|
if lastBlock != []:
|
||||||
lastBlock = lastBlock[-1]
|
lastBlock = lastBlock[-1]
|
||||||
|
|
||||||
@ -171,7 +175,8 @@ def createBlock(self):
|
|||||||
transaction_count = 0
|
transaction_count = 0
|
||||||
for transaction in transactions:
|
for transaction in transactions:
|
||||||
if transaction_count not in selected_transactions:
|
if transaction_count not in selected_transactions:
|
||||||
utilityHelper.saveFile("../data/transaction_pool.dat", transactions[i])
|
utilityHelper.saveFile("../data/transaction_pool.dat", transaction)
|
||||||
|
transaction_count += 1
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -311,3 +316,173 @@ def getPersonalTransactions(self):
|
|||||||
print(f"Total balance: {total_output - total_input}")
|
print(f"Total balance: {total_output - total_input}")
|
||||||
print("-----------------------------------------------------------------------------------")
|
print("-----------------------------------------------------------------------------------")
|
||||||
|
|
||||||
|
def pendingTransactions(self):
|
||||||
|
transactions = utilityHelper.loadFile("../data/transaction_pool.dat")
|
||||||
|
total = 0
|
||||||
|
total_amount = 0
|
||||||
|
user_transactions = {}
|
||||||
|
for transaction in transactions:
|
||||||
|
|
||||||
|
# continue if transaction is a reward
|
||||||
|
if transaction.type != 0:
|
||||||
|
continue
|
||||||
|
if 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]}")
|
||||||
|
total_amount += transaction.inputs[0][1]
|
||||||
|
user_transactions[total] = transaction
|
||||||
|
|
||||||
|
if total == 0:
|
||||||
|
print("No transactions found")
|
||||||
|
return False
|
||||||
|
|
||||||
|
print("-----------------------------------------------------------------------------------")
|
||||||
|
print(f"Total transactions: {total}")
|
||||||
|
print(f"Total spent: {total_amount}")
|
||||||
|
print("-----------------------------------------------------------------------------------")
|
||||||
|
|
||||||
|
print("0 -- Go back")
|
||||||
|
print("1 -- Cancel/Modify transaction")
|
||||||
|
choice = input(">>: ")
|
||||||
|
|
||||||
|
match choice:
|
||||||
|
case "0":
|
||||||
|
utilityHelper.clearScreen()
|
||||||
|
return
|
||||||
|
case "1":
|
||||||
|
print("Select a transaction to modify/cancel")
|
||||||
|
user_input = input(">>: ")
|
||||||
|
try:
|
||||||
|
user_input = int(user_input)
|
||||||
|
except:
|
||||||
|
utilityHelper.clearScreen()
|
||||||
|
print("Wrong input, try again")
|
||||||
|
return
|
||||||
|
|
||||||
|
if user_input > total or user_input < 1:
|
||||||
|
utilityHelper.clearScreen()
|
||||||
|
print("Wrong input, try again")
|
||||||
|
return
|
||||||
|
|
||||||
|
if user_transactions[user_input].type == 1:
|
||||||
|
utilityHelper.clearScreen()
|
||||||
|
print("You cant modify/cancel a reward transaction")
|
||||||
|
return
|
||||||
|
|
||||||
|
# print info of that transaction
|
||||||
|
utilityHelper.clearScreen()
|
||||||
|
print(f"---------------------------------------{str(user_input)}-------------------------------------------")
|
||||||
|
print(f"Transaction input: {user_transactions.get(user_input).inputs[0][1]}")
|
||||||
|
print(f"Transaction output: {user_transactions.get(user_input).outputs[0][1]}")
|
||||||
|
print(f"Transaction fees: {user_transactions.get(user_input).inputs[0][1] - user_transactions.get(user_input).outputs[0][1]}")
|
||||||
|
print(f"Transaction sender: \n{user_transactions.get(user_input).inputs[0][0]}")
|
||||||
|
print(f"Transaction recipient: \n{user_transactions.get(user_input).outputs[0][0]}")
|
||||||
|
print(f"---------------------------------------END-------------------------------------------")
|
||||||
|
print("Modifying a transaction will bring you back in line, your transaction will lose the place in the pool.")
|
||||||
|
print("0 -- Go back")
|
||||||
|
print("1 -- Change amount")
|
||||||
|
print("2 -- Change Recipient")
|
||||||
|
print("3 -- Cancel transaction")
|
||||||
|
choice = input(">>: ")
|
||||||
|
|
||||||
|
match choice:
|
||||||
|
case "0":
|
||||||
|
utilityHelper.clearScreen()
|
||||||
|
return
|
||||||
|
case "1":
|
||||||
|
utilityHelper.clearScreen()
|
||||||
|
print("Enter a new amount")
|
||||||
|
amount = input(">>: ")
|
||||||
|
try:
|
||||||
|
amount = float(amount)
|
||||||
|
except:
|
||||||
|
utilityHelper.clearScreen()
|
||||||
|
print("Wrong input, try again")
|
||||||
|
return
|
||||||
|
|
||||||
|
print("Enter a new fee")
|
||||||
|
fee = input(">>: ")
|
||||||
|
|
||||||
|
try:
|
||||||
|
fee = float(fee)
|
||||||
|
except:
|
||||||
|
utilityHelper.clearScreen()
|
||||||
|
print("Wrong input, try again")
|
||||||
|
return
|
||||||
|
|
||||||
|
if amount + fee > getBalanceWithOutgoingPool(self, getBalance(self)):
|
||||||
|
utilityHelper.clearScreen()
|
||||||
|
print("You dont have enough money")
|
||||||
|
print("Nothing happened to the old transaction")
|
||||||
|
return False
|
||||||
|
|
||||||
|
new_tx = Tx()
|
||||||
|
new_tx.createTransaction(self.user.public_ser, self.user.private_ser, amount, fee, user_transactions[user_input].outputs[0][0])
|
||||||
|
|
||||||
|
# remove old transaction from array
|
||||||
|
transactions.remove(user_transactions[user_input])
|
||||||
|
utilityHelper.resetFile("../data/transaction_pool.dat")
|
||||||
|
|
||||||
|
# add old transactions to pool
|
||||||
|
for transaction in transactions:
|
||||||
|
utilityHelper.saveFile("../data/transaction_pool.dat", transaction)
|
||||||
|
utilityHelper.saveFile("../data/transaction_pool.dat", new_tx)
|
||||||
|
|
||||||
|
utilityHelper.clearScreen()
|
||||||
|
print("Transaction modified")
|
||||||
|
return
|
||||||
|
case "2":
|
||||||
|
print("Select a new recipient")
|
||||||
|
recipient = input(">>: ")
|
||||||
|
recipient_data = self.db.fetchUserByUsername(recipient)
|
||||||
|
if not recipient_data:
|
||||||
|
utilityHelper.clearScreen()
|
||||||
|
print("Username not found")
|
||||||
|
return False
|
||||||
|
|
||||||
|
if recipient_data[1] == self.user.public_ser:
|
||||||
|
utilityHelper.clearScreen()
|
||||||
|
print("You cant send money to yourself")
|
||||||
|
return False
|
||||||
|
|
||||||
|
new_tx = Tx()
|
||||||
|
new_tx.createTransaction(self.user.public_ser, self.user.private_ser, user_transactions[user_input].inputs[0][1], user_transactions[user_input].inputs[0][1] - user_transactions[user_input].outputs[0][1], recipient_data[1])
|
||||||
|
|
||||||
|
# remove old transaction from array
|
||||||
|
transactions.remove(user_transactions[user_input])
|
||||||
|
utilityHelper.resetFile("../data/transaction_pool.dat")
|
||||||
|
|
||||||
|
# add old transactions to pool
|
||||||
|
for transaction in transactions:
|
||||||
|
print(transaction)
|
||||||
|
utilityHelper.saveFile("../data/transaction_pool.dat", transaction)
|
||||||
|
utilityHelper.saveFile("../data/transaction_pool.dat", new_tx)
|
||||||
|
|
||||||
|
utilityHelper.clearScreen()
|
||||||
|
print("Transaction modified")
|
||||||
|
return
|
||||||
|
|
||||||
|
case "3":
|
||||||
|
# remove old transaction from array
|
||||||
|
transactions.remove(user_transactions[user_input])
|
||||||
|
utilityHelper.resetFile("../data/transaction_pool.dat")
|
||||||
|
|
||||||
|
# add old transactions to pool
|
||||||
|
for transaction in transactions:
|
||||||
|
utilityHelper.saveFile("../data/transaction_pool.dat", transaction)
|
||||||
|
utilityHelper.clearScreen()
|
||||||
|
print("Transaction cancelled")
|
||||||
|
return
|
||||||
|
case _:
|
||||||
|
utilityHelper.clearScreen()
|
||||||
|
print("Wrong input, try again")
|
||||||
|
return
|
||||||
|
case _:
|
||||||
|
utilityHelper.clearScreen()
|
||||||
|
print("Wrong input, try again")
|
||||||
|
return
|
Loading…
x
Reference in New Issue
Block a user