From c4405d3ee7611e74a370b4cb0b1008a8e6ece678 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Fri, 20 Sep 2013 16:45:31 +0200 Subject: [PATCH] Wallet: Split CoinSelector out into a top level interface in the wallet package. --- .../bitcoin/core/TransactionConfidence.java | 4 ++-- .../java/com/google/bitcoin/core/Wallet.java | 13 ++----------- .../com/google/bitcoin/wallet/CoinSelector.java | 17 +++++++++++++++++ .../bitcoin/wallet/KeyTimeCoinSelector.java | 2 +- 4 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 core/src/main/java/com/google/bitcoin/wallet/CoinSelector.java diff --git a/core/src/main/java/com/google/bitcoin/core/TransactionConfidence.java b/core/src/main/java/com/google/bitcoin/core/TransactionConfidence.java index 5f95cbe9..d7f64f23 100644 --- a/core/src/main/java/com/google/bitcoin/core/TransactionConfidence.java +++ b/core/src/main/java/com/google/bitcoin/core/TransactionConfidence.java @@ -423,7 +423,7 @@ public class TransactionConfidence implements Serializable { /** * The source of a transaction tries to identify where it came from originally. For instance, did we download it * from the peer to peer network, or make it ourselves, or receive it via Bluetooth, or import it from another app, - * and so on. This information is useful for {@link Wallet.CoinSelector} implementations to risk analyze + * and so on. This information is useful for {@link com.google.bitcoin.wallet.CoinSelector} implementations to risk analyze * transactions and decide when to spend them. */ public synchronized Source getSource() { @@ -433,7 +433,7 @@ public class TransactionConfidence implements Serializable { /** * The source of a transaction tries to identify where it came from originally. For instance, did we download it * from the peer to peer network, or make it ourselves, or receive it via Bluetooth, or import it from another app, - * and so on. This information is useful for {@link Wallet.CoinSelector} implementations to risk analyze + * and so on. This information is useful for {@link com.google.bitcoin.wallet.CoinSelector} implementations to risk analyze * transactions and decide when to spend them. */ public synchronized void setSource(Source source) { 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 277a724f..09cf97ee 100644 --- a/core/src/main/java/com/google/bitcoin/core/Wallet.java +++ b/core/src/main/java/com/google/bitcoin/core/Wallet.java @@ -25,6 +25,7 @@ import com.google.bitcoin.store.UnreadableWalletException; import com.google.bitcoin.store.WalletProtobufSerializer; import com.google.bitcoin.utils.ListenerRegistration; import com.google.bitcoin.utils.Threading; +import com.google.bitcoin.wallet.CoinSelector; import com.google.bitcoin.wallet.KeyTimeCoinSelector; import com.google.bitcoin.wallet.WalletFiles; import com.google.common.base.Preconditions; @@ -164,16 +165,6 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi } } - /** - * A CoinSelector is responsible for picking some outputs to spend, from the list of all spendable outputs. It - * allows you to customize the policies for creation of transactions to suit your needs. The select operation - * may return a {@link CoinSelection} that has a valueGathered lower than the requested target, if there's not - * enough money in the wallet. - */ - public interface CoinSelector { - public CoinSelection select(BigInteger target, LinkedList candidates); - } - /** * This class implements a {@link CoinSelector} which attempts to get the highest priority possible. This means that * the transaction is the most likely to get confirmed @@ -1636,7 +1627,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi public KeyParameter aesKey = null; /** - * If not null, the {@link Wallet.CoinSelector} to use instead of the wallets default. Coin selectors are + * If not null, the {@link com.google.bitcoin.wallet.CoinSelector} to use instead of the wallets default. Coin selectors are * responsible for choosing which transaction outputs (coins) in a wallet to use given the desired send value * amount. */ diff --git a/core/src/main/java/com/google/bitcoin/wallet/CoinSelector.java b/core/src/main/java/com/google/bitcoin/wallet/CoinSelector.java new file mode 100644 index 00000000..4742f40a --- /dev/null +++ b/core/src/main/java/com/google/bitcoin/wallet/CoinSelector.java @@ -0,0 +1,17 @@ +package com.google.bitcoin.wallet; + +import com.google.bitcoin.core.TransactionOutput; +import com.google.bitcoin.core.Wallet; + +import java.math.BigInteger; +import java.util.LinkedList; + +/** + * A CoinSelector is responsible for picking some outputs to spend, from the list of all spendable outputs. It + * allows you to customize the policies for creation of transactions to suit your needs. The select operation + * may return a {@link com.google.bitcoin.core.Wallet.CoinSelection} that has a valueGathered lower than the requested target, if there's not + * enough money in the wallet. + */ +public interface CoinSelector { + public Wallet.CoinSelection select(BigInteger target, LinkedList candidates); +} diff --git a/core/src/main/java/com/google/bitcoin/wallet/KeyTimeCoinSelector.java b/core/src/main/java/com/google/bitcoin/wallet/KeyTimeCoinSelector.java index dc4b5234..00fb4c0b 100644 --- a/core/src/main/java/com/google/bitcoin/wallet/KeyTimeCoinSelector.java +++ b/core/src/main/java/com/google/bitcoin/wallet/KeyTimeCoinSelector.java @@ -29,7 +29,7 @@ import java.util.LinkedList; * A coin selector that takes all coins assigned to keys created before the given timestamp. * Used as part of the implementation of {@link Wallet#setKeyRotationTime(java.util.Date)}. */ -public class KeyTimeCoinSelector implements Wallet.CoinSelector { +public class KeyTimeCoinSelector implements CoinSelector { private static final Logger log = LoggerFactory.getLogger(KeyTimeCoinSelector.class); /** A number of inputs chosen to avoid hitting {@link com.google.bitcoin.core.Transaction.MAX_STANDARD_TX_SIZE} */