mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-31 23:32:16 +00:00
Split some selection logic into a static method of DefaultCoinSelector. Resolves issue 322.
This commit is contained in:
parent
27a49655fb
commit
e57068451d
@ -244,6 +244,17 @@ public class Wallet implements Serializable, BlockChainListener {
|
||||
// bit over (excessive value will be change).
|
||||
for (TransactionOutput output : sortedOutputs) {
|
||||
if (total >= target) break;
|
||||
// Only pick chain-included transactions, or transactions that are ours and pending.
|
||||
if (!isSelectable(output)) continue;
|
||||
selected.add(output);
|
||||
total += output.getValue().longValue();
|
||||
}
|
||||
// Total may be lower than target here, if the given candidates were insufficient to create to requested
|
||||
// transaction.
|
||||
return new CoinSelection(BigInteger.valueOf(total), selected);
|
||||
}
|
||||
|
||||
public static boolean isSelectable(TransactionOutput output) {
|
||||
// Only pick chain-included transactions, or transactions that are ours and pending.
|
||||
TransactionConfidence confidence = output.parentTransaction.getConfidence();
|
||||
ConfidenceType type = confidence.getConfidenceType();
|
||||
@ -252,19 +263,14 @@ public class Wallet implements Serializable, BlockChainListener {
|
||||
boolean confirmed = type.equals(ConfidenceType.BUILDING);
|
||||
if (!confirmed) {
|
||||
// If the transaction is still pending ...
|
||||
if (!pending) continue;
|
||||
if (!pending) return false;
|
||||
// And it was created by us ...
|
||||
if (!confidence.getSource().equals(TransactionConfidence.Source.SELF)) continue;
|
||||
if (!confidence.getSource().equals(TransactionConfidence.Source.SELF)) return false;
|
||||
// And it's been seen by the network and propagated ...
|
||||
if (confidence.numBroadcastPeers() <= 1) continue;
|
||||
if (confidence.numBroadcastPeers() <= 1) return false;
|
||||
// Then it's OK to select.
|
||||
}
|
||||
selected.add(output);
|
||||
total += output.getValue().longValue();
|
||||
}
|
||||
// Total may be lower than target here, if the given candidates were insufficient to create to requested
|
||||
// transaction.
|
||||
return new CoinSelection(BigInteger.valueOf(total), selected);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -570,7 +576,6 @@ public class Wallet implements Serializable, BlockChainListener {
|
||||
* @param delayTime How many time units to wait until saving the wallet on a background thread.
|
||||
* @param timeUnit the unit of measurement for delayTime.
|
||||
* @param eventListener callback to be informed when the auto-save thread does things, or null
|
||||
* @throws IOException
|
||||
*/
|
||||
public synchronized void autosaveToFile(File f, long delayTime, TimeUnit timeUnit,
|
||||
AutosaveEventListener eventListener) {
|
||||
|
Loading…
Reference in New Issue
Block a user