From ec833b43e97358536e4b95bfd13f09da27066e18 Mon Sep 17 00:00:00 2001 From: Michael Wozniak Date: Sat, 2 Aug 2014 14:52:28 -0400 Subject: [PATCH 1/5] update imports --- plugins/trezor.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/trezor.py b/plugins/trezor.py index ecbdcbc0..e98fae42 100644 --- a/plugins/trezor.py +++ b/plugins/trezor.py @@ -5,12 +5,12 @@ from sys import stderr from gui.qt.password_dialog import make_password_dialog, run_password_dialog from gui.qt.util import ok_cancel_buttons -from lib.account import BIP32_Account -from lib.bitcoin import EncodeBase58Check -from lib.i18n import _ -from lib.plugins import BasePlugin -from lib.transaction import deserialize -from lib.wallet import NewWallet +from electrum.account import BIP32_Account +from electrum.bitcoin import EncodeBase58Check +from electrum.i18n import _ +from electrum.plugins import BasePlugin +from electrum.transaction import deserialize +from electrum.wallet import NewWallet try: From 14f00609aabea2b8e805ccc28a9e3825c8c85e55 Mon Sep 17 00:00:00 2001 From: Michael Wozniak Date: Sat, 2 Aug 2014 20:09:29 -0400 Subject: [PATCH 2/5] update imports for gui --- plugins/trezor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/trezor.py b/plugins/trezor.py index e98fae42..db78dc91 100644 --- a/plugins/trezor.py +++ b/plugins/trezor.py @@ -3,8 +3,8 @@ from binascii import unhexlify from struct import pack from sys import stderr -from gui.qt.password_dialog import make_password_dialog, run_password_dialog -from gui.qt.util import ok_cancel_buttons +from electrum_gui.qt.password_dialog import make_password_dialog, run_password_dialog +from electrum_gui.qt.util import ok_cancel_buttons from electrum.account import BIP32_Account from electrum.bitcoin import EncodeBase58Check from electrum.i18n import _ From 6206da00e06de133d2cad172d9c4dcc5a01911ef Mon Sep 17 00:00:00 2001 From: Michael Wozniak Date: Sat, 2 Aug 2014 23:18:02 -0400 Subject: [PATCH 3/5] update trezor plugin waiting dialog update waiting dialog so that ok/cancel doesn't need to be used on the GUI, only on the trezor device --- plugins/trezor.py | 49 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/plugins/trezor.py b/plugins/trezor.py index db78dc91..fb777aaf 100644 --- a/plugins/trezor.py +++ b/plugins/trezor.py @@ -1,7 +1,8 @@ -from PyQt4.Qt import QMessageBox, QDialog, QVBoxLayout, QLabel +from PyQt4.Qt import QMessageBox, QDialog, QVBoxLayout, QLabel, QThread, SIGNAL, QObject from binascii import unhexlify from struct import pack from sys import stderr +from time import sleep from electrum_gui.qt.password_dialog import make_password_dialog, run_password_dialog from electrum_gui.qt.util import ok_cancel_buttons @@ -27,6 +28,8 @@ def log(msg): stderr.write("%s\n" % msg) stderr.flush() +gl_emitter = QObject() +window_open = False class Plugin(BasePlugin): @@ -174,6 +177,7 @@ class TrezorWallet(NewWallet): inputs = self.tx_inputs(tx) outputs = self.tx_outputs(tx) signed_tx = self.get_client().sign_tx('Bitcoin', inputs, outputs)[1] + gl_emitter.emit(SIGNAL('trezor_done')) values = [i['value'] for i in tx.inputs] raw = signed_tx.encode('hex') tx.update(raw) @@ -280,10 +284,16 @@ class TrezorQtGuiMixin(object): super(TrezorQtGuiMixin, self).__init__(*args, **kwargs) def callback_ButtonRequest(self, msg): - i = QMessageBox.question(None, _('Trezor'), _("Please check request on Trezor's screen"), _('OK'), _('Cancel')) - if i == 0: - return proto.ButtonAck() - return proto.Cancel() + if window_open: + gl_emitter.emit(SIGNAL('trezor_done')) + if msg.code == 3: + message = "Confirm transaction outputs on Trezor device to continue" + elif msg.code == 8: + message = "Confirm transaction fee on Trezor device to continue" + else: + message = "Check Trezor device to continue" + twd.start(message) + return proto.ButtonAck() def callback_PinMatrixRequest(self, msg): if msg.type == 1: @@ -339,6 +349,32 @@ class TrezorQtGuiMixin(object): if not d.exec_(): return return str(matrix.get_value()) +class TrezorWaitingDialog(QThread): + def __init__(self): + QThread.__init__(self) + + def start(self, message): + self.done = False + self.d = QDialog() + self.d.setModal(True) + self.d.setWindowTitle('Please Check Trezor Device') + l = QLabel(message) + vbox = QVBoxLayout(self.d) + vbox.addWidget(l) + self.d.show() + window_open = True + self.d.connect(gl_emitter, SIGNAL('trezor_done'), self.stop) + + def run(self): + while not self.done: + sleep(0.1) + + def stop(self): + self.d.hide() + window_open = False + self.done = True + + if TREZOR: class QtGuiTrezorClient(ProtocolMixin, TrezorQtGuiMixin, BaseClient): def call_raw(self, msg): @@ -349,3 +385,6 @@ if TREZOR: raise return resp + + twd = TrezorWaitingDialog() + From e9e8b7e960de1db0012fdc457a49fb69154240a1 Mon Sep 17 00:00:00 2001 From: Michael Wozniak Date: Sat, 2 Aug 2014 23:38:16 -0400 Subject: [PATCH 4/5] Clean up dialog code TODO: fix dialog for cancelled tx from Trezor --- plugins/trezor.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/plugins/trezor.py b/plugins/trezor.py index fb777aaf..d2410115 100644 --- a/plugins/trezor.py +++ b/plugins/trezor.py @@ -29,7 +29,6 @@ def log(msg): stderr.flush() gl_emitter = QObject() -window_open = False class Plugin(BasePlugin): @@ -284,8 +283,6 @@ class TrezorQtGuiMixin(object): super(TrezorQtGuiMixin, self).__init__(*args, **kwargs) def callback_ButtonRequest(self, msg): - if window_open: - gl_emitter.emit(SIGNAL('trezor_done')) if msg.code == 3: message = "Confirm transaction outputs on Trezor device to continue" elif msg.code == 8: @@ -352,9 +349,9 @@ class TrezorQtGuiMixin(object): class TrezorWaitingDialog(QThread): def __init__(self): QThread.__init__(self) + self.waiting = False def start(self, message): - self.done = False self.d = QDialog() self.d.setModal(True) self.d.setWindowTitle('Please Check Trezor Device') @@ -362,17 +359,13 @@ class TrezorWaitingDialog(QThread): vbox = QVBoxLayout(self.d) vbox.addWidget(l) self.d.show() - window_open = True - self.d.connect(gl_emitter, SIGNAL('trezor_done'), self.stop) - - def run(self): - while not self.done: - sleep(0.1) + if not self.waiting: + self.waiting = True + self.d.connect(gl_emitter, SIGNAL('trezor_done'), self.stop) def stop(self): self.d.hide() - window_open = False - self.done = True + self.waiting = False if TREZOR: From ef6ccf2bcd102390ddfd77c30f82eafb8859f028 Mon Sep 17 00:00:00 2001 From: Michael Wozniak Date: Sat, 2 Aug 2014 23:41:27 -0400 Subject: [PATCH 5/5] Fix dialog for cancelled TX on Trezor --- plugins/trezor.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/trezor.py b/plugins/trezor.py index d2410115..360eb78c 100644 --- a/plugins/trezor.py +++ b/plugins/trezor.py @@ -175,8 +175,12 @@ class TrezorWallet(NewWallet): inputs = self.tx_inputs(tx) outputs = self.tx_outputs(tx) - signed_tx = self.get_client().sign_tx('Bitcoin', inputs, outputs)[1] - gl_emitter.emit(SIGNAL('trezor_done')) + try: + signed_tx = self.get_client().sign_tx('Bitcoin', inputs, outputs)[1] + except Exception, e: + raise e + finally: + gl_emitter.emit(SIGNAL('trezor_done')) values = [i['value'] for i in tx.inputs] raw = signed_tx.encode('hex') tx.update(raw)