Skip to content

Commit 4b2716d

Browse files
committed
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
1 parent 7d77eb1 commit 4b2716d

File tree

3 files changed

+43
-43
lines changed

3 files changed

+43
-43
lines changed

src/wallet/coinselection.h

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,44 @@
88
#include <amount.h>
99
#include <primitives/transaction.h>
1010
#include <random.h>
11-
#include <wallet/wallet.h>
11+
12+
//! target minimum change amount
13+
static const CAmount MIN_CHANGE = CENT;
14+
//! final minimum change amount after paying for fees
15+
static const CAmount MIN_FINAL_CHANGE = MIN_CHANGE/2;
16+
17+
class CInputCoin {
18+
public:
19+
CInputCoin(const CTransactionRef& tx, unsigned int i)
20+
{
21+
if (!tx)
22+
throw std::invalid_argument("tx should not be null");
23+
if (i >= tx->vout.size())
24+
throw std::out_of_range("The output index is out of range");
25+
26+
outpoint = COutPoint(tx->GetHash(), i);
27+
txout = tx->vout[i];
28+
effective_value = txout.nValue;
29+
}
30+
31+
COutPoint outpoint;
32+
CTxOut txout;
33+
CAmount effective_value;
34+
CAmount fee = 0;
35+
CAmount long_term_fee = 0;
36+
37+
bool operator<(const CInputCoin& rhs) const {
38+
return outpoint < rhs.outpoint;
39+
}
40+
41+
bool operator!=(const CInputCoin& rhs) const {
42+
return outpoint != rhs.outpoint;
43+
}
44+
45+
bool operator==(const CInputCoin& rhs) const {
46+
return outpoint == rhs.outpoint;
47+
}
48+
};
1249

1350
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);
1451

src/wallet/wallet.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,7 +2516,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const CoinEligibil
25162516
if (!OutputEligibleForSpending(output, eligibilty_filter))
25172517
continue;
25182518

2519-
CInputCoin coin = CInputCoin(output.tx, output.i);
2519+
CInputCoin coin = CInputCoin(output.tx->tx, output.i);
25202520

25212521
if (coin.txout.nValue == nTargetValue)
25222522
{
@@ -2606,7 +2606,7 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm
26062606
if (!out.fSpendable)
26072607
continue;
26082608
nValueRet += out.tx->tx->vout[out.i].nValue;
2609-
setCoinsRet.insert(CInputCoin(out.tx, out.i));
2609+
setCoinsRet.insert(CInputCoin(out.tx->tx, out.i));
26102610
}
26112611
return (nValueRet >= nTargetValue);
26122612
}
@@ -2628,15 +2628,15 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm
26282628
if (pcoin->tx->vout.size() <= outpoint.n)
26292629
return false;
26302630
nValueFromPresetInputs += pcoin->tx->vout[outpoint.n].nValue;
2631-
setPresetCoins.insert(CInputCoin(pcoin, outpoint.n));
2631+
setPresetCoins.insert(CInputCoin(pcoin->tx, outpoint.n));
26322632
} else
26332633
return false; // TODO: Allow non-wallet inputs
26342634
}
26352635

26362636
// remove preset inputs from vCoins
26372637
for (std::vector<COutput>::iterator it = vCoins.begin(); it != vCoins.end() && coinControl && coinControl->HasSelected();)
26382638
{
2639-
if (setPresetCoins.count(CInputCoin(it->tx, it->i)))
2639+
if (setPresetCoins.count(CInputCoin(it->tx->tx, it->i)))
26402640
it = vCoins.erase(it);
26412641
else
26422642
++it;

src/wallet/wallet.h

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <script/sign.h>
1818
#include <util.h>
1919
#include <wallet/crypter.h>
20+
#include <wallet/coinselection.h>
2021
#include <wallet/walletdb.h>
2122
#include <wallet/rpcwallet.h>
2223

@@ -53,10 +54,6 @@ static const CAmount DEFAULT_DISCARD_FEE = 10000;
5354
static const CAmount DEFAULT_TRANSACTION_MINFEE = 1000;
5455
//! minimum recommended increment for BIP 125 replacement txs
5556
static const CAmount WALLET_INCREMENTAL_RELAY_FEE = 5000;
56-
//! target minimum change amount
57-
static const CAmount MIN_CHANGE = CENT;
58-
//! final minimum change amount after paying for fees
59-
static const CAmount MIN_FINAL_CHANGE = MIN_CHANGE/2;
6057
//! Default for -spendzeroconfchange
6158
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
6259
//! Default for -walletrejectlongchains
@@ -497,40 +494,6 @@ class CWalletTx : public CMerkleTx
497494
std::set<uint256> GetConflicts() const;
498495
};
499496

500-
501-
class CInputCoin {
502-
public:
503-
CInputCoin(const CWalletTx* walletTx, unsigned int i)
504-
{
505-
if (!walletTx)
506-
throw std::invalid_argument("walletTx should not be null");
507-
if (i >= walletTx->tx->vout.size())
508-
throw std::out_of_range("The output index is out of range");
509-
510-
outpoint = COutPoint(walletTx->GetHash(), i);
511-
txout = walletTx->tx->vout[i];
512-
effective_value = txout.nValue;
513-
}
514-
515-
COutPoint outpoint;
516-
CTxOut txout;
517-
CAmount effective_value;
518-
CAmount fee = 0;
519-
CAmount long_term_fee = 0;
520-
521-
bool operator<(const CInputCoin& rhs) const {
522-
return outpoint < rhs.outpoint;
523-
}
524-
525-
bool operator!=(const CInputCoin& rhs) const {
526-
return outpoint != rhs.outpoint;
527-
}
528-
529-
bool operator==(const CInputCoin& rhs) const {
530-
return outpoint == rhs.outpoint;
531-
}
532-
};
533-
534497
class COutput
535498
{
536499
public:

0 commit comments

Comments
 (0)