nip19.rs (1219B)
1 use crate::error::Error; 2 use nostr_sdk::nips::nip19::Nip19; 3 use nostr_sdk::prelude::*; 4 5 pub fn to_filters(nip19: &Nip19) -> Result<Vec<Filter>, Error> { 6 match nip19 { 7 Nip19::Event(ev) => { 8 let mut filters = vec![Filter::new().id(ev.event_id).limit(1)]; 9 if let Some(author) = ev.author { 10 filters.push(Filter::new().author(author).kind(Kind::Metadata).limit(1)) 11 } 12 Ok(filters) 13 } 14 Nip19::EventId(evid) => Ok(vec![Filter::new().id(*evid).limit(1)]), 15 Nip19::Profile(prof) => Ok(vec![Filter::new() 16 .author(prof.public_key) 17 .kind(Kind::Metadata) 18 .limit(1)]), 19 Nip19::Pubkey(pk) => Ok(vec![Filter::new() 20 .author(*pk) 21 .kind(Kind::Metadata) 22 .limit(1)]), 23 Nip19::Secret(_sec) => Err(Error::InvalidNip19), 24 Nip19::Coordinate(_coord) => Err(Error::InvalidNip19), 25 } 26 } 27 28 pub fn to_relays(nip19: &Nip19) -> Vec<String> { 29 let mut relays: Vec<String> = vec![]; 30 match nip19 { 31 Nip19::Event(ev) => relays.extend(ev.relays.clone()), 32 Nip19::Profile(p) => relays.extend(p.relays.clone()), 33 _ => (), 34 } 35 relays 36 }