diff --git a/src/wallet/coinselection.h b/src/wallet/coinselection.h --- a/src/wallet/coinselection.h +++ b/src/wallet/coinselection.h @@ -8,7 +8,45 @@ #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, diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -46,10 +47,6 @@ static const Amount DEFAULT_FALLBACK_FEE(20000 * SATOSHI); //! minimum recommended increment for BIP 125 replacement txs static const Amount WALLET_INCREMENTAL_RELAY_FEE(5000 * SATOSHI); -//! 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; //! Default for -spendzeroconfchange static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true; //! Default for -walletrejectlongchains @@ -480,40 +477,6 @@ std::set GetConflicts() const; }; -class CInputCoin { -public: - CInputCoin(const CWalletTx *walletTx, unsigned int i) { - if (!walletTx) { - throw std::invalid_argument("walletTx should not be null"); - } - if (i >= walletTx->tx->vout.size()) { - throw std::out_of_range("The output index is out of range"); - } - - outpoint = COutPoint(walletTx->GetId(), i); - txout = walletTx->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; - } -}; - class COutput { public: const CWalletTx *tx; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2600,7 +2600,7 @@ continue; } - CInputCoin coin = CInputCoin(output.tx, output.i); + CInputCoin coin = CInputCoin(output.tx->tx, output.i); if (coin.txout.nValue == nTargetValue) { setCoinsRet.insert(coin); @@ -2693,7 +2693,7 @@ } nValueRet += out.tx->tx->vout[out.i].nValue; - setCoinsRet.insert(CInputCoin(out.tx, out.i)); + setCoinsRet.insert(CInputCoin(out.tx->tx, out.i)); } return (nValueRet >= nTargetValue); @@ -2723,13 +2723,13 @@ } nValueFromPresetInputs += pcoin->tx->vout[outpoint.GetN()].nValue; - setPresetCoins.insert(CInputCoin(pcoin, outpoint.GetN())); + setPresetCoins.insert(CInputCoin(pcoin->tx, outpoint.GetN())); } // Remove preset inputs from vCoins. for (std::vector::iterator it = vCoins.begin(); it != vCoins.end() && coinControl && coinControl->HasSelected();) { - if (setPresetCoins.count(CInputCoin(it->tx, it->i))) { + if (setPresetCoins.count(CInputCoin(it->tx->tx, it->i))) { it = vCoins.erase(it); } else { ++it;