From 9365b0f924a41284b471ba6a0521003dd76151ac Mon Sep 17 00:00:00 2001 From: SomberNight Date: Thu, 14 Jun 2018 22:36:54 +0200 Subject: [PATCH] RBF: better exception handling --- gui/qt/main_window.py | 7 +++---- lib/wallet.py | 7 +++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py index 13ff3388e..ed914efa1 100644 --- a/gui/qt/main_window.py +++ b/gui/qt/main_window.py @@ -53,7 +53,7 @@ from electrum.util import (format_time, format_satoshis, format_fee_satoshis, from electrum import Transaction from electrum import util, bitcoin, commands, coinchooser from electrum import paymentrequest -from electrum.wallet import Multisig_Wallet, AddTransactionException +from electrum.wallet import Multisig_Wallet, AddTransactionException, CannotBumpFee from .amountedit import AmountEdit, BTCAmountEdit, MyLineEdit, FeerateEdit from .qrcodewidget import QRCodeWidget, QRDialog @@ -3165,9 +3165,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): return try: new_tx = self.wallet.bump_fee(tx, delta) - except BaseException as e: - traceback.print_exc(file=sys.stderr) - self.show_error(_('Error bumping fee') + ':\n' + str(e)) + except CannotBumpFee as e: + self.show_error(str(e)) return if is_final: new_tx.set_rbf(False) diff --git a/lib/wallet.py b/lib/wallet.py index e0f968f7e..5126c15fa 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -170,6 +170,9 @@ class UnrelatedTransactionException(AddTransactionException): return _("Transaction is unrelated to this wallet.") +class CannotBumpFee(Exception): pass + + class Abstract_Wallet(PrintError): """ Wallet classes are created to handle various address generation methods. @@ -1377,7 +1380,7 @@ class Abstract_Wallet(PrintError): def bump_fee(self, tx, delta): if tx.is_final(): - raise Exception(_('Cannot bump fee') + ': ' + _('transaction is final')) + raise CannotBumpFee(_('Cannot bump fee') + ': ' + _('transaction is final')) tx = Transaction(tx.serialize()) tx.deserialize(force_full_parse=True) # need to parse inputs inputs = copy.deepcopy(tx.inputs()) @@ -1410,7 +1413,7 @@ class Abstract_Wallet(PrintError): if delta > 0: continue if delta > 0: - raise Exception(_('Cannot bump fee') + ': ' + _('could not find suitable outputs')) + raise CannotBumpFee(_('Cannot bump fee') + ': ' + _('could not find suitable outputs')) locktime = self.get_local_height() tx_new = Transaction.from_io(inputs, outputs, locktime=locktime) tx_new.BIP_LI01_sort()