@@ -1242,8 +1242,8 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, const std::ma
1242
1242
bool fExisted = mapWallet.count (tx.GetHash ()) != 0 ;
1243
1243
if (fExisted && !fUpdate ) return false ;
1244
1244
1245
- auto sp_data = GetSilentPaymentsData (tx, spent_coins) ;
1246
- bool isMineSilentPayment = !tx.IsCoinBase () && sp_data && IsMineSilentPayment (sp_data-> first , sp_data-> second );
1245
+ std::map<XOnlyPubKey, std::optional<CPubKey>> silent_payment_outputs ;
1246
+ bool isMineSilentPayment = !tx.IsCoinBase () && IsMineSilentPayment (tx, spent_coins, silent_payment_outputs );
1247
1247
if (fExisted || IsMine (tx) || isMineSilentPayment || IsFromMe (tx))
1248
1248
{
1249
1249
/* Check if any keys in the wallet keypool that were supposed to be unused
@@ -1275,11 +1275,15 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, const std::ma
1275
1275
}
1276
1276
1277
1277
SilentPaymentDescriptorScriptPubKeyMan* sp_spk_man = dynamic_cast <SilentPaymentDescriptorScriptPubKeyMan*>(spk_man);
1278
- if (sp_spk_man == nullptr || !isMineSilentPayment) continue ;
1279
-
1280
1278
CTxDestination dest;
1281
1279
ExtractDestination (txout.scriptPubKey , dest);
1282
- auto parent_dest = sp_spk_man->GetLabelledSPDestination (dest, sp_data->second );
1280
+ const WitnessV1Taproot* xonlypubkey = std::get_if<WitnessV1Taproot>(&dest);
1281
+ if (sp_spk_man == nullptr || !isMineSilentPayment || xonlypubkey == nullptr ) continue ;
1282
+
1283
+ auto it = silent_payment_outputs.find (*xonlypubkey);
1284
+ if (it == silent_payment_outputs.end () || !it->second .has_value ()) continue ;
1285
+
1286
+ auto parent_dest = sp_spk_man->GetLabelledSPDestination (*xonlypubkey, it->second .value ());
1283
1287
if (!parent_dest.has_value ()) continue ;
1284
1288
auto parent_addr_data = FindAddressBookEntry (parent_dest.value ());
1285
1289
if (parent_addr_data) {
@@ -1684,11 +1688,12 @@ bool CWallet::IsMine(const CTransaction& tx) const
1684
1688
}
1685
1689
1686
1690
1687
- bool CWallet::IsMineSilentPayment (std::vector<XOnlyPubKey> output_keys, BIP352::PubTweakData &public_data ) {
1691
+ bool CWallet::IsMineSilentPayment (const CTransaction& tx, const std::map<COutPoint, Coin>& spent_coins, std::map<XOnlyPubKey, std::optional<CPubKey>>& found_outputs ) {
1688
1692
AssertLockHeld (cs_wallet);
1689
1693
1694
+ auto sp_data = GetSilentPaymentsData (tx, spent_coins);
1690
1695
for (SilentPaymentDescriptorScriptPubKeyMan* sp_spkm : GetSilentPaymentsSPKMs ()) {
1691
- if (sp_spkm->IsMine (output_keys, public_data )) {
1696
+ if (sp_spkm->IsMine (sp_data-> first , sp_data-> second , found_outputs )) {
1692
1697
return true ;
1693
1698
}
1694
1699
}
0 commit comments