Skip to content

Commit 25749f1

Browse files
committed
wallet: unify “allow/block other inputs“ concept
Seeking to make the `CoinControl` option less confusing/redundant. In #16377 the `CoinControl` flag ‘m_add_inputs’ was added to tell the coin filtering and selection process two things: - Coin Filtering: Only use the provided inputs. Skip the Rest. - Coin Selection: Search the wtxs-outputs and append all the `CoinControl` selected outpoints to the selection result (skipping all the available output checks). Nothing else. Meanwhile, in `CoinControl` we already have a flag ‘fAllowOtherInputs’ which is already saying: - Coin Filtering: Only use the provided inputs. Skip the Rest. - Coin Selection: If false, no selection process -> append all the `CoinControl` selected outpoints to the selection result (while they passed all the `AvailableCoins` checks and are available in the 'vCoins' vector). As can notice, the first point in the coin filtering process is duplicated in the two option flags. And the second one, is slightly different merely because it takes into account whether the coin is on the `AvailableCoins` vector or not. So it makes sense to merge ‘m_add_inputs’ and ‘fAllowOtherInputs’ into a single field for the coin filtering process while introduce other changes to add the missing/skipped coins into 'vCoins' vector if they were manually selected by the user (follow-up commits).
1 parent 8e7eeb5 commit 25749f1

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

src/wallet/coincontrol.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ class CCoinControl
3333
CTxDestination destChange = CNoDestination();
3434
//! Override the default change type if set, ignored if destChange is set
3535
std::optional<OutputType> m_change_type;
36-
//! If false, only selected inputs are used
37-
bool m_add_inputs = true;
3836
//! If false, only safe inputs will be used
3937
bool m_include_unsafe_inputs = false;
40-
//! If false, allows unselected inputs, but requires all selected inputs be used
38+
//! If true, the selection process can add extra unselected inputs from the wallet
39+
//! while requires all selected inputs be used
4140
bool fAllowOtherInputs = false;
4241
//! Includes watch only addresses which are solvable
4342
bool fAllowWatchOnly = false;

src/wallet/rpc/spend.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,8 @@ void FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& fee_out,
535535
},
536536
true, true);
537537

538-
if (options.exists("add_inputs") ) {
539-
coinControl.m_add_inputs = options["add_inputs"].get_bool();
538+
if (options.exists("add_inputs")) {
539+
coinControl.fAllowOtherInputs = options["add_inputs"].get_bool();
540540
}
541541

542542
if (options.exists("changeAddress") || options.exists("change_address")) {
@@ -823,7 +823,7 @@ RPCHelpMan fundrawtransaction()
823823
int change_position;
824824
CCoinControl coin_control;
825825
// Automatically select (additional) coins. Can be overridden by options.add_inputs.
826-
coin_control.m_add_inputs = true;
826+
coin_control.fAllowOtherInputs = true;
827827
FundTransaction(*pwallet, tx, fee, change_position, request.params[1], coin_control, /*override_min_fee=*/true);
828828

829829
UniValue result(UniValue::VOBJ);
@@ -1225,7 +1225,7 @@ RPCHelpMan send()
12251225
CCoinControl coin_control;
12261226
// Automatically select coins, unless at least one is manually selected. Can
12271227
// be overridden by options.add_inputs.
1228-
coin_control.m_add_inputs = rawTx.vin.size() == 0;
1228+
coin_control.fAllowOtherInputs = rawTx.vin.size() == 0;
12291229
SetOptionsInputWeights(options["inputs"], options);
12301230
FundTransaction(*pwallet, rawTx, fee, change_position, options, coin_control, /*override_min_fee=*/false);
12311231

@@ -1649,7 +1649,7 @@ RPCHelpMan walletcreatefundedpsbt()
16491649
CCoinControl coin_control;
16501650
// Automatically select coins, unless at least one is manually selected. Can
16511651
// be overridden by options.add_inputs.
1652-
coin_control.m_add_inputs = rawTx.vin.size() == 0;
1652+
coin_control.fAllowOtherInputs = rawTx.vin.size() == 0;
16531653
SetOptionsInputWeights(request.params[0], options);
16541654
FundTransaction(wallet, rawTx, fee, change_position, options, coin_control, /*override_min_fee=*/true);
16551655

src/wallet/spend.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,6 @@ CoinsResult AvailableCoins(const CWallet& wallet,
168168
const CTxOut& output = wtx.tx->vout[i];
169169
const COutPoint outpoint(wtxid, i);
170170

171-
// Only consider selected coins if add_inputs is false
172-
if (coinControl && !coinControl->m_add_inputs && !coinControl->IsSelected(outpoint)) {
173-
continue;
174-
}
175-
176171
if (output.nValue < nMinimumAmount || output.nValue > nMaximumAmount)
177172
continue;
178173

@@ -1033,8 +1028,6 @@ bool FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& nFeeRet,
10331028
vecSend.push_back(recipient);
10341029
}
10351030

1036-
coinControl.fAllowOtherInputs = true;
1037-
10381031
// Acquire the locks to prevent races to the new locked unspents between the
10391032
// CreateTransaction call and LockCoin calls (when lockUnspents is true).
10401033
LOCK(wallet.cs_wallet);

0 commit comments

Comments
 (0)