Merge branch 'master' of git://github.com/spesmilo/electrum
This commit is contained in:
commit
93e8c7da6e
@ -1043,7 +1043,31 @@ class ElectrumWindow(QMainWindow):
|
|||||||
self.completions.setStringList(l)
|
self.completions.setStringList(l)
|
||||||
|
|
||||||
def protected(func):
|
def protected(func):
|
||||||
return lambda s, *args: s.do_protect(func, args)
|
'''Password request wrapper. The password is passed to the function
|
||||||
|
as the 'password' named argument. Return value is a 2-element
|
||||||
|
tuple: (Cancelled, Result) where Cancelled is True if the user
|
||||||
|
cancels the password request, otherwise False. Result is the
|
||||||
|
return value of the wrapped function, or None if cancelled.
|
||||||
|
'''
|
||||||
|
def request_password(self, *args, **kwargs):
|
||||||
|
parent = kwargs.get('parent', self)
|
||||||
|
if self.wallet.use_encryption:
|
||||||
|
while True:
|
||||||
|
password = self.password_dialog(parent=parent)
|
||||||
|
if not password:
|
||||||
|
return True, None
|
||||||
|
try:
|
||||||
|
self.wallet.check_password(password)
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
QMessageBox.warning(parent, _('Error'), str(e), _('OK'))
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
password = None
|
||||||
|
|
||||||
|
kwargs['password'] = password
|
||||||
|
return False, func(self, *args, **kwargs)
|
||||||
|
return request_password
|
||||||
|
|
||||||
def read_send_tab(self):
|
def read_send_tab(self):
|
||||||
if self.payment_request and self.payment_request.has_expired():
|
if self.payment_request and self.payment_request.has_expired():
|
||||||
@ -1141,10 +1165,12 @@ class ElectrumWindow(QMainWindow):
|
|||||||
|
|
||||||
|
|
||||||
@protected
|
@protected
|
||||||
def sign_tx(self, tx, callback, password):
|
def sign_tx(self, tx, callback, password, parent=None):
|
||||||
'''Sign the transaction in a separate thread. When done, calls
|
'''Sign the transaction in a separate thread. When done, calls
|
||||||
the callback with a success code of True or False.
|
the callback with a success code of True or False.
|
||||||
'''
|
'''
|
||||||
|
if parent == None:
|
||||||
|
parent = self
|
||||||
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
|
||||||
@ -1162,11 +1188,11 @@ class ElectrumWindow(QMainWindow):
|
|||||||
callback(success[0])
|
callback(success[0])
|
||||||
|
|
||||||
# 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 transaction...', sign_thread, on_sign_successful, on_dialog_close)
|
self.waiting_dialog = WaitingDialog(parent, 'Signing transaction...', sign_thread, on_sign_successful, on_dialog_close)
|
||||||
self.waiting_dialog.start()
|
self.waiting_dialog.start()
|
||||||
|
|
||||||
|
|
||||||
def broadcast_transaction(self, tx, tx_desc):
|
def broadcast_transaction(self, tx, tx_desc, parent=None):
|
||||||
|
|
||||||
def broadcast_thread():
|
def broadcast_thread():
|
||||||
# non-GUI thread
|
# non-GUI thread
|
||||||
@ -1193,14 +1219,16 @@ class ElectrumWindow(QMainWindow):
|
|||||||
if status:
|
if status:
|
||||||
if tx_desc is not None and tx.is_complete():
|
if tx_desc is not None and tx.is_complete():
|
||||||
self.wallet.set_label(tx.hash(), tx_desc)
|
self.wallet.set_label(tx.hash(), tx_desc)
|
||||||
QMessageBox.information(self, '', _('Payment sent.') + '\n' + msg, _('OK'))
|
QMessageBox.information(parent, '', _('Payment sent.') + '\n' + msg, _('OK'))
|
||||||
self.update_invoices_list()
|
self.update_invoices_list()
|
||||||
self.do_clear()
|
self.do_clear()
|
||||||
else:
|
else:
|
||||||
QMessageBox.warning(self, _('Error'), msg, _('OK'))
|
QMessageBox.warning(parent, _('Error'), msg, _('OK'))
|
||||||
self.send_button.setDisabled(False)
|
self.send_button.setDisabled(False)
|
||||||
|
|
||||||
self.waiting_dialog = WaitingDialog(self, 'Broadcasting transaction...', broadcast_thread, broadcast_done)
|
if parent == None:
|
||||||
|
parent = self
|
||||||
|
self.waiting_dialog = WaitingDialog(parent, 'Broadcasting transaction...', broadcast_thread, broadcast_done)
|
||||||
self.waiting_dialog.start()
|
self.waiting_dialog.start()
|
||||||
|
|
||||||
|
|
||||||
@ -1858,29 +1886,6 @@ class ElectrumWindow(QMainWindow):
|
|||||||
d = QRDialog(data, self, title)
|
d = QRDialog(data, self, title)
|
||||||
d.exec_()
|
d.exec_()
|
||||||
|
|
||||||
|
|
||||||
def do_protect(self, func, args):
|
|
||||||
if self.wallet.use_encryption:
|
|
||||||
while True:
|
|
||||||
password = self.password_dialog()
|
|
||||||
if not password:
|
|
||||||
return
|
|
||||||
try:
|
|
||||||
self.wallet.check_password(password)
|
|
||||||
break
|
|
||||||
except Exception as e:
|
|
||||||
QMessageBox.warning(self, _('Error'), str(e), _('OK'))
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
password = None
|
|
||||||
|
|
||||||
if args != (False,):
|
|
||||||
args = (self,) + args + (password,)
|
|
||||||
else:
|
|
||||||
args = (self, password)
|
|
||||||
apply(func, args)
|
|
||||||
|
|
||||||
|
|
||||||
def show_public_keys(self, address):
|
def show_public_keys(self, address):
|
||||||
if not address: return
|
if not address: return
|
||||||
try:
|
try:
|
||||||
@ -2060,8 +2065,10 @@ class ElectrumWindow(QMainWindow):
|
|||||||
def show_warning(self, msg):
|
def show_warning(self, msg):
|
||||||
QMessageBox.warning(self, _('Warning'), msg, _('OK'))
|
QMessageBox.warning(self, _('Warning'), msg, _('OK'))
|
||||||
|
|
||||||
def password_dialog(self, msg=None):
|
def password_dialog(self, msg=None, parent=None):
|
||||||
d = QDialog(self)
|
if parent == None:
|
||||||
|
parent = self
|
||||||
|
d = QDialog(parent)
|
||||||
d.setModal(1)
|
d.setModal(1)
|
||||||
d.setWindowTitle(_("Enter Password"))
|
d.setWindowTitle(_("Enter Password"))
|
||||||
pw = QLineEdit()
|
pw = QLineEdit()
|
||||||
|
|||||||
@ -116,7 +116,7 @@ class TxDialog(QWidget):
|
|||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def do_broadcast(self):
|
def do_broadcast(self):
|
||||||
self.parent.broadcast_transaction(self.tx, self.desc)
|
self.parent.broadcast_transaction(self.tx, self.desc, parent=self)
|
||||||
self.broadcast = True
|
self.broadcast = True
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
@ -142,10 +142,15 @@ class TxDialog(QWidget):
|
|||||||
|
|
||||||
def sign(self):
|
def sign(self):
|
||||||
def sign_done(success):
|
def sign_done(success):
|
||||||
|
self.sign_button.setDisabled(False)
|
||||||
self.prompt_if_unsaved = True
|
self.prompt_if_unsaved = True
|
||||||
self.saved = False
|
self.saved = False
|
||||||
self.update()
|
self.update()
|
||||||
self.parent.sign_tx(self.tx, sign_done)
|
self.sign_button.setDisabled(True)
|
||||||
|
cancelled, ret = self.parent.sign_tx(self.tx, sign_done, parent=self)
|
||||||
|
if cancelled:
|
||||||
|
self.sign_button.setDisabled(False)
|
||||||
|
|
||||||
|
|
||||||
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
Block a user