Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dead endpoints #963

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 4 additions & 30 deletions xmtp_api_grpc/src/grpc_api_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ use xmtp_proto::{
},
xmtp::mls::api::v1::{
mls_api_client::MlsApiClient as ProtoMlsApiClient, FetchKeyPackagesRequest,
FetchKeyPackagesResponse, GetIdentityUpdatesRequest, GetIdentityUpdatesResponse,
QueryGroupMessagesRequest, QueryGroupMessagesResponse, QueryWelcomeMessagesRequest,
QueryWelcomeMessagesResponse, RegisterInstallationRequest, RegisterInstallationResponse,
SendGroupMessagesRequest, SendWelcomeMessagesRequest, SubscribeGroupMessagesRequest,
SubscribeWelcomeMessagesRequest, UploadKeyPackageRequest,
FetchKeyPackagesResponse, QueryGroupMessagesRequest, QueryGroupMessagesResponse,
QueryWelcomeMessagesRequest, QueryWelcomeMessagesResponse, SendGroupMessagesRequest,
SendWelcomeMessagesRequest, SubscribeGroupMessagesRequest, SubscribeWelcomeMessagesRequest,
UploadKeyPackageRequest,
},
};

Expand Down Expand Up @@ -344,19 +343,6 @@ impl MutableApiSubscription for GrpcMutableSubscription {

#[async_trait]
impl XmtpMlsClient for Client {
#[tracing::instrument(level = "trace", skip_all)]
async fn register_installation(
&self,
req: RegisterInstallationRequest,
) -> Result<RegisterInstallationResponse, Error> {
let client = &mut self.mls_client.clone();
let res = client.register_installation(req).await;
match res {
Ok(response) => Ok(response.into_inner()),
Err(e) => Err(Error::new(ErrorKind::MlsError).with(e)),
}
}

#[tracing::instrument(level = "trace", skip_all)]
async fn upload_key_package(&self, req: UploadKeyPackageRequest) -> Result<(), Error> {
let client = &mut self.mls_client.clone();
Expand Down Expand Up @@ -425,18 +411,6 @@ impl XmtpMlsClient for Client {
.map_err(|e| Error::new(ErrorKind::MlsError).with(e))
}

#[tracing::instrument(level = "trace", skip_all)]
async fn get_identity_updates(
&self,
req: GetIdentityUpdatesRequest,
) -> Result<GetIdentityUpdatesResponse, Error> {
let client = &mut self.mls_client.clone();
let res = client.get_identity_updates(req).await;

res.map(|r| r.into_inner())
.map_err(|e| Error::new(ErrorKind::MlsError).with(e))
}

async fn subscribe_group_messages(
&self,
req: SubscribeGroupMessagesRequest,
Expand Down
40 changes: 6 additions & 34 deletions xmtp_api_http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ use xmtp_proto::xmtp::mls::api::v1::{GroupMessage, WelcomeMessage};
use xmtp_proto::{
api_client::{GroupMessageStream, WelcomeMessageStream, XmtpMlsClient},
xmtp::mls::api::v1::{
FetchKeyPackagesRequest, FetchKeyPackagesResponse, GetIdentityUpdatesRequest,
GetIdentityUpdatesResponse, QueryGroupMessagesRequest, QueryGroupMessagesResponse,
QueryWelcomeMessagesRequest, QueryWelcomeMessagesResponse, RegisterInstallationRequest,
RegisterInstallationResponse, SendGroupMessagesRequest, SendWelcomeMessagesRequest,
SubscribeGroupMessagesRequest, SubscribeWelcomeMessagesRequest, UploadKeyPackageRequest,
FetchKeyPackagesRequest, FetchKeyPackagesResponse, QueryGroupMessagesRequest,
QueryGroupMessagesResponse, QueryWelcomeMessagesRequest, QueryWelcomeMessagesResponse,
SendGroupMessagesRequest, SendWelcomeMessagesRequest, SubscribeGroupMessagesRequest,
SubscribeWelcomeMessagesRequest, UploadKeyPackageRequest,
},
};

Expand Down Expand Up @@ -54,25 +53,6 @@ impl XmtpHttpApiClient {
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
impl XmtpMlsClient for XmtpHttpApiClient {
async fn register_installation(
&self,
request: RegisterInstallationRequest,
) -> Result<RegisterInstallationResponse, Error> {
let res = self
.http_client
.post(self.endpoint(ApiEndpoints::REGISTER_INSTALLATION))
.json(&request)
.send()
.await
.map_err(|e| Error::new(ErrorKind::MlsError).with(e))?
.bytes()
.await
.map_err(|e| Error::new(ErrorKind::MlsError).with(e))?;

log::debug!("register_installation");
handle_error(&*res)
}

async fn upload_key_package(&self, request: UploadKeyPackageRequest) -> Result<(), Error> {
let res = self
.http_client
Expand Down Expand Up @@ -143,14 +123,6 @@ impl XmtpMlsClient for XmtpHttpApiClient {
handle_error(&*res)
}

// deprecated
async fn get_identity_updates(
&self,
_request: GetIdentityUpdatesRequest,
) -> Result<GetIdentityUpdatesResponse, Error> {
unimplemented!()
}

async fn query_group_messages(
&self,
request: QueryGroupMessagesRequest,
Expand Down Expand Up @@ -287,10 +259,10 @@ mod tests {
use super::*;

#[tokio::test]
async fn test_register_installation() {
async fn test_upload_key_package() {
let client = XmtpHttpApiClient::new(ApiUrls::LOCAL_ADDRESS.to_string()).unwrap();
let result = client
.register_installation(RegisterInstallationRequest {
.upload_key_package(UploadKeyPackageRequest {
is_inbox_id_credential: false,
key_package: Some(KeyPackageUpload {
key_package_tls_serialized: vec![1, 2, 3],
Expand Down
198 changes: 6 additions & 192 deletions xmtp_mls/src/api/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ use xmtp_proto::api_client::{
Error as ApiError, ErrorKind, GroupMessageStream, WelcomeMessageStream,
};
use xmtp_proto::xmtp::mls::api::v1::{
get_identity_updates_response::update::Kind as UpdateKind,
group_message_input::{Version as GroupMessageInputVersion, V1 as GroupMessageInputV1},
subscribe_group_messages_request::Filter as GroupFilterProto,
subscribe_welcome_messages_request::Filter as WelcomeFilterProto,
FetchKeyPackagesRequest, GetIdentityUpdatesRequest, GroupMessage, GroupMessageInput,
KeyPackageUpload, PagingInfo, QueryGroupMessagesRequest, QueryWelcomeMessagesRequest,
RegisterInstallationRequest, SendGroupMessagesRequest, SendWelcomeMessagesRequest,
SortDirection, SubscribeGroupMessagesRequest, SubscribeWelcomeMessagesRequest,
UploadKeyPackageRequest, WelcomeMessage, WelcomeMessageInput,
FetchKeyPackagesRequest, GroupMessage, GroupMessageInput, KeyPackageUpload, PagingInfo,
QueryGroupMessagesRequest, QueryWelcomeMessagesRequest, SendGroupMessagesRequest,
SendWelcomeMessagesRequest, SortDirection, SubscribeGroupMessagesRequest,
SubscribeWelcomeMessagesRequest, UploadKeyPackageRequest, WelcomeMessage, WelcomeMessageInput,
};

/// A filter for querying group messages
Expand Down Expand Up @@ -63,8 +61,6 @@ pub enum IdentityUpdate {

type KeyPackageMap = HashMap<Vec<u8>, Vec<u8>>;

type IdentityUpdatesMap = HashMap<String, Vec<IdentityUpdate>>;

impl<ApiClient> ApiClientWrapper<ApiClient>
where
ApiClient: XmtpApi,
Expand Down Expand Up @@ -157,33 +153,6 @@ where
Ok(out)
}

/// Register an XMTP KeyPackage with the network.
/// New InboxID clients should set `is_inbox_id_credential` to true.
/// V3 clients should have `is_inbox_id_credential` to `false`.
/// Not indicating your client version will result in validation failure.
#[tracing::instrument(level = "trace", skip_all)]
pub async fn register_installation(
&self,
key_package: Vec<u8>,
is_inbox_id_credential: bool,
) -> Result<Vec<u8>, ApiError> {
let res = retry_async!(
self.retry_strategy,
(async {
self.api_client
.register_installation(RegisterInstallationRequest {
key_package: Some(KeyPackageUpload {
key_package_tls_serialized: key_package.to_vec(),
}),
is_inbox_id_credential,
})
.await
})
)?;

Ok(res.installation_key)
}

/// Upload a KeyPackage to the network
/// New InboxID clients should set `is_inbox_id_credential` to true.
/// V3 clients should have `is_inbox_id_credential` to `false`.
Expand Down Expand Up @@ -266,66 +235,6 @@ where
Ok(())
}

#[tracing::instrument(level = "trace", skip_all)]
pub async fn get_identity_updates(
&self,
start_time_ns: u64,
account_addresses: Vec<String>,
) -> Result<IdentityUpdatesMap, ApiError> {
let result = retry_async!(
self.retry_strategy,
(async {
self.api_client
.get_identity_updates(GetIdentityUpdatesRequest {
start_time_ns,
account_addresses: account_addresses.clone(),
})
.await
})
)?;

if result.updates.len() != account_addresses.len() {
println!("mismatched number of results");
return Err(ApiError::new(ErrorKind::MlsError));
}

let mapping: IdentityUpdatesMap = result
.updates
.into_iter()
.zip(account_addresses.into_iter())
.map(|(update, account_address)| {
(
account_address,
update
.updates
.into_iter()
.map(|update| match update.kind {
Some(UpdateKind::NewInstallation(new_installation)) => {
IdentityUpdate::NewInstallation(NewInstallation {
timestamp_ns: update.timestamp_ns,
installation_key: new_installation.installation_key,
credential_bytes: new_installation.credential_identity,
})
}
Some(UpdateKind::RevokedInstallation(revoke_installation)) => {
IdentityUpdate::RevokeInstallation(RevokeInstallation {
timestamp_ns: update.timestamp_ns,
installation_key: revoke_installation.installation_key,
})
}
None => {
println!("no update kind");
IdentityUpdate::Invalid
}
})
.collect(),
)
})
.collect();

Ok(mapping)
}

#[tracing::instrument(level = "trace", skip_all)]
pub async fn send_group_messages(&self, group_messages: Vec<&[u8]>) -> Result<(), ApiError> {
let to_send: Vec<GroupMessageInput> = group_messages
Expand Down Expand Up @@ -387,31 +296,11 @@ pub mod tests {
use xmtp_proto::{
api_client::{Error, ErrorKind},
xmtp::mls::api::v1::{
fetch_key_packages_response::KeyPackage,
get_identity_updates_response::{
update::Kind as UpdateKind, NewInstallationUpdate, Update, WalletUpdates,
},
FetchKeyPackagesResponse, GetIdentityUpdatesResponse, PagingInfo,
QueryGroupMessagesResponse, RegisterInstallationResponse,
fetch_key_packages_response::KeyPackage, FetchKeyPackagesResponse, PagingInfo,
QueryGroupMessagesResponse,
},
};

#[tokio::test]
async fn test_register_installation() {
let mut mock_api = MockApiClient::new();
mock_api.expect_register_installation().returning(move |_| {
Ok(RegisterInstallationResponse {
installation_key: vec![1, 2, 3],
})
});
let wrapper = ApiClientWrapper::new(mock_api, Retry::default());
let result = wrapper
.register_installation(vec![2, 3, 4], false)
.await
.unwrap();
assert_eq!(result, vec![1, 2, 3]);
}

#[tokio::test]
async fn test_upload_key_package() {
let mut mock_api = MockApiClient::new();
Expand Down Expand Up @@ -465,81 +354,6 @@ pub mod tests {
}
}

#[tokio::test]
async fn test_get_identity_updates() {
let mut mock_api = MockApiClient::new();
let start_time_ns = 12;
let account_addresses = vec!["wallet1".to_string(), "wallet2".to_string()];
// account_addresses gets moved below but needs to be used for assertions later
let account_addresses_clone = account_addresses.clone();
mock_api
.expect_get_identity_updates()
.withf(move |req| {
req.start_time_ns.eq(&start_time_ns) && req.account_addresses.eq(&account_addresses)
})
.returning(move |_| {
Ok(GetIdentityUpdatesResponse {
updates: {
vec![
WalletUpdates {
updates: vec![Update {
timestamp_ns: 1,
kind: Some(UpdateKind::NewInstallation(
NewInstallationUpdate {
installation_key: vec![1, 2, 3],
credential_identity: vec![4, 5, 6],
},
)),
}],
},
WalletUpdates {
updates: vec![Update {
timestamp_ns: 2,
kind: Some(UpdateKind::NewInstallation(
NewInstallationUpdate {
installation_key: vec![7, 8, 9],
credential_identity: vec![10, 11, 12],
},
)),
}],
},
]
},
})
});

let wrapper = ApiClientWrapper::new(mock_api, Retry::default());
let result = wrapper
.get_identity_updates(start_time_ns, account_addresses_clone.clone())
.await
.unwrap();
assert_eq!(result.len(), 2);

for (k, v) in result {
if k.eq(&account_addresses_clone[0]) {
assert_eq!(v.len(), 1);
assert_eq!(
v[0],
super::IdentityUpdate::NewInstallation(super::NewInstallation {
installation_key: vec![1, 2, 3],
credential_bytes: vec![4, 5, 6],
timestamp_ns: 1,
})
);
} else {
assert_eq!(v.len(), 1);
assert_eq!(
v[0],
super::IdentityUpdate::NewInstallation(super::NewInstallation {
installation_key: vec![7, 8, 9],
credential_bytes: vec![10, 11, 12],
timestamp_ns: 2,
})
);
}
}
}

#[tokio::test]
async fn test_read_group_messages_single_page() {
let mut mock_api = MockApiClient::new();
Expand Down
Loading