lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README | LICENSE

custom.rs (1723B)


      1 #![forbid(unsafe_code)]
      2 
      3 use crate::error::{NetError, Result};
      4 use radroots_nostr::prelude::{
      5     RadrootsNostrEvent, RadrootsNostrFilter, radroots_nostr_build_event, radroots_nostr_send_event,
      6 };
      7 
      8 use crate::nostr_client::manager::NostrClientManager;
      9 
     10 impl NostrClientManager {
     11     pub async fn send_custom_event(
     12         &self,
     13         kind: u32,
     14         content: String,
     15         tags: Vec<Vec<String>>,
     16     ) -> Result<String> {
     17         let builder = radroots_nostr_build_event(kind, content, tags)
     18             .map_err(|e| NetError::Msg(e.to_string()))?;
     19         let out = radroots_nostr_send_event(&self.inner.client, builder)
     20             .await
     21             .map_err(|e| NetError::Msg(e.to_string()))?;
     22         Ok(out.val.to_string())
     23     }
     24 
     25     pub fn send_custom_event_blocking(
     26         &self,
     27         kind: u32,
     28         content: String,
     29         tags: Vec<Vec<String>>,
     30     ) -> Result<String> {
     31         let rt = self.inner.rt.clone();
     32         let this = self.clone();
     33         rt.block_on(async move { this.send_custom_event(kind, content, tags).await })
     34     }
     35 
     36     pub async fn fetch_events(
     37         &self,
     38         filter: RadrootsNostrFilter,
     39         timeout: core::time::Duration,
     40     ) -> Result<Vec<RadrootsNostrEvent>> {
     41         self.inner
     42             .client
     43             .fetch_events(filter, timeout)
     44             .await
     45             .map_err(|e| NetError::Msg(e.to_string()))
     46     }
     47 
     48     pub fn fetch_events_blocking(
     49         &self,
     50         filter: RadrootsNostrFilter,
     51         timeout: core::time::Duration,
     52     ) -> Result<Vec<RadrootsNostrEvent>> {
     53         let rt = self.inner.rt.clone();
     54         let this = self.clone();
     55         rt.block_on(async move { this.fetch_events(filter, timeout).await })
     56     }
     57 }