xmtp_api_d14n/queries/v3/
client.rs

1use xmtp_common::{MaybeSend, MaybeSync};
2use xmtp_proto::api::IsConnectedCheck;
3use xmtp_proto::prelude::ApiBuilder;
4
5#[derive(Clone)]
6pub struct V3Client<C, Store> {
7    pub(super) client: C,
8    pub(super) cursor_store: Store,
9}
10
11impl<C, Store> V3Client<C, Store> {
12    pub fn new(client: C, cursor_store: Store) -> Self {
13        Self {
14            client,
15            cursor_store,
16        }
17    }
18
19    pub fn client_mut(&mut self) -> &mut C {
20        &mut self.client
21    }
22}
23
24#[cfg_attr(any(test, feature = "test-utils"), derive(Clone))]
25pub struct V3ClientBuilder<Builder, Store> {
26    client: Builder,
27    store: Store,
28}
29
30impl<Builder, Store> V3ClientBuilder<Builder, Store> {
31    pub fn new(client: Builder, store: Store) -> Self {
32        Self { client, store }
33    }
34
35    pub fn cursor_store(&mut self, store: Store) -> &mut Self {
36        self.store = store;
37        self
38    }
39}
40
41impl<Builder, Store> ApiBuilder for V3ClientBuilder<Builder, Store>
42where
43    Builder: ApiBuilder,
44    Store: MaybeSend + MaybeSync,
45{
46    type Output = V3Client<<Builder as ApiBuilder>::Output, Store>;
47
48    type Error = <Builder as ApiBuilder>::Error;
49    fn build(self) -> Result<Self::Output, Self::Error> {
50        Ok(V3Client {
51            client: <Builder as ApiBuilder>::build(self.client)?,
52            cursor_store: self.store,
53        })
54    }
55}
56
57#[xmtp_common::async_trait]
58impl<C, Store> IsConnectedCheck for V3Client<C, Store>
59where
60    C: IsConnectedCheck,
61    Store: MaybeSend + MaybeSync,
62{
63    async fn is_connected(&self) -> bool {
64        self.client.is_connected().await
65    }
66}