Skip to content

Commit

Permalink
Remove ChainHandle dependency from query connections CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
ljoss17 committed Nov 29, 2024
1 parent 08374ff commit 1202bfd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
4 changes: 2 additions & 2 deletions crates/cli/cli/src/commands/query/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use hermes_cosmos_relayer::contexts::chain::CosmosChain;
use hermes_relayer_components::chain::traits::queries::chain_status::CanQueryChainHeight;

use ibc::core::channel::types::proto::v1::query_client::QueryClient;
use ibc_relayer::chain::requests::QueryChannelsRequest;
use ibc::core::channel::types::proto::v1::QueryChannelsRequest;
use ibc_relayer_types::core::ics04_channel::channel::{IdentifiedChannelEnd, State};
use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ChannelId, ClientId, PortId};

Expand Down Expand Up @@ -57,7 +57,7 @@ impl CommandRunner<HermesApp> for QueryChannels {
.await
.unwrap();

let request = tonic::Request::new(QueryChannelsRequest { pagination: None }.into());
let request = tonic::Request::new(QueryChannelsRequest { pagination: None });

let response = client.channels(request).await.unwrap().into_inner();

Expand Down
32 changes: 18 additions & 14 deletions crates/cli/cli/src/commands/query/connections.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
use core::marker::PhantomData;
use tracing::{info, warn};

use hermes_cli_components::traits::build::CanLoadBuilder;
use hermes_cli_framework::command::CommandRunner;
use hermes_cli_framework::output::{json, Output};
use hermes_cosmos_chain_components::traits::chain_handle::HasBlockingChainHandle;
use hermes_cosmos_chain_components::traits::grpc_address::HasGrpcAddress;
use hermes_cosmos_relayer::contexts::chain::CosmosChain;
use hermes_relayer_components::chain::traits::queries::client_state::CanQueryClientStateWithLatestHeight;
use ibc_relayer::chain::handle::ChainHandle;
use ibc_relayer::chain::requests::{PageRequest, QueryConnectionsRequest};

use ibc::core::connection::types::proto::v1::query_client::QueryClient;
use ibc::core::connection::types::proto::v1::QueryConnectionsRequest;
use ibc_relayer_types::core::ics02_client::client_state::ClientState;
use ibc_relayer_types::core::ics03_connection::connection::IdentifiedConnectionEnd;
use ibc_relayer_types::core::ics24_host::identifier::ChainId;
use tracing::{info, warn};

use crate::contexts::app::HermesApp;
use crate::impls::error_wrapper::ErrorWrapper;
use crate::Result;

#[derive(Debug, clap::Parser)]
Expand Down Expand Up @@ -50,16 +51,19 @@ impl CommandRunner<HermesApp> for QueryConnections {
let counterparty_chain_id = self.counterparty_chain_id.clone();
let verbose = self.verbose;

let all_connections = chain
.with_blocking_chain_handle(move |handle| {
handle
.query_connections(QueryConnectionsRequest {
pagination: Some(PageRequest::all()),
})
.map_err(From::from)
})
let mut client = QueryClient::connect(chain.grpc_address().clone())
.await
.wrap_error("Failed to query connections for host chain")?;
.unwrap();

let request = tonic::Request::new(QueryConnectionsRequest { pagination: None });

let response = client.connections(request).await.unwrap().into_inner();

let all_connections = response
.connections
.into_iter()
.filter_map(|co| IdentifiedConnectionEnd::try_from(co.clone()).ok())
.collect::<Vec<IdentifiedConnectionEnd>>();

info!(
"Found {} connections on chain `{chain_id}`",
Expand Down

0 comments on commit 1202bfd

Please sign in to comment.