diff options
author | josibake <josibake@protonmail.com> | 2024-05-05 14:16:08 +0200 |
---|---|---|
committer | josibake <josibake@protonmail.com> | 2024-06-17 20:25:03 +0200 |
commit | adc6ab25bba42ce9e7ed6bd7599aabb6dead6987 (patch) | |
tree | 6ee273b2179b43a3409d67b07cd9e1b1bc47ab5f /src/wallet/spend.cpp | |
parent | 2c79abc7ad4850e9e3ba32a04c530155cda7f980 (diff) | |
download | bitcoin-adc6ab25bba42ce9e7ed6bd7599aabb6dead6987.tar.xz |
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.
Diffstat (limited to 'src/wallet/spend.cpp')
-rw-r--r-- | src/wallet/spend.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index 4cbcfdb60f..39744f714a 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -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); |