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() {