Merge pull request #1275 from kyuupichan/tx_dialog_send_tx
Have transaction_dialog use send_tx()
This commit is contained in:
commit
7e0a80b697
|
@ -1073,7 +1073,7 @@ class ElectrumWindow(QMainWindow):
|
||||||
r = self.read_send_tab()
|
r = self.read_send_tab()
|
||||||
if not r:
|
if not r:
|
||||||
return
|
return
|
||||||
outputs, fee, label, coins = r
|
outputs, fee, tx_desc, coins = r
|
||||||
try:
|
try:
|
||||||
tx = self.wallet.make_unsigned_transaction(coins, outputs, fee)
|
tx = self.wallet.make_unsigned_transaction(coins, outputs, fee)
|
||||||
if not tx:
|
if not tx:
|
||||||
|
@ -1096,39 +1096,45 @@ class ElectrumWindow(QMainWindow):
|
||||||
if not self.question(_("The fee for this transaction seems unusually high.\nAre you really sure you want to pay %(fee)s in fees?")%{ 'fee' : self.format_amount(fee) + ' '+ self.base_unit()}):
|
if not self.question(_("The fee for this transaction seems unusually high.\nAre you really sure you want to pay %(fee)s in fees?")%{ 'fee' : self.format_amount(fee) + ' '+ self.base_unit()}):
|
||||||
return
|
return
|
||||||
|
|
||||||
self.send_tx(tx, label)
|
def sign_done(success):
|
||||||
|
if success:
|
||||||
|
if not tx.is_complete() or self.config.get('show_before_broadcast'):
|
||||||
|
self.show_transaction(tx)
|
||||||
|
self.do_clear()
|
||||||
|
else:
|
||||||
|
self.broadcast_transaction(tx, tx_desc)
|
||||||
|
|
||||||
|
self.send_tx(tx, sign_done)
|
||||||
|
|
||||||
|
|
||||||
@protected
|
@protected
|
||||||
def send_tx(self, tx, label, password):
|
def send_tx(self, tx, callback, password):
|
||||||
|
'''Sign the transaction in a separate thread. When done, calls
|
||||||
|
the callback with a success code of True or False.
|
||||||
|
'''
|
||||||
self.send_button.setDisabled(True)
|
self.send_button.setDisabled(True)
|
||||||
|
|
||||||
# call hook to see if plugin needs gui interaction
|
# call hook to see if plugin needs gui interaction
|
||||||
run_hook('send_tx', tx)
|
run_hook('send_tx', tx)
|
||||||
|
|
||||||
# sign the tx
|
# sign the tx
|
||||||
|
success = [False] # Array to work around python scoping
|
||||||
def sign_thread():
|
def sign_thread():
|
||||||
if self.wallet.is_watching_only():
|
if not self.wallet.is_watching_only():
|
||||||
return tx
|
self.wallet.sign_transaction(tx, password)
|
||||||
self.wallet.sign_transaction(tx, password)
|
def on_sign_successful(ret):
|
||||||
return tx
|
success[0] = True
|
||||||
|
def on_dialog_close():
|
||||||
def sign_done(tx):
|
self.send_button.setDisabled(False)
|
||||||
if label and tx.is_complete():
|
callback(success[0])
|
||||||
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()
|
|
||||||
return
|
|
||||||
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, lambda: self.send_button.setDisabled(False))
|
self.waiting_dialog = WaitingDialog(self, 'Signing transaction...', sign_thread, on_sign_successful, on_dialog_close)
|
||||||
self.waiting_dialog.start()
|
self.waiting_dialog.start()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def broadcast_transaction(self, tx):
|
def broadcast_transaction(self, tx, tx_desc):
|
||||||
|
|
||||||
def broadcast_thread():
|
def broadcast_thread():
|
||||||
# non-GUI thread
|
# non-GUI thread
|
||||||
|
@ -1153,6 +1159,8 @@ class ElectrumWindow(QMainWindow):
|
||||||
def broadcast_done(status, msg):
|
def broadcast_done(status, msg):
|
||||||
# GUI thread
|
# GUI thread
|
||||||
if status:
|
if status:
|
||||||
|
if tx_desc is not None and tx.is_complete():
|
||||||
|
self.wallet.set_label(tx.hash(), tx_desc)
|
||||||
QMessageBox.information(self, '', _('Payment sent.') + '\n' + msg, _('OK'))
|
QMessageBox.information(self, '', _('Payment sent.') + '\n' + msg, _('OK'))
|
||||||
self.update_invoices_list()
|
self.update_invoices_list()
|
||||||
self.do_clear()
|
self.do_clear()
|
||||||
|
@ -1160,7 +1168,7 @@ class ElectrumWindow(QMainWindow):
|
||||||
QMessageBox.warning(self, _('Error'), msg, _('OK'))
|
QMessageBox.warning(self, _('Error'), msg, _('OK'))
|
||||||
self.send_button.setDisabled(False)
|
self.send_button.setDisabled(False)
|
||||||
|
|
||||||
self.waiting_dialog = WaitingDialog(self, 'Broadcasting..', broadcast_thread, broadcast_done)
|
self.waiting_dialog = WaitingDialog(self, 'Broadcasting transaction...', broadcast_thread, broadcast_done)
|
||||||
self.waiting_dialog.start()
|
self.waiting_dialog.start()
|
||||||
|
|
||||||
|
|
||||||
|
@ -2114,14 +2122,6 @@ class ElectrumWindow(QMainWindow):
|
||||||
return self.tx_from_text(file_content)
|
return self.tx_from_text(file_content)
|
||||||
|
|
||||||
|
|
||||||
@protected
|
|
||||||
def sign_raw_transaction(self, tx, password):
|
|
||||||
try:
|
|
||||||
self.wallet.sign_transaction(tx, password)
|
|
||||||
except Exception as e:
|
|
||||||
traceback.print_exc(file=sys.stdout)
|
|
||||||
QMessageBox.warning(self, _("Error"), str(e))
|
|
||||||
|
|
||||||
def do_process_from_text(self):
|
def do_process_from_text(self):
|
||||||
text = text_dialog(self, _('Input raw transaction'), _("Transaction:"), _("Load transaction"))
|
text = text_dialog(self, _('Input raw transaction'), _("Transaction:"), _("Load transaction"))
|
||||||
if not text:
|
if not text:
|
||||||
|
|
|
@ -103,7 +103,7 @@ class TxDialog(QWidget):
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def do_broadcast(self):
|
def do_broadcast(self):
|
||||||
self.parent.broadcast_transaction(self.tx)
|
self.parent.broadcast_transaction(self.tx, None)
|
||||||
self.saved = True
|
self.saved = True
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
@ -124,9 +124,11 @@ class TxDialog(QWidget):
|
||||||
|
|
||||||
|
|
||||||
def sign(self):
|
def sign(self):
|
||||||
self.parent.sign_raw_transaction(self.tx)
|
def sign_done(success):
|
||||||
self.update()
|
self.sign_button.setDisabled(False)
|
||||||
|
self.update()
|
||||||
|
self.sign_button.setDisabled(True)
|
||||||
|
self.parent.send_tx(self.tx, sign_done)
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
name = 'signed_%s.txn' % (self.tx.hash()[0:8]) if self.tx.is_complete() else 'unsigned.txn'
|
name = 'signed_%s.txn' % (self.tx.hash()[0:8]) if self.tx.is_complete() else 'unsigned.txn'
|
||||||
|
|
Loading…
Reference in New Issue