3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-07 14:54:15 +00:00

Wallet: null out the candidates list after selection so selectors can edit the list if they want.

This commit is contained in:
Mike Hearn 2014-04-23 15:44:45 +02:00
parent 6e999c6054
commit 38e3f6fb9d
2 changed files with 7 additions and 0 deletions

View File

@ -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);

View File

@ -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<TransactionOutput> candidates);
}