Browse Source

trezor/keepkey: catch exception during device init

3.2.x
SomberNight 7 years ago
parent
commit
ba7d905dfb
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 14
      plugins/keepkey/plugin.py
  2. 14
      plugins/trezor/trezor.py

14
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()

14
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()

Loading…
Cancel
Save