From f758d7e0abf23bf8f51bb512d6fbe6ca44fbc7ac Mon Sep 17 00:00:00 2001 From: Inso <insomniak.fr@gmail.com> Date: Tue, 6 Jan 2015 20:44:57 +0100 Subject: [PATCH] Added error when not enough sources / money is available --- src/cutecoin/core/wallet.py | 3 ++- src/cutecoin/gui/transfer.py | 5 +++++ src/cutecoin/tools/exceptions.py | 8 ++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/cutecoin/core/wallet.py b/src/cutecoin/core/wallet.py index 888f0e42..ad02a6ef 100644 --- a/src/cutecoin/core/wallet.py +++ b/src/cutecoin/core/wallet.py @@ -178,7 +178,8 @@ class Wallet(object): self.available_inputs = (block['number'], buf_inputs) return inputs - raise NotEnoughMoneyError(amount, value) + raise NotEnoughMoneyError(amount, community.currency, + len(inputs), value) return [] def tx_outputs(self, pubkey, amount, inputs): diff --git a/src/cutecoin/gui/transfer.py b/src/cutecoin/gui/transfer.py index 146aa472..9e249701 100644 --- a/src/cutecoin/gui/transfer.py +++ b/src/cutecoin/gui/transfer.py @@ -5,6 +5,7 @@ Created on 2 févr. 2014 ''' from PyQt5.QtWidgets import QDialog, QErrorMessage, QInputDialog, QLineEdit, QMessageBox +from ..tools.exceptions import NotEnoughMoneyError from ..core.person import Person from ..gen_resources.transfer_uic import Ui_TransferMoneyDialog @@ -65,6 +66,10 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): QMessageBox.critical(self, "Money transfer", "Something wrong happened : {0}".format(e), QMessageBox.Ok) + except NotEnoughMoneyError as e: + QMessageBox.critical(self, "Money transfer", + "You don't have enough money available in this block : \n{0}" + .format(e.message)) self.accepted.emit() self.close() diff --git a/src/cutecoin/tools/exceptions.py b/src/cutecoin/tools/exceptions.py index 246f94ed..94be374c 100644 --- a/src/cutecoin/tools/exceptions.py +++ b/src/cutecoin/tools/exceptions.py @@ -120,9 +120,13 @@ class NotEnoughMoneyError(Error): a key already used for another account. ''' - def __init__(self, available, requested): + def __init__(self, available, currency, nb_inputs, requested): ''' Constructor ''' super() .__init__( - "Key owns only {0} money, needs {1}".format(available, requested)) + "Only {0} {1} available in {2} sources, needs {3}" + .format(available, + currency, + nb_inputs, + requested)) -- GitLab