From 7b3ff2a6d39f533f4fa3927eed78dcd9bf904f6c Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Fri, 4 Mar 2022 10:36:47 +0200 Subject: [PATCH] fix various refresh history issues when updating node sets --- drongo | 2 +- .../com/sparrowwallet/sparrow/net/ElectrumServer.java | 6 +++++- .../java/com/sparrowwallet/sparrow/wallet/WalletForm.java | 8 ++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/drongo b/drongo index 0734757a..04631be8 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit 0734757a177627600a63cb3347804ea126b0d417 +Subproject commit 04631be8c10bf0ef72ebd7f7ef26254cccecb282 diff --git a/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java b/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java index ca7253ad..18d1ca3e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java @@ -1303,6 +1303,11 @@ public class ElectrumServer { return false; } + Set nodes = (filterToNodes == null ? null : filterToNodes.stream().filter(node -> node.getWallet().equals(wallet)).collect(Collectors.toSet())); + if(filterToNodes != null && nodes.isEmpty()) { + return false; + } + boolean initial = (walletSynchronizeLocks.putIfAbsent(wallet, new Object()) == null); synchronized(walletSynchronizeLocks.get(wallet)) { if(initial) { @@ -1311,7 +1316,6 @@ public class ElectrumServer { if(isConnected()) { ElectrumServer electrumServer = new ElectrumServer(); - Set nodes = (filterToNodes == null ? null : filterToNodes.stream().filter(node -> node.getWallet().equals(wallet)).collect(Collectors.toSet())); Map previousScriptHashes = getCalculatedScriptHashes(wallet); Map> nodeTransactionMap = (nodes == null ? electrumServer.getHistory(wallet) : electrumServer.getHistory(wallet, nodes)); diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java index 94dde6ac..1767ddf4 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java @@ -259,12 +259,12 @@ public class WalletForm { } private List getHistoryChangedNodes(Set previousNodes, Set currentNodes) { - Map previousNodeMap = new HashMap<>(previousNodes.size()); - previousNodes.forEach(walletNode -> previousNodeMap.put(walletNode, walletNode)); + Map previousNodeMap = new HashMap<>(previousNodes.size()); + previousNodes.forEach(walletNode -> previousNodeMap.put(walletNode.getDerivationPath(), walletNode)); List changedNodes = new ArrayList<>(); for(WalletNode currentNode : currentNodes) { - WalletNode previousNode = previousNodeMap.get(currentNode); + WalletNode previousNode = previousNodeMap.get(currentNode.getDerivationPath()); if(previousNode != null) { if(!currentNode.getTransactionOutputs().equals(previousNode.getTransactionOutputs())) { changedNodes.add(currentNode); @@ -286,7 +286,7 @@ public class WalletForm { return null; } - Set allNodes = new LinkedHashSet<>(); + Set allNodes = new LinkedHashSet<>(walletNodes); for(WalletNode walletNode : walletNodes) { for(Set nodes : walletTransactionNodes) { if(nodes.contains(walletNode)) {