mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-10 17:26:28 +01:00
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:
parent
ac2e244bc8
commit
cd57fea864
2 changed files with 4 additions and 16 deletions
|
@ -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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue