From 1f52b75ad90cf67b4e578b819f2b679429ef6fe6 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Fri, 20 Sep 2013 17:38:41 +0200 Subject: [PATCH] Move AllowUnconfirmedCoinSelector out into wallet package. --- .../java/com/google/bitcoin/core/Wallet.java | 22 +----------------- .../channels/PaymentChannelClientState.java | 3 ++- .../wallet/AllowUnconfirmedCoinSelector.java | 23 +++++++++++++++++++ 3 files changed, 26 insertions(+), 22 deletions(-) create mode 100644 core/src/main/java/com/google/bitcoin/wallet/AllowUnconfirmedCoinSelector.java diff --git a/core/src/main/java/com/google/bitcoin/core/Wallet.java b/core/src/main/java/com/google/bitcoin/core/Wallet.java index 00dff175..d85bc6c9 100644 --- a/core/src/main/java/com/google/bitcoin/core/Wallet.java +++ b/core/src/main/java/com/google/bitcoin/core/Wallet.java @@ -153,26 +153,6 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi private volatile long vKeyRotationTimestamp; private volatile boolean vKeyRotationEnabled; - /** - * This coin selector will select any transaction at all, regardless of where it came from or whether it was - * confirmed yet. However immature coinbases will not be included (would be a protocol violation). - */ - public static class AllowUnconfirmedCoinSelector extends DefaultCoinSelector { - @Override protected boolean shouldSelect(Transaction tx) { - return true; - } - - private static AllowUnconfirmedCoinSelector instance; - - /** Returns a global static instance of the selector. */ - public static AllowUnconfirmedCoinSelector get() { - // This doesn't have to be thread safe as the object has no state, so discarded duplicates are harmless. - if (instance == null) - instance = new AllowUnconfirmedCoinSelector(); - return instance; - } - } - private transient CoinSelector coinSelector = new DefaultCoinSelector(); // The keyCrypter for the wallet. This specifies the algorithm used for encrypting and decrypting the private keys. @@ -2836,7 +2816,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi * be dangerous - only use this if you absolutely know what you're doing! */ public void allowSpendingUnconfirmedTransactions() { - setCoinSelector(Wallet.AllowUnconfirmedCoinSelector.get()); + setCoinSelector(AllowUnconfirmedCoinSelector.get()); } private static class BalanceFutureRequest { diff --git a/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelClientState.java b/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelClientState.java index 4b3ada8b..af9b7abf 100644 --- a/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelClientState.java +++ b/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelClientState.java @@ -20,6 +20,7 @@ import com.google.bitcoin.core.*; import com.google.bitcoin.crypto.TransactionSignature; import com.google.bitcoin.script.Script; import com.google.bitcoin.script.ScriptBuilder; +import com.google.bitcoin.wallet.AllowUnconfirmedCoinSelector; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; @@ -176,7 +177,7 @@ public class PaymentChannelClientState { if (multisigOutput.getMinNonDustValue().compareTo(totalValue) > 0) throw new ValueOutOfRangeException("totalValue too small to use"); Wallet.SendRequest req = Wallet.SendRequest.forTx(template); - req.coinSelector = Wallet.AllowUnconfirmedCoinSelector.get(); + req.coinSelector = AllowUnconfirmedCoinSelector.get(); editContractSendRequest(req); if (!wallet.completeTx(req)) throw new ValueOutOfRangeException("Cannot afford this channel"); diff --git a/core/src/main/java/com/google/bitcoin/wallet/AllowUnconfirmedCoinSelector.java b/core/src/main/java/com/google/bitcoin/wallet/AllowUnconfirmedCoinSelector.java new file mode 100644 index 00000000..0a9a546f --- /dev/null +++ b/core/src/main/java/com/google/bitcoin/wallet/AllowUnconfirmedCoinSelector.java @@ -0,0 +1,23 @@ +package com.google.bitcoin.wallet; + +import com.google.bitcoin.core.Transaction; + +/** + * This coin selector will select any transaction at all, regardless of where it came from or whether it was + * confirmed yet. However immature coinbases will not be included (would be a protocol violation). + */ +public class AllowUnconfirmedCoinSelector extends DefaultCoinSelector { + @Override protected boolean shouldSelect(Transaction tx) { + return true; + } + + private static AllowUnconfirmedCoinSelector instance; + + /** Returns a global static instance of the selector. */ + public static AllowUnconfirmedCoinSelector get() { + // This doesn't have to be thread safe as the object has no state, so discarded duplicates are harmless. + if (instance == null) + instance = new AllowUnconfirmedCoinSelector(); + return instance; + } +}