From 4c58ebf138624cf1c5df4e2ae1c59fc8f9eede55 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 12 Oct 2020 11:08:24 +0200 Subject: [PATCH] correct handling of nodeTransactionMap empty map references --- .../com/sparrowwallet/sparrow/net/ElectrumServer.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java b/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java index dfe9999e..a3b13192 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java @@ -158,17 +158,17 @@ public class ElectrumServer { gapLimitSize = getGapLimitSize(wallet, nodeTransactionMap); } - //All WalletNode keys in nodeTransactionMap with non-null values need to have their history fetched - Collection usedNodes = nodeTransactionMap.entrySet().stream().filter(entry -> entry.getValue() != null).map(Map.Entry::getKey).collect(Collectors.toList()); + //All WalletNode keys in nodeTransactionMap need to have their history fetched + Collection usedNodes = new ArrayList<>(nodeTransactionMap.keySet()); log.debug("Retrieving history for " + usedNodes.stream().map(WalletNode::getDerivationPath).collect(Collectors.joining(", "))); getReferences(wallet, usedNodes, nodeTransactionMap); //Set the remaining WalletNode keys to empty sets to indicate no history - nodeTransactionMap.entrySet().stream().filter(entry -> entry.getValue() == null).forEach(entry -> entry.setValue(Collections.emptySet())); + purposeNode.getChildren().stream().filter(node -> !nodeTransactionMap.containsKey(node)).forEach(node -> nodeTransactionMap.put(node, Collections.emptySet())); } private int getGapLimitSize(Wallet wallet, Map> nodeTransactionMap) { - int highestIndex = nodeTransactionMap.entrySet().stream().filter(entry -> !entry.getValue().isEmpty()).map(entry -> entry.getKey().getIndex()).max(Comparator.comparing(Integer::valueOf)).orElse(-1); + int highestIndex = nodeTransactionMap.keySet().stream().map(WalletNode::getIndex).max(Comparator.comparing(Integer::valueOf)).orElse(-1); return highestIndex + wallet.getGapLimit() + 1; }