From 40124eb5fb36d6abd12e62eac305d195bbd404f3 Mon Sep 17 00:00:00 2001 From: Andrew Plaza Date: Mon, 16 Dec 2024 11:47:43 -0500 Subject: [PATCH] add replication client stubs --- xmtp_debug/src/app/clients.rs | 27 +++++++++++++++++++++++++-- xmtp_debug/src/args.rs | 32 ++++++++++++++++++++++++++------ xmtp_debug/src/constants.rs | 7 +++++++ xmtp_debug/src/main.rs | 4 +++- 4 files changed, 61 insertions(+), 9 deletions(-) diff --git a/xmtp_debug/src/app/clients.rs b/xmtp_debug/src/app/clients.rs index 6824ca39e..5497838ef 100644 --- a/xmtp_debug/src/app/clients.rs +++ b/xmtp_debug/src/app/clients.rs @@ -1,5 +1,7 @@ //! Different ways to create a [`crate::DbgClient`] +use xmtp_mls::XmtpApi; + use super::*; use crate::app::types::*; @@ -60,7 +62,7 @@ async fn new_client_inner( let url = url::Url::from(network.clone()); let is_secure = url.scheme() == "https"; trace!(url = %url, is_secure, "create grpc"); - let api = crate::GrpcClient::create(url.as_str().to_string(), is_secure).await?; + let api = create_grpc(&url, is_secure, network.d14n).await?; let nonce = 1; let inbox_id = generate_inbox_id(&wallet.get_address(), &nonce).unwrap(); @@ -127,7 +129,7 @@ async fn existing_client_inner( ) -> Result { let url = url::Url::from(network.clone()); let is_secure = url.scheme() == "https"; - let api = crate::GrpcClient::create(url.as_str().to_string(), is_secure).await?; + let api = create_grpc(&url, is_secure, network.d14n).await?; let store = EncryptedMessageStore::new( StorageOption::Persistent(db_path.clone().into_os_string().into_string().unwrap()), @@ -145,3 +147,24 @@ async fn existing_client_inner( Ok(client) } + +async fn create_grpc( + url: &url::Url, + is_secure: bool, + replication: bool, +) -> Result> { + if replication { + Ok(Box::new( + xmtp_api_grpc::replication_client::ClientV4::create( + url.as_str().to_string(), + "test".to_string(), + is_secure, + ) + .await?, + )) + } else { + Ok(Box::new( + crate::GrpcClient::create(url.as_str().to_string(), is_secure).await?, + )) + } +} diff --git a/xmtp_debug/src/args.rs b/xmtp_debug/src/args.rs index d4ca414ce..24605bb22 100644 --- a/xmtp_debug/src/args.rs +++ b/xmtp_debug/src/args.rs @@ -193,6 +193,9 @@ pub struct BackendOpts { conflicts_with = "constant-backend" )] pub url: Option, + /// Enable the decentralization backend + #[arg(short, long)] + pub d14n: bool, } impl<'a> From<&'a BackendOpts> for u64 { @@ -202,10 +205,13 @@ impl<'a> From<&'a BackendOpts> for u64 { if let Some(ref url) = value.url { xxh3::xxh3_64(url.as_str().as_bytes()) } else { - match value.backend { - Production => 2, - Dev => 1, - Local => 0, + match (value.backend, value.d14n) { + (Production, false) => 2, + (Dev, false) => 1, + (Local, false) => 0, + (Production, true) => 5, + (Dev, true) => 4, + (Local, true) => 3, } } } @@ -219,8 +225,8 @@ impl From for u64 { impl From for url::Url { fn from(value: BackendOpts) -> Self { - let BackendOpts { backend, url } = value; - url.unwrap_or(backend.into()) + let BackendOpts { backend, url, d14n } = value; + url.unwrap_or(backend.to_url(d14n)) } } @@ -232,6 +238,20 @@ pub enum BackendKind { Local, } +impl BackendKind { + fn to_url(self, d14n: bool) -> url::Url { + use BackendKind::*; + match (self, d14n) { + (Dev, false) => (*crate::constants::XMTP_DEV).clone(), + (Production, false) => (*crate::constants::XMTP_PRODUCTION).clone(), + (Local, false) => (*crate::constants::XMTP_LOCAL).clone(), + (Dev, true) => (*crate::constants::XMTP_DEV_D14N).clone(), + (Production, true) => (*crate::constants::XMTP_PRODUCTION_D14N).clone(), + (Local, true) => (*crate::constants::XMTP_LOCAL_D14N).clone(), + } + } +} + impl From for url::Url { fn from(value: BackendKind) -> Self { use BackendKind::*; diff --git a/xmtp_debug/src/constants.rs b/xmtp_debug/src/constants.rs index fb970d518..4e8f7ccd9 100644 --- a/xmtp_debug/src/constants.rs +++ b/xmtp_debug/src/constants.rs @@ -9,5 +9,12 @@ pub static XMTP_DEV: LazyLock = LazyLock::new(|| Url::parse("https://grpc.dev.xmtp.network:443").unwrap()); pub static XMTP_LOCAL: LazyLock = LazyLock::new(|| Url::parse("http://localhost:5556").unwrap()); + +pub static XMTP_PRODUCTION_D14N: LazyLock = LazyLock::new(|| Url::parse("").unwrap()); +pub static XMTP_DEV_D14N: LazyLock = + LazyLock::new(|| Url::parse("https://grpc.dev.test.network:443").unwrap()); +pub static XMTP_LOCAL_D14N: LazyLock = + LazyLock::new(|| Url::parse("http://test:5556").unwrap()); + pub static TMPDIR: LazyLock = LazyLock::::new(|| TempDir::new().unwrap()); pub const STORAGE_PREFIX: &str = "xdbg"; diff --git a/xmtp_debug/src/main.rs b/xmtp_debug/src/main.rs index 10dbeb294..fbaf4deb7 100644 --- a/xmtp_debug/src/main.rs +++ b/xmtp_debug/src/main.rs @@ -7,8 +7,10 @@ use clap::Parser; use color_eyre::eyre::Result; use xmtp_api_grpc::grpc_api_helper::Client as GrpcClient; +use xmtp_mls::XmtpApi; -pub type DbgClient = xmtp_mls::client::Client; +// pub type DbgClient = xmtp_mls::client::Client; +type DbgClient = xmtp_mls::client::Client>; #[macro_use] extern crate tracing;