0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-08 14:34:53 -05:00

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.
This commit is contained in:
Andrew Chow 2022-06-20 12:03:03 -04:00 committed by Andrew Chow
parent 5321786b9d
commit 596642c5a9
6 changed files with 13 additions and 25 deletions

View file

@ -41,12 +41,6 @@ PreselectedInput& CCoinControl::Select(const COutPoint& outpoint)
{ {
return m_selected[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) void CCoinControl::UnSelect(const COutPoint& outpoint)
{ {
m_selected.erase(outpoint); m_selected.erase(outpoint);

View file

@ -108,11 +108,6 @@ public:
* The output will be included in the transaction even if it's not the most optimal choice. * The output will be included in the transaction even if it's not the most optimal choice.
*/ */
PreselectedInput& Select(const COutPoint& outpoint); 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. * Unselects the given output.
*/ */

View file

@ -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))); errors.push_back(Untranslated(strprintf("%s:%u is already spent", txin.prevout.hash.GetHex(), txin.prevout.n)));
return Result::MISC_ERROR; return Result::MISC_ERROR;
} }
if (wallet.IsMine(txin.prevout)) { PreselectedInput& preset_txin = new_coin_control.Select(txin.prevout);
new_coin_control.Select(txin.prevout); if (!wallet.IsMine(txin.prevout)) {
} else { preset_txin.SetTxOut(coin.out);
new_coin_control.SelectExternal(txin.prevout, coin.out);
} }
input_value += coin.out.nValue; input_value += coin.out.nValue;
spent_outputs.push_back(coin.out); spent_outputs.push_back(coin.out);

View file

@ -1347,15 +1347,15 @@ bool FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& nFeeRet,
for (const CTxIn& txin : tx.vin) { for (const CTxIn& txin : tx.vin) {
const auto& outPoint = txin.prevout; const auto& outPoint = txin.prevout;
if (wallet.IsMine(outPoint)) { PreselectedInput& preset_txin = coinControl.Select(outPoint);
// The input was found in the wallet, so select as internal if (!wallet.IsMine(outPoint)) {
coinControl.Select(outPoint); if (coins[outPoint].out.IsNull()) {
} else if (coins[outPoint].out.IsNull()) {
error = _("Unable to find UTXO for external input"); error = _("Unable to find UTXO for external input");
return false; return false;
} else { }
// The input was not in the wallet, but is in the UTXO set, so select as external // 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);
} }
} }

View file

@ -1282,7 +1282,7 @@ BOOST_AUTO_TEST_CASE(SelectCoins_effective_value_test)
cc.m_allow_other_inputs = false; cc.m_allow_other_inputs = false;
COutput output = available_coins.All().at(0); COutput output = available_coins.All().at(0);
cc.SetInputWeight(output.outpoint, 148); cc.SetInputWeight(output.outpoint, 148);
cc.SelectExternal(output.outpoint, output.txout); cc.Select(output.outpoint).SetTxOut(output.txout);
LOCK(wallet->cs_wallet); LOCK(wallet->cs_wallet);
const auto preset_inputs = *Assert(FetchSelectedInputs(*wallet, cc, cs_params)); const auto preset_inputs = *Assert(FetchSelectedInputs(*wallet, cc, cs_params));

View file

@ -60,7 +60,7 @@ FUZZ_TARGET(coincontrol, .init = initialize_coincontrol)
}, },
[&] { [&] {
const CTxOut tx_out{ConsumeMoney(fuzzed_data_provider), ConsumeScript(fuzzed_data_provider)}; 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); (void)coin_control.UnSelect(out_point);