Skip to content

Commit

Permalink
Teach testnet to use separate endpoints for payer and grpc APIs (#1346)
Browse files Browse the repository at this point in the history
We have split the payer service from the API service.
  • Loading branch information
mkysel authored Nov 26, 2024
1 parent 964a227 commit 41204ab
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
22 changes: 16 additions & 6 deletions examples/cli/cli-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,22 @@ async fn main() -> color_eyre::eyre::Result<()> {
info!("Starting CLI Client....");

let grpc: Box<dyn XmtpApi> = match (cli.testnet, &cli.env) {
(true, Env::Local) => {
Box::new(ClientV4::create("http://localhost:5050".into(), false).await?)
}
(true, Env::Dev) => {
Box::new(ClientV4::create("https://grpc.testnet.xmtp.network:443".into(), true).await?)
}
(true, Env::Local) => Box::new(
ClientV4::create(
"http://localhost:5050".into(),
"http://localhost:5050".into(),
false,
)
.await?,
),
(true, Env::Dev) => Box::new(
ClientV4::create(
"https://grpc.testnet.xmtp.network:443".into(),
"https://payer.testnet.xmtp.network:443".into(),
true,
)
.await?,
),
(false, Env::Local) => {
Box::new(ClientV3::create("http://localhost:5556".into(), false).await?)
}
Expand Down
26 changes: 19 additions & 7 deletions xmtp_api_grpc/src/replication_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,37 @@ pub struct ClientV4 {
}

impl ClientV4 {
pub async fn create(host: String, is_secure: bool) -> Result<Self, Error> {
let host = host.to_string();
pub async fn create(
grpc_url: String,
payer_url: String,
is_secure: bool,
) -> Result<Self, Error> {
let app_version = MetadataValue::try_from(&String::from("0.0.0"))
.map_err(|e| Error::new(ErrorKind::MetadataError).with(e))?;
let libxmtp_version = MetadataValue::try_from(&String::from("0.0.0"))
.map_err(|e| Error::new(ErrorKind::MetadataError).with(e))?;

let channel = match is_secure {
true => create_tls_channel(host).await?,
false => Channel::from_shared(host)
let grpc_channel = match is_secure {
true => create_tls_channel(grpc_url).await?,
false => Channel::from_shared(grpc_url)
.map_err(|e| Error::new(ErrorKind::SetupCreateChannelError).with(e))?
.connect()
.await
.map_err(|e| Error::new(ErrorKind::SetupConnectionError).with(e))?,
};

let payer_channel = match is_secure {
true => create_tls_channel(payer_url).await?,
false => Channel::from_shared(payer_url)
.map_err(|e| Error::new(ErrorKind::SetupCreateChannelError).with(e))?
.connect()
.await
.map_err(|e| Error::new(ErrorKind::SetupConnectionError).with(e))?,
};

// GroupMessageInputTODO(mkysel) for now we assume both payer and replication are on the same host
let client = ReplicationApiClient::new(channel.clone());
let payer_client = PayerApiClient::new(channel.clone());
let client = ReplicationApiClient::new(grpc_channel.clone());
let payer_client = PayerApiClient::new(payer_channel.clone());

Ok(Self {
client,
Expand Down

0 comments on commit 41204ab

Please sign in to comment.