mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-26 07:23:53 +01:00
Wallet: expose the calculateAllSpendCandidates method as public.
This commit is contained in:
parent
86f68c8ffa
commit
016837a593
1 changed files with 23 additions and 14 deletions
|
@ -1845,7 +1845,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi
|
||||||
// change - it could be pre-calculated and held in RAM, and this is probably an optimization worth doing.
|
// change - it could be pre-calculated and held in RAM, and this is probably an optimization worth doing.
|
||||||
// Note that output.isMine(this) needs to test the keychain which is currently an array, so it's
|
// Note that output.isMine(this) needs to test the keychain which is currently an array, so it's
|
||||||
// O(candidate outputs ^ keychain.size())! There's lots of low hanging fruit here.
|
// O(candidate outputs ^ keychain.size())! There's lots of low hanging fruit here.
|
||||||
LinkedList<TransactionOutput> candidates = calculateSpendCandidates(true);
|
LinkedList<TransactionOutput> candidates = calculateAllSpendCandidates(true);
|
||||||
CoinSelection bestCoinSelection;
|
CoinSelection bestCoinSelection;
|
||||||
TransactionOutput bestChangeOutput = null;
|
TransactionOutput bestChangeOutput = null;
|
||||||
if (!req.emptyWallet) {
|
if (!req.emptyWallet) {
|
||||||
|
@ -1929,8 +1929,14 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private LinkedList<TransactionOutput> calculateSpendCandidates(boolean excludeImmatureCoinbases) {
|
/**
|
||||||
checkState(lock.isHeldByCurrentThread());
|
* Returns a list of all possible outputs we could possibly spend, potentially even including immature coinbases
|
||||||
|
* (which the protocol may forbid us from spending). In other words, return all outputs that this wallet holds
|
||||||
|
* keys for and which are not already marked as spent.
|
||||||
|
*/
|
||||||
|
public LinkedList<TransactionOutput> calculateAllSpendCandidates(boolean excludeImmatureCoinbases) {
|
||||||
|
lock.lock();
|
||||||
|
try {
|
||||||
LinkedList<TransactionOutput> candidates = Lists.newLinkedList();
|
LinkedList<TransactionOutput> candidates = Lists.newLinkedList();
|
||||||
for (Transaction tx : Iterables.concat(unspent.values(), pending.values())) {
|
for (Transaction tx : Iterables.concat(unspent.values(), pending.values())) {
|
||||||
// Do not try and spend coinbases that were mined too recently, the protocol forbids it.
|
// Do not try and spend coinbases that were mined too recently, the protocol forbids it.
|
||||||
|
@ -1942,6 +1948,9 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return candidates;
|
return candidates;
|
||||||
|
} finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the address used for change outputs. Note: this will probably go away in future. */
|
/** Returns the address used for change outputs. Note: this will probably go away in future. */
|
||||||
|
@ -2101,7 +2110,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi
|
||||||
if (balanceType == BalanceType.AVAILABLE) {
|
if (balanceType == BalanceType.AVAILABLE) {
|
||||||
return getBalance(coinSelector);
|
return getBalance(coinSelector);
|
||||||
} else if (balanceType == BalanceType.ESTIMATED) {
|
} else if (balanceType == BalanceType.ESTIMATED) {
|
||||||
LinkedList<TransactionOutput> all = calculateSpendCandidates(false);
|
LinkedList<TransactionOutput> all = calculateAllSpendCandidates(false);
|
||||||
BigInteger value = BigInteger.ZERO;
|
BigInteger value = BigInteger.ZERO;
|
||||||
for (TransactionOutput out : all) value = value.add(out.getValue());
|
for (TransactionOutput out : all) value = value.add(out.getValue());
|
||||||
return value;
|
return value;
|
||||||
|
@ -2121,7 +2130,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
checkNotNull(selector);
|
checkNotNull(selector);
|
||||||
LinkedList<TransactionOutput> candidates = calculateSpendCandidates(true);
|
LinkedList<TransactionOutput> candidates = calculateAllSpendCandidates(true);
|
||||||
CoinSelection selection = selector.select(NetworkParameters.MAX_MONEY, candidates);
|
CoinSelection selection = selector.select(NetworkParameters.MAX_MONEY, candidates);
|
||||||
return selection.valueGathered;
|
return selection.valueGathered;
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Loading…
Add table
Reference in a new issue