Skip to content

Commit

Permalink
Merge pull request #1187 from MutinyWallet/nwc-p-tag
Browse files Browse the repository at this point in the history
Match NWC events by p tag instead event pk
  • Loading branch information
TonyGiorgio authored May 31, 2024
2 parents 34add2f + f79c4eb commit fd829a7
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions mutiny-core/src/nostr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1607,9 +1607,25 @@ impl<S: MutinyStorage, P: PrimalApi, C: NostrClient> NostrManager<S, P, C> {
) -> anyhow::Result<Option<Event>> {
let nwc = {
let vec = self.nwc.read().unwrap();
vec.iter()
.find(|nwc| nwc.client_pubkey() == event.pubkey)
.cloned()
// Need to find the p tag, not the client pubkey because there can be duplicates
// of the same client pubkey but we guarantee that the p tag is unique.
let p_tag = event
.tags
.iter()
.find_map(|tag| {
if let Tag::PublicKey {
public_key,
uppercase: false,
..
} = tag
{
Some(*public_key)
} else {
None
}
})
.ok_or(anyhow::anyhow!("No P tag found"))?;
vec.iter().find(|nwc| nwc.server_pubkey() == p_tag).cloned()
};

self.storage.set_nwc_sync_time(event.created_at.as_u64())?;
Expand Down

0 comments on commit fd829a7

Please sign in to comment.