use std::fmt::Debug;
use async_trait::async_trait;
use auto_impl::auto_impl;
use ethers_core::types::U256;
use serde::{de::DeserializeOwned, Serialize};
use serde_json::value::RawValue;
use crate::{ProviderError, RpcError};
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
#[auto_impl(&, Box, Arc)]
pub trait JsonRpcClient: Debug + Send + Sync {
type Error: Into<ProviderError> + RpcError;
async fn request<T, R>(&self, method: &str, params: T) -> Result<R, Self::Error>
where
T: Debug + Serialize + Send + Sync,
R: DeserializeOwned + Send;
}
pub trait PubsubClient: JsonRpcClient {
type NotificationStream: futures_core::Stream<Item = Box<RawValue>> + Send + Unpin;
fn subscribe<T: Into<U256>>(&self, id: T) -> Result<Self::NotificationStream, Self::Error>;
fn unsubscribe<T: Into<U256>>(&self, id: T) -> Result<(), Self::Error>;
}