electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit ba7d905dfbf30b0204fdf9aa461c59e699f63e16
parent fcfe3406b33e6a8304d91d22fe84ef87883d461f
Author: SomberNight <somber.night@protonmail.com>
Date:   Tue,  1 May 2018 14:35:55 +0200

trezor/keepkey: catch exception during device init

Diffstat:
Mplugins/keepkey/plugin.py | 14++++++++++++--
Mplugins/trezor/trezor.py | 14++++++++++++--
2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/plugins/keepkey/plugin.py b/plugins/keepkey/plugin.py @@ -1,4 +1,6 @@ from binascii import hexlify, unhexlify +import traceback +import sys from electrum.util import bfh, bh2u from electrum.bitcoin import (b58_address_to_hash160, xpub_from_pubkey, @@ -161,12 +163,21 @@ class KeepKeyCompatiblePlugin(HW_PluginBase): def f(method): import threading settings = self.request_trezor_init_settings(wizard, method, self.device) - t = threading.Thread(target = self._initialize_device, args=(settings, method, device_id, wizard, handler)) + t = threading.Thread(target=self._initialize_device_safe, args=(settings, method, device_id, wizard, handler)) t.setDaemon(True) t.start() wizard.loop.exec_() wizard.choice_dialog(title=_('Initialize Device'), message=msg, choices=choices, run_next=f) + def _initialize_device_safe(self, settings, method, device_id, wizard, handler): + try: + self._initialize_device(settings, method, device_id, wizard, handler) + except BaseException as e: + traceback.print_exc(file=sys.stderr) + handler.show_error(str(e)) + finally: + wizard.loop.exit(0) + def _initialize_device(self, settings, method, device_id, wizard, handler): item, label, pin_protection, passphrase_protection = settings @@ -192,7 +203,6 @@ class KeepKeyCompatiblePlugin(HW_PluginBase): pin = pin_protection # It's the pin, not a boolean client.load_device_by_xprv(item, pin, passphrase_protection, label, language) - wizard.loop.exit(0) def setup_device(self, device_info, wizard, purpose): devmgr = self.device_manager() diff --git a/plugins/trezor/trezor.py b/plugins/trezor/trezor.py @@ -1,4 +1,6 @@ from binascii import hexlify, unhexlify +import traceback +import sys from electrum.util import bfh, bh2u, versiontuple from electrum.bitcoin import (b58_address_to_hash160, xpub_from_pubkey, @@ -196,12 +198,21 @@ class TrezorPlugin(HW_PluginBase): def f(method): import threading settings = self.request_trezor_init_settings(wizard, method, self.device) - t = threading.Thread(target = self._initialize_device, args=(settings, method, device_id, wizard, handler)) + t = threading.Thread(target=self._initialize_device_safe, args=(settings, method, device_id, wizard, handler)) t.setDaemon(True) t.start() wizard.loop.exec_() wizard.choice_dialog(title=_('Initialize Device'), message=msg, choices=choices, run_next=f) + def _initialize_device_safe(self, settings, method, device_id, wizard, handler): + try: + self._initialize_device(settings, method, device_id, wizard, handler) + except BaseException as e: + traceback.print_exc(file=sys.stderr) + handler.show_error(str(e)) + finally: + wizard.loop.exit(0) + def _initialize_device(self, settings, method, device_id, wizard, handler): item, label, pin_protection, passphrase_protection = settings @@ -240,7 +251,6 @@ class TrezorPlugin(HW_PluginBase): pin = pin_protection # It's the pin, not a boolean client.load_device_by_xprv(item, pin, passphrase_protection, label, language) - wizard.loop.exit(0) def setup_device(self, device_info, wizard, purpose): devmgr = self.device_manager()