From d0a75fd26809d47fddf0c432bd8f6e6a9a522c64 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Sat, 30 May 2020 13:15:28 +0200 Subject: [PATCH] highest used index --- .../com/sparrowwallet/drongo/wallet/Wallet.java | 13 ++++++++++++- .../com/sparrowwallet/drongo/wallet/WalletNode.java | 6 ++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java index 2a0700e..b293edf 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java @@ -105,7 +105,7 @@ public class Wallet { public int getLookAhead(WalletNode node) { //TODO: Calculate using seen transactions int lookAhead = DEFAULT_LOOKAHEAD; - Integer maxIndex = node.getHighestIndex(); + Integer maxIndex = node.getHighestUsedIndex(); if(maxIndex != null) { lookAhead = Math.max(maxIndex + lookAhead/2, lookAhead); } @@ -193,6 +193,17 @@ public class Wallet { } } + public void clearHistory() { + for(WalletNode purposeNode : purposeNodes) { + purposeNode.getHistory().clear(); + for(WalletNode addressNode : purposeNode.getChildren()) { + addressNode.getHistory().clear(); + } + } + + transactions.clear(); + } + public boolean isValid() { if(policyType == null || scriptType == null || defaultPolicy == null || keystores.isEmpty()) { return false; diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/WalletNode.java b/src/main/java/com/sparrowwallet/drongo/wallet/WalletNode.java index baafaee..40890a7 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/WalletNode.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/WalletNode.java @@ -112,10 +112,12 @@ public class WalletNode implements Comparable { } } - public Integer getHighestIndex() { + public Integer getHighestUsedIndex() { WalletNode highestNode = null; for(WalletNode childNode : getChildren()) { - highestNode = childNode; + if(!childNode.getHistory().isEmpty()) { + highestNode = childNode; + } } return highestNode == null ? null : highestNode.index;