diff --git a/crates/cli/cli/src/commands/query/channel/end.rs b/crates/cli/cli/src/commands/query/channel/end.rs deleted file mode 100644 index c6fb42e33..000000000 --- a/crates/cli/cli/src/commands/query/channel/end.rs +++ /dev/null @@ -1,96 +0,0 @@ -use hermes_chain_components::traits::queries::chain_status::CanQueryChainHeight; -use hermes_cli_components::traits::build::CanLoadBuilder; -use hermes_cli_framework::command::CommandRunner; -use hermes_cli_framework::output::Output; -use hermes_cosmos_chain_components::traits::abci_query::CanQueryAbci; -use ibc::core::channel::types::channel::{ChannelEnd, State}; -use ibc::core::client::types::Height; -use ibc::core::host::types::identifiers::{ChainId, ChannelId, PortId}; -use ibc::cosmos_host::IBC_QUERY_PATH; -use ibc::primitives::proto::Protobuf; -use oneline_eyre::eyre::eyre; - -use crate::contexts::app::HermesApp; -use crate::Result; - -#[derive(Debug, clap::Parser)] -pub struct QueryChannelEnd { - #[clap( - long = "chain", - required = true, - value_name = "CHAIN_ID", - help_heading = "REQUIRED", - help = "Identifier of the chain to query" - )] - chain_id: ChainId, - - #[clap( - long = "port", - required = true, - value_name = "PORT_ID", - help_heading = "REQUIRED", - help = "Identifier of the port to query" - )] - port_id: PortId, - - #[clap( - long = "channel", - required = true, - value_name = "CHANNEL_ID", - help_heading = "REQUIRED", - help = "Identifier of the channel to query" - )] - channel_id: ChannelId, - - #[clap( - long = "height", - value_name = "HEIGHT", - help = "Height of the state to query. Leave unspecified for the latest height." - )] - height: Option, -} - -impl CommandRunner for QueryChannelEnd { - async fn run(&self, app: &HermesApp) -> Result { - let builder = app.load_builder().await?; - - let chain = builder.build_chain(&self.chain_id).await?; - let channel_id = self.channel_id.clone(); - let port_id = self.port_id.clone(); - let height = self.height; - - let query_height = if let Some(height) = height { - Height::new(chain.chain_id.revision_number(), height)? - } else { - chain.query_chain_height().await? - }; - - // channel end query path - let channel_end_path = format!("channelEnds/ports/{port_id}/channels/{channel_id}"); - - let channel_end_bytes = chain - .query_abci(IBC_QUERY_PATH, channel_end_path.as_bytes(), &query_height) - .await?; - - let channel_end = ChannelEnd::decode_vec(&channel_end_bytes); - - match channel_end { - Ok(channel_end) => { - if channel_end - .verify_state_matches(&State::Uninitialized) - .is_ok() - { - Err(eyre!( - "port '{}' & channel '{}' do not exist", - self.port_id, - self.channel_id, - ) - .into()) - } else { - Ok(Output::success(channel_end)) - } - } - Err(e) => Err(e.into()), - } - } -} diff --git a/crates/cli/cli/src/commands/query/channel/mod.rs b/crates/cli/cli/src/commands/query/channel/mod.rs index 9741e8b74..b97f0a2b0 100644 --- a/crates/cli/cli/src/commands/query/channel/mod.rs +++ b/crates/cli/cli/src/commands/query/channel/mod.rs @@ -1,10 +1,10 @@ mod client; -mod end; mod ends; pub use client::QueryChannelClient; -pub use end::QueryChannelEnd; pub use ends::QueryChannelEnds; +use hermes_cli_components::impls::commands::queries::channel_end::QueryChannelEndArgs; +use hermes_cli_components::traits::command::CanRunCommand; use hermes_cli_framework::command::CommandRunner; use hermes_cli_framework::output::Output; @@ -13,7 +13,7 @@ use crate::Result; #[derive(Debug, clap::Subcommand)] pub enum QueryChannel { - End(QueryChannelEnd), + End(QueryChannelEndArgs), Ends(QueryChannelEnds), Client(QueryChannelClient), } @@ -21,7 +21,7 @@ pub enum QueryChannel { impl QueryChannel { pub async fn run(&self, app: &HermesApp) -> Result { match self { - Self::End(cmd) => cmd.run(app).await, + Self::End(cmd) => app.run_command(cmd).await, Self::Ends(cmd) => cmd.run(app).await, Self::Client(cmd) => cmd.run(app).await, }