1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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;
}