mirror of
https://github.com/scsibug/nostr-rs-relay.git
synced 2024-11-14 15:09:07 -05:00
Successful parsing of requests from stream
This commit is contained in:
parent
c001726402
commit
4e2ec93584
|
@ -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<NostrRequest> {
|
|||
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),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Subscription> {
|
||||
// use serde to parse the ReqCmd, and then extract elements
|
||||
// }
|
||||
// }
|
||||
|
||||
impl Subscription {
|
||||
pub fn parse(json: &str) -> Result<Subscription> {
|
||||
serde_json::from_str(json).map_err(|e| Error::JsonParseFailed(e))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
|
Loading…
Reference in New Issue
Block a user