use ac_primitives::RpcParams;
#[cfg(all(not(feature = "sync-api"), not(feature = "std")))]
use alloc::boxed::Box;
use alloc::string::{String, ToString};
use serde::de::DeserializeOwned;
#[cfg(feature = "ws-client")]
#[allow(deprecated)]
pub use ws_client::WsRpcClient;
#[cfg(feature = "ws-client")]
#[allow(deprecated)]
pub mod ws_client;
#[cfg(feature = "tungstenite-client")]
pub use tungstenite_client::TungsteniteRpcClient;
#[cfg(feature = "tungstenite-client")]
pub mod tungstenite_client;
#[cfg(all(feature = "jsonrpsee-client", not(feature = "sync-api")))]
pub use jsonrpsee_client::JsonrpseeClient;
#[cfg(all(feature = "jsonrpsee-client", not(feature = "sync-api")))]
#[allow(dead_code)]
#[allow(unused_imports)]
pub mod jsonrpsee_client;
pub mod error;
#[cfg(any(feature = "ws-client", feature = "tungstenite-client"))]
mod helpers;
pub use error::{Error, Result};
#[cfg(test)]
pub mod mocks;
#[maybe_async::maybe_async(?Send)]
pub trait Request {
async fn request<R: DeserializeOwned>(&self, method: &str, params: RpcParams) -> Result<R>;
}
#[maybe_async::maybe_async(?Send)]
pub trait Subscribe {
type Subscription<Notification>: HandleSubscription<Notification>
where
Notification: DeserializeOwned;
async fn subscribe<Notification: DeserializeOwned>(
&self,
sub: &str,
params: RpcParams,
unsub: &str,
) -> Result<Self::Subscription<Notification>>;
}
#[maybe_async::maybe_async(?Send)]
pub trait HandleSubscription<Notification: DeserializeOwned> {
async fn next(&mut self) -> Option<Result<Notification>>;
async fn unsubscribe(self) -> Result<()>;
}
pub fn to_json_req(method: &str, params: RpcParams) -> Result<String> {
Ok(serde_json::json!({
"method": method,
"params": params.to_json_value()?,
"jsonrpc": "2.0",
"id": "1",
})
.to_string())
}