mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-14 11:15:51 +00:00
Wallet: null out the candidates list after selection so selectors can edit the list if they want.
This commit is contained in:
parent
6e999c6054
commit
38e3f6fb9d
@ -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.");
|
checkState(req.tx.getOutputs().size() == 1, "Empty wallet TX must have a single output only.");
|
||||||
CoinSelector selector = req.coinSelector == null ? coinSelector : req.coinSelector;
|
CoinSelector selector = req.coinSelector == null ? coinSelector : req.coinSelector;
|
||||||
bestCoinSelection = selector.select(NetworkParameters.MAX_MONEY, candidates);
|
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);
|
req.tx.getOutput(0).setValue(bestCoinSelection.valueGathered);
|
||||||
totalOutput = 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.
|
// Of the coins we could spend, pick some that we actually will spend.
|
||||||
CoinSelector selector = req.coinSelector == null ? coinSelector : req.coinSelector;
|
CoinSelector selector = req.coinSelector == null ? coinSelector : req.coinSelector;
|
||||||
CoinSelection selection = selector.select(valueNeeded, candidates);
|
CoinSelection selection = selector.select(valueNeeded, candidates);
|
||||||
|
candidates = null; // Selector took ownership and might have changed candidates. Don't access again.
|
||||||
// Can we afford this?
|
// Can we afford this?
|
||||||
if (selection.valueGathered.compareTo(valueNeeded) < 0) {
|
if (selection.valueGathered.compareTo(valueNeeded) < 0) {
|
||||||
valueMissing = valueNeeded.subtract(selection.valueGathered);
|
valueMissing = valueNeeded.subtract(selection.valueGathered);
|
||||||
|
@ -12,5 +12,10 @@ import java.util.LinkedList;
|
|||||||
* enough money in the wallet.
|
* enough money in the wallet.
|
||||||
*/
|
*/
|
||||||
public interface CoinSelector {
|
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);
|
public CoinSelection select(BigInteger target, LinkedList<TransactionOutput> candidates);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user