rig/client/
verify.rs

1use crate::{
2    client::{AsVerify, ProviderClient},
3    http_client,
4    wasm_compat::{WasmBoxedFuture, WasmCompatSend},
5};
6use thiserror::Error;
7
8#[derive(Debug, Error)]
9pub enum VerifyError {
10    #[error("invalid authentication")]
11    InvalidAuthentication,
12    #[error("provider error: {0}")]
13    ProviderError(String),
14    #[error("http error: {0}")]
15    HttpError(
16        #[from]
17        #[source]
18        http_client::Error,
19    ),
20}
21
22/// A provider client that can verify the configuration.
23/// Clone is required for conversions between client types.
24pub trait VerifyClient: ProviderClient + Clone {
25    /// Verify the configuration.
26    fn verify(&self) -> impl Future<Output = Result<(), VerifyError>> + WasmCompatSend;
27}
28
29pub trait VerifyClientDyn: ProviderClient {
30    /// Verify the configuration.
31    fn verify(&self) -> WasmBoxedFuture<'_, Result<(), VerifyError>>;
32}
33
34impl<T> VerifyClientDyn for T
35where
36    T: VerifyClient,
37{
38    fn verify(&self) -> WasmBoxedFuture<'_, Result<(), VerifyError>> {
39        Box::pin(self.verify())
40    }
41}
42
43impl<T> AsVerify for T
44where
45    T: VerifyClientDyn + Clone + 'static,
46{
47    fn as_verify(&self) -> Option<Box<dyn VerifyClientDyn>> {
48        Some(Box::new(self.clone()))
49    }
50}