Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit fd829a7

Browse files
Merge pull request #1187 from MutinyWallet/nwc-p-tag
Match NWC events by p tag instead event pk
2 parents 34add2f + f79c4eb commit fd829a7

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

mutiny-core/src/nostr/mod.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,9 +1607,25 @@ impl<S: MutinyStorage, P: PrimalApi, C: NostrClient> NostrManager<S, P, C> {
16071607
) -> anyhow::Result<Option<Event>> {
16081608
let nwc = {
16091609
let vec = self.nwc.read().unwrap();
1610-
vec.iter()
1611-
.find(|nwc| nwc.client_pubkey() == event.pubkey)
1612-
.cloned()
1610+
// Need to find the p tag, not the client pubkey because there can be duplicates
1611+
// of the same client pubkey but we guarantee that the p tag is unique.
1612+
let p_tag = event
1613+
.tags
1614+
.iter()
1615+
.find_map(|tag| {
1616+
if let Tag::PublicKey {
1617+
public_key,
1618+
uppercase: false,
1619+
..
1620+
} = tag
1621+
{
1622+
Some(*public_key)
1623+
} else {
1624+
None
1625+
}
1626+
})
1627+
.ok_or(anyhow::anyhow!("No P tag found"))?;
1628+
vec.iter().find(|nwc| nwc.server_pubkey() == p_tag).cloned()
16131629
};
16141630

16151631
self.storage.set_nwc_sync_time(event.created_at.as_u64())?;

0 commit comments

Comments
 (0)