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

Teach example/CLI how to talk to V4/Replication Node #1214

Merged
merged 28 commits into from
Nov 20, 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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bindings_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum GenericError {
#[error("Storage error: {0}")]
Storage(#[from] xmtp_mls::storage::StorageError),
#[error("API error: {0}")]
ApiError(#[from] xmtp_proto::api_client::Error),
ApiError(#[from] xmtp_proto::Error),
#[error("Group error: {0}")]
GroupError(#[from] xmtp_mls::groups::GroupError),
#[error("Signature: {0}")]
Expand Down
3 changes: 2 additions & 1 deletion bindings_ffi/src/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,8 @@ mod tests {
use tokio::sync::Notify;

use futures::stream;
use xmtp_proto::api_client::{Envelope, Error as ApiError};
use xmtp_proto::api_client::Envelope;
use xmtp_proto::Error as ApiError;

use crate::{
v2::{
Expand Down
53 changes: 29 additions & 24 deletions examples/cli/cli-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use xmtp_cryptography::{
use xmtp_id::associations::unverified::{UnverifiedRecoverableEcdsaSignature, UnverifiedSignature};
use xmtp_id::associations::{generate_inbox_id, AssociationError, AssociationState, MemberKind};
use xmtp_mls::groups::device_sync::DeviceSyncContent;
use xmtp_mls::groups::scoped_client::ScopedGroupClient;
use xmtp_mls::storage::group::GroupQueryArgs;
use xmtp_mls::storage::group_message::{GroupMessageKind, MsgQueryArgs};
use xmtp_mls::XmtpApi;
Expand Down Expand Up @@ -141,6 +142,10 @@ enum Commands {
/// Information about the account that owns the DB
Info {},
Clear {},
GetInboxId {
#[arg(value_name = "Account Address")]
account_address: String,
},
#[command(subcommand)]
Debug(DebugCommands),
}
Expand Down Expand Up @@ -196,7 +201,9 @@ async fn main() -> color_eyre::eyre::Result<()> {
color_eyre::install()?;
let cli = Cli::parse();
let crate_name = env!("CARGO_PKG_NAME");
let filter = EnvFilter::builder().parse(format!("{crate_name}=INFO,xmtp_mls=INFO"))?;
let filter = EnvFilter::builder().parse(format!(
"{crate_name}=INFO,xmtp_mls=INFO,xmtp_api_grpc=INFO"
))?;
if cli.json {
let fmt = tracing_subscriber::fmt::layer()
.json()
Expand Down Expand Up @@ -225,30 +232,20 @@ 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
.unwrap(),
),
(true, Env::Dev) => Box::new(
ClientV4::create("https://grpc.testnet.xmtp.network:443".into(), true)
.await
.unwrap(),
),
(false, Env::Local) => Box::new(
ClientV3::create("http://localhost:5556".into(), false)
.await
.unwrap(),
),
(false, Env::Dev) => Box::new(
ClientV3::create("https://grpc.dev.xmtp.network:443".into(), true)
.await
.unwrap(),
),
(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?)
}
(false, Env::Local) => {
Box::new(ClientV3::create("http://localhost:5556".into(), false).await?)
}
(false, Env::Dev) => {
Box::new(ClientV3::create("https://grpc.dev.xmtp.network:443".into(), true).await?)
}
(false, Env::Production) => Box::new(
ClientV3::create("https://grpc.production.xmtp.network:443".into(), true)
.await
.unwrap(),
ClientV3::create("https://grpc.production.xmtp.network:443".into(), true).await?,
),
(true, Env::Production) => todo!("not supported"),
};
Expand Down Expand Up @@ -478,6 +475,14 @@ async fn main() -> color_eyre::eyre::Result<()> {
Commands::Debug(debug_commands) => {
debug::handle_debug(&client, debug_commands).await.unwrap();
}
Commands::GetInboxId { account_address } => {
let mapping = client
.api()
.get_inbox_ids(vec![account_address.clone()])
.await?;
let inbox_id = mapping.get(account_address).unwrap();
info!("Inbox_id {inbox_id}");
}
}

Ok(())
Expand Down
7 changes: 3 additions & 4 deletions xmtp_api_grpc/src/grpc_api_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ use tonic::{metadata::MetadataValue, transport::Channel, Request, Streaming};
use xmtp_proto::api_client::{ClientWithMetadata, XmtpMlsStreams};
use xmtp_proto::xmtp::mls::api::v1::{GroupMessage, WelcomeMessage};
use xmtp_proto::{
api_client::{
Error, ErrorKind, MutableApiSubscription, XmtpApiClient, XmtpApiSubscription, XmtpMlsClient,
},
api_client::{MutableApiSubscription, XmtpApiClient, XmtpApiSubscription, XmtpMlsClient},
xmtp::identity::api::v1::identity_api_client::IdentityApiClient as ProtoIdentityApiClient,
xmtp::message_api::v1::{
message_api_client::MessageApiClient, BatchQueryRequest, BatchQueryResponse, Envelope,
Expand All @@ -27,9 +25,10 @@ use xmtp_proto::{
SendWelcomeMessagesRequest, SubscribeGroupMessagesRequest, SubscribeWelcomeMessagesRequest,
UploadKeyPackageRequest,
},
Error, ErrorKind,
};

async fn create_tls_channel(address: String) -> Result<Channel, Error> {
pub async fn create_tls_channel(address: String) -> Result<Channel, Error> {
let channel = Channel::from_shared(address)
.map_err(|e| Error::new(ErrorKind::SetupCreateChannelError).with(e))?
// Purpose: This setting controls the size of the initial connection-level flow control window for HTTP/2, which is the underlying protocol for gRPC.
Expand Down
3 changes: 2 additions & 1 deletion xmtp_api_grpc/src/identity.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use crate::Client;
use xmtp_proto::{
api_client::{Error, ErrorKind, XmtpIdentityClient},
api_client::XmtpIdentityClient,
xmtp::identity::api::v1::{
GetIdentityUpdatesRequest as GetIdentityUpdatesV2Request,
GetIdentityUpdatesResponse as GetIdentityUpdatesV2Response, GetInboxIdsRequest,
GetInboxIdsResponse, PublishIdentityUpdateRequest, PublishIdentityUpdateResponse,
VerifySmartContractWalletSignaturesRequest, VerifySmartContractWalletSignaturesResponse,
},
Error, ErrorKind,
};

#[async_trait::async_trait]
Expand Down
Loading