Skip to content

Commit d1f60fb

Browse files
committed
wallet: Use CTxDestination in CRecipient rather than scriptPubKey
1 parent 248f881 commit d1f60fb

File tree

7 files changed

+17
-18
lines changed

7 files changed

+17
-18
lines changed

src/wallet/feebumper.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,12 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
247247
const auto& txouts = outputs.empty() ? wtx.tx->vout : outputs;
248248
for (size_t i = 0; i < txouts.size(); ++i) {
249249
const CTxOut& output = txouts.at(i);
250+
CTxDestination dest;
251+
ExtractDestination(output.scriptPubKey, dest);
250252
if (reduce_output.has_value() ? reduce_output.value() == i : OutputIsChange(wallet, output)) {
251-
CTxDestination change_dest;
252-
ExtractDestination(output.scriptPubKey, change_dest);
253-
new_coin_control.destChange = change_dest;
253+
new_coin_control.destChange = dest;
254254
} else {
255-
CRecipient recipient = {output.scriptPubKey, output.nValue, false};
255+
CRecipient recipient = {dest, output.nValue, false};
256256
recipients.push_back(recipient);
257257
}
258258
new_outputs_value += output.nValue;
@@ -268,7 +268,7 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
268268

269269
// Add change as recipient with SFFO flag enabled, so fees are deduced from it.
270270
// If the output differs from the original tx output (because the user customized it) a new change output will be created.
271-
recipients.emplace_back(CRecipient{GetScriptForDestination(new_coin_control.destChange), new_outputs_value, /*fSubtractFeeFromAmount=*/true});
271+
recipients.emplace_back(CRecipient{new_coin_control.destChange, new_outputs_value, /*fSubtractFeeFromAmount=*/true});
272272
new_coin_control.destChange = CNoDestination();
273273
}
274274

src/wallet/rpc/spend.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ static void ParseRecipients(const UniValue& address_amounts, const UniValue& sub
3939
}
4040
destinations.insert(dest);
4141

42-
CScript script_pub_key = GetScriptForDestination(dest);
4342
CAmount amount = AmountFromValue(address_amounts[i++]);
4443

4544
bool subtract_fee = false;
@@ -50,7 +49,7 @@ static void ParseRecipients(const UniValue& address_amounts, const UniValue& sub
5049
}
5150
}
5251

53-
CRecipient recipient = {script_pub_key, amount, subtract_fee};
52+
CRecipient recipient = {dest, amount, subtract_fee};
5453
recipients.push_back(recipient);
5554
}
5655
}

src/wallet/spend.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
945945
// vouts to the payees
946946
for (const auto& recipient : vecSend)
947947
{
948-
CTxOut txout(recipient.nAmount, recipient.scriptPubKey);
948+
CTxOut txout(recipient.nAmount, GetScriptForDestination(recipient.dest));
949949

950950
// Include the fee cost for outputs.
951951
coin_selection_params.tx_noinputs_size += ::GetSerializeSize(txout, PROTOCOL_VERSION);
@@ -1193,7 +1193,9 @@ bool FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& nFeeRet,
11931193
// Turn the txout set into a CRecipient vector.
11941194
for (size_t idx = 0; idx < tx.vout.size(); idx++) {
11951195
const CTxOut& txOut = tx.vout[idx];
1196-
CRecipient recipient = {txOut.scriptPubKey, txOut.nValue, setSubtractFeeFromOutputs.count(idx) == 1};
1196+
CTxDestination dest;
1197+
ExtractDestination(txOut.scriptPubKey, dest);
1198+
CRecipient recipient = {dest, txOut.nValue, setSubtractFeeFromOutputs.count(idx) == 1};
11971199
vecSend.push_back(recipient);
11981200
}
11991201

src/wallet/test/spend_tests.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ BOOST_FIXTURE_TEST_CASE(SubtractFee, TestChain100Setup)
2727
// leftover input amount which would have been change to the recipient
2828
// instead of the miner.
2929
auto check_tx = [&wallet](CAmount leftover_input_amount) {
30-
CRecipient recipient{GetScriptForRawPubKey({}), 50 * COIN - leftover_input_amount, /*subtract_fee=*/true};
30+
CRecipient recipient{PubKeyDestination({}), 50 * COIN - leftover_input_amount, /*subtract_fee=*/true};
3131
constexpr int RANDOM_CHANGE_POSITION = -1;
3232
CCoinControl coin_control;
3333
coin_control.m_feerate.emplace(10000);

src/wallet/test/wallet_tests.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ void TestCoinsResult(ListCoinsTest& context, OutputType out_type, CAmount amount
644644
{
645645
LOCK(context.wallet->cs_wallet);
646646
util::Result<CTxDestination> dest = Assert(context.wallet->GetNewDestination(out_type, ""));
647-
CWalletTx& wtx = context.AddTx(CRecipient{{GetScriptForDestination(*dest)}, amount, /*fSubtractFeeFromAmount=*/true});
647+
CWalletTx& wtx = context.AddTx(CRecipient{*dest, amount, /*fSubtractFeeFromAmount=*/true});
648648
CoinFilterParams filter;
649649
filter.skip_locked = false;
650650
CoinsResult available_coins = AvailableCoins(*context.wallet, nullptr, std::nullopt, filter);

src/wallet/wallet.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -2272,15 +2272,13 @@ OutputType CWallet::TransactionChangeType(const std::optional<OutputType>& chang
22722272
bool any_pkh{false};
22732273

22742274
for (const auto& recipient : vecSend) {
2275-
std::vector<std::vector<uint8_t>> dummy;
2276-
const TxoutType type{Solver(recipient.scriptPubKey, dummy)};
2277-
if (type == TxoutType::WITNESS_V1_TAPROOT) {
2275+
if (std::get_if<WitnessV1Taproot>(&recipient.dest)) {
22782276
any_tr = true;
2279-
} else if (type == TxoutType::WITNESS_V0_KEYHASH) {
2277+
} else if (std::get_if<WitnessV0KeyHash>(&recipient.dest)) {
22802278
any_wpkh = true;
2281-
} else if (type == TxoutType::SCRIPTHASH) {
2279+
} else if (std::get_if<ScriptHash>(&recipient.dest)) {
22822280
any_sh = true;
2283-
} else if (type == TxoutType::PUBKEYHASH) {
2281+
} else if (std::get_if<PKHash>(&recipient.dest)) {
22842282
any_pkh = true;
22852283
}
22862284
}

src/wallet/wallet.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ inline std::optional<AddressPurpose> PurposeFromString(std::string_view s)
265265

266266
struct CRecipient
267267
{
268-
CScript scriptPubKey;
268+
CTxDestination dest;
269269
CAmount nAmount;
270270
bool fSubtractFeeFromAmount;
271271
};

0 commit comments

Comments
 (0)