diff options
author | Andrew Chow <achow101-github@achow101.com> | 2018-03-07 12:18:37 -0500 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2018-03-13 12:39:26 -0400 |
commit | 4b2716da46e96c45206db869b83c28c5fc7889f4 (patch) | |
tree | 79b43ea07fa17c0a2a56a3fcea75cd93aae510ba /src/wallet/coinselection.h | |
parent | 7d77eb1a5b980a7d56acbf0b3861434c5e195c54 (diff) |
Remove coinselection.h -> wallet.h circular dependency
Changes CInputCoin to coinselection and to use CTransactionRef in
order to avoid a circular dependency. Also moves other coin selection
specific variables out of wallet.h to coinselectoin.h
Diffstat (limited to 'src/wallet/coinselection.h')
-rw-r--r-- | src/wallet/coinselection.h | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/wallet/coinselection.h b/src/wallet/coinselection.h index a98f1cc7c1..bbfa08a242 100644 --- a/src/wallet/coinselection.h +++ b/src/wallet/coinselection.h @@ -8,7 +8,44 @@ #include <amount.h> #include <primitives/transaction.h> #include <random.h> -#include <wallet/wallet.h> + +//! target minimum change amount +static const CAmount MIN_CHANGE = CENT; +//! final minimum change amount after paying for fees +static const CAmount MIN_FINAL_CHANGE = MIN_CHANGE/2; + +class CInputCoin { +public: + CInputCoin(const CTransactionRef& tx, unsigned int i) + { + if (!tx) + throw std::invalid_argument("tx should not be null"); + if (i >= tx->vout.size()) + throw std::out_of_range("The output index is out of range"); + + outpoint = COutPoint(tx->GetHash(), i); + txout = tx->vout[i]; + effective_value = txout.nValue; + } + + COutPoint outpoint; + CTxOut txout; + CAmount effective_value; + CAmount fee = 0; + CAmount long_term_fee = 0; + + bool operator<(const CInputCoin& rhs) const { + return outpoint < rhs.outpoint; + } + + bool operator!=(const CInputCoin& rhs) const { + return outpoint != rhs.outpoint; + } + + bool operator==(const CInputCoin& rhs) const { + return outpoint == rhs.outpoint; + } +}; bool SelectCoinsBnB(std::vector<CInputCoin>& utxo_pool, const CAmount& target_value, const CAmount& cost_of_change, std::set<CInputCoin>& out_set, CAmount& value_ret, CAmount not_input_fees); |