pub trait NostrEventStream: Stream {}

pub trait WebsocketHandler {

type EventStream: NostrEventStream + Unpin;

/// Write a text message to the websocket

fn write_text_message(

&mut self,

message: &str,

) -> Result>;

}

pub async fn fetch_event(

websocket_handler: &mut W,

id: IdHex,

) -> Result, Box> {

let mut filter = Filter::new();

filter.add_id(&id, None);

let message = ClientMessage::Req(SubscriptionId("fetch".to_owned()), vec![filter]);

let wire = serde_json::to_string(&message).expect("Could not serialize message");

let mut stream = websocket_handler.write_text_message(&wire)?;

Ok(stream.next().await)

}

Reply to this note

Please Login to reply.

Discussion

No replies yet.