From 596642c5a9f52dda2599b0bde424366bb22b3c6e Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Mon, 20 Jun 2022 12:03:03 -0400 Subject: 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. --- src/wallet/coincontrol.cpp | 6 ------ src/wallet/coincontrol.h | 5 ----- src/wallet/feebumper.cpp | 7 +++---- src/wallet/spend.cpp | 16 ++++++++-------- src/wallet/test/coinselector_tests.cpp | 2 +- src/wallet/test/fuzz/coincontrol.cpp | 2 +- 6 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/wallet/coincontrol.cpp b/src/wallet/coincontrol.cpp index 94218b45c1..00852b5f85 100644 --- a/src/wallet/coincontrol.cpp +++ b/src/wallet/coincontrol.cpp @@ -41,12 +41,6 @@ PreselectedInput& CCoinControl::Select(const COutPoint& outpoint) { return m_selected[outpoint]; } - -void CCoinControl::SelectExternal(const COutPoint& outpoint, const CTxOut& txout) -{ - m_selected[outpoint].SetTxOut(txout); -} - void CCoinControl::UnSelect(const COutPoint& outpoint) { m_selected.erase(outpoint); diff --git a/src/wallet/coincontrol.h b/src/wallet/coincontrol.h index 1d1f5c4da2..e7a16e37df 100644 --- a/src/wallet/coincontrol.h +++ b/src/wallet/coincontrol.h @@ -108,11 +108,6 @@ public: * The output will be included in the transaction even if it's not the most optimal choice. */ PreselectedInput& Select(const COutPoint& outpoint); - /** - * Lock-in the given output as an external input for spending because it is not in the wallet. - * The output will be included in the transaction even if it's not the most optimal choice. - */ - void SelectExternal(const COutPoint& outpoint, const CTxOut& txout); /** * Unselects the given output. */ diff --git a/src/wallet/feebumper.cpp b/src/wallet/feebumper.cpp index d9a08310a8..d3df9ceeff 100644 --- a/src/wallet/feebumper.cpp +++ b/src/wallet/feebumper.cpp @@ -203,10 +203,9 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo errors.push_back(Untranslated(strprintf("%s:%u is already spent", txin.prevout.hash.GetHex(), txin.prevout.n))); return Result::MISC_ERROR; } - if (wallet.IsMine(txin.prevout)) { - new_coin_control.Select(txin.prevout); - } else { - new_coin_control.SelectExternal(txin.prevout, coin.out); + PreselectedInput& preset_txin = new_coin_control.Select(txin.prevout); + if (!wallet.IsMine(txin.prevout)) { + preset_txin.SetTxOut(coin.out); } input_value += coin.out.nValue; spent_outputs.push_back(coin.out); diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index 2fb238fccd..c3fd695eb9 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -1347,15 +1347,15 @@ bool FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& nFeeRet, for (const CTxIn& txin : tx.vin) { const auto& outPoint = txin.prevout; - if (wallet.IsMine(outPoint)) { - // The input was found in the wallet, so select as internal - coinControl.Select(outPoint); - } else if (coins[outPoint].out.IsNull()) { - error = _("Unable to find UTXO for external input"); - return false; - } else { + PreselectedInput& preset_txin = coinControl.Select(outPoint); + if (!wallet.IsMine(outPoint)) { + if (coins[outPoint].out.IsNull()) { + error = _("Unable to find UTXO for external input"); + return false; + } + // The input was not in the wallet, but is in the UTXO set, so select as external - coinControl.SelectExternal(outPoint, coins[outPoint].out); + preset_txin.SetTxOut(coins[outPoint].out); } } diff --git a/src/wallet/test/coinselector_tests.cpp b/src/wallet/test/coinselector_tests.cpp index 9569210ba0..fa0dfa5556 100644 --- a/src/wallet/test/coinselector_tests.cpp +++ b/src/wallet/test/coinselector_tests.cpp @@ -1282,7 +1282,7 @@ BOOST_AUTO_TEST_CASE(SelectCoins_effective_value_test) cc.m_allow_other_inputs = false; COutput output = available_coins.All().at(0); cc.SetInputWeight(output.outpoint, 148); - cc.SelectExternal(output.outpoint, output.txout); + cc.Select(output.outpoint).SetTxOut(output.txout); LOCK(wallet->cs_wallet); const auto preset_inputs = *Assert(FetchSelectedInputs(*wallet, cc, cs_params)); diff --git a/src/wallet/test/fuzz/coincontrol.cpp b/src/wallet/test/fuzz/coincontrol.cpp index 64ed4f245d..f1efbc1cb8 100644 --- a/src/wallet/test/fuzz/coincontrol.cpp +++ b/src/wallet/test/fuzz/coincontrol.cpp @@ -60,7 +60,7 @@ FUZZ_TARGET(coincontrol, .init = initialize_coincontrol) }, [&] { const CTxOut tx_out{ConsumeMoney(fuzzed_data_provider), ConsumeScript(fuzzed_data_provider)}; - (void)coin_control.SelectExternal(out_point, tx_out); + (void)coin_control.Select(out_point).SetTxOut(tx_out); }, [&] { (void)coin_control.UnSelect(out_point); -- cgit v1.2.3