Skip to content

Commit b0c6cd7

Browse files
committed
Cache xpubs
1 parent 70fad02 commit b0c6cd7

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

hwilib/commands.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ def getdescriptor(client, master_xpub, testnet=False, path=None, internal=False,
153153
path_base = path.rsplit(path_suffix)[0]
154154

155155
# Get the key at the base
156-
base_key = client.get_pubkey_at_path(path_base)['xpub']
157-
return Descriptor(master_fpr, path_base.replace('m', ''), base_key, path_suffix, client.is_testnet, sh_wpkh, wpkh)
156+
if client.xpub_cache.get(path_base) is None:
157+
client.xpub_cache[path_base] = client.get_pubkey_at_path(path_base)['xpub']
158+
159+
return Descriptor(master_fpr, path_base.replace('m', ''), client.xpub_cache.get(path_base), path_suffix, client.is_testnet, sh_wpkh, wpkh)
158160

159161
# wrapper to allow both internal and external entries when path not given
160162
def getkeypool(client, path, start, end, internal=False, keypool=False, account=0, sh_wpkh=False, wpkh=True):

hwilib/hwwclient.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def __init__(self, path, password):
99
self.message_magic = b"\x18Bitcoin Signed Message:\n"
1010
self.is_testnet = False
1111
self.fingerprint = None
12+
self.xpub_cache = {}
1213

1314
# Get the master BIP 44 pubkey
1415
def get_master_xpub(self):

0 commit comments

Comments
 (0)