DefaultCoinSelector, AllowUnconfirmedCoinSelector: remove singleton pattern

Instantiating these classes is cheap, as they're stateless. And we
only do that once per `Wallet` instance.
This commit is contained in:
Andreas Schildbach 2023-04-01 22:34:08 +02:00
parent ac2e244bc8
commit cd57fea864
2 changed files with 4 additions and 16 deletions

View file

@ -23,17 +23,12 @@ import org.bitcoinj.core.Transaction;
* confirmed yet. However immature coinbases will not be included (would be a protocol violation). * confirmed yet. However immature coinbases will not be included (would be a protocol violation).
*/ */
public class AllowUnconfirmedCoinSelector extends DefaultCoinSelector { public class AllowUnconfirmedCoinSelector extends DefaultCoinSelector {
@Override protected boolean shouldSelect(Transaction tx) { @Override
protected boolean shouldSelect(Transaction tx) {
return true; return true;
} }
private static AllowUnconfirmedCoinSelector instance;
/** Returns a global static instance of the selector. */
public static AllowUnconfirmedCoinSelector get() { public static AllowUnconfirmedCoinSelector get() {
// This doesn't have to be thread safe as the object has no state, so discarded duplicates are harmless. return new AllowUnconfirmedCoinSelector();
if (instance == null)
instance = new AllowUnconfirmedCoinSelector();
return instance;
} }
} }

View file

@ -104,14 +104,7 @@ public class DefaultCoinSelector implements CoinSelector {
(confidence.numBroadcastPeers() > 0 || tx.getParams().network() == BitcoinNetwork.REGTEST); (confidence.numBroadcastPeers() > 0 || tx.getParams().network() == BitcoinNetwork.REGTEST);
} }
private static DefaultCoinSelector instance;
/** Returns a global static instance of the selector. */
public static DefaultCoinSelector get() { public static DefaultCoinSelector get() {
// This doesn't have to be thread safe as the object has no state, so discarded duplicates are return new DefaultCoinSelector();
// harmless.
if (instance == null)
instance = new DefaultCoinSelector();
return instance;
} }
} }