Make change selectable in regtest mode even if there is only one peer.

This commit is contained in:
Mike Hearn 2014-01-30 11:14:13 +01:00
parent 28b24d0eaa
commit b5127f4414
2 changed files with 12 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import com.google.bitcoin.core.NetworkParameters;
import com.google.bitcoin.core.Transaction;
import com.google.bitcoin.core.TransactionConfidence;
import com.google.bitcoin.core.TransactionOutput;
import com.google.bitcoin.params.RegTestParams;
import com.google.common.annotations.VisibleForTesting;
import java.math.BigInteger;
@ -78,10 +79,12 @@ public class DefaultCoinSelector implements CoinSelector {
// Only pick chain-included transactions, or transactions that are ours and pending.
TransactionConfidence confidence = tx.getConfidence();
TransactionConfidence.ConfidenceType type = confidence.getConfidenceType();
if (type.equals(TransactionConfidence.ConfidenceType.BUILDING))
return true;
return type.equals(TransactionConfidence.ConfidenceType.PENDING) &&
return type.equals(TransactionConfidence.ConfidenceType.BUILDING) ||
type.equals(TransactionConfidence.ConfidenceType.PENDING) &&
confidence.getSource().equals(TransactionConfidence.Source.SELF) &&
confidence.numBroadcastPeers() > 1;
// In regtest mode we expect to have only one peer, so we won't see transactions propagate.
// TODO: The value 1 below dates from a time when transactions we broadcast *to* were counted, set to 0
(confidence.numBroadcastPeers() > 1 || tx.getParams() == RegTestParams.get());
}
}

View File

@ -17,6 +17,7 @@
package com.google.bitcoin.wallet;
import com.google.bitcoin.core.*;
import com.google.bitcoin.params.RegTestParams;
import com.google.bitcoin.params.UnitTestParams;
import com.google.bitcoin.utils.TestUtils;
import com.google.bitcoin.utils.TestWithWallet;
@ -61,6 +62,10 @@ public class DefaultCoinSelectorTest extends TestWithWallet {
t = new Transaction(params);
t.getConfidence().setConfidenceType(TransactionConfidence.ConfidenceType.BUILDING);
assertTrue(DefaultCoinSelector.isSelectable(t));
t = new Transaction(RegTestParams.get());
t.getConfidence().setConfidenceType(TransactionConfidence.ConfidenceType.PENDING);
t.getConfidence().setSource(TransactionConfidence.Source.SELF);
assertTrue(DefaultCoinSelector.isSelectable(t));
}
@Test