mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-24 07:51:24 +02: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:
parent
2c79abc7ad
commit
adc6ab25bb
@ -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(
|
static util::Result<CreatedTransactionResult> CreateTransactionInternal(
|
||||||
CWallet& wallet,
|
CWallet& wallet,
|
||||||
const std::vector<CRecipient>& vecSend,
|
const std::vector<CRecipient>& vecSend,
|
||||||
@ -1097,9 +1107,9 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
|
|||||||
CTxOut txout(recipient.nAmount, GetScriptForDestination(recipient.dest));
|
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);
|
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")};
|
return util::Error{_("Transaction amount too small")};
|
||||||
}
|
}
|
||||||
txNew.vout.push_back(txout);
|
txNew.vout.push_back(txout);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user