simplify error handling during transaction signing
This commit is contained in:
parent
c226b29ff4
commit
f00c4ed547
|
@ -1081,8 +1081,6 @@ class ElectrumWindow(QMainWindow):
|
||||||
tx = self.wallet.make_unsigned_transaction(outputs, fee, None, coins = coins)
|
tx = self.wallet.make_unsigned_transaction(outputs, fee, None, coins = coins)
|
||||||
if not tx:
|
if not tx:
|
||||||
raise BaseException(_("Insufficient funds"))
|
raise BaseException(_("Insufficient funds"))
|
||||||
else:
|
|
||||||
tx.error = None
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc(file=sys.stdout)
|
traceback.print_exc(file=sys.stdout)
|
||||||
self.show_message(str(e))
|
self.show_message(str(e))
|
||||||
|
@ -1116,32 +1114,21 @@ class ElectrumWindow(QMainWindow):
|
||||||
if self.wallet.is_watching_only():
|
if self.wallet.is_watching_only():
|
||||||
return tx
|
return tx
|
||||||
keypairs = {}
|
keypairs = {}
|
||||||
try:
|
|
||||||
self.wallet.add_keypairs(tx, keypairs, password)
|
self.wallet.add_keypairs(tx, keypairs, password)
|
||||||
self.wallet.sign_transaction(tx, keypairs, password)
|
self.wallet.sign_transaction(tx, keypairs, password)
|
||||||
except Exception as e:
|
|
||||||
traceback.print_exc(file=sys.stdout)
|
|
||||||
tx.error = str(e)
|
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
def sign_done(tx):
|
def sign_done(tx):
|
||||||
if tx.error:
|
|
||||||
self.show_message(tx.error)
|
|
||||||
self.send_button.setDisabled(False)
|
|
||||||
return
|
|
||||||
if label:
|
if label:
|
||||||
self.wallet.set_label(tx.hash(), label)
|
self.wallet.set_label(tx.hash(), label)
|
||||||
|
|
||||||
if not tx.is_complete() or self.config.get('show_before_broadcast'):
|
if not tx.is_complete() or self.config.get('show_before_broadcast'):
|
||||||
self.show_transaction(tx)
|
self.show_transaction(tx)
|
||||||
self.do_clear()
|
self.do_clear()
|
||||||
self.send_button.setDisabled(False)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
self.broadcast_transaction(tx)
|
self.broadcast_transaction(tx)
|
||||||
|
|
||||||
# keep a reference to WaitingDialog or the gui might crash
|
# 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()
|
self.waiting_dialog.start()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ else:
|
||||||
|
|
||||||
|
|
||||||
class WaitingDialog(QThread):
|
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)
|
QThread.__init__(self)
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.d = QDialog(parent)
|
self.d = QDialog(parent)
|
||||||
|
@ -26,6 +26,7 @@ class WaitingDialog(QThread):
|
||||||
vbox = QVBoxLayout(self.d)
|
vbox = QVBoxLayout(self.d)
|
||||||
vbox.addWidget(l)
|
vbox.addWidget(l)
|
||||||
self.run_task = run_task
|
self.run_task = run_task
|
||||||
|
self.on_success = on_success
|
||||||
self.on_complete = on_complete
|
self.on_complete = on_complete
|
||||||
self.d.connect(self.d, SIGNAL('done'), self.close)
|
self.d.connect(self.d, SIGNAL('done'), self.close)
|
||||||
self.d.show()
|
self.d.show()
|
||||||
|
@ -43,14 +44,14 @@ class WaitingDialog(QThread):
|
||||||
self.d.accept()
|
self.d.accept()
|
||||||
if self.error:
|
if self.error:
|
||||||
QMessageBox.warning(self.parent, _('Error'), self.error, _('OK'))
|
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 self.on_complete:
|
||||||
if type(self.result) is tuple:
|
self.on_complete()
|
||||||
self.on_complete(*self.result)
|
|
||||||
else:
|
|
||||||
self.on_complete(self.result)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Timer(QThread):
|
class Timer(QThread):
|
||||||
|
|
Loading…
Reference in New Issue