From 6cefec5cecd3d2099b905909f6d99ee6172c28c5 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 27 Apr 2026 08:28:09 +0200 Subject: [PATCH] avoid unnecessary xpub string roundtrip --- .../sparrow/control/DevicePane.java | 16 +++++++------- .../com/sparrowwallet/sparrow/io/Hwi.java | 22 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/control/DevicePane.java b/src/main/java/com/sparrowwallet/sparrow/control/DevicePane.java index 6ac41823..befe1983 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/DevicePane.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/DevicePane.java @@ -756,7 +756,7 @@ public class DevicePane extends TitledDescriptionPane { Hwi.GetXpubService getXpubService = new Hwi.GetXpubService(device, passphrase.get(), derivationPath); getXpubService.setOnSucceeded(workerStateEvent -> { - String xpub = getXpubService.getValue(); + ExtendedKey xpub = getXpubService.getValue(); try { Keystore keystore = new Keystore(); @@ -764,7 +764,7 @@ public class DevicePane extends TitledDescriptionPane { keystore.setSource(KeystoreSource.HW_USB); keystore.setWalletModel(device.getModel()); keystore.setKeyDerivation(new KeyDerivation(device.getFingerprint(), derivationPath)); - keystore.setExtendedPublicKey(ExtendedKey.fromDescriptor(xpub)); + keystore.setExtendedPublicKey(xpub); importKeystore(derivation, keystore); } catch(Exception e) { @@ -976,9 +976,9 @@ public class DevicePane extends TitledDescriptionPane { Hwi.GetXpubsService getXpubsService = new Hwi.GetXpubsService(device, passphrase.get(), derivationPaths); getXpubsService.setOnSucceeded(_ -> { - Map accountXpubs = getXpubsService.getValue(); + Map accountXpubs = getXpubsService.getValue(); - for(Map.Entry entry : accountXpubs.entrySet()) { + for(Map.Entry entry : accountXpubs.entrySet()) { try { Wallet wallet = new Wallet(device.getModel().toDisplayString()); wallet.setPolicyType(PolicyType.SINGLE_HD); @@ -988,7 +988,7 @@ public class DevicePane extends TitledDescriptionPane { keystore.setSource(KeystoreSource.HW_USB); keystore.setWalletModel(device.getModel()); keystore.setKeyDerivation(new KeyDerivation(device.getFingerprint(), derivationPaths.get(entry.getKey()))); - keystore.setExtendedPublicKey(ExtendedKey.fromDescriptor(entry.getValue())); + keystore.setExtendedPublicKey(entry.getValue()); wallet.getKeystores().add(keystore); wallet.setDefaultPolicy(Policy.getPolicy(PolicyType.SINGLE_HD, entry.getKey().scriptType(), wallet.getKeystores(), 1)); if(entry.getKey().standardAccount().equals(StandardAccount.ACCOUNT_0)) { @@ -1070,16 +1070,16 @@ public class DevicePane extends TitledDescriptionPane { Map importedKeystores = new LinkedHashMap<>(); Hwi.GetXpubsService getXpubsService = new Hwi.GetXpubsService(device, passphrase.get(), accountDerivationPaths); getXpubsService.setOnSucceeded(workerStateEvent -> { - Map accountXpubs = getXpubsService.getValue(); + Map accountXpubs = getXpubsService.getValue(); - for(Map.Entry entry : accountXpubs.entrySet()) { + for(Map.Entry entry : accountXpubs.entrySet()) { try { Keystore keystore = new Keystore(); keystore.setLabel(device.getModel().toDisplayString()); keystore.setSource(KeystoreSource.HW_USB); keystore.setWalletModel(device.getModel()); keystore.setKeyDerivation(new KeyDerivation(masterFingerprint, accountDerivationPaths.get(entry.getKey()))); - keystore.setExtendedPublicKey(ExtendedKey.fromDescriptor(entry.getValue())); + keystore.setExtendedPublicKey(entry.getValue()); importedKeystores.put(entry.getKey().standardAccount(), keystore); } catch(Exception e) { setError("Could not retrieve xpub", e.getMessage()); diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java b/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java index 2122e101..d62c77c3 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java @@ -146,7 +146,7 @@ public class Hwi { } } - public Map getXpubs(Device device, String passphrase, Map accountDerivationPaths, Map accountXpubs) throws ImportException { + public Map getXpubs(Device device, String passphrase, Map accountDerivationPaths, Map accountXpubs) throws ImportException { for(Map.Entry entry : accountDerivationPaths.entrySet()) { accountXpubs.put(entry.getKey(), getXpub(device, passphrase, entry.getValue())); } @@ -154,12 +154,12 @@ public class Hwi { return accountXpubs; } - public String getXpub(Device device, String passphrase, String derivationPath) throws ImportException { + public ExtendedKey getXpub(Device device, String passphrase, String derivationPath) throws ImportException { try { Lark lark = getLark(passphrase); ExtendedKey xpub = lark.getPubKeyAtPath(device.getType(), device.getPath(), derivationPath); isPromptActive = false; - return xpub.toString(); + return xpub; } catch(DeviceException e) { throw new ImportException(e.getMessage(), e); } catch(RuntimeException e) { @@ -436,7 +436,7 @@ public class Hwi { } } - public static class GetXpubService extends Service { + public static class GetXpubService extends Service { private final Device device; private final String passphrase; private final String derivationPath; @@ -448,9 +448,9 @@ public class Hwi { } @Override - protected Task createTask() { + protected Task createTask() { return new Task<>() { - protected String call() throws ImportException { + protected ExtendedKey call() throws ImportException { Hwi hwi = new Hwi(); return hwi.getXpub(device, passphrase, derivationPath); } @@ -480,7 +480,7 @@ public class Hwi { } } - public static class GetXpubsService extends Service> { + public static class GetXpubsService extends Service> { private final Device device; private final String passphrase; private final Map accountDerivationPaths; @@ -492,13 +492,13 @@ public class Hwi { } @Override - protected Task> createTask() { + protected Task> createTask() { return new Task<>() { - protected Map call() throws ImportException { + protected Map call() throws ImportException { Hwi hwi = new Hwi(); updateProgress(0, accountDerivationPaths.size()); - ObservableMap accountXpubs = FXCollections.observableMap(new LinkedHashMap<>()); - accountXpubs.addListener((MapChangeListener) _ -> updateProgress(accountXpubs.size(), accountDerivationPaths.size())); + ObservableMap accountXpubs = FXCollections.observableMap(new LinkedHashMap<>()); + accountXpubs.addListener((MapChangeListener) _ -> updateProgress(accountXpubs.size(), accountDerivationPaths.size())); return hwi.getXpubs(device, passphrase, accountDerivationPaths, accountXpubs); } };