device manager: index devices by xpub
This commit is contained in:
@@ -48,6 +48,7 @@ class HW_PluginBase(BasePlugin):
|
||||
|
||||
@hook
|
||||
def close_wallet(self, wallet):
|
||||
if isinstance(wallet.get_keystore(), self.keystore_class):
|
||||
self.device_manager().unpair_wallet(wallet)
|
||||
keystore = wallet.get_keystore()
|
||||
if isinstance(keystore, self.keystore_class):
|
||||
self.device_manager().unpair_xpub(keystore.xpub)
|
||||
|
||||
|
||||
@@ -3,6 +3,5 @@ from electrum.i18n import _
|
||||
fullname = 'KeepKey'
|
||||
description = _('Provides support for KeepKey hardware wallet')
|
||||
requires = [('keepkeylib','github.com/keepkey/python-keepkey')]
|
||||
#requires_wallet_type = ['keepkey']
|
||||
registers_keystore = ('hardware', 'keepkey', _("KeepKey wallet"))
|
||||
available_for = ['qt', 'cmdline']
|
||||
|
||||
@@ -3,6 +3,5 @@ from electrum.i18n import _
|
||||
fullname = 'Ledger Wallet'
|
||||
description = 'Provides support for Ledger hardware wallet'
|
||||
requires = [('btchip', 'github.com/ledgerhq/btchip-python')]
|
||||
#requires_wallet_type = ['btchip']
|
||||
registers_keystore = ('hardware', 'btchip', _("Ledger wallet"))
|
||||
available_for = ['qt', 'cmdline']
|
||||
|
||||
@@ -3,7 +3,6 @@ from electrum.i18n import _
|
||||
fullname = 'TREZOR Wallet'
|
||||
description = _('Provides support for TREZOR hardware wallet')
|
||||
requires = [('trezorlib','github.com/trezor/python-trezor')]
|
||||
#requires_wallet_type = ['trezor']
|
||||
registers_keystore = ('hardware', 'trezor', _("TREZOR wallet"))
|
||||
available_for = ['qt', 'cmdline']
|
||||
|
||||
|
||||
@@ -31,10 +31,6 @@ class TrezorCompatibleKeyStore(Hardware_KeyStore):
|
||||
def get_client(self, force_pair=True):
|
||||
return self.plugin.get_client(self, force_pair)
|
||||
|
||||
def init_xpub(self):
|
||||
client = self.get_client()
|
||||
self.xpub = client.get_xpub(self.get_derivation())
|
||||
|
||||
def decrypt_message(self, pubkey, message, password):
|
||||
raise RuntimeError(_('Electrum and %s encryption and decryption are currently incompatible') % self.device)
|
||||
address = public_key_to_bc_address(pubkey.decode('hex'))
|
||||
@@ -142,7 +138,11 @@ class TrezorCompatiblePlugin(HW_PluginBase):
|
||||
# All client interaction should not be in the main GUI thread
|
||||
assert self.main_thread != threading.current_thread()
|
||||
devmgr = self.device_manager()
|
||||
client = devmgr.client_for_keystore(self, keystore, force_pair)
|
||||
derivation = keystore.get_derivation()
|
||||
xpub = keystore.xpub
|
||||
handler = keystore.handler
|
||||
client = devmgr.client_for_xpub(self, xpub, derivation, handler, force_pair)
|
||||
# returns the client for a given keystore. can use xpub
|
||||
if client:
|
||||
client.used()
|
||||
return client
|
||||
@@ -202,24 +202,31 @@ class TrezorCompatiblePlugin(HW_PluginBase):
|
||||
pin = pin_protection # It's the pin, not a boolean
|
||||
client.load_device_by_xprv(item, pin, passphrase_protection,
|
||||
label, language)
|
||||
# After successful initialization create accounts
|
||||
keystore.init_xpub()
|
||||
#wallet.create_main_account()
|
||||
# After successful initialization get xpub
|
||||
self.xpub = client.get_xpub(derivation)
|
||||
|
||||
return initialize_method
|
||||
|
||||
def setup_device(self, keystore, on_done, on_error):
|
||||
def init_xpub(self, derivation, device_id, handler):
|
||||
devmgr = self.device_manager()
|
||||
client = devmgr.client_by_id(device_id, handler)
|
||||
if client:
|
||||
client.used()
|
||||
self.xpub = client.get_xpub(derivation)
|
||||
|
||||
def setup_device(self, derivation, thread, handler, on_done, on_error):
|
||||
'''Called when creating a new wallet. Select the device to use. If
|
||||
the device is uninitialized, go through the intialization
|
||||
process. Then create the wallet accounts.'''
|
||||
devmgr = self.device_manager()
|
||||
device_info = devmgr.select_device(keystore, self)
|
||||
devmgr.pair_wallet(keystore, device_info.device.id_)
|
||||
device_info = devmgr.select_device(handler, self)
|
||||
device_id = device_info.device.id_
|
||||
#devmgr.pair_wallet(keystore, device_info.device.id_)
|
||||
if device_info.initialized:
|
||||
task = keystore.init_xpub
|
||||
task = lambda: self.init_xpub(derivation, device_id, handler)
|
||||
else:
|
||||
task = self.initialize_device(keystore)
|
||||
keystore.thread.add(task, on_done=on_done, on_error=on_error)
|
||||
thread.add(task, on_done=on_done, on_error=on_error)
|
||||
|
||||
def sign_transaction(self, keystore, tx, prev_tx, xpub_path):
|
||||
self.prev_tx = prev_tx
|
||||
|
||||
@@ -284,19 +284,23 @@ def qt_plugin_class(base_plugin_class):
|
||||
# Trigger a pairing
|
||||
keystore.thread.add(partial(self.get_client, keystore))
|
||||
|
||||
def on_create_wallet(self, keystore, wizard):
|
||||
keystore.handler = self.create_handler(wizard)
|
||||
keystore.thread = TaskThread(wizard, wizard.on_error)
|
||||
def on_create_wallet(self, storage, wizard):
|
||||
from electrum.keystore import load_keystore
|
||||
handler = self.create_handler(wizard)
|
||||
thread = TaskThread(wizard, wizard.on_error)
|
||||
# Setup device and create accounts in separate thread; wait until done
|
||||
loop = QEventLoop()
|
||||
exc_info = []
|
||||
self.setup_device(keystore, on_done=loop.quit,
|
||||
derivation = "m/44'/0'/%d'"%storage.get('account_id')
|
||||
self.setup_device(derivation, thread, handler, on_done=loop.quit,
|
||||
on_error=lambda info: exc_info.extend(info))
|
||||
loop.exec_()
|
||||
# If an exception was thrown, show to user and exit install wizard
|
||||
if exc_info:
|
||||
wizard.on_error(exc_info)
|
||||
raise UserCancelled
|
||||
storage.put('master_public_keys', {'/x':self.xpub})
|
||||
keystore = load_keystore(storage, '/x') # this calls the dynamic constructor
|
||||
wizard.create_wallet(keystore, None)
|
||||
|
||||
@hook
|
||||
@@ -316,9 +320,9 @@ def qt_plugin_class(base_plugin_class):
|
||||
'''This dialog box should be usable even if the user has
|
||||
forgotten their PIN or it is in bootloader mode.'''
|
||||
keystore = window.wallet.get_keystore()
|
||||
device_id = self.device_manager().wallet_id(keystore)
|
||||
device_id = self.device_manager().xpub_id(keystore.xpub)
|
||||
if not device_id:
|
||||
info = self.device_manager().select_device(keystore, self)
|
||||
info = self.device_manager().select_device(keystore.handler, self)
|
||||
device_id = info.device.id_
|
||||
return device_id
|
||||
|
||||
|
||||
Reference in New Issue
Block a user