Skip to content

Commit 27a1610

Browse files
committed
wallet: Use CTxDestination in CRecipient rather than scriptPubKey
1 parent 9da533b commit 27a1610

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
@@ -1044,7 +1044,7 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
10441044
// vouts to the payees
10451045
for (const auto& recipient : vecSend)
10461046
{
1047-
CTxOut txout(recipient.nAmount, recipient.scriptPubKey);
1047+
CTxOut txout(recipient.nAmount, GetScriptForDestination(recipient.dest));
10481048

10491049
// Include the fee cost for outputs.
10501050
coin_selection_params.tx_noinputs_size += ::GetSerializeSize(txout, PROTOCOL_VERSION);
@@ -1292,7 +1292,9 @@ bool FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& nFeeRet,
12921292
// Turn the txout set into a CRecipient vector.
12931293
for (size_t idx = 0; idx < tx.vout.size(); idx++) {
12941294
const CTxOut& txOut = tx.vout[idx];
1295-
CRecipient recipient = {txOut.scriptPubKey, txOut.nValue, setSubtractFeeFromOutputs.count(idx) == 1};
1295+
CTxDestination dest;
1296+
ExtractDestination(txOut.scriptPubKey, dest);
1297+
CRecipient recipient = {dest, txOut.nValue, setSubtractFeeFromOutputs.count(idx) == 1};
12961298
vecSend.push_back(recipient);
12971299
}
12981300

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
@@ -645,7 +645,7 @@ void TestCoinsResult(ListCoinsTest& context, OutputType out_type, CAmount amount
645645
{
646646
LOCK(context.wallet->cs_wallet);
647647
util::Result<CTxDestination> dest = Assert(context.wallet->GetNewDestination(out_type, ""));
648-
CWalletTx& wtx = context.AddTx(CRecipient{{GetScriptForDestination(*dest)}, amount, /*fSubtractFeeFromAmount=*/true});
648+
CWalletTx& wtx = context.AddTx(CRecipient{*dest, amount, /*fSubtractFeeFromAmount=*/true});
649649
CoinFilterParams filter;
650650
filter.skip_locked = false;
651651
CoinsResult available_coins = AvailableCoins(*context.wallet, nullptr, std::nullopt, filter);

src/wallet/wallet.cpp

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

22152215
for (const auto& recipient : vecSend) {
2216-
std::vector<std::vector<uint8_t>> dummy;
2217-
const TxoutType type{Solver(recipient.scriptPubKey, dummy)};
2218-
if (type == TxoutType::WITNESS_V1_TAPROOT) {
2216+
if (std::get_if<WitnessV1Taproot>(&recipient.dest)) {
22192217
any_tr = true;
2220-
} else if (type == TxoutType::WITNESS_V0_KEYHASH) {
2218+
} else if (std::get_if<WitnessV0KeyHash>(&recipient.dest)) {
22212219
any_wpkh = true;
2222-
} else if (type == TxoutType::SCRIPTHASH) {
2220+
} else if (std::get_if<ScriptHash>(&recipient.dest)) {
22232221
any_sh = true;
2224-
} else if (type == TxoutType::PUBKEYHASH) {
2222+
} else if (std::get_if<PKHash>(&recipient.dest)) {
22252223
any_pkh = true;
22262224
}
22272225
}

src/wallet/wallet.h

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

289289
struct CRecipient
290290
{
291-
CScript scriptPubKey;
291+
CTxDestination dest;
292292
CAmount nAmount;
293293
bool fSubtractFeeFromAmount;
294294
};

0 commit comments

Comments
 (0)