diff --git a/src/proto.rs b/src/proto.rs index cf40037..62488e8 100644 --- a/src/proto.rs +++ b/src/proto.rs @@ -1,5 +1,5 @@ use crate::error::{Error, Result}; -use crate::event; +use crate::{event, request}; use log::{debug, info}; use uuid::Uuid; @@ -39,6 +39,7 @@ pub enum NostrRawMessage { #[derive(PartialEq, Debug)] pub enum NostrRequest { Event(event::Event), + Subscription(request::Subscription), } // Wrap the message in the expected request type @@ -60,7 +61,10 @@ pub fn parse_type(msg: String) -> Result { let typ = msg_type_wrapper(msg)?; match typ { NostrRawMessage::Event(_) => Err(Error::EventParseFailed), - NostrRawMessage::Req(_) => Err(Error::ReqParseFailed), + NostrRawMessage::Req(m) => { + let s = request::Subscription::parse(&m)?; + Ok(NostrRequest::Subscription(s)) + } NostrRawMessage::Close(_) => Err(Error::CloseParseFailed), } } diff --git a/src/request.rs b/src/request.rs index a52b803..367ebcf 100644 --- a/src/request.rs +++ b/src/request.rs @@ -1,4 +1,4 @@ -use crate::error::Result; +use crate::error::{Error, Result}; use serde::{Deserialize, Deserializer, Serialize}; //use serde_json::json; //use serde_json::Result; @@ -78,11 +78,12 @@ impl<'de> Deserialize<'de> for Subscription { }) } } -// impl Subscription { -// pub fn parse(json: &str) -> Result { -// use serde to parse the ReqCmd, and then extract elements -// } -// } + +impl Subscription { + pub fn parse(json: &str) -> Result { + serde_json::from_str(json).map_err(|e| Error::JsonParseFailed(e)) + } +} #[cfg(test)] mod tests {