Skip to content

Commit c598672

Browse files
authored
Compatibility Layer stubs for d14n and ApiClientWrapper (#1642)
* compat layer * add compat layer for d14n * dont forget client trait
1 parent 7d6b8b1 commit c598672

File tree

10 files changed

+251
-9
lines changed

10 files changed

+251
-9
lines changed

Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

xmtp_api_d14n/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ license.workspace = true
55
version.workspace = true
66

77
[dependencies]
8+
async-trait.workspace = true
89
derive_builder = "0.20"
910
once_cell.workspace = true
1011
parking_lot.workspace = true
1112
prost.workspace = true
1213
prost-types.workspace = true
14+
xmtp_common.workspace = true
1315
xmtp_proto.workspace = true
1416

1517
[dev-dependencies]

xmtp_api_d14n/src/compat/d14n.rs

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
//! Compatibility layer for d14n and previous xmtp_api crate
2+
3+
//TODO: Remove once d14n integration complete
4+
#![allow(unused)]
5+
use xmtp_common::RetryableError;
6+
use xmtp_proto::api_client::{XmtpIdentityClient, XmtpMlsClient, XmtpMlsStreams};
7+
use xmtp_proto::traits::ApiError;
8+
use xmtp_proto::traits::Client;
9+
10+
use xmtp_proto::xmtp::identity::api::v1::{
11+
GetIdentityUpdatesRequest, GetIdentityUpdatesResponse, GetInboxIdsRequest, GetInboxIdsResponse,
12+
PublishIdentityUpdateRequest, PublishIdentityUpdateResponse,
13+
VerifySmartContractWalletSignaturesRequest, VerifySmartContractWalletSignaturesResponse,
14+
};
15+
use xmtp_proto::XmtpApiError;
16+
use xmtp_proto::{
17+
xmtp::identity::api::v1::identity_api_client::IdentityApiClient as ProtoIdentityApiClient,
18+
xmtp::message_api::v1::{
19+
message_api_client::MessageApiClient, BatchQueryRequest, BatchQueryResponse, Envelope,
20+
PublishRequest, PublishResponse, QueryRequest, QueryResponse, SubscribeRequest,
21+
},
22+
xmtp::mls::api::v1::{
23+
mls_api_client::MlsApiClient as ProtoMlsApiClient, FetchKeyPackagesRequest,
24+
FetchKeyPackagesResponse, QueryGroupMessagesRequest, QueryGroupMessagesResponse,
25+
QueryWelcomeMessagesRequest, QueryWelcomeMessagesResponse, SendGroupMessagesRequest,
26+
SendWelcomeMessagesRequest, SubscribeGroupMessagesRequest, SubscribeWelcomeMessagesRequest,
27+
UploadKeyPackageRequest,
28+
},
29+
};
30+
31+
use crate::endpoints::{GetInboxIds, PublishClientEnvelopes, QueryEnvelopes};
32+
pub struct D14nClient<C, P, E> {
33+
message_client: C,
34+
payer_client: P,
35+
_marker: E,
36+
}
37+
38+
#[async_trait::async_trait]
39+
impl<C, P, E> XmtpMlsClient for D14nClient<C, P, E>
40+
where
41+
E: std::error::Error + RetryableError + Send + Sync + 'static,
42+
P: Send + Sync + Client,
43+
C: Send + Sync + Client,
44+
{
45+
type Error = ApiError<E>;
46+
async fn upload_key_package(
47+
&self,
48+
request: UploadKeyPackageRequest,
49+
) -> Result<(), Self::Error> {
50+
todo!()
51+
}
52+
async fn fetch_key_packages(
53+
&self,
54+
request: FetchKeyPackagesRequest,
55+
) -> Result<FetchKeyPackagesResponse, Self::Error> {
56+
todo!()
57+
}
58+
async fn send_group_messages(
59+
&self,
60+
request: SendGroupMessagesRequest,
61+
) -> Result<(), Self::Error> {
62+
todo!()
63+
}
64+
async fn send_welcome_messages(
65+
&self,
66+
request: SendWelcomeMessagesRequest,
67+
) -> Result<(), Self::Error> {
68+
todo!()
69+
}
70+
async fn query_group_messages(
71+
&self,
72+
request: QueryGroupMessagesRequest,
73+
) -> Result<QueryGroupMessagesResponse, Self::Error> {
74+
todo!()
75+
}
76+
async fn query_welcome_messages(
77+
&self,
78+
request: QueryWelcomeMessagesRequest,
79+
) -> Result<QueryWelcomeMessagesResponse, Self::Error> {
80+
todo!()
81+
}
82+
}
83+
84+
#[async_trait::async_trait]
85+
impl<C, P, E> XmtpIdentityClient for D14nClient<C, P, E>
86+
where
87+
E: std::error::Error + RetryableError + Send + Sync + 'static,
88+
P: Send + Sync + Client,
89+
C: Send + Sync + Client,
90+
{
91+
type Error = ApiError<E>;
92+
93+
async fn publish_identity_update(
94+
&self,
95+
request: PublishIdentityUpdateRequest,
96+
) -> Result<PublishIdentityUpdateResponse, Self::Error> {
97+
todo!()
98+
}
99+
100+
async fn get_identity_updates_v2(
101+
&self,
102+
request: GetIdentityUpdatesRequest,
103+
) -> Result<GetIdentityUpdatesResponse, Self::Error> {
104+
todo!()
105+
}
106+
107+
async fn get_inbox_ids(
108+
&self,
109+
request: GetInboxIdsRequest,
110+
) -> Result<GetInboxIdsResponse, Self::Error> {
111+
todo!()
112+
}
113+
114+
async fn verify_smart_contract_wallet_signatures(
115+
&self,
116+
request: VerifySmartContractWalletSignaturesRequest,
117+
) -> Result<VerifySmartContractWalletSignaturesResponse, Self::Error> {
118+
todo!()
119+
}
120+
}

xmtp_api_d14n/src/compat/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
mod v3;
3+
pub use v3::*;
4+
*/
5+
mod d14n;
6+
pub use d14n::*;

xmtp_api_d14n/src/compat/v3.rs

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
use xmtp_proto::api_client::{XmtpApiClient, XmtpIdentityClient, XmtpMlsClient, XmtpMlsStreams};
2+
use xmtp_proto::traits::ApiError;
3+
4+
pub struct V3Client<C> {
5+
client: C,
6+
}
7+
8+
#[async_trait::async_trait]
9+
impl<C> XmtpMlsClient for V3Client<C> {
10+
type Error = ApiError<Box<dyn XmtpApiError>>;
11+
12+
async fn upload_key_package(
13+
&self,
14+
request: UploadKeyPackageRequest,
15+
) -> Result<(), Self::Error> {
16+
todo!()
17+
}
18+
async fn fetch_key_packages(
19+
&self,
20+
request: FetchKeyPackagesRequest,
21+
) -> Result<FetchKeyPackagesResponse, Self::Error> {
22+
todo!()
23+
}
24+
async fn send_group_messages(
25+
&self,
26+
request: SendGroupMessagesRequest,
27+
) -> Result<(), Self::Error> {
28+
todo!()
29+
}
30+
async fn send_welcome_messages(
31+
&self,
32+
request: SendWelcomeMessagesRequest,
33+
) -> Result<(), Self::Error> {
34+
todo!()
35+
}
36+
async fn query_group_messages(
37+
&self,
38+
request: QueryGroupMessagesRequest,
39+
) -> Result<QueryGroupMessagesResponse, Self::Error> {
40+
todo!()
41+
}
42+
async fn query_welcome_messages(
43+
&self,
44+
request: QueryWelcomeMessagesRequest,
45+
) -> Result<QueryWelcomeMessagesResponse, Self::Error> {
46+
todo!()
47+
}
48+
}
49+
50+
#[async_trait::async_trait]
51+
impl<C> XmtpIdentityClient for V3Client<C> {
52+
type Error = ApiError<Box<dyn XmtpApiError>>;
53+
54+
async fn publish_identity_update(
55+
&self,
56+
request: PublishIdentityUpdateRequest,
57+
) -> Result<PublishIdentityUpdateResponse, Self::Error> {
58+
todo!()
59+
}
60+
61+
async fn get_identity_updates_v2(
62+
&self,
63+
request: GetIdentityUpdatesV2Request,
64+
) -> Result<GetIdentityUpdatesV2Response, Self::Error> {
65+
todo!()
66+
}
67+
68+
async fn get_inbox_ids(
69+
&self,
70+
request: GetInboxIdsRequest,
71+
) -> Result<GetInboxIdsResponse, Self::Error> {
72+
todo!()
73+
}
74+
75+
async fn verify_smart_contract_wallet_signatures(
76+
&self,
77+
request: VerifySmartContractWalletSignaturesRequest,
78+
) -> Result<VerifySmartContractWalletSignaturesResponse, Self::Error> {
79+
todo!()
80+
}
81+
}

xmtp_api_d14n/src/endpoints/d14n/get_inbox_ids.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ use derive_builder::Builder;
22
use prost::Message;
33
use std::borrow::Cow;
44
use xmtp_proto::traits::{BodyError, Endpoint};
5-
use xmtp_proto::xmtp::mls::api::v1::FetchKeyPackagesRequest;
6-
use xmtp_proto::xmtp::xmtpv4::message_api::FILE_DECRIPTOR_SET;
7-
use xmtp_proto::xmtp::xmtpv4::message_api::{GetInboxIdsRequest, GetInboxIdsResponse};
5+
use xmtp_proto::xmtp::xmtpv4::message_api::FILE_DESCRIPTOR_SET;
6+
use xmtp_proto::xmtp::xmtpv4::message_api::{
7+
get_inbox_ids_request, GetInboxIdsRequest, GetInboxIdsResponse,
8+
};
89

910
#[derive(Debug, Builder, Default)]
1011
#[builder(setter(strip_option))]
1112
pub struct GetInboxIds {
1213
#[builder(setter(into))]
13-
envelopes: Vec<ClientEnvelope>,
14+
addresses: Vec<String>,
1415
}
1516

1617
impl GetInboxIds {
@@ -27,12 +28,17 @@ impl Endpoint for GetInboxIds {
2728
}
2829

2930
fn grpc_endpoint(&self) -> Cow<'static, str> {
30-
crate::path_and_query::<PublishClientEnvelopesRequest>(FILE_DESCRIPTOR_SET)
31+
crate::path_and_query::<GetInboxIdsRequest>(FILE_DESCRIPTOR_SET)
3132
}
3233

3334
fn body(&self) -> Result<Vec<u8>, BodyError> {
34-
Ok(PublishClientEnvelopesRequest {
35-
envelopes: self.envelopes.clone(),
35+
Ok(GetInboxIdsRequest {
36+
requests: self
37+
.addresses
38+
.iter()
39+
.cloned()
40+
.map(|i| get_inbox_ids_request::Request { address: i })
41+
.collect(),
3642
}
3743
.encode_to_vec())
3844
}

xmtp_api_d14n/src/endpoints/d14n/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ pub use publish_client_envelopes::*;
33

44
mod query_envelopes;
55
pub use query_envelopes::*;
6+
7+
mod get_inbox_ids;
8+
pub use get_inbox_ids::*;

xmtp_api_d14n/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ pub use endpoints::*;
33

44
mod proto_cache;
55
pub(crate) use proto_cache::*;
6+
7+
pub mod compat;
8+
pub use compat::*;

xmtp_proto/src/gen/xmtp.xmtpv4.message_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -888,4 +888,4 @@ pub const FILE_DESCRIPTOR_SET: &[u8] = &[
888888
];
889889
include!("xmtp.xmtpv4.message_api.serde.rs");
890890
include!("xmtp.xmtpv4.message_api.tonic.rs");
891-
// @@protoc_insertion_point(module)
891+
// @@protoc_insertion_point(module)

xmtp_proto/src/traits.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use std::borrow::Cow;
55
use thiserror::Error;
66
use xmtp_common::{retry_async, retryable, BoxedRetry, RetryableError};
77

8+
use crate::{ApiEndpoint, Code, XmtpApiError};
9+
810
pub trait Endpoint {
911
type Output: prost::Message + Default;
1012

@@ -23,11 +25,11 @@ where
2325
inner: S,
2426
}
2527
*/
28+
2629
#[allow(async_fn_in_trait)]
2730
pub trait Client {
2831
type Error: std::error::Error + Send + Sync + 'static;
2932
type Stream: futures::Stream;
30-
// TODO: probably need type: Stream here
3133

3234
async fn request(
3335
&self,
@@ -104,6 +106,23 @@ where
104106
Conversion(#[from] crate::ConversionError),
105107
}
106108

109+
impl<E> XmtpApiError for ApiError<E>
110+
where
111+
E: std::error::Error + Send + Sync + RetryableError + 'static,
112+
{
113+
fn api_call(&self) -> Option<ApiEndpoint> {
114+
None
115+
}
116+
117+
fn code(&self) -> Option<Code> {
118+
None
119+
}
120+
121+
fn grpc_message(&self) -> Option<&str> {
122+
None
123+
}
124+
}
125+
107126
impl<E> RetryableError for ApiError<E>
108127
where
109128
E: RetryableError + std::error::Error + Send + Sync + 'static,

0 commit comments

Comments
 (0)