diff --git a/core/src/main/java/com/google/bitcoin/core/Wallet.java b/core/src/main/java/com/google/bitcoin/core/Wallet.java index 93df4387..2df5d65f 100644 --- a/core/src/main/java/com/google/bitcoin/core/Wallet.java +++ b/core/src/main/java/com/google/bitcoin/core/Wallet.java @@ -1923,6 +1923,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi checkState(req.tx.getOutputs().size() == 1, "Empty wallet TX must have a single output only."); CoinSelector selector = req.coinSelector == null ? coinSelector : req.coinSelector; bestCoinSelection = selector.select(NetworkParameters.MAX_MONEY, candidates); + candidates = null; // Selector took ownership and might have changed candidates. Don't access again. req.tx.getOutput(0).setValue(bestCoinSelection.valueGathered); totalOutput = bestCoinSelection.valueGathered; } @@ -3450,6 +3451,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi // Of the coins we could spend, pick some that we actually will spend. CoinSelector selector = req.coinSelector == null ? coinSelector : req.coinSelector; CoinSelection selection = selector.select(valueNeeded, candidates); + candidates = null; // Selector took ownership and might have changed candidates. Don't access again. // Can we afford this? if (selection.valueGathered.compareTo(valueNeeded) < 0) { valueMissing = valueNeeded.subtract(selection.valueGathered); diff --git a/core/src/main/java/com/google/bitcoin/wallet/CoinSelector.java b/core/src/main/java/com/google/bitcoin/wallet/CoinSelector.java index a68dcc58..d2b8f86d 100644 --- a/core/src/main/java/com/google/bitcoin/wallet/CoinSelector.java +++ b/core/src/main/java/com/google/bitcoin/wallet/CoinSelector.java @@ -12,5 +12,10 @@ import java.util.LinkedList; * enough money in the wallet. */ public interface CoinSelector { + /** + * Creates a CoinSelection that tries to meet the target amount of value. The candidates list is given to + * this call and can be edited freely. See the docs for CoinSelection to learn more, or look a the implementation + * of {@link com.google.bitcoin.wallet.DefaultCoinSelector}. + */ public CoinSelection select(BigInteger target, LinkedList candidates); }