0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-02 09:46:52 -05:00

wallet: use CRecipient instead of CTxOut

Now that a CRecipient holds a CTxDestination, we can get the serialized
size and determine if the output is dust using the CRecipient directly.
This does not change any current behavior, but provides a nice generalization
that can be used to apply special logic to a CTxDestination serialization
and dust calculations in the future.

Specifically, in a later PR when support for `V0SilentPayment` destinations is
added, we need to use `WitnessV1Taproot` as the scriptPubKey for serialized
size calcuations whenever the `CRecipient` destination is a `V0SilentPayment`
destination.
This commit is contained in:
josibake 2024-05-05 14:16:08 +02:00
parent 2c79abc7ad
commit adc6ab25bb
No known key found for this signature in database
GPG key ID: 8ADCB558C4F33D65

View file

@ -976,6 +976,16 @@ static void DiscourageFeeSniping(CMutableTransaction& tx, FastRandomContext& rng
}
}
size_t GetSerializeSizeForRecipient(const CRecipient& recipient)
{
return ::GetSerializeSize(CTxOut(recipient.nAmount, GetScriptForDestination(recipient.dest)));
}
bool IsDust(const CRecipient& recipient, const CFeeRate& dustRelayFee)
{
return ::IsDust(CTxOut(recipient.nAmount, GetScriptForDestination(recipient.dest)), dustRelayFee);
}
static util::Result<CreatedTransactionResult> CreateTransactionInternal(
CWallet& wallet,
const std::vector<CRecipient>& vecSend,
@ -1097,9 +1107,9 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
CTxOut txout(recipient.nAmount, GetScriptForDestination(recipient.dest));
// Include the fee cost for outputs.
coin_selection_params.tx_noinputs_size += ::GetSerializeSize(txout);
coin_selection_params.tx_noinputs_size += GetSerializeSizeForRecipient(recipient);
if (IsDust(txout, wallet.chain().relayDustFee())) {
if (IsDust(recipient, wallet.chain().relayDustFee())) {
return util::Error{_("Transaction amount too small")};
}
txNew.vout.push_back(txout);