Skip to content

Commit

Permalink
Wallet: null out the candidates list after selection so selectors can…
Browse files Browse the repository at this point in the history
… edit the list if they want.
  • Loading branch information
mikehearn committed Apr 23, 2014
1 parent 6e999c6 commit 38e3f6f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/src/main/java/com/google/bitcoin/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -1923,6 +1923,7 @@ public void completeTx(SendRequest req) throws InsufficientMoneyException {
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;
}
Expand Down Expand Up @@ -3450,6 +3451,7 @@ public FeeCalculation(SendRequest req, BigInteger value, List<TransactionInput>
// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@
* 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<TransactionOutput> candidates);
}

0 comments on commit 38e3f6f

Please sign in to comment.