From 81378b28b25d02dca8cdfc21a6b4fae0421d82b1 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Fri, 19 Jun 2020 15:35:29 +0200 Subject: [PATCH] various improvements --- .../com/sparrowwallet/drongo/wallet/Wallet.java | 8 ++------ .../sparrowwallet/drongo/wallet/WalletNode.java | 14 +++++++++++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java index f21dd35..7189856 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java @@ -13,7 +13,7 @@ import java.util.*; import java.util.stream.Collectors; public class Wallet { - private static final int DEFAULT_LOOKAHEAD = 20; + public static final int DEFAULT_LOOKAHEAD = 20; private String name; private PolicyType policyType; @@ -75,10 +75,6 @@ public class Wallet { return keystores; } - public void setKeystores(List keystores) { - this.keystores = keystores; - } - private Set getPurposeNodes() { return purposeNodes; } @@ -113,7 +109,7 @@ public class Wallet { int lookAhead = DEFAULT_LOOKAHEAD; Integer highestUsed = node.getHighestUsedIndex(); if(highestUsed != null) { - lookAhead = Math.max(highestUsed + lookAhead/2, lookAhead); + lookAhead = highestUsed + lookAhead; } return lookAhead; diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/WalletNode.java b/src/main/java/com/sparrowwallet/drongo/wallet/WalletNode.java index f388c52..19cdd92 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/WalletNode.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/WalletNode.java @@ -157,7 +157,19 @@ public class WalletNode implements Comparable { @Override public int compareTo(WalletNode node) { - return getIndex() - node.getIndex(); + if(getDerivation().size() != node.getDerivation().size()) { + return getDerivation().size() - node.getDerivation().size(); + } + + for(int i = 0; i < getDerivation().size(); i++) { + ChildNumber thisChild = getDerivation().get(i); + ChildNumber nodeChild = node.getDerivation().get(i); + if(thisChild.num() != nodeChild.num()) { + return thisChild.num() - nodeChild.num(); + } + } + + return 0; } public void clearHistory() {