diff --git a/Cargo.lock b/Cargo.lock index 0946b7e2cf..17d6c59a8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8686,6 +8686,7 @@ dependencies = [ "openmls", "openmls_rust_crypto", "parking_lot 0.12.5", + "pbjson-types", "pin-project-lite", "proptest", "prost", diff --git a/crates/xmtp_api_d14n/Cargo.toml b/crates/xmtp_api_d14n/Cargo.toml index 393ea02cae..c0de4b4398 100644 --- a/crates/xmtp_api_d14n/Cargo.toml +++ b/crates/xmtp_api_d14n/Cargo.toml @@ -21,6 +21,7 @@ impl-trait-for-tuples = "0.2" itertools.workspace = true openmls_rust_crypto = { workspace = true } parking_lot.workspace = true +pbjson-types.workspace = true pin-project-lite = { workspace = true } prost.workspace = true thiserror.workspace = true diff --git a/crates/xmtp_api_d14n/src/endpoints/d14n/fetch_d14n_cutover.rs b/crates/xmtp_api_d14n/src/endpoints/d14n/fetch_d14n_cutover.rs new file mode 100644 index 0000000000..9a98014378 --- /dev/null +++ b/crates/xmtp_api_d14n/src/endpoints/d14n/fetch_d14n_cutover.rs @@ -0,0 +1,48 @@ +use prost::Message; +use prost::bytes::Bytes; +use std::borrow::Cow; +use xmtp_proto::api::{BodyError, Endpoint}; +use xmtp_proto::xmtp::migration::api::v1::FetchD14nCutoverResponse; + +#[derive(Debug, Default)] +pub struct FetchD14nCutover; + +impl Endpoint for FetchD14nCutover { + type Output = FetchD14nCutover; + fn grpc_endpoint(&self) -> Cow<'static, str> { + xmtp_proto::path_and_query::() + } + + fn body(&self) -> Result { + Ok(pbjson_types::Empty::default().encode_to_vec().into()) + } +} + +#[cfg(test)] +mod test { + use super::*; + use xmtp_api_grpc::test::NodeGoClient; + use xmtp_proto::{api, prelude::*}; + + #[xmtp_common::test] + fn test_grpc_endpoint_returns_correct_path() { + let endpoint = FetchD14nCutover; + assert_eq!( + endpoint.grpc_endpoint(), + "/xmtp.migration.api.v1.D14nMigrationApi/FetchD14nCutover", + "Expected correct grpc method path but got {}", + endpoint.grpc_endpoint() + ); + } + + // ignored until service implemented + #[ignore] + #[xmtp_common::test] + async fn test_fetch_d14n_cutover() { + let client = NodeGoClient::create(); + let client = client.build().unwrap(); + + let endpoint = FetchD14nCutover; + api::ignore(endpoint).query(&client).await.unwrap(); + } +} diff --git a/crates/xmtp_api_d14n/src/endpoints/d14n/mod.rs b/crates/xmtp_api_d14n/src/endpoints/d14n/mod.rs index 4f64c9ebd3..f96282cf31 100644 --- a/crates/xmtp_api_d14n/src/endpoints/d14n/mod.rs +++ b/crates/xmtp_api_d14n/src/endpoints/d14n/mod.rs @@ -18,3 +18,6 @@ pub use health_check::*; mod get_nodes; pub use get_nodes::*; + +mod fetch_d14n_cutover; +pub use fetch_d14n_cutover::*; diff --git a/crates/xmtp_proto/src/gen/mod.rs b/crates/xmtp_proto/src/gen/mod.rs index 3a64deff4d..596421528f 100644 --- a/crates/xmtp_proto/src/gen/mod.rs +++ b/crates/xmtp_proto/src/gen/mod.rs @@ -97,4 +97,12 @@ pub mod xmtp { include!("xmtp.xmtpv4.payer_api.serde.rs"); } } + pub mod migration { + pub mod api { + pub mod v1 { + include!("xmtp.migration.api.v1.rs"); + include!("xmtp.migration.api.v1.serde.rs"); + } + } + } } diff --git a/crates/xmtp_proto/src/proto_cache.rs b/crates/xmtp_proto/src/proto_cache.rs index 61cfb70817..357b23616d 100644 --- a/crates/xmtp_proto/src/proto_cache.rs +++ b/crates/xmtp_proto/src/proto_cache.rs @@ -10,6 +10,7 @@ type Cache = HashMap<(Cow<'static, str>, Cow<'static, str>), Cow<'static, str>>; // lookup a method path&query based on a type name & package pub static METHOD_LOOKUP: LazyLock = LazyLock::new(|| { + use Cow::*; let pnq = |package: &str, service: &ServiceDescriptorProto, method: &MethodDescriptorProto| @@ -29,12 +30,19 @@ pub static METHOD_LOOKUP: LazyLock = LazyLock::new(|| { }; for service in fd.service.iter() { for method in service.method.iter() { + if let Some(output_t) = method.output_type().split('.').next_back() { + map.insert( + (Owned(package.clone()), Owned(output_t.to_string())), + Owned(pnq(package, service, method)), + ); + }; + let Some(input_t) = method.input_type().split('.').next_back() else { continue; }; map.insert( - (Cow::Owned(package.clone()), Cow::Owned(input_t.to_string())), - Cow::Owned(pnq(package, service, method)), + (Owned(package.clone()), Owned(input_t.to_string())), + Owned(pnq(package, service, method)), ); } }