Skip to content

Commit

Permalink
Add query chain-status CLI (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
ljoss17 authored Dec 23, 2024
1 parent 315bed3 commit 36bdeb7
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 32 deletions.
60 changes: 30 additions & 30 deletions relayer/Cargo.lock

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

15 changes: 14 additions & 1 deletion relayer/crates/starknet-chain-components/src/types/status.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
use core::fmt::{Display, Formatter, Result};

use hermes_cosmos_chain_components::types::status::Time;
use serde::Serialize;
use starknet::core::types::Felt;

#[derive(Debug)]
#[derive(Debug, Serialize)]
pub struct StarknetChainStatus {
pub height: u64,
pub block_hash: Felt,
pub time: Time,
}

impl Display for StarknetChainStatus {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
write!(
f,
"height: {}, block_hash: {}, time: {}",
self.height, self.block_hash, self.time
)
}
}
7 changes: 6 additions & 1 deletion relayer/crates/starknet-cli/src/commands/query/subcommand.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use hermes_cli_components::impls::commands::queries::chain_status::QueryChainStatusArgs;
use hermes_cli_components::impls::commands::queries::client_state::QueryClientStateArgs;
use hermes_cli_components::impls::commands::queries::consensus_state::QueryConsensusStateArgs;
use hermes_cli_components::traits::command::{CanRunCommand, CommandRunner};
Expand All @@ -6,13 +7,16 @@ use hermes_cli_components::traits::command::{CanRunCommand, CommandRunner};
pub enum QuerySubCommand {
ClientState(QueryClientStateArgs),
ConsensusState(QueryConsensusStateArgs),
ChainStatus(QueryChainStatusArgs),
}

pub struct RunQuerySubCommand;

impl<App> CommandRunner<App, QuerySubCommand> for RunQuerySubCommand
where
App: CanRunCommand<QueryClientStateArgs> + CanRunCommand<QueryConsensusStateArgs>,
App: CanRunCommand<QueryClientStateArgs>
+ CanRunCommand<QueryConsensusStateArgs>
+ CanRunCommand<QueryChainStatusArgs>,
{
async fn run_command(
app: &App,
Expand All @@ -21,6 +25,7 @@ where
match subcommand {
QuerySubCommand::ClientState(args) => app.run_command(args).await,
QuerySubCommand::ConsensusState(args) => app.run_command(args).await,
QuerySubCommand::ChainStatus(args) => app.run_command(args).await,
}
}
}
6 changes: 6 additions & 0 deletions relayer/crates/starknet-cli/src/contexts/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ use hermes_cli_components::impls::commands::bootstrap::chain::RunBootstrapChainC
use hermes_cli_components::impls::commands::client::update::{
RunUpdateClientCommand, UpdateClientArgs,
};
use hermes_cli_components::impls::commands::queries::chain_status::{
QueryChainStatusArgs, RunQueryChainStatusCommand,
};
use hermes_cli_components::impls::commands::queries::client_state::{
QueryClientStateArgs, RunQueryClientStateCommand,
};
Expand Down Expand Up @@ -140,6 +143,8 @@ delegate_components! {
(QueryConsensusStateArgs, symbol!("query_height")): ParseFromOptionalString<u64>,
(QueryConsensusStateArgs, symbol!("consensus_height")): ParseFromOptionalString<Height>,

(QueryChainStatusArgs, symbol!("chain_id")): ParseFromString<Felt>,

(UpdateClientArgs, symbol!("host_chain_id")): ParseFromString<Felt>,
(UpdateClientArgs, symbol!("client_id")): ParseFromString<ClientId>,
(UpdateClientArgs, symbol!("counterparty_client_id")): ParseFromString<CosmosClientId>,
Expand All @@ -155,6 +160,7 @@ delegate_components! {
QuerySubCommand: RunQuerySubCommand,
QueryClientStateArgs: RunQueryClientStateCommand,
QueryConsensusStateArgs: RunQueryConsensusStateCommand,
QueryChainStatusArgs: RunQueryChainStatusCommand,

ClientSubCommand: RunClientSubCommand,
UpdateClientArgs: RunUpdateClientCommand,
Expand Down

0 comments on commit 36bdeb7

Please sign in to comment.