feat: parse and validate events from websockets

Establishes a websocket listener, parses events, and performs
validation to ensure valid signatures.
This commit is contained in:
Greg Heartsfield
2021-12-05 16:53:26 -06:00
parent d0c2b242cd
commit 92e9a5e639
6 changed files with 506 additions and 2 deletions
+39
View File
@@ -0,0 +1,39 @@
//! Error handling.
use std::result;
use thiserror::Error;
use tungstenite::error::Error as WsError;
pub type Result<T, E = Error> = result::Result<T, E>;
#[derive(Error, Debug)]
pub enum Error {
#[error("Protocol parse error")]
ProtoParseError,
#[error("Connection error")]
ConnError,
#[error("Client write error")]
ConnWriteError,
#[error("Event parse failed")]
EventParseFailed,
#[error("Event validation failed")]
EventInvalid,
#[error("JSON parsing failed")]
JsonParseFailed(serde_json::Error),
#[error("WebSocket proto error")]
WebsocketError(WsError),
#[error("Command unknown")]
CommandUnknownError,
}
impl From<serde_json::Error> for Error {
fn from(r: serde_json::Error) -> Self {
Error::JsonParseFailed(r)
}
}
impl From<WsError> for Error {
fn from(r: WsError) -> Self {
Error::WebsocketError(r)
}
}