use std::fmt;
use std::sync::Arc;
use crate::transport::core::{TransportError, TransportTrait};
use crate::transport::DefaultTransport;
pub struct RpcClient {
transport: Arc<dyn TransportTrait>,
}
impl fmt::Debug for RpcClient {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("RpcClient").field("transport", &"<dyn TransportTrait>").finish()
}
}
impl RpcClient {
pub fn from_transport(inner: Arc<dyn TransportTrait>) -> Self { Self { transport: inner } }
pub fn new(url: &str) -> Self {
let transport = DefaultTransport::new(url, None);
Self { transport: Arc::new(transport) }
}
pub async fn call_method(
&self,
method: &str,
params: &[serde_json::Value],
) -> Result<serde_json::Value, TransportError> {
self.transport.send_request(method, params).await
}
}