From 0fbce035a3083f1cd5dc9f168b0cd4365a75ce40 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Sun, 23 Aug 2020 15:46:30 +0200 Subject: [PATCH] dont consider height when selecting --- .../drongo/wallet/PresetUtxoSelector.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/PresetUtxoSelector.java b/src/main/java/com/sparrowwallet/drongo/wallet/PresetUtxoSelector.java index 47121fc..da48706 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/PresetUtxoSelector.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/PresetUtxoSelector.java @@ -14,8 +14,17 @@ public class PresetUtxoSelector implements UtxoSelector { @Override public Collection select(long targetValue, Collection candidates) { - List utxos = new ArrayList<>(presetUtxos); - utxos.retainAll(candidates.stream().flatMap(outputGroup -> outputGroup.getUtxos().stream()).collect(Collectors.toList())); + List flattenedCandidates = candidates.stream().flatMap(outputGroup -> outputGroup.getUtxos().stream()).collect(Collectors.toList()); + List utxos = new ArrayList<>(); + + //Don't use equals() here as we don't want to consider height which may change as txes are confirmed + for(BlockTransactionHashIndex candidate : flattenedCandidates) { + for(BlockTransactionHashIndex presetUtxo : presetUtxos) { + if(candidate.getHash().equals(presetUtxo.getHash()) && candidate.getIndex() == presetUtxo.getIndex()) { + utxos.add(candidate); + } + } + } return utxos; }