optimize retrieving unspent utxos

This commit is contained in:
Craig Raw 2022-07-14 15:08:01 +02:00
parent 377843a4a5
commit c4d2041a77

View file

@ -166,8 +166,13 @@ public class WalletNode extends Persistable implements Comparable<WalletNode> {
} }
public Set<BlockTransactionHashIndex> getUnspentTransactionOutputs(boolean includeSpentMempoolOutputs) { public Set<BlockTransactionHashIndex> getUnspentTransactionOutputs(boolean includeSpentMempoolOutputs) {
if(transactionOutputs.isEmpty()) {
return Collections.emptySet();
}
Set<BlockTransactionHashIndex> unspentTXOs = new TreeSet<>(transactionOutputs); Set<BlockTransactionHashIndex> 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() { public long getUnspentValue() {