From c4d2041a770a3f880d09ea0e5e7aa721d340df39 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Thu, 14 Jul 2022 15:08:01 +0200 Subject: [PATCH] optimize retrieving unspent utxos --- .../java/com/sparrowwallet/drongo/wallet/WalletNode.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/WalletNode.java b/src/main/java/com/sparrowwallet/drongo/wallet/WalletNode.java index c2676ea..269e99e 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/WalletNode.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/WalletNode.java @@ -166,8 +166,13 @@ public class WalletNode extends Persistable implements Comparable { } public Set getUnspentTransactionOutputs(boolean includeSpentMempoolOutputs) { + if(transactionOutputs.isEmpty()) { + return Collections.emptySet(); + } + Set unspentTXOs = new TreeSet<>(transactionOutputs); - return unspentTXOs.stream().filter(txo -> !txo.isSpent() || (includeSpentMempoolOutputs && txo.getSpentBy().getHeight() <= 0)).collect(Collectors.toCollection(HashSet::new)); + unspentTXOs.removeIf(txo -> txo.isSpent() && (!includeSpentMempoolOutputs || txo.getSpentBy().getHeight() > 0)); + return unspentTXOs; } public long getUnspentValue() {