mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
commit 10c46477f3a6f2fbc0596345511e0994253081eb Author: SomberNight <somber.night@protonmail.com> Date: Wed Jul 25 19:40:05 2018 +0200 backport changes of trezor plugin commit 213619e880f709188c1ea6272758896748e681a8 Merge: a855b75b66899ca252
Author: Jean-Christophe Rona <jc@rona.fr> Date: Wed Jul 25 18:45:19 2018 +0200 Merge branch 'master' into safe-t-mini commit a855b75b6f5af5f707c4680d0bac79eb66a85ace Author: Jean-Christophe Rona <rona@archos.com> Date: Wed Jul 25 18:37:12 2018 +0200 Safe-T: Switch to safet 0.1.3 to remove the rlp dependency commit 9bee44ca33289158c91c03d47dec45de6577f17b Author: SomberNight <somber.night@protonmail.com> Date: Wed Jul 18 14:01:10 2018 +0200 safe-t: bump min fw to 1.0.5 older fw has a bug when restoring from seed commit 01816607e8ba308cb5cff96b5fb844e4f6b8fcc1 Author: SomberNight <somber.night@protonmail.com> Date: Wed Jul 18 13:57:17 2018 +0200 safe-t: fix rlp version to avoid eth stuff commit 430206bea1fa10b762ff953fbc7652ce0d0e939d Merge: a999ae266b4b862b0c
Author: SomberNight <somber.night@protonmail.com> Date: Wed Jul 18 13:29:41 2018 +0200 Merge branch 'master' into pr/4445 commit a999ae266f499f180946d53d4e860cc871d562ab Author: Jean-Christophe Rona <rona@archos.com> Date: Tue Jun 19 14:18:03 2018 +0200 Safe-T mini: Remove supported coins This is not really useful there. commit 7922df1031b2c4b132f7f9c90232480b5bf9585c Author: Jean-Christophe Rona <rona@archos.com> Date: Tue May 29 16:43:37 2018 +0200 Safe-T mini: Add support for the Safe-T mini
95 lines
3.4 KiB
Python
95 lines
3.4 KiB
Python
from electrum.util import PrintError
|
|
|
|
|
|
class SafeTTransport(PrintError):
|
|
|
|
@staticmethod
|
|
def all_transports():
|
|
"""Reimplemented safetlib.transport.all_transports so that we can
|
|
enable/disable specific transports.
|
|
"""
|
|
try:
|
|
# only to detect safetlib version
|
|
from safetlib.transport import all_transports
|
|
except ImportError:
|
|
# old safetlib. compat for safetlib < 0.9.2
|
|
transports = []
|
|
#try:
|
|
# from safetlib.transport_bridge import BridgeTransport
|
|
# transports.append(BridgeTransport)
|
|
#except BaseException:
|
|
# pass
|
|
try:
|
|
from safetlib.transport_hid import HidTransport
|
|
transports.append(HidTransport)
|
|
except BaseException:
|
|
pass
|
|
try:
|
|
from safetlib.transport_udp import UdpTransport
|
|
transports.append(UdpTransport)
|
|
except BaseException:
|
|
pass
|
|
try:
|
|
from safetlib.transport_webusb import WebUsbTransport
|
|
transports.append(WebUsbTransport)
|
|
except BaseException:
|
|
pass
|
|
else:
|
|
# new safetlib.
|
|
transports = []
|
|
#try:
|
|
# from safetlib.transport.bridge import BridgeTransport
|
|
# transports.append(BridgeTransport)
|
|
#except BaseException:
|
|
# pass
|
|
try:
|
|
from safetlib.transport.hid import HidTransport
|
|
transports.append(HidTransport)
|
|
except BaseException:
|
|
pass
|
|
try:
|
|
from safetlib.transport.udp import UdpTransport
|
|
transports.append(UdpTransport)
|
|
except BaseException:
|
|
pass
|
|
try:
|
|
from safetlib.transport.webusb import WebUsbTransport
|
|
transports.append(WebUsbTransport)
|
|
except BaseException:
|
|
pass
|
|
return transports
|
|
return transports
|
|
|
|
def enumerate_devices(self):
|
|
"""Just like safetlib.transport.enumerate_devices,
|
|
but with exception catching, so that transports can fail separately.
|
|
"""
|
|
devices = []
|
|
for transport in self.all_transports():
|
|
try:
|
|
new_devices = transport.enumerate()
|
|
except BaseException as e:
|
|
self.print_error('enumerate failed for {}. error {}'
|
|
.format(transport.__name__, str(e)))
|
|
else:
|
|
devices.extend(new_devices)
|
|
return devices
|
|
|
|
def get_transport(self, path=None):
|
|
"""Reimplemented safetlib.transport.get_transport,
|
|
(1) for old safetlib
|
|
(2) to be able to disable specific transports
|
|
(3) to call our own enumerate_devices that catches exceptions
|
|
"""
|
|
if path is None:
|
|
try:
|
|
return self.enumerate_devices()[0]
|
|
except IndexError:
|
|
raise Exception("No Safe-T mini found") from None
|
|
|
|
def match_prefix(a, b):
|
|
return a.startswith(b) or b.startswith(a)
|
|
transports = [t for t in self.all_transports() if match_prefix(path, t.PATH_PREFIX)]
|
|
if transports:
|
|
return transports[0].find_by_path(path)
|
|
raise Exception("Unknown path prefix '%s'" % path)
|