Skip to content

Commit 386ba92

Browse files
committed
Merge bitcoin/bitcoin#21910: refactor: remove redundant fOnlySafe argument
c30dd02 refactor: remove redundant fOnlySafe argument (t-bast) Pull request description: The `fOnlySafe` argument to `AvailableCoins` is now redundant, since #21359 added a similar field inside the `CCoinControl` struct (see bitcoin/bitcoin#21359 (comment)). Not all code paths create a `CCoinControl` instance, but when it's missing we can default to using only safe inputs which is backwards-compatible. ACKs for top commit: instagibbs: utACK c30dd02 promag: Code review ACK c30dd02. achow101: ACK c30dd02 meshcollider: Code review + test run ACK c30dd02 Tree-SHA512: af3cb598d06f233fc48a7c9c45bb14da92b5cf4168b8dbd4f134dc3e0c2b615c6590238ddb1eaf380aea5bbdd3386d2ac8ecd7d22dfc93579adc39248542839b
2 parents db2990d + c30dd02 commit 386ba92

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2970,8 +2970,9 @@ static RPCHelpMan listunspent()
29702970
cctl.m_avoid_address_reuse = false;
29712971
cctl.m_min_depth = nMinDepth;
29722972
cctl.m_max_depth = nMaxDepth;
2973+
cctl.m_include_unsafe_inputs = include_unsafe;
29732974
LOCK(pwallet->cs_wallet);
2974-
pwallet->AvailableCoins(vecOutputs, !include_unsafe, &cctl, nMinimumAmount, nMaximumAmount, nMinimumSumAmount, nMaximumCount);
2975+
pwallet->AvailableCoins(vecOutputs, &cctl, nMinimumAmount, nMaximumAmount, nMinimumSumAmount, nMaximumCount);
29752976
}
29762977

29772978
LOCK(pwallet->cs_wallet);

src/wallet/wallet.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,7 +2197,7 @@ CAmount CWallet::GetAvailableBalance(const CCoinControl* coinControl) const
21972197

21982198
CAmount balance = 0;
21992199
std::vector<COutput> vCoins;
2200-
AvailableCoins(vCoins, true, coinControl);
2200+
AvailableCoins(vCoins, coinControl);
22012201
for (const COutput& out : vCoins) {
22022202
if (out.fSpendable) {
22032203
balance += out.tx->tx->vout[out.i].nValue;
@@ -2206,7 +2206,7 @@ CAmount CWallet::GetAvailableBalance(const CCoinControl* coinControl) const
22062206
return balance;
22072207
}
22082208

2209-
void CWallet::AvailableCoins(std::vector<COutput>& vCoins, bool fOnlySafe, const CCoinControl* coinControl, const CAmount& nMinimumAmount, const CAmount& nMaximumAmount, const CAmount& nMinimumSumAmount, const uint64_t nMaximumCount) const
2209+
void CWallet::AvailableCoins(std::vector<COutput>& vCoins, const CCoinControl* coinControl, const CAmount& nMinimumAmount, const CAmount& nMaximumAmount, const CAmount& nMinimumSumAmount, const uint64_t nMaximumCount) const
22102210
{
22112211
AssertLockHeld(cs_wallet);
22122212

@@ -2217,6 +2217,7 @@ void CWallet::AvailableCoins(std::vector<COutput>& vCoins, bool fOnlySafe, const
22172217
bool allow_used_addresses = !IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE) || (coinControl && !coinControl->m_avoid_address_reuse);
22182218
const int min_depth = {coinControl ? coinControl->m_min_depth : DEFAULT_MIN_DEPTH};
22192219
const int max_depth = {coinControl ? coinControl->m_max_depth : DEFAULT_MAX_DEPTH};
2220+
const bool only_safe = {coinControl ? !coinControl->m_include_unsafe_inputs : true};
22202221

22212222
std::set<uint256> trusted_parents;
22222223
for (const auto& entry : mapWallet)
@@ -2273,7 +2274,7 @@ void CWallet::AvailableCoins(std::vector<COutput>& vCoins, bool fOnlySafe, const
22732274
safeTx = false;
22742275
}
22752276

2276-
if (fOnlySafe && !safeTx) {
2277+
if (only_safe && !safeTx) {
22772278
continue;
22782279
}
22792280

@@ -2843,7 +2844,7 @@ bool CWallet::CreateTransactionInternal(
28432844
txNew.nLockTime = GetLocktimeForNewTransaction(chain(), GetLastBlockHash(), GetLastBlockHeight());
28442845
{
28452846
std::vector<COutput> vAvailableCoins;
2846-
AvailableCoins(vAvailableCoins, !coin_control.m_include_unsafe_inputs, &coin_control, 1, MAX_MONEY, MAX_MONEY, 0);
2847+
AvailableCoins(vAvailableCoins, &coin_control, 1, MAX_MONEY, MAX_MONEY, 0);
28472848
CoinSelectionParams coin_selection_params; // Parameters for coin selection, init with dummy
28482849
coin_selection_params.m_avoid_partial_spends = coin_control.m_avoid_partial_spends;
28492850

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
850850
/**
851851
* populate vCoins with vector of available COutputs.
852852
*/
853-
void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlySafe = true, const CCoinControl* coinControl = nullptr, const CAmount& nMinimumAmount = 1, const CAmount& nMaximumAmount = MAX_MONEY, const CAmount& nMinimumSumAmount = MAX_MONEY, const uint64_t nMaximumCount = 0) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
853+
void AvailableCoins(std::vector<COutput>& vCoins, const CCoinControl* coinControl = nullptr, const CAmount& nMinimumAmount = 1, const CAmount& nMaximumAmount = MAX_MONEY, const CAmount& nMinimumSumAmount = MAX_MONEY, const uint64_t nMaximumCount = 0) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
854854

855855
/**
856856
* Return list of available coins and locked coins grouped by non-change output address.

0 commit comments

Comments
 (0)