xmtp_api_d14n/queries/d14n/
client.rs

1use std::sync::Arc;
2
3use xmtp_common::MaybeSend;
4use xmtp_common::MaybeSync;
5use xmtp_id::scw_verifier::MultiSmartContractSignatureVerifier;
6use xmtp_id::scw_verifier::VerifierError;
7use xmtp_proto::api::IsConnectedCheck;
8
9#[derive(Clone)]
10pub struct D14nClient<C, Store> {
11    pub(super) client: C,
12    pub(super) cursor_store: Store,
13    pub(super) scw_verifier: Arc<MultiSmartContractSignatureVerifier>,
14}
15
16impl<C, Store> D14nClient<C, Store> {
17    pub fn new(client: C, cursor_store: Store) -> Result<Self, VerifierError> {
18        Ok(Self {
19            client,
20            cursor_store,
21            scw_verifier: Arc::new(MultiSmartContractSignatureVerifier::new_from_env()?),
22        })
23    }
24}
25xmtp_common::if_test! {
26    use xmtp_proto::api::mock::MockNetworkClient;
27    use crate::protocol::NoCursorStore;
28
29    impl crate::MockD14nClient {
30        pub fn new_mock() -> Self {
31            Self {
32                client: MockNetworkClient::new(),
33                cursor_store: NoCursorStore,
34                scw_verifier: Arc::new(MultiSmartContractSignatureVerifier::new_from_env().expect("scw failed")),
35            }
36        }
37    }
38    impl<S> D14nClient<MockNetworkClient, S> {
39        pub fn new_mock_with_store(store: S) -> Self {
40        Self {
41            client: MockNetworkClient::new(),
42            cursor_store: store,
43            scw_verifier: Arc::new(MultiSmartContractSignatureVerifier::new_from_env().expect("scw failed")),
44        }
45    }
46}
47
48}
49#[xmtp_common::async_trait]
50impl<C, Store> IsConnectedCheck for D14nClient<C, Store>
51where
52    C: IsConnectedCheck,
53    Store: MaybeSend + MaybeSync,
54{
55    async fn is_connected(&self) -> bool {
56        self.client.is_connected().await
57    }
58}