use std::error::Error;
use futures::stream::Stream;
use jsonrpc_types::*;
#[async_trait::async_trait]
pub trait Transport {
type Error: Error;
async fn request<M>(&self, method: M, params: Option<Params>) -> Result<Output, Self::Error>
where
M: Into<String> + Send;
}
#[async_trait::async_trait]
pub trait BatchTransport: Transport {
async fn request_batch<I, M>(&self, batch: I) -> Result<Vec<Output>, Self::Error>
where
I: IntoIterator<Item = (M, Option<Params>)> + Send,
I::IntoIter: Send,
M: Into<String>;
}
#[async_trait::async_trait]
pub trait PubsubTransport: Transport {
type NotificationStream: Stream<Item = SubscriptionNotification>;
async fn subscribe<M>(
&self,
subscribe_method: M,
params: Option<Params>,
) -> Result<(Id, Self::NotificationStream), Self::Error>
where
M: Into<String> + Send;
async fn unsubscribe<M>(&self, unsubscribe_method: M, subscription_id: Id) -> Result<bool, Self::Error>
where
M: Into<String> + Send;
}