Skip to content

Commit adc6ab2

Browse files
committed
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.
1 parent 2c79abc commit adc6ab2

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/wallet/spend.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,16 @@ static void DiscourageFeeSniping(CMutableTransaction& tx, FastRandomContext& rng
976976
}
977977
}
978978

979+
size_t GetSerializeSizeForRecipient(const CRecipient& recipient)
980+
{
981+
return ::GetSerializeSize(CTxOut(recipient.nAmount, GetScriptForDestination(recipient.dest)));
982+
}
983+
984+
bool IsDust(const CRecipient& recipient, const CFeeRate& dustRelayFee)
985+
{
986+
return ::IsDust(CTxOut(recipient.nAmount, GetScriptForDestination(recipient.dest)), dustRelayFee);
987+
}
988+
979989
static util::Result<CreatedTransactionResult> CreateTransactionInternal(
980990
CWallet& wallet,
981991
const std::vector<CRecipient>& vecSend,
@@ -1097,9 +1107,9 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
10971107
CTxOut txout(recipient.nAmount, GetScriptForDestination(recipient.dest));
10981108

10991109
// Include the fee cost for outputs.
1100-
coin_selection_params.tx_noinputs_size += ::GetSerializeSize(txout);
1110+
coin_selection_params.tx_noinputs_size += GetSerializeSizeForRecipient(recipient);
11011111

1102-
if (IsDust(txout, wallet.chain().relayDustFee())) {
1112+
if (IsDust(recipient, wallet.chain().relayDustFee())) {
11031113
return util::Error{_("Transaction amount too small")};
11041114
}
11051115
txNew.vout.push_back(txout);

0 commit comments

Comments
 (0)