mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-04 13:55:23 -05:00
wallet: Use CTxDestination in CRecipient rather than scriptPubKey
This commit is contained in:
parent
07d3bdf4eb
commit
ad0c469d98
7 changed files with 17 additions and 18 deletions
|
@ -247,12 +247,12 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
|
||||||
const auto& txouts = outputs.empty() ? wtx.tx->vout : outputs;
|
const auto& txouts = outputs.empty() ? wtx.tx->vout : outputs;
|
||||||
for (size_t i = 0; i < txouts.size(); ++i) {
|
for (size_t i = 0; i < txouts.size(); ++i) {
|
||||||
const CTxOut& output = txouts.at(i);
|
const CTxOut& output = txouts.at(i);
|
||||||
|
CTxDestination dest;
|
||||||
|
ExtractDestination(output.scriptPubKey, dest);
|
||||||
if (reduce_output.has_value() ? reduce_output.value() == i : OutputIsChange(wallet, output)) {
|
if (reduce_output.has_value() ? reduce_output.value() == i : OutputIsChange(wallet, output)) {
|
||||||
CTxDestination change_dest;
|
new_coin_control.destChange = dest;
|
||||||
ExtractDestination(output.scriptPubKey, change_dest);
|
|
||||||
new_coin_control.destChange = change_dest;
|
|
||||||
} else {
|
} else {
|
||||||
CRecipient recipient = {output.scriptPubKey, output.nValue, false};
|
CRecipient recipient = {dest, output.nValue, false};
|
||||||
recipients.push_back(recipient);
|
recipients.push_back(recipient);
|
||||||
}
|
}
|
||||||
new_outputs_value += output.nValue;
|
new_outputs_value += output.nValue;
|
||||||
|
@ -268,7 +268,7 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
|
||||||
|
|
||||||
// Add change as recipient with SFFO flag enabled, so fees are deduced from it.
|
// Add change as recipient with SFFO flag enabled, so fees are deduced from it.
|
||||||
// If the output differs from the original tx output (because the user customized it) a new change output will be created.
|
// If the output differs from the original tx output (because the user customized it) a new change output will be created.
|
||||||
recipients.emplace_back(CRecipient{GetScriptForDestination(new_coin_control.destChange), new_outputs_value, /*fSubtractFeeFromAmount=*/true});
|
recipients.emplace_back(CRecipient{new_coin_control.destChange, new_outputs_value, /*fSubtractFeeFromAmount=*/true});
|
||||||
new_coin_control.destChange = CNoDestination();
|
new_coin_control.destChange = CNoDestination();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,6 @@ static void ParseRecipients(const UniValue& address_amounts, const UniValue& sub
|
||||||
}
|
}
|
||||||
destinations.insert(dest);
|
destinations.insert(dest);
|
||||||
|
|
||||||
CScript script_pub_key = GetScriptForDestination(dest);
|
|
||||||
CAmount amount = AmountFromValue(address_amounts[i++]);
|
CAmount amount = AmountFromValue(address_amounts[i++]);
|
||||||
|
|
||||||
bool subtract_fee = false;
|
bool subtract_fee = false;
|
||||||
|
@ -50,7 +49,7 @@ static void ParseRecipients(const UniValue& address_amounts, const UniValue& sub
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CRecipient recipient = {script_pub_key, amount, subtract_fee};
|
CRecipient recipient = {dest, amount, subtract_fee};
|
||||||
recipients.push_back(recipient);
|
recipients.push_back(recipient);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1044,7 +1044,7 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
|
||||||
// vouts to the payees
|
// vouts to the payees
|
||||||
for (const auto& recipient : vecSend)
|
for (const auto& recipient : vecSend)
|
||||||
{
|
{
|
||||||
CTxOut txout(recipient.nAmount, recipient.scriptPubKey);
|
CTxOut txout(recipient.nAmount, GetScriptForDestination(recipient.dest));
|
||||||
|
|
||||||
// Include the fee cost for outputs.
|
// Include the fee cost for outputs.
|
||||||
coin_selection_params.tx_noinputs_size += ::GetSerializeSize(txout, PROTOCOL_VERSION);
|
coin_selection_params.tx_noinputs_size += ::GetSerializeSize(txout, PROTOCOL_VERSION);
|
||||||
|
@ -1292,7 +1292,9 @@ bool FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& nFeeRet,
|
||||||
// Turn the txout set into a CRecipient vector.
|
// Turn the txout set into a CRecipient vector.
|
||||||
for (size_t idx = 0; idx < tx.vout.size(); idx++) {
|
for (size_t idx = 0; idx < tx.vout.size(); idx++) {
|
||||||
const CTxOut& txOut = tx.vout[idx];
|
const CTxOut& txOut = tx.vout[idx];
|
||||||
CRecipient recipient = {txOut.scriptPubKey, txOut.nValue, setSubtractFeeFromOutputs.count(idx) == 1};
|
CTxDestination dest;
|
||||||
|
ExtractDestination(txOut.scriptPubKey, dest);
|
||||||
|
CRecipient recipient = {dest, txOut.nValue, setSubtractFeeFromOutputs.count(idx) == 1};
|
||||||
vecSend.push_back(recipient);
|
vecSend.push_back(recipient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ BOOST_FIXTURE_TEST_CASE(SubtractFee, TestChain100Setup)
|
||||||
// leftover input amount which would have been change to the recipient
|
// leftover input amount which would have been change to the recipient
|
||||||
// instead of the miner.
|
// instead of the miner.
|
||||||
auto check_tx = [&wallet](CAmount leftover_input_amount) {
|
auto check_tx = [&wallet](CAmount leftover_input_amount) {
|
||||||
CRecipient recipient{GetScriptForRawPubKey({}), 50 * COIN - leftover_input_amount, /*subtract_fee=*/true};
|
CRecipient recipient{PubKeyDestination({}), 50 * COIN - leftover_input_amount, /*subtract_fee=*/true};
|
||||||
constexpr int RANDOM_CHANGE_POSITION = -1;
|
constexpr int RANDOM_CHANGE_POSITION = -1;
|
||||||
CCoinControl coin_control;
|
CCoinControl coin_control;
|
||||||
coin_control.m_feerate.emplace(10000);
|
coin_control.m_feerate.emplace(10000);
|
||||||
|
|
|
@ -645,7 +645,7 @@ void TestCoinsResult(ListCoinsTest& context, OutputType out_type, CAmount amount
|
||||||
{
|
{
|
||||||
LOCK(context.wallet->cs_wallet);
|
LOCK(context.wallet->cs_wallet);
|
||||||
util::Result<CTxDestination> dest = Assert(context.wallet->GetNewDestination(out_type, ""));
|
util::Result<CTxDestination> dest = Assert(context.wallet->GetNewDestination(out_type, ""));
|
||||||
CWalletTx& wtx = context.AddTx(CRecipient{{GetScriptForDestination(*dest)}, amount, /*fSubtractFeeFromAmount=*/true});
|
CWalletTx& wtx = context.AddTx(CRecipient{*dest, amount, /*fSubtractFeeFromAmount=*/true});
|
||||||
CoinFilterParams filter;
|
CoinFilterParams filter;
|
||||||
filter.skip_locked = false;
|
filter.skip_locked = false;
|
||||||
CoinsResult available_coins = AvailableCoins(*context.wallet, nullptr, std::nullopt, filter);
|
CoinsResult available_coins = AvailableCoins(*context.wallet, nullptr, std::nullopt, filter);
|
||||||
|
|
|
@ -2213,15 +2213,13 @@ OutputType CWallet::TransactionChangeType(const std::optional<OutputType>& chang
|
||||||
bool any_pkh{false};
|
bool any_pkh{false};
|
||||||
|
|
||||||
for (const auto& recipient : vecSend) {
|
for (const auto& recipient : vecSend) {
|
||||||
std::vector<std::vector<uint8_t>> dummy;
|
if (std::get_if<WitnessV1Taproot>(&recipient.dest)) {
|
||||||
const TxoutType type{Solver(recipient.scriptPubKey, dummy)};
|
|
||||||
if (type == TxoutType::WITNESS_V1_TAPROOT) {
|
|
||||||
any_tr = true;
|
any_tr = true;
|
||||||
} else if (type == TxoutType::WITNESS_V0_KEYHASH) {
|
} else if (std::get_if<WitnessV0KeyHash>(&recipient.dest)) {
|
||||||
any_wpkh = true;
|
any_wpkh = true;
|
||||||
} else if (type == TxoutType::SCRIPTHASH) {
|
} else if (std::get_if<ScriptHash>(&recipient.dest)) {
|
||||||
any_sh = true;
|
any_sh = true;
|
||||||
} else if (type == TxoutType::PUBKEYHASH) {
|
} else if (std::get_if<PKHash>(&recipient.dest)) {
|
||||||
any_pkh = true;
|
any_pkh = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -288,7 +288,7 @@ inline std::optional<AddressPurpose> PurposeFromString(std::string_view s)
|
||||||
|
|
||||||
struct CRecipient
|
struct CRecipient
|
||||||
{
|
{
|
||||||
CScript scriptPubKey;
|
CTxDestination dest;
|
||||||
CAmount nAmount;
|
CAmount nAmount;
|
||||||
bool fSubtractFeeFromAmount;
|
bool fSubtractFeeFromAmount;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue