Skip to content

Commit 596642c

Browse files
committed
wallet: Replace SelectExternal with SetTxOut
Instead of having a separate CCoinControl::SelectExternal function, we can use the normal CCoinControl::Select function and explicitly use PreselectedInput::SetTxOut in the caller. The semantics of what an external input is remains.
1 parent 5321786 commit 596642c

File tree

6 files changed

+13
-25
lines changed

6 files changed

+13
-25
lines changed

src/wallet/coincontrol.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ PreselectedInput& CCoinControl::Select(const COutPoint& outpoint)
4141
{
4242
return m_selected[outpoint];
4343
}
44-
45-
void CCoinControl::SelectExternal(const COutPoint& outpoint, const CTxOut& txout)
46-
{
47-
m_selected[outpoint].SetTxOut(txout);
48-
}
49-
5044
void CCoinControl::UnSelect(const COutPoint& outpoint)
5145
{
5246
m_selected.erase(outpoint);

src/wallet/coincontrol.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,6 @@ class CCoinControl
108108
* The output will be included in the transaction even if it's not the most optimal choice.
109109
*/
110110
PreselectedInput& Select(const COutPoint& outpoint);
111-
/**
112-
* Lock-in the given output as an external input for spending because it is not in the wallet.
113-
* The output will be included in the transaction even if it's not the most optimal choice.
114-
*/
115-
void SelectExternal(const COutPoint& outpoint, const CTxOut& txout);
116111
/**
117112
* Unselects the given output.
118113
*/

src/wallet/feebumper.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,9 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
203203
errors.push_back(Untranslated(strprintf("%s:%u is already spent", txin.prevout.hash.GetHex(), txin.prevout.n)));
204204
return Result::MISC_ERROR;
205205
}
206-
if (wallet.IsMine(txin.prevout)) {
207-
new_coin_control.Select(txin.prevout);
208-
} else {
209-
new_coin_control.SelectExternal(txin.prevout, coin.out);
206+
PreselectedInput& preset_txin = new_coin_control.Select(txin.prevout);
207+
if (!wallet.IsMine(txin.prevout)) {
208+
preset_txin.SetTxOut(coin.out);
210209
}
211210
input_value += coin.out.nValue;
212211
spent_outputs.push_back(coin.out);

src/wallet/spend.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,15 +1347,15 @@ bool FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& nFeeRet,
13471347

13481348
for (const CTxIn& txin : tx.vin) {
13491349
const auto& outPoint = txin.prevout;
1350-
if (wallet.IsMine(outPoint)) {
1351-
// The input was found in the wallet, so select as internal
1352-
coinControl.Select(outPoint);
1353-
} else if (coins[outPoint].out.IsNull()) {
1354-
error = _("Unable to find UTXO for external input");
1355-
return false;
1356-
} else {
1350+
PreselectedInput& preset_txin = coinControl.Select(outPoint);
1351+
if (!wallet.IsMine(outPoint)) {
1352+
if (coins[outPoint].out.IsNull()) {
1353+
error = _("Unable to find UTXO for external input");
1354+
return false;
1355+
}
1356+
13571357
// The input was not in the wallet, but is in the UTXO set, so select as external
1358-
coinControl.SelectExternal(outPoint, coins[outPoint].out);
1358+
preset_txin.SetTxOut(coins[outPoint].out);
13591359
}
13601360
}
13611361

src/wallet/test/coinselector_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ BOOST_AUTO_TEST_CASE(SelectCoins_effective_value_test)
12821282
cc.m_allow_other_inputs = false;
12831283
COutput output = available_coins.All().at(0);
12841284
cc.SetInputWeight(output.outpoint, 148);
1285-
cc.SelectExternal(output.outpoint, output.txout);
1285+
cc.Select(output.outpoint).SetTxOut(output.txout);
12861286

12871287
LOCK(wallet->cs_wallet);
12881288
const auto preset_inputs = *Assert(FetchSelectedInputs(*wallet, cc, cs_params));

src/wallet/test/fuzz/coincontrol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ FUZZ_TARGET(coincontrol, .init = initialize_coincontrol)
6060
},
6161
[&] {
6262
const CTxOut tx_out{ConsumeMoney(fuzzed_data_provider), ConsumeScript(fuzzed_data_provider)};
63-
(void)coin_control.SelectExternal(out_point, tx_out);
63+
(void)coin_control.Select(out_point).SetTxOut(tx_out);
6464
},
6565
[&] {
6666
(void)coin_control.UnSelect(out_point);

0 commit comments

Comments
 (0)