Skip to content

Commit b522496

Browse files
committed
Add MaybeSilentPayment helper
1 parent 8e7dd0a commit b522496

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/common/bip352.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ std::optional<PublicData> CreateInputPubkeysTweak(
151151
return public_data;
152152
}
153153

154+
bool MaybeSilentPayment(const CTransactionRef &tx) {
155+
if (tx->IsCoinBase()) return false;
156+
157+
if (std::none_of(tx->vout.begin(), tx->vout.end(), [](const CTxOut& txout) {
158+
return txout.scriptPubKey.IsPayToTaproot();
159+
})) {
160+
return false;
161+
}
162+
163+
return true;
164+
}
165+
154166
std::optional<PublicData> GetSilentPaymentsPublicData(const std::vector<CTxIn>& vin, const std::map<COutPoint, Coin>& coins)
155167
{
156168
// Extract the keys from the inputs

src/common/bip352.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ std::pair<CPubKey, uint256> CreateLabelTweak(const CKey& scan_key, const int m);
117117
*/
118118
V0SilentPaymentDestination GenerateSilentPaymentLabeledAddress(const V0SilentPaymentDestination& recipient, const uint256& label);
119119

120+
/**
121+
* @brief: Check if a transaction could be a silent payment.
122+
*
123+
* A coinbase transaction can't be a silent payment.
124+
* A transaction with no Taproot outputs can't be a silent payment.
125+
*
126+
* @param tx The transaction to check
127+
* @return false if a transaction can't be a silent payment, true otherwise.
128+
*/
129+
bool MaybeSilentPayment(const CTransactionRef &tx);
130+
120131
/**
121132
* @brief Get silent payment public data from transaction inputs.
122133
*

0 commit comments

Comments
 (0)