diff --git a/src/wallet/coinselection.h b/src/wallet/coinselection.h index 405c0e8b9..eedee8490 100644 --- a/src/wallet/coinselection.h +++ b/src/wallet/coinselection.h @@ -1,18 +1,56 @@ // Copyright (c) 2017 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_COINSELECTION_H #define BITCOIN_COINSELECTION_H #include #include #include -#include + +//! target minimum change amount +static const Amount MIN_CHANGE = CENT; +//! final minimum change amount after paying for fees +static const Amount 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->GetId(), i); + txout = tx->vout[i]; + effective_value = txout.nValue; + } + + COutPoint outpoint; + CTxOut txout; + Amount effective_value; + Amount fee = Amount::zero(); + Amount long_term_fee = Amount::zero(); + + 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 &utxo_pool, const Amount &target_value, const Amount &cost_of_change, std::set &out_set, Amount &value_ret, Amount not_input_fees); #endif // BITCOIN_COINSELECTION_H diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index fb3b960f2..e6772a871 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1,4555 +1,4555 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2016 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // for IsDeprecatedRPCEnabled #include #include