diff --git a/relay_rpc/src/domain.rs b/relay_rpc/src/domain.rs index 3b5d977..62035bf 100644 --- a/relay_rpc/src/domain.rs +++ b/relay_rpc/src/domain.rs @@ -12,7 +12,7 @@ use { #[cfg(test)] mod tests; -#[derive(Debug, thiserror::Error)] +#[derive(Debug, Clone, thiserror::Error)] pub enum ClientIdDecodingError { #[error("Invalid issuer multicodec base")] Base, @@ -27,7 +27,7 @@ pub enum ClientIdDecodingError { Length, } -#[derive(Debug, thiserror::Error, PartialEq, Eq)] +#[derive(Debug, Clone, thiserror::Error, PartialEq, Eq)] pub enum DecodingError { #[error("Invalid encoding")] Encoding, diff --git a/relay_rpc/src/rpc.rs b/relay_rpc/src/rpc.rs index 5e46ff3..5ccc4d8 100644 --- a/relay_rpc/src/rpc.rs +++ b/relay_rpc/src/rpc.rs @@ -4,7 +4,7 @@ use { crate::domain::{DecodingError, MessageId, SubscriptionId, Topic}, serde::{de::DeserializeOwned, Deserialize, Serialize}, - std::sync::Arc, + std::{fmt::Debug, sync::Arc}, }; #[cfg(test)] @@ -29,7 +29,7 @@ pub const MAX_FETCH_BATCH_SIZE: usize = 500; type BoxError = Box; /// Errors covering payload validation problems. -#[derive(Debug, thiserror::Error, PartialEq, Eq)] +#[derive(Debug, Clone, thiserror::Error, PartialEq, Eq)] pub enum ValidationError { #[error("Topic decoding failed: {0}")] TopicDecoding(DecodingError), @@ -109,14 +109,23 @@ where } } +pub trait Serializable: + Debug + Clone + PartialEq + Eq + Serialize + DeserializeOwned + Send + Sync + 'static +{ +} +impl Serializable for T where + T: Debug + Clone + PartialEq + Eq + Serialize + DeserializeOwned + Send + Sync + 'static +{ +} + /// Trait that adds validation capabilities and strong typing to errors and /// successful responses. Implemented for all possible RPC request types. -pub trait RequestPayload { +pub trait RequestPayload: Serializable { /// The error representing a failed request. - type Error: Into; + type Error: Into + Send + 'static; /// The type of a successful response. - type Response: Serialize + DeserializeOwned; + type Response: Serializable; /// Validates the request parameters. fn validate(&self) -> Result<(), ValidationError> {