From 9b3d92f806994e75ba99a7f22812ac3bc2267815 Mon Sep 17 00:00:00 2001 From: Luca Joss <43531661+ljoss17@users.noreply.github.com> Date: Tue, 24 Dec 2024 12:10:15 +0100 Subject: [PATCH] Remove cosmos-specific implementation of client update CLI (#512) --- crates/cli/cli/src/commands/client/mod.rs | 8 +- crates/cli/cli/src/commands/client/update.rs | 96 -------------------- 2 files changed, 3 insertions(+), 101 deletions(-) delete mode 100644 crates/cli/cli/src/commands/client/update.rs diff --git a/crates/cli/cli/src/commands/client/mod.rs b/crates/cli/cli/src/commands/client/mod.rs index 4eceacd72..912e21f44 100644 --- a/crates/cli/cli/src/commands/client/mod.rs +++ b/crates/cli/cli/src/commands/client/mod.rs @@ -1,3 +1,4 @@ +use hermes_cli_components::impls::commands::client::update::UpdateClientArgs; use hermes_cli_components::traits::command::CanRunCommand; use hermes_cli_framework::command::CommandRunner; use hermes_cli_framework::output::Output; @@ -8,23 +9,20 @@ use crate::Result; pub mod create; -mod update; -pub use update::ClientUpdate; - #[derive(Debug, clap::Subcommand)] pub enum ClientCommands { /// Create a new client Create(CreateClientArgs), /// Update a client - Update(ClientUpdate), + Update(UpdateClientArgs), } impl CommandRunner for ClientCommands { async fn run(&self, app: &HermesApp) -> Result { match self { Self::Create(cmd) => app.run_command(cmd).await, - Self::Update(cmd) => cmd.run(app).await, + Self::Update(cmd) => app.run_command(cmd).await, } } } diff --git a/crates/cli/cli/src/commands/client/update.rs b/crates/cli/cli/src/commands/client/update.rs deleted file mode 100644 index 5b52b1492..000000000 --- a/crates/cli/cli/src/commands/client/update.rs +++ /dev/null @@ -1,96 +0,0 @@ -use core::marker::PhantomData; - -use hermes_cli_components::traits::build::CanLoadBuilder; -use hermes_cli_framework::command::CommandRunner; -use hermes_cli_framework::output::Output; -use hermes_cosmos_relayer::contexts::chain::CosmosChain; -use hermes_relayer_components::build::traits::builders::relay_builder::CanBuildRelay; -use hermes_relayer_components::chain::traits::queries::chain_status::CanQueryChainHeight; -use hermes_relayer_components::chain::traits::queries::client_state::CanQueryClientStateWithLatestHeight; -use hermes_relayer_components::multi::types::index::Index; -use hermes_relayer_components::relay::traits::target::SourceTarget; -use hermes_relayer_components::relay::traits::update_client_message_builder::CanSendTargetUpdateClientMessage; -use ibc::core::client::types::Height; -use ibc::core::host::types::identifiers::{ChainId, ClientId}; -use oneline_eyre::eyre::Context; -use tracing::info; - -use crate::contexts::app::HermesApp; -use crate::impls::error_wrapper::ErrorWrapper; -use crate::Result; - -#[derive(Debug, clap::Parser)] -pub struct ClientUpdate { - #[clap( - long = "host-chain", - required = true, - value_name = "HOST_CHAIN_ID", - help_heading = "REQUIRED", - help = "Identifier of the chain that hosts the client" - )] - host_chain_id: ChainId, - - #[clap( - long = "client", - required = true, - value_name = "CLIENT_ID", - help_heading = "REQUIRED", - help = "Identifier of the client to update" - )] - client_id: ClientId, - - #[clap( - long = "height", - value_name = "HEIGHT", - help = "The target height of the client update. Leave unspecified for latest height." - )] - target_height: Option, -} - -impl CommandRunner for ClientUpdate { - async fn run(&self, app: &HermesApp) -> Result { - let builder = app.load_builder().await?; - - let host_chain = builder.build_chain(&self.host_chain_id).await?; - - let client_state = host_chain - .query_client_state_with_latest_height(PhantomData::, &self.client_id) - .await?; - - let reference_chain_id = client_state.chain_id.clone(); - let reference_chain = builder.build_chain(&reference_chain_id).await?; - - let relayer = builder - .build_relay( - PhantomData::<(Index<0>, Index<1>)>, - &self.host_chain_id, - &reference_chain_id, - &self.client_id, - &self.client_id, // nothing to pass here - ) - .await?; - - let target_height = match self.target_height { - Some(height) => { - let height = Height::new(reference_chain_id.revision_number(), height) - .wrap_err("Invalid value for --target-height")?; - - info!("Updating client using specified target height: {height}"); - height - } - None => { - let height = reference_chain.query_chain_height().await?; - - info!("Updating client using specified target height: {height}"); - height - } - }; - - relayer - .send_target_update_client_messages(SourceTarget, &target_height) - .await - .wrap_error("Failed to send update client message")?; - - Ok(Output::success_msg("Client successfully updated!")) - } -}