From ffe3cef21acd67a4e98e51b49fd13ba1123c7652 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Mon, 6 Apr 2020 16:49:11 +0200 Subject: [PATCH] bitbox02: don't run show_xpub on GUI thread --- electrum/plugins/bitbox02/bitbox02.py | 9 ++++++++- electrum/plugins/bitbox02/qt.py | 7 +++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/electrum/plugins/bitbox02/bitbox02.py b/electrum/plugins/bitbox02/bitbox02.py index 087546dc4..5c3f85d45 100644 --- a/electrum/plugins/bitbox02/bitbox02.py +++ b/electrum/plugins/bitbox02/bitbox02.py @@ -196,7 +196,7 @@ class BitBox02Client(HardwareClientBase): node = bip32.BIP32Node.from_xkey(xpub, net = constants.BitcoinMainnet()).subkey_at_public_derivation(()) return node.eckey.get_public_key_bytes(compressed=True).hex() - def get_xpub(self, bip32_path: str, xtype: str, display: bool = False) -> str: + def get_xpub(self, bip32_path: str, xtype: str, *, display: bool = False) -> str: if self.bitbox02_device is None: self.pairing_dialog(wizard=False) @@ -612,3 +612,10 @@ class BitBox02Plugin(HW_PluginBase): txin_type = wallet.get_txin_type(address) sequence = wallet.get_address_index(address) keystore.show_address(sequence, txin_type, wallet) + + def show_xpub(self, keystore: BitBox02_KeyStore): + client = keystore.get_client() + assert isinstance(client, BitBox02Client) + derivation = keystore.get_derivation_prefix() + xtype = keystore.get_bip32_node_for_xpub().xtype + client.get_xpub(derivation, xtype, display=True) diff --git a/electrum/plugins/bitbox02/qt.py b/electrum/plugins/bitbox02/qt.py index 2a63b681f..9b1ccc261 100644 --- a/electrum/plugins/bitbox02/qt.py +++ b/electrum/plugins/bitbox02/qt.py @@ -28,7 +28,6 @@ from electrum.i18n import _ from electrum.plugin import hook from electrum.wallet import Multisig_Wallet from electrum.transaction import PartialTransaction -from electrum import keystore from .bitbox02 import BitBox02Plugin from ..hw_wallet.qt import QtHandlerBase, QtPluginBase @@ -77,11 +76,11 @@ class Plugin(BitBox02Plugin, QtPluginBase): selected_keystore_index = labels_clayout.selected_index() keystores = wallet.get_keystores() selected_keystore = keystores[selected_keystore_index] - derivation = selected_keystore.get_derivation_prefix() if type(selected_keystore) != self.keystore_class: main_window.show_error("Select a BitBox02 xpub") - selected_keystore.get_client().get_xpub( - derivation, keystore.xtype_from_derivation(derivation), True + return + selected_keystore.thread.add( + partial(self.show_xpub, keystore=selected_keystore) ) btn.clicked.connect(lambda unused: on_button_click())