When a Ledger Nano S was unlocked and then went into the auto lock, EC does not react to it well. Starting a new EC instance with a Ledger in this state connected results in the following:
Traceback (most recent call last):
File "/home/user/src/electrum/gui/qt/util.py", line 691, in run
result = task.task()
File "/home/user/src/electrum/plugins/ledger/ledger.py", line 549, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/user/src/electrum/lib/plugins.py", line 718, in client_for_keystore
client = self.force_pair_xpub(plugin, handler, info, xpub, derivation, devices)
File "/home/user/src/electrum/lib/plugins.py", line 748, in force_pair_xpub
client_xpub = client.get_xpub(derivation, xtype)
File "/home/user/src/electrum/plugins/ledger/ledger.py", line 78, in catch_exception
return func(self, *args, **kwargs)
File "/home/user/src/electrum/plugins/ledger/ledger.py", line 88, in get_xpub
self.checkDevice()
File "/home/user/src/electrum/plugins/ledger/ledger.py", line 208, in checkDevice
raise e
File "/home/user/src/electrum/plugins/ledger/ledger.py", line 204, in checkDevice
self.perform_hw1_preflight()
File "/home/user/src/electrum/plugins/ledger/ledger.py", line 199, in perform_hw1_preflight
raise e
File "/home/user/src/electrum/plugins/ledger/ledger.py", line 185, in perform_hw1_preflight
raise e
File "/home/user/src/electrum/plugins/ledger/ledger.py", line 181, in perform_hw1_preflight
self.dongleObject.getWalletPublicKey("44'/145'/0'/0/0", showOnScreen=False, cashAddr=True)
File "/home/user/.local/lib/python3.5/site-packages/btchip/btchip.py", line 124, in getWalletPublicKey
response = self.dongle.exchange(bytearray(apdu))
File "/home/user/.local/lib/python3.5/site-packages/btchip/btchipComm.py", line 127, in exchange
raise BTChipException("Invalid status %04x" % sw, sw)
btchip.btchipException.BTChipException: Exception : Invalid status 6f04
After this, when I click the Ledger icon to retry the connection I get this:
Traceback (most recent call last):
File "/home/user/src/electrum/gui/qt/main_window.py", line 82, in onPress
self.func()
File "/home/user/src/electrum/plugins/hw_wallet/qt.py", line 230, in show_settings_dialog
device_id = self.choose_device(window, keystore)
File "/home/user/src/electrum/plugins/hw_wallet/qt.py", line 223, in choose_device
info = self.device_manager().select_device(self, keystore.handler, keystore)
File "/home/user/src/electrum/lib/plugins.py", line 786, in select_device
infos = self.unpaired_device_infos(handler, plugin, devices)
File "/home/user/src/electrum/lib/plugins.py", line 775, in unpaired_device_infos
client = self.create_client(device, handler, plugin)
File "/home/user/src/electrum/lib/plugins.py", line 651, in create_client
client = plugin.create_client(device, handler)
File "/home/user/src/electrum/plugins/ledger/ledger.py", line 522, in create_client
client = self.get_btchip_device(device)
File "/home/user/src/electrum/plugins/ledger/ledger.py", line 515, in get_btchip_device
dev.open_path(device.path)
File "hid.pyx", line 72, in hid.device.open_path
OSError: open failed
Seems that the device was not properly released and can't be reopened. After restarting EC I then get the following:
Traceback (most recent call last):
File "/home/user/src/electrum/plugins/ledger/ledger.py", line 149, in perform_hw1_preflight
firmwareInfo = self.dongleObject.getFirmwareVersion()
File "/home/user/.local/lib/python3.5/site-packages/btchip/btchip.py", line 561, in getFirmwareVersion
response = self.dongle.exchange(bytearray(apdu))
File "/home/user/.local/lib/python3.5/site-packages/btchip/btchipComm.py", line 127, in exchange
raise BTChipException("Invalid status %04x" % sw, sw)
btchip.btchipException.BTChipException: Exception : Invalid status 6faa
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/user/src/electrum/gui/qt/util.py", line 691, in run
result = task.task()
File "/home/user/src/electrum/plugins/ledger/ledger.py", line 549, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/user/src/electrum/lib/plugins.py", line 718, in client_for_keystore
client = self.force_pair_xpub(plugin, handler, info, xpub, derivation, devices)
File "/home/user/src/electrum/lib/plugins.py", line 748, in force_pair_xpub
client_xpub = client.get_xpub(derivation, xtype)
File "/home/user/src/electrum/plugins/ledger/ledger.py", line 78, in catch_exception
return func(self, *args, **kwargs)
File "/home/user/src/electrum/plugins/ledger/ledger.py", line 88, in get_xpub
self.checkDevice()
File "/home/user/src/electrum/plugins/ledger/ledger.py", line 204, in checkDevice
self.perform_hw1_preflight()
File "/home/user/src/electrum/plugins/ledger/ledger.py", line 192, in perform_hw1_preflight
raise Exception("Dongle is temporarily locked - please unplug it and replug it again")
Exception: Dongle is temporarily locked - please unplug it and replug it again
Ugh. I had similar problems with Trezor and I ended up fixing them somewhat.
I lack a Nano so I look to you or others to hopefully help fix these.
I do appreciate your opening the issue though -- hopefully someobody can pitch in and get it to do the right thing.
Thanks
No worries, I will try to fix these. I am opening these to remind me.
You can assign me to this issue and #1243
So, first I'm going to use inspection to determine whether btchip-python supports CashAddr like this:
gwpkArgSpecs = inspect.getfullargspec(self.dongleObject.getWalletPublicKey)
self.cashaddrSWSupported = 'cashAddr' in gwpkArgSpecs.args
This way we do not have to actually call getWalletPublicKey in perform_hw1_preflight.
Sounds good to me. 馃憤
Second change is to get the improved error handling from https://github.com/spesmilo/electrum
Most helpful comment
No worries, I will try to fix these. I am opening these to remind me.