From d4d191429e4228902cf10717a4e03a16d6743c5f Mon Sep 17 00:00:00 2001 From: CodeFace Date: Wed, 1 Jun 2022 13:42:27 +0800 Subject: [PATCH] un-support AddressType.WIT for ledger_nano_x --- hwilib/commands.py | 10 ++++++---- hwilib/hwwclient.py | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/hwilib/commands.py b/hwilib/commands.py index 9181cef1d..332bb9708 100644 --- a/hwilib/commands.py +++ b/hwilib/commands.py @@ -70,7 +70,7 @@ # Get the client for the device -def get_client(device_type: str, device_path: str, password: str = "", expert: bool = False, chain: Chain = Chain.MAIN) -> Optional[HardwareWalletClient]: +def get_client(device_type: str, device_path: str, password: str = "", expert: bool = False, chain: Chain = Chain.MAIN, model: str = "") -> Optional[HardwareWalletClient]: """ Returns a HardwareWalletClient for the given device type at the device path @@ -95,7 +95,7 @@ def get_client(device_type: str, device_path: str, password: str = "", expert: b if client: client.close() raise UnknownDeviceError('Unknown device type specified') - + client.model = model return client # Get a list of all available hardware wallets @@ -150,7 +150,7 @@ def find_device( try: assert isinstance(d["type"], str) assert isinstance(d["path"], str) - client = get_client(d['type'], d['path'], password, expert, chain) + client = get_client(d['type'], d['path'], password, expert, chain, d['model']) if client is None: raise Exception() @@ -405,10 +405,12 @@ def getdescriptors( master_fpr = client.get_master_fingerprint() result = {} + support_addr_types = [AddressType.LEGACY, AddressType.SH_WIT] if client.model == "ledger_nano_x" \ + else [AddressType.LEGACY, AddressType.WIT, AddressType.SH_WIT] for internal in [False, True]: descriptors = [] - for addr_type in (AddressType.LEGACY, AddressType.SH_WIT, AddressType.WIT): + for addr_type in support_addr_types: try: desc = getdescriptor(client, master_fpr=master_fpr, internal=internal, addr_type=addr_type, account=account) except UnavailableActionError: diff --git a/hwilib/hwwclient.py b/hwilib/hwwclient.py index afbc6e5ae..0c3142498 100644 --- a/hwilib/hwwclient.py +++ b/hwilib/hwwclient.py @@ -43,6 +43,7 @@ def __init__(self, path: str, password: str, expert: bool, chain: Chain = Chain. # {bip32_path: } self.xpub_cache: Dict[str, str] = {} self.expert = expert + self.model = None def get_master_xpub(self, addrtype: AddressType = AddressType.WIT, account: int = 0) -> ExtendedKey: """