From e54aa6a56995e4599021c23cae039cccd307affe Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 18 May 2023 20:03:11 +0300 Subject: [PATCH] lightclient: Add light client Error Signed-off-by: Alexandru Vasile --- subxt/src/error/mod.rs | 7 +++++++ subxt/src/rpc/lightclient/mod.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 subxt/src/rpc/lightclient/mod.rs diff --git a/subxt/src/error/mod.rs b/subxt/src/error/mod.rs index 96fb6dfad2..331f3e58ef 100644 --- a/subxt/src/error/mod.rs +++ b/subxt/src/error/mod.rs @@ -8,6 +8,9 @@ mod dispatch_error; use core::fmt::Debug; +#[cfg(feature = "experimental-light-client")] +pub use crate::rpc::LightClientError; + // Re-export dispatch error types: pub use dispatch_error::{ ArithmeticError, DispatchError, ModuleError, RawModuleError, TokenError, TransactionalError, @@ -63,6 +66,10 @@ pub enum Error { /// The bytes representing an error that we were unable to decode. #[error("An error occurred but it could not be decoded: {0:?}")] Unknown(Vec), + /// Light client error. + #[cfg(feature = "experimental-light-client")] + #[error("An error occurred but it could not be decoded: {0:?}")] + LightClient(#[from] LightClientError), /// Other error. #[error("Other error: {0}")] Other(String), diff --git a/subxt/src/rpc/lightclient/mod.rs b/subxt/src/rpc/lightclient/mod.rs new file mode 100644 index 0000000000..cdb620ee24 --- /dev/null +++ b/subxt/src/rpc/lightclient/mod.rs @@ -0,0 +1,32 @@ +mod background; +mod client; + +pub use client::LightClient; + +/// Light client error. +#[derive(Debug, thiserror::Error)] +pub enum LightClientError { + /// Error encountered while adding the chain to the light-client. + #[error("Failed to add the chain to the light client: {0}")] + AddChainError(String), + /// The background task is closed. + #[error("Failed to communicate with the background task.")] + BackgroundClosed, + /// Invalid RPC parameters cannot be serialized as JSON string. + #[error("RPC parameters cannot be serialized as JSON string.")] + InvalidParams, + /// Error originated while trying to submit a RPC request. + #[error("RPC request cannot be sent: {0}")] + Request(String), + /// The provided URL scheme is invalid. + /// + /// Supported versions: WS, WSS. + #[error("The provided URL scheme is invalid.")] + InvalidScheme, + /// The provided URL is invalid. + #[error("The provided URL scheme is invalid.")] + InvalidUrl, + /// Handshake error while connecting to a node. + #[error("WS handshake failed")] + Handshake, +}