mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-10 10:52:31 -05:00
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
This commit is contained in:
parent
7d77eb1a5b
commit
4b2716da46
3 changed files with 43 additions and 43 deletions
|
@ -8,7 +8,44 @@
|
||||||
#include <amount.h>
|
#include <amount.h>
|
||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
#include <random.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);
|
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);
|
||||||
|
|
||||||
|
|
|
@ -2516,7 +2516,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const CoinEligibil
|
||||||
if (!OutputEligibleForSpending(output, eligibilty_filter))
|
if (!OutputEligibleForSpending(output, eligibilty_filter))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
CInputCoin coin = CInputCoin(output.tx, output.i);
|
CInputCoin coin = CInputCoin(output.tx->tx, output.i);
|
||||||
|
|
||||||
if (coin.txout.nValue == nTargetValue)
|
if (coin.txout.nValue == nTargetValue)
|
||||||
{
|
{
|
||||||
|
@ -2606,7 +2606,7 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm
|
||||||
if (!out.fSpendable)
|
if (!out.fSpendable)
|
||||||
continue;
|
continue;
|
||||||
nValueRet += out.tx->tx->vout[out.i].nValue;
|
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);
|
return (nValueRet >= nTargetValue);
|
||||||
}
|
}
|
||||||
|
@ -2628,7 +2628,7 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm
|
||||||
if (pcoin->tx->vout.size() <= outpoint.n)
|
if (pcoin->tx->vout.size() <= outpoint.n)
|
||||||
return false;
|
return false;
|
||||||
nValueFromPresetInputs += pcoin->tx->vout[outpoint.n].nValue;
|
nValueFromPresetInputs += pcoin->tx->vout[outpoint.n].nValue;
|
||||||
setPresetCoins.insert(CInputCoin(pcoin, outpoint.n));
|
setPresetCoins.insert(CInputCoin(pcoin->tx, outpoint.n));
|
||||||
} else
|
} else
|
||||||
return false; // TODO: Allow non-wallet inputs
|
return false; // TODO: Allow non-wallet inputs
|
||||||
}
|
}
|
||||||
|
@ -2636,7 +2636,7 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm
|
||||||
// remove preset inputs from vCoins
|
// remove preset inputs from vCoins
|
||||||
for (std::vector<COutput>::iterator it = vCoins.begin(); it != vCoins.end() && coinControl && coinControl->HasSelected();)
|
for (std::vector<COutput>::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);
|
it = vCoins.erase(it);
|
||||||
else
|
else
|
||||||
++it;
|
++it;
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <script/sign.h>
|
#include <script/sign.h>
|
||||||
#include <util.h>
|
#include <util.h>
|
||||||
#include <wallet/crypter.h>
|
#include <wallet/crypter.h>
|
||||||
|
#include <wallet/coinselection.h>
|
||||||
#include <wallet/walletdb.h>
|
#include <wallet/walletdb.h>
|
||||||
#include <wallet/rpcwallet.h>
|
#include <wallet/rpcwallet.h>
|
||||||
|
|
||||||
|
@ -53,10 +54,6 @@ static const CAmount DEFAULT_DISCARD_FEE = 10000;
|
||||||
static const CAmount DEFAULT_TRANSACTION_MINFEE = 1000;
|
static const CAmount DEFAULT_TRANSACTION_MINFEE = 1000;
|
||||||
//! minimum recommended increment for BIP 125 replacement txs
|
//! minimum recommended increment for BIP 125 replacement txs
|
||||||
static const CAmount WALLET_INCREMENTAL_RELAY_FEE = 5000;
|
static const CAmount WALLET_INCREMENTAL_RELAY_FEE = 5000;
|
||||||
//! 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;
|
|
||||||
//! Default for -spendzeroconfchange
|
//! Default for -spendzeroconfchange
|
||||||
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
|
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
|
||||||
//! Default for -walletrejectlongchains
|
//! Default for -walletrejectlongchains
|
||||||
|
@ -497,40 +494,6 @@ public:
|
||||||
std::set<uint256> GetConflicts() const;
|
std::set<uint256> 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->GetHash(), i);
|
|
||||||
txout = walletTx->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;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class COutput
|
class COutput
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Add table
Reference in a new issue