1
0

TrezorClient: should be in a separate thread

First steps; get show_address working.
Client is not responsible for showing exceptions.
Suppress uninteresting exceptions.
This commit is contained in:
Neil Booth
2016-01-17 19:38:32 +09:00
parent c99f0acfba
commit 06c262d0dc
5 changed files with 33 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
from sys import stderr
from electrum.i18n import _
from electrum.util import PrintError
from electrum.util import PrintError, SilentException
class GuiMixin(object):
@@ -20,6 +20,16 @@ class GuiMixin(object):
'passphrase': _("Confirm on %s device to continue"),
}
def callback_Failure(self, msg):
# BaseClient's unfortunate call() implementation forces us to
# raise exceptions on failure in order to unwind the stack.
# However, making the user acknowledge they cancelled
# gets old very quickly, so we suppress those.
if msg.code in (self.types.Failure_PinCancelled,
self.types.Failure_ActionCancelled):
raise SilentException()
raise RuntimeError(msg.message)
def callback_ButtonRequest(self, msg):
msg_code = self.msg_code_override or msg.code
message = self.messages.get(msg_code, self.messages['default'])
@@ -65,6 +75,7 @@ class TrezorClientBase(GuiMixin, PrintError):
self.handler = handler
self.hid_id_ = hid_id
self.tx_api = plugin
self.types = plugin.types
self.msg_code_override = None
def __str__(self):
@@ -172,9 +183,6 @@ class TrezorClientBase(GuiMixin, PrintError):
def wrapped(self, *args, **kwargs):
try:
return func(self, *args, **kwargs)
except BaseException as e:
self.handler.show_error(str(e))
raise e
finally:
self.handler.finished()