Skip to main content

xmtp_proto/api_client/
impls.rs

1use super::*;
2
3#[xmtp_common::async_trait]
4impl<T: XmtpBackendClient + ?Sized> XmtpBackendClient for Box<T> {
5    type Error = T::Error;
6    async fn publish(&self, request: PublishRequest) -> Result<PublishResponse, Self::Error> {
7        (**self).publish(request).await
8    }
9    async fn query(&self, request: QueryRequest) -> Result<QueryResponse, Self::Error> {
10        (**self).query(request).await
11    }
12    async fn query_newest(
13        &self,
14        request: QueryNewestRequest,
15    ) -> Result<QueryNewestResponse, Self::Error> {
16        (**self).query_newest(request).await
17    }
18    async fn get_inbox_ids(
19        &self,
20        request: GetInboxIdsRequest,
21    ) -> Result<GetInboxIdsResponse, Self::Error> {
22        (**self).get_inbox_ids(request).await
23    }
24    async fn get_configuration(
25        &self,
26        request: GetConfigurationRequest,
27    ) -> Result<GetConfigurationResponse, Self::Error> {
28        (**self).get_configuration(request).await
29    }
30    fn backend_url(&self) -> Option<&str> {
31        (**self).backend_url()
32    }
33
34    fn has_credential_source(&self) -> bool {
35        (**self).has_credential_source()
36    }
37
38    fn set_limits(&self, limits: std::sync::Arc<xmtp_configuration::LimitsConfiguration>) {
39        (**self).set_limits(limits)
40    }
41    async fn verify_smart_contract_wallet_signatures(
42        &self,
43        request: VerifySmartContractWalletSignaturesRequest,
44    ) -> Result<VerifySmartContractWalletSignaturesResponse, Self::Error> {
45        (**self)
46            .verify_smart_contract_wallet_signatures(request)
47            .await
48    }
49    async fn register(&self, request: RegisterRequest) -> Result<RecipientState, Self::Error> {
50        (**self).register(request).await
51    }
52    async fn unregister(
53        &self,
54        request: UnregisterRequest,
55    ) -> Result<UnregisterResponse, Self::Error> {
56        (**self).unregister(request).await
57    }
58    async fn update_subscriptions(
59        &self,
60        request: UpdateSubscriptionsRequest,
61    ) -> Result<RecipientState, Self::Error> {
62        (**self).update_subscriptions(request).await
63    }
64}
65
66#[xmtp_common::async_trait]
67impl<T: XmtpMlsStreams + ?Sized> XmtpMlsStreams for Box<T> {
68    type Error = T::Error;
69    type GroupMessageStream = T::GroupMessageStream;
70    type WelcomeMessageStream = T::WelcomeMessageStream;
71    async fn subscribe_envelopes_with_cursors(
72        &self,
73        cursors: &TopicCursor,
74        limits: IncomingBatchLimits,
75    ) -> Result<IncomingSubscription<Self::Error>, Self::Error> {
76        (**self)
77            .subscribe_envelopes_with_cursors(cursors, limits)
78            .await
79    }
80    async fn subscribe_group_messages(
81        &self,
82        group_ids: &[&GroupId],
83    ) -> Result<Self::GroupMessageStream, Self::Error> {
84        (**self).subscribe_group_messages(group_ids).await
85    }
86    async fn subscribe_group_messages_with_cursors(
87        &self,
88        cursors: &TopicCursor,
89    ) -> Result<Self::GroupMessageStream, Self::Error> {
90        (**self)
91            .subscribe_group_messages_with_cursors(cursors)
92            .await
93    }
94    async fn subscribe_welcome_messages(
95        &self,
96        installations: &[&InstallationId],
97    ) -> Result<Self::WelcomeMessageStream, Self::Error> {
98        (**self).subscribe_welcome_messages(installations).await
99    }
100    async fn subscribe_welcome_messages_with_cursors(
101        &self,
102        cursors: &TopicCursor,
103    ) -> Result<Self::WelcomeMessageStream, Self::Error> {
104        (**self)
105            .subscribe_welcome_messages_with_cursors(cursors)
106            .await
107    }
108}
109
110#[xmtp_common::async_trait]
111impl<T: XmtpBackendClient + ?Sized> XmtpBackendClient for Arc<T> {
112    type Error = T::Error;
113    async fn publish(&self, request: PublishRequest) -> Result<PublishResponse, Self::Error> {
114        (**self).publish(request).await
115    }
116    async fn query(&self, request: QueryRequest) -> Result<QueryResponse, Self::Error> {
117        (**self).query(request).await
118    }
119    async fn query_newest(
120        &self,
121        request: QueryNewestRequest,
122    ) -> Result<QueryNewestResponse, Self::Error> {
123        (**self).query_newest(request).await
124    }
125    async fn get_inbox_ids(
126        &self,
127        request: GetInboxIdsRequest,
128    ) -> Result<GetInboxIdsResponse, Self::Error> {
129        (**self).get_inbox_ids(request).await
130    }
131    async fn get_configuration(
132        &self,
133        request: GetConfigurationRequest,
134    ) -> Result<GetConfigurationResponse, Self::Error> {
135        (**self).get_configuration(request).await
136    }
137    fn backend_url(&self) -> Option<&str> {
138        (**self).backend_url()
139    }
140
141    fn has_credential_source(&self) -> bool {
142        (**self).has_credential_source()
143    }
144
145    fn set_limits(&self, limits: std::sync::Arc<xmtp_configuration::LimitsConfiguration>) {
146        (**self).set_limits(limits)
147    }
148    async fn verify_smart_contract_wallet_signatures(
149        &self,
150        request: VerifySmartContractWalletSignaturesRequest,
151    ) -> Result<VerifySmartContractWalletSignaturesResponse, Self::Error> {
152        (**self)
153            .verify_smart_contract_wallet_signatures(request)
154            .await
155    }
156    async fn register(&self, request: RegisterRequest) -> Result<RecipientState, Self::Error> {
157        (**self).register(request).await
158    }
159    async fn unregister(
160        &self,
161        request: UnregisterRequest,
162    ) -> Result<UnregisterResponse, Self::Error> {
163        (**self).unregister(request).await
164    }
165    async fn update_subscriptions(
166        &self,
167        request: UpdateSubscriptionsRequest,
168    ) -> Result<RecipientState, Self::Error> {
169        (**self).update_subscriptions(request).await
170    }
171}
172
173#[xmtp_common::async_trait]
174impl<T: XmtpMlsStreams + ?Sized> XmtpMlsStreams for Arc<T> {
175    type Error = T::Error;
176    type GroupMessageStream = T::GroupMessageStream;
177    type WelcomeMessageStream = T::WelcomeMessageStream;
178    async fn subscribe_envelopes_with_cursors(
179        &self,
180        cursors: &TopicCursor,
181        limits: IncomingBatchLimits,
182    ) -> Result<IncomingSubscription<Self::Error>, Self::Error> {
183        (**self)
184            .subscribe_envelopes_with_cursors(cursors, limits)
185            .await
186    }
187    async fn subscribe_group_messages(
188        &self,
189        group_ids: &[&GroupId],
190    ) -> Result<Self::GroupMessageStream, Self::Error> {
191        (**self).subscribe_group_messages(group_ids).await
192    }
193    async fn subscribe_group_messages_with_cursors(
194        &self,
195        cursors: &TopicCursor,
196    ) -> Result<Self::GroupMessageStream, Self::Error> {
197        (**self)
198            .subscribe_group_messages_with_cursors(cursors)
199            .await
200    }
201    async fn subscribe_welcome_messages(
202        &self,
203        installations: &[&InstallationId],
204    ) -> Result<Self::WelcomeMessageStream, Self::Error> {
205        (**self).subscribe_welcome_messages(installations).await
206    }
207    async fn subscribe_welcome_messages_with_cursors(
208        &self,
209        cursors: &TopicCursor,
210    ) -> Result<Self::WelcomeMessageStream, Self::Error> {
211        (**self)
212            .subscribe_welcome_messages_with_cursors(cursors)
213            .await
214    }
215}
216
217#[xmtp_common::async_trait]
218impl<T: XmtpBackendClient + ?Sized> XmtpBackendClient for &T {
219    type Error = T::Error;
220    async fn publish(&self, request: PublishRequest) -> Result<PublishResponse, Self::Error> {
221        (**self).publish(request).await
222    }
223    async fn query(&self, request: QueryRequest) -> Result<QueryResponse, Self::Error> {
224        (**self).query(request).await
225    }
226    async fn query_newest(
227        &self,
228        request: QueryNewestRequest,
229    ) -> Result<QueryNewestResponse, Self::Error> {
230        (**self).query_newest(request).await
231    }
232    async fn get_inbox_ids(
233        &self,
234        request: GetInboxIdsRequest,
235    ) -> Result<GetInboxIdsResponse, Self::Error> {
236        (**self).get_inbox_ids(request).await
237    }
238    async fn get_configuration(
239        &self,
240        request: GetConfigurationRequest,
241    ) -> Result<GetConfigurationResponse, Self::Error> {
242        (**self).get_configuration(request).await
243    }
244    fn backend_url(&self) -> Option<&str> {
245        (**self).backend_url()
246    }
247
248    fn has_credential_source(&self) -> bool {
249        (**self).has_credential_source()
250    }
251
252    fn set_limits(&self, limits: std::sync::Arc<xmtp_configuration::LimitsConfiguration>) {
253        (**self).set_limits(limits)
254    }
255    async fn verify_smart_contract_wallet_signatures(
256        &self,
257        request: VerifySmartContractWalletSignaturesRequest,
258    ) -> Result<VerifySmartContractWalletSignaturesResponse, Self::Error> {
259        (**self)
260            .verify_smart_contract_wallet_signatures(request)
261            .await
262    }
263    async fn register(&self, request: RegisterRequest) -> Result<RecipientState, Self::Error> {
264        (**self).register(request).await
265    }
266    async fn unregister(
267        &self,
268        request: UnregisterRequest,
269    ) -> Result<UnregisterResponse, Self::Error> {
270        (**self).unregister(request).await
271    }
272    async fn update_subscriptions(
273        &self,
274        request: UpdateSubscriptionsRequest,
275    ) -> Result<RecipientState, Self::Error> {
276        (**self).update_subscriptions(request).await
277    }
278}
279
280#[xmtp_common::async_trait]
281impl<T: XmtpMlsStreams + ?Sized> XmtpMlsStreams for &T {
282    type Error = T::Error;
283    type GroupMessageStream = T::GroupMessageStream;
284    type WelcomeMessageStream = T::WelcomeMessageStream;
285    async fn subscribe_envelopes_with_cursors(
286        &self,
287        cursors: &TopicCursor,
288        limits: IncomingBatchLimits,
289    ) -> Result<IncomingSubscription<Self::Error>, Self::Error> {
290        (**self)
291            .subscribe_envelopes_with_cursors(cursors, limits)
292            .await
293    }
294    async fn subscribe_group_messages(
295        &self,
296        group_ids: &[&GroupId],
297    ) -> Result<Self::GroupMessageStream, Self::Error> {
298        (**self).subscribe_group_messages(group_ids).await
299    }
300    async fn subscribe_group_messages_with_cursors(
301        &self,
302        cursors: &TopicCursor,
303    ) -> Result<Self::GroupMessageStream, Self::Error> {
304        (**self)
305            .subscribe_group_messages_with_cursors(cursors)
306            .await
307    }
308    async fn subscribe_welcome_messages(
309        &self,
310        installations: &[&InstallationId],
311    ) -> Result<Self::WelcomeMessageStream, Self::Error> {
312        (**self).subscribe_welcome_messages(installations).await
313    }
314    async fn subscribe_welcome_messages_with_cursors(
315        &self,
316        cursors: &TopicCursor,
317    ) -> Result<Self::WelcomeMessageStream, Self::Error> {
318        (**self)
319            .subscribe_welcome_messages_with_cursors(cursors)
320            .await
321    }
322}
323
324xmtp_common::if_native! {
325    // `XmtpMlsBidiStreams` is native-only (see `api_client.rs`), so its boxed /
326    // arced forwarders are gated the same way. Without these, erasing a client
327    // into `Box<dyn XmtpMlsBidiStreams>` / `Arc<dyn XmtpMlsBidiStreams>` would
328    // fail to compile on `subscribe_bidi`, unlike every other client trait here.
329    #[xmtp_common::async_trait]
330    impl<T> XmtpMlsBidiStreams for Box<T>
331    where
332        T: XmtpMlsBidiStreams + Sync + ?Sized,
333    {
334        type Error = <T as XmtpMlsBidiStreams>::Error;
335        type SubscribeStream = <T as XmtpMlsBidiStreams>::SubscribeStream;
336
337        fn host(&self) -> &str {
338            (**self).host()
339        }
340
341        fn bidi_limits(&self) -> std::sync::Arc<xmtp_configuration::LimitsConfiguration> {
342            (**self).bidi_limits()
343        }
344
345        async fn subscribe_bidi(
346            &self,
347            requests: futures::stream::BoxStream<'static, crate::backend_v1::SubscribeRequest>,
348        ) -> Result<Self::SubscribeStream, Self::Error> {
349            (**self).subscribe_bidi(requests).await
350        }
351    }
352
353    #[xmtp_common::async_trait]
354    impl<T> XmtpMlsBidiStreams for Arc<T>
355    where
356        T: XmtpMlsBidiStreams + ?Sized,
357    {
358        type Error = <T as XmtpMlsBidiStreams>::Error;
359        type SubscribeStream = <T as XmtpMlsBidiStreams>::SubscribeStream;
360
361        fn host(&self) -> &str {
362            (**self).host()
363        }
364
365        fn bidi_limits(&self) -> std::sync::Arc<xmtp_configuration::LimitsConfiguration> {
366            (**self).bidi_limits()
367        }
368
369        async fn subscribe_bidi(
370            &self,
371            requests: futures::stream::BoxStream<'static, crate::backend_v1::SubscribeRequest>,
372        ) -> Result<Self::SubscribeStream, Self::Error> {
373            (**self).subscribe_bidi(requests).await
374        }
375    }
376}