mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-02 18:25:21 +00:00
trezor/keepkey: catch exception during device init
This commit is contained in:
parent
fcfe3406b3
commit
ba7d905dfb
2 changed files with 24 additions and 4 deletions
|
@ -1,4 +1,6 @@
|
||||||
from binascii import hexlify, unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
|
import traceback
|
||||||
|
import sys
|
||||||
|
|
||||||
from electrum.util import bfh, bh2u
|
from electrum.util import bfh, bh2u
|
||||||
from electrum.bitcoin import (b58_address_to_hash160, xpub_from_pubkey,
|
from electrum.bitcoin import (b58_address_to_hash160, xpub_from_pubkey,
|
||||||
|
@ -161,12 +163,21 @@ class KeepKeyCompatiblePlugin(HW_PluginBase):
|
||||||
def f(method):
|
def f(method):
|
||||||
import threading
|
import threading
|
||||||
settings = self.request_trezor_init_settings(wizard, method, self.device)
|
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.setDaemon(True)
|
||||||
t.start()
|
t.start()
|
||||||
wizard.loop.exec_()
|
wizard.loop.exec_()
|
||||||
wizard.choice_dialog(title=_('Initialize Device'), message=msg, choices=choices, run_next=f)
|
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):
|
def _initialize_device(self, settings, method, device_id, wizard, handler):
|
||||||
item, label, pin_protection, passphrase_protection = settings
|
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
|
pin = pin_protection # It's the pin, not a boolean
|
||||||
client.load_device_by_xprv(item, pin, passphrase_protection,
|
client.load_device_by_xprv(item, pin, passphrase_protection,
|
||||||
label, language)
|
label, language)
|
||||||
wizard.loop.exit(0)
|
|
||||||
|
|
||||||
def setup_device(self, device_info, wizard, purpose):
|
def setup_device(self, device_info, wizard, purpose):
|
||||||
devmgr = self.device_manager()
|
devmgr = self.device_manager()
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
from binascii import hexlify, unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
|
import traceback
|
||||||
|
import sys
|
||||||
|
|
||||||
from electrum.util import bfh, bh2u, versiontuple
|
from electrum.util import bfh, bh2u, versiontuple
|
||||||
from electrum.bitcoin import (b58_address_to_hash160, xpub_from_pubkey,
|
from electrum.bitcoin import (b58_address_to_hash160, xpub_from_pubkey,
|
||||||
|
@ -196,12 +198,21 @@ class TrezorPlugin(HW_PluginBase):
|
||||||
def f(method):
|
def f(method):
|
||||||
import threading
|
import threading
|
||||||
settings = self.request_trezor_init_settings(wizard, method, self.device)
|
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.setDaemon(True)
|
||||||
t.start()
|
t.start()
|
||||||
wizard.loop.exec_()
|
wizard.loop.exec_()
|
||||||
wizard.choice_dialog(title=_('Initialize Device'), message=msg, choices=choices, run_next=f)
|
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):
|
def _initialize_device(self, settings, method, device_id, wizard, handler):
|
||||||
item, label, pin_protection, passphrase_protection = settings
|
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
|
pin = pin_protection # It's the pin, not a boolean
|
||||||
client.load_device_by_xprv(item, pin, passphrase_protection,
|
client.load_device_by_xprv(item, pin, passphrase_protection,
|
||||||
label, language)
|
label, language)
|
||||||
wizard.loop.exit(0)
|
|
||||||
|
|
||||||
def setup_device(self, device_info, wizard, purpose):
|
def setup_device(self, device_info, wizard, purpose):
|
||||||
devmgr = self.device_manager()
|
devmgr = self.device_manager()
|
||||||
|
|
Loading…
Add table
Reference in a new issue