ethers_providers/rpc/
connections.rs

1use crate::{ProviderError, RpcError};
2use async_trait::async_trait;
3use auto_impl::auto_impl;
4use serde::{de::DeserializeOwned, Serialize};
5use std::fmt::Debug;
6
7#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
8#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
9#[auto_impl(&, Box, Arc)]
10/// Trait which must be implemented by data transports to be used with the Ethereum
11/// JSON-RPC provider.
12pub trait JsonRpcClient: Debug + Send + Sync {
13    /// A JSON-RPC Error
14    type Error: Into<ProviderError> + RpcError;
15
16    /// Sends a request with the provided JSON-RPC and parameters serialized as JSON
17    async fn request<T, R>(&self, method: &str, params: T) -> Result<R, Self::Error>
18    where
19        T: Debug + Serialize + Send + Sync,
20        R: DeserializeOwned + Send;
21}