Use Bridge transport if available; implementing #1139
Bumping required TREZOR firmware to 1.3.3 (includes important fixes)
This commit is contained in:
parent
10d26806d9
commit
18b7337aea
|
@ -2,7 +2,7 @@ import base64
|
||||||
import re
|
import re
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
from binascii import unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from electrum.account import BIP32_Account
|
from electrum.account import BIP32_Account
|
||||||
|
@ -98,18 +98,33 @@ class TrezorCompatiblePlugin(HW_PluginBase):
|
||||||
if self.libraries_available:
|
if self.libraries_available:
|
||||||
self.device_manager().register_devices(self.DEVICE_IDS)
|
self.device_manager().register_devices(self.DEVICE_IDS)
|
||||||
|
|
||||||
def create_client(self, device, handler):
|
def _try_hid(self, device):
|
||||||
|
self.print_error("Trying to connect over USB...")
|
||||||
if device.interface_number == 1:
|
if device.interface_number == 1:
|
||||||
pair = [None, device.path]
|
pair = [None, device.path]
|
||||||
else:
|
else:
|
||||||
pair = [device.path, None]
|
pair = [device.path, None]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
transport = self.HidTransport(pair)
|
return self.HidTransport(pair)
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
# We were probably just disconnected; never mind
|
|
||||||
self.print_error("cannot connect at", device.path, str(e))
|
self.print_error("cannot connect at", device.path, str(e))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def _try_bridge(self, device):
|
||||||
|
self.print_error("Trying to connect over Trezor Bridge...")
|
||||||
|
try:
|
||||||
|
return self.BridgeTransport({'path': hexlify(device.path)})
|
||||||
|
except BaseException as e:
|
||||||
|
self.print_error("cannot connect to bridge", str(e))
|
||||||
|
return None
|
||||||
|
|
||||||
|
def create_client(self, device, handler):
|
||||||
|
transport = self._try_bridge(device) or self._try_hid(device)
|
||||||
|
if not transport:
|
||||||
|
self.print_error("cannot connect to device")
|
||||||
|
return
|
||||||
|
|
||||||
self.print_error("connected to device at", device.path)
|
self.print_error("connected to device at", device.path)
|
||||||
|
|
||||||
client = self.client_class(transport, handler, self)
|
client = self.client_class(transport, handler, self)
|
||||||
|
|
|
@ -9,13 +9,14 @@ class TrezorWallet(TrezorCompatibleWallet):
|
||||||
class TrezorPlugin(TrezorCompatiblePlugin):
|
class TrezorPlugin(TrezorCompatiblePlugin):
|
||||||
firmware_URL = 'https://www.mytrezor.com'
|
firmware_URL = 'https://www.mytrezor.com'
|
||||||
libraries_URL = 'https://github.com/trezor/python-trezor'
|
libraries_URL = 'https://github.com/trezor/python-trezor'
|
||||||
minimum_firmware = (1, 2, 1)
|
minimum_firmware = (1, 3, 3)
|
||||||
wallet_class = TrezorWallet
|
wallet_class = TrezorWallet
|
||||||
try:
|
try:
|
||||||
from .client import TrezorClient as client_class
|
from .client import TrezorClient as client_class
|
||||||
import trezorlib.ckd_public as ckd_public
|
import trezorlib.ckd_public as ckd_public
|
||||||
from trezorlib.client import types
|
from trezorlib.client import types
|
||||||
from trezorlib.transport_hid import HidTransport, DEVICE_IDS
|
from trezorlib.transport_hid import HidTransport, DEVICE_IDS
|
||||||
|
from trezorlib.transport_bridge import BridgeTransport
|
||||||
libraries_available = True
|
libraries_available = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
libraries_available = False
|
libraries_available = False
|
||||||
|
|
Loading…
Reference in New Issue