#![cfg_attr(docsrs, feature(doc_cfg))]
use crate::provider::HttpProvider;
#[cfg(feature = "pubsub")]
use crate::pubsub_provider::PubsubProvider;
mod methods;
pub mod provider;
#[cfg(feature = "pubsub")]
mod pubsub_methods;
#[cfg(feature = "pubsub")]
#[cfg_attr(docsrs, doc(cfg(feature = "pubsub")))]
pub mod pubsub_provider;
#[derive(Clone, Debug)]
pub struct WasmClient {
provider: HttpProvider,
}
impl WasmClient {
#[must_use = "client must be used to make requests"]
pub fn new(url: impl ToString) -> Self {
let provider = HttpProvider::new(url);
Self { provider }
}
pub fn url(&self) -> &str {
&self.provider.url
}
#[must_use]
pub fn with_header(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.provider = self.provider.with_header(key, value);
self
}
#[must_use]
pub fn with_max_response_size(mut self, bytes: usize) -> Self {
self.provider = self.provider.with_max_response_size(bytes);
self
}
}
#[cfg(feature = "pubsub")]
#[cfg_attr(docsrs, doc(cfg(feature = "pubsub")))]
pub struct WasmPubsubClient {
provider: PubsubProvider,
}
#[cfg(feature = "pubsub")]
impl WasmPubsubClient {
#[must_use = "connection result must be handled"]
pub fn connect(
url: impl ToString,
) -> Result<Self, Box<solana_rpc_client_types::request::RpcError>> {
let provider = PubsubProvider::connect(url)?;
Ok(Self { provider })
}
pub fn url(&self) -> &str {
self.provider.url()
}
pub fn is_connected(&self) -> bool {
self.provider.is_connected()
}
}