simplify error handling during transaction signing

This commit is contained in:
ThomasV 2014-10-23 16:32:27 +02:00
parent c226b29ff4
commit f00c4ed547
2 changed files with 11 additions and 23 deletions

View File

@ -1081,8 +1081,6 @@ class ElectrumWindow(QMainWindow):
tx = self.wallet.make_unsigned_transaction(outputs, fee, None, coins = coins)
if not tx:
raise BaseException(_("Insufficient funds"))
else:
tx.error = None
except Exception as e:
traceback.print_exc(file=sys.stdout)
self.show_message(str(e))
@ -1116,32 +1114,21 @@ class ElectrumWindow(QMainWindow):
if self.wallet.is_watching_only():
return tx
keypairs = {}
try:
self.wallet.add_keypairs(tx, keypairs, password)
self.wallet.sign_transaction(tx, keypairs, password)
except Exception as e:
traceback.print_exc(file=sys.stdout)
tx.error = str(e)
self.wallet.add_keypairs(tx, keypairs, password)
self.wallet.sign_transaction(tx, keypairs, password)
return tx
def sign_done(tx):
if tx.error:
self.show_message(tx.error)
self.send_button.setDisabled(False)
return
if label:
self.wallet.set_label(tx.hash(), label)
if not tx.is_complete() or self.config.get('show_before_broadcast'):
self.show_transaction(tx)
self.do_clear()
self.send_button.setDisabled(False)
return
self.broadcast_transaction(tx)
# keep a reference to WaitingDialog or the gui might crash
self.waiting_dialog = WaitingDialog(self, 'Signing..', sign_thread, sign_done)
self.waiting_dialog = WaitingDialog(self, 'Signing..', sign_thread, sign_done, lambda: self.send_button.setDisabled(False))
self.waiting_dialog.start()

View File

@ -17,7 +17,7 @@ else:
class WaitingDialog(QThread):
def __init__(self, parent, message, run_task, on_complete=None):
def __init__(self, parent, message, run_task, on_success=None, on_complete=None):
QThread.__init__(self)
self.parent = parent
self.d = QDialog(parent)
@ -26,6 +26,7 @@ class WaitingDialog(QThread):
vbox = QVBoxLayout(self.d)
vbox.addWidget(l)
self.run_task = run_task
self.on_success = on_success
self.on_complete = on_complete
self.d.connect(self.d, SIGNAL('done'), self.close)
self.d.show()
@ -43,14 +44,14 @@ class WaitingDialog(QThread):
self.d.accept()
if self.error:
QMessageBox.warning(self.parent, _('Error'), self.error, _('OK'))
return
else:
if self.on_success:
if type(self.result) is not tuple:
self.result = (self.result,)
self.on_success(*self.result)
if self.on_complete:
if type(self.result) is tuple:
self.on_complete(*self.result)
else:
self.on_complete(self.result)
self.on_complete()
class Timer(QThread):