diff --git a/src/main/java/com/sparrowwallet/sparrow/control/TransactionsTreeTable.java b/src/main/java/com/sparrowwallet/sparrow/control/TransactionsTreeTable.java index 8b9f5109..7763e077 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/TransactionsTreeTable.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/TransactionsTreeTable.java @@ -70,6 +70,7 @@ public class TransactionsTreeTable extends TreeTableView { } public void updateHistory(List updatedNodes) { + //Recalculate from scratch and update according - any changes may affect the balance of other transactions WalletTransactionsEntry rootEntry = (WalletTransactionsEntry)getRoot().getValue(); rootEntry.updateTransactions(); sort(); diff --git a/src/main/java/com/sparrowwallet/sparrow/io/ElectrumServer.java b/src/main/java/com/sparrowwallet/sparrow/io/ElectrumServer.java index 867d2a41..d3270228 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/ElectrumServer.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/ElectrumServer.java @@ -142,15 +142,20 @@ public class ElectrumServer { getHistory(wallet, purposeNode.getChildren(), nodeTransactionMap, 0); int historySize = purposeNode.getChildren().size(); - int gapLimitSize = nodeTransactionMap.size() + Wallet.DEFAULT_LOOKAHEAD; + int gapLimitSize = getGapLimitSize(nodeTransactionMap); while(historySize < gapLimitSize) { purposeNode.fillToIndex(gapLimitSize - 1); getHistory(wallet, purposeNode.getChildren(), nodeTransactionMap, historySize); historySize = purposeNode.getChildren().size(); - gapLimitSize = nodeTransactionMap.size() + Wallet.DEFAULT_LOOKAHEAD; + gapLimitSize = getGapLimitSize(nodeTransactionMap); } } + private int getGapLimitSize(Map> nodeTransactionMap) { + int highestIndex = nodeTransactionMap.entrySet().stream().filter(entry -> !entry.getValue().isEmpty()).map(entry -> entry.getKey().getIndex()).max(Comparator.comparing(Integer::valueOf)).orElse(-1); + return highestIndex + Wallet.DEFAULT_LOOKAHEAD + 1; + } + public void getHistory(Wallet wallet, Collection nodes, Map> nodeTransactionMap, int startIndex) throws ServerException { getReferences(wallet, "blockchain.scripthash.get_history", nodes, nodeTransactionMap, startIndex); } @@ -188,7 +193,7 @@ public class ElectrumServer { Set references = Arrays.stream(txes).map(ScriptHashTx::getBlockchainTransactionHash).collect(Collectors.toCollection(TreeSet::new)); Set existingReferences = nodeTransactionMap.get(node); - if(existingReferences == null && !references.isEmpty()) { + if(existingReferences == null) { nodeTransactionMap.put(node, references); } else { for(BlockTransactionHash reference : references) {