diff --git a/src/wallet/coinselection.h b/src/wallet/coinselection.h index da1d85216..09ebdc21d 100644 --- a/src/wallet/coinselection.h +++ b/src/wallet/coinselection.h @@ -1,76 +1,87 @@ // 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_WALLET_COINSELECTION_H #define BITCOIN_WALLET_COINSELECTION_H #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; } + CInputCoin(const CTransactionRef &tx, unsigned int i, int input_bytes) + : CInputCoin(tx, i) { + m_input_bytes = input_bytes; + } + COutPoint outpoint; CTxOut txout; Amount effective_value; Amount fee = Amount::zero(); Amount long_term_fee = Amount::zero(); + /** + * Pre-computed estimated size of this output as a fully-signed input in a + * transaction. Can be -1 if it could not be calculated. + */ + int m_input_bytes{-1}; + 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; } }; struct CoinEligibilityFilter { const int conf_mine; const int conf_theirs; const uint64_t max_ancestors; const uint64_t max_descendants; CoinEligibilityFilter(int conf_mine_, int conf_theirs_, uint64_t max_ancestors_) : conf_mine(conf_mine_), conf_theirs(conf_theirs_), max_ancestors(max_ancestors_), max_descendants(max_ancestors_) {} CoinEligibilityFilter(int conf_mine_, int conf_theirs_, uint64_t max_ancestors_, uint64_t max_descendants_) : conf_mine(conf_mine_), conf_theirs(conf_theirs_), max_ancestors(max_ancestors_), max_descendants(max_descendants_) {} }; bool SelectCoinsBnB(std::vector &utxo_pool, const Amount &target_value, const Amount &cost_of_change, std::set &out_set, Amount &value_ret, const Amount not_input_fees); // Original coin selection algorithm as a fallback bool KnapsackSolver(const Amount nTargetValue, std::vector &vCoins, std::set &setCoinsRet, Amount &nValueRet); #endif // BITCOIN_WALLET_COINSELECTION_H diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index af14af160..0ac89fdae 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1,1394 +1,1398 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2016 The Bitcoin Core developers // Copyright (c) 2018 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_WALLET_WALLET_H #define BITCOIN_WALLET_WALLET_H #include #include