1
0

Use a shared device manager

Use a shared device manager across USB devices (not yet taken
advantage of by ledger).  This reduces USB scans and abstracts
device management cleanly.

We no longer scan at regular intervals in a background thread.
This commit is contained in:
Neil Booth
2016-01-05 06:47:14 +09:00
parent 5b8e096d57
commit 3d9f321cae
6 changed files with 331 additions and 186 deletions

View File

@@ -77,7 +77,7 @@ def trezor_client_class(protocol_mixin, base_client, proto):
self.msg_code_override = None
def __str__(self):
return "%s/%s/%s" % (self.label(), self.device_id(), self.path[0])
return "%s/%s/%s" % (self.label(), self.device_id(), self.path)
def label(self):
'''The name given by the user to the device.'''
@@ -91,6 +91,9 @@ def trezor_client_class(protocol_mixin, base_client, proto):
'''True if initialized, False if wiped.'''
return self.features.initialized
def pair_wallet(self, wallet):
self.wallet = wallet
def handler(self):
assert self.wallet and self.wallet.handler
return self.wallet.handler
@@ -111,6 +114,15 @@ def trezor_client_class(protocol_mixin, base_client, proto):
path.append(abs(int(x)) | prime)
return path
def first_address(self, wallet, derivation):
assert not self.wallet
# Assign the wallet so we have a handler
self.wallet = wallet
try:
return self.address_from_derivation(derivation)
finally:
self.wallet = None
def address_from_derivation(self, derivation):
return self.get_address('Bitcoin', self.expand_path(derivation))
@@ -128,6 +140,24 @@ def trezor_client_class(protocol_mixin, base_client, proto):
finally:
self.msg_code_override = None
def clear_session(self):
'''Clear the session to force pin (and passphrase if enabled)
re-entry. Does not leak exceptions.'''
self.print_error("clear session:", self)
try:
super(TrezorClient, self).clear_session()
except BaseException as e:
# If the device was removed it has the same effect...
self.print_error("clear_session: ignoring error", str(e))
pass
def close(self):
'''Called when Our wallet was closed or the device removed.'''
self.print_error("disconnected")
self.clear_session()
# Release the device
self.transport.close()
def firmware_version(self):
f = self.features
return (f.major_version, f.minor_version, f.patch_version)