From c2efb097349d71652e0eadc7e2c46383eaf23437 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Sun, 17 Jan 2016 22:03:57 +0900 Subject: [PATCH] Threaded wallet creation --- gui/qt/installwizard.py | 6 ++++++ plugins/trezor/plugin.py | 38 ++++++++++++++++++++---------------- plugins/trezor/qt_generic.py | 7 ++++++- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/gui/qt/installwizard.py b/gui/qt/installwizard.py index f4d1e477..66e5f3e5 100644 --- a/gui/qt/installwizard.py +++ b/gui/qt/installwizard.py @@ -14,6 +14,7 @@ from password_dialog import PasswordLayout, PW_NEW, PW_PASSPHRASE from electrum.wallet import Wallet from electrum.mnemonic import prepare_seed +from electrum.util import SilentException from electrum.wizard import (WizardBase, UserCancelled, MSG_ENTER_PASSWORD, MSG_RESTORE_PASSPHRASE, MSG_COSIGNER, MSG_ENTER_SEED_OR_MPK, @@ -116,6 +117,11 @@ class InstallWizard(WindowModalDialog, WizardBase): self.accept() self.refresh_gui() + def on_error(self, exc_info): + if not isinstance(exc_info[1], SilentException): + traceback.print_exception(*exc_info) + self.show_error(str(exc_info[1])) + def set_icon(self, filename): prior_filename, self.icon_filename = self.icon_filename, filename self.logo.setPixmap(QPixmap(filename).scaledToWidth(60)) diff --git a/plugins/trezor/plugin.py b/plugins/trezor/plugin.py index 82f54e08..e313926d 100644 --- a/plugins/trezor/plugin.py +++ b/plugins/trezor/plugin.py @@ -285,26 +285,30 @@ class TrezorCompatiblePlugin(BasePlugin, ThreadJob): (item, label, pin_protection, passphrase_protection) \ = wallet.handler.request_trezor_init_settings(method, self.device) - client = self.get_client(wallet) language = 'english' - if method == TIM_NEW: - strength = 64 * (item + 2) # 128, 192 or 256 - client.reset_device(True, strength, passphrase_protection, - pin_protection, label, language) - elif method == TIM_RECOVER: - word_count = 6 * (item + 2) # 12, 18 or 24 - client.recovery_device(word_count, passphrase_protection, - pin_protection, label, language) - elif method == TIM_MNEMONIC: - pin = pin_protection # It's the pin, not a boolean - client.load_device_by_mnemonic(str(item), pin, - passphrase_protection, + def initialize_device(): + client = self.get_client(wallet) + + if method == TIM_NEW: + strength = 64 * (item + 2) # 128, 192 or 256 + client.reset_device(True, strength, passphrase_protection, + pin_protection, label, language) + elif method == TIM_RECOVER: + word_count = 6 * (item + 2) # 12, 18 or 24 + client.recovery_device(word_count, passphrase_protection, + pin_protection, label, language) + elif method == TIM_MNEMONIC: + pin = pin_protection # It's the pin, not a boolean + client.load_device_by_mnemonic(str(item), pin, + passphrase_protection, + label, language) + else: + pin = pin_protection # It's the pin, not a boolean + client.load_device_by_xprv(item, pin, passphrase_protection, label, language) - else: - pin = pin_protection # It's the pin, not a boolean - client.load_device_by_xprv(item, pin, passphrase_protection, - label, language) + + wallet.thread.add(initialize_device) def unpaired_clients(self, handler): '''Returns all connected, unpaired devices as a list of clients and a diff --git a/plugins/trezor/qt_generic.py b/plugins/trezor/qt_generic.py index bd6c2a65..3984f950 100644 --- a/plugins/trezor/qt_generic.py +++ b/plugins/trezor/qt_generic.py @@ -237,8 +237,13 @@ def qt_plugin_class(base_plugin_class): def on_create_wallet(self, wallet, wizard): assert type(wallet) == self.wallet_class wallet.handler = self.create_handler(wizard) + wallet.thread = TaskThread(wizard, wizard.on_error) self.select_device(wallet) - wallet.create_hd_account(None) + # Create accounts in separate thread; wait until done + loop = QEventLoop() + wallet.thread.add(partial(wallet.create_hd_account, None), + on_done=loop.quit) + loop.exec_() @hook def receive_menu(self, menu, addrs, wallet):