From 50c92e3a941821780d1050627eeb1eec865a29a2 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Wed, 22 Jul 2020 08:36:12 -0700 Subject: [PATCH] Add block-height subcommand --- cli/src/cli.rs | 3 +++ cli/src/cli_output.rs | 6 +++++- cli/src/cluster_query.rs | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index d7424235d2..65b9b16bfb 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -198,6 +198,7 @@ pub enum CliCommand { GetEpochInfo, GetGenesisHash, GetSlot, + GetBlockHeight, GetTransactionCount, LargestAccounts { filter: Option, @@ -638,6 +639,7 @@ pub fn parse_command( }), ("epoch", Some(matches)) => parse_get_epoch(matches), ("slot", Some(matches)) => parse_get_slot(matches), + ("block-height", Some(matches)) => parse_get_block_height(matches), ("largest-accounts", Some(matches)) => parse_largest_accounts(matches), ("supply", Some(matches)) => parse_supply(matches), ("total-supply", Some(matches)) => parse_total_supply(matches), @@ -1829,6 +1831,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult { CliCommand::GetEpochInfo => process_get_epoch_info(&rpc_client, config), CliCommand::GetGenesisHash => process_get_genesis_hash(&rpc_client), CliCommand::GetSlot => process_get_slot(&rpc_client, config), + CliCommand::GetBlockHeight => process_get_block_height(&rpc_client, config), CliCommand::LargestAccounts { filter } => { process_largest_accounts(&rpc_client, config, filter.clone()) } diff --git a/cli/src/cli_output.rs b/cli/src/cli_output.rs index 57da4d877d..a2e0338afd 100644 --- a/cli/src/cli_output.rs +++ b/cli/src/cli_output.rs @@ -206,7 +206,11 @@ impl From for CliEpochInfo { impl fmt::Display for CliEpochInfo { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { writeln!(f)?; - writeln_name_value(f, "Block height:", &self.epoch_info.block_height.to_string())?; + writeln_name_value( + f, + "Block height:", + &self.epoch_info.block_height.to_string(), + )?; writeln_name_value(f, "Slot:", &self.epoch_info.absolute_slot.to_string())?; writeln_name_value(f, "Epoch:", &self.epoch_info.epoch.to_string())?; let start_slot = self.epoch_info.absolute_slot - self.epoch_info.slot_index; diff --git a/cli/src/cluster_query.rs b/cli/src/cluster_query.rs index f90e92bcf2..4741f01ad9 100644 --- a/cli/src/cluster_query.rs +++ b/cli/src/cluster_query.rs @@ -115,6 +115,10 @@ impl ClusterQuerySubCommands for App<'_, '_> { .alias("get-slot") .arg(commitment_arg()), ) + .subcommand( + SubCommand::with_name("block-height").about("Get current block height") + .arg(commitment_arg()), + ) .subcommand( SubCommand::with_name("epoch").about("Get current epoch") .arg(commitment_arg()), @@ -362,6 +366,13 @@ pub fn parse_get_slot(_matches: &ArgMatches<'_>) -> Result) -> Result { + Ok(CliCommandInfo { + command: CliCommand::GetBlockHeight, + signers: vec![], + }) +} + pub fn parse_largest_accounts(matches: &ArgMatches<'_>) -> Result { let filter = if matches.is_present("circulating") { Some(RpcLargestAccountsFilter::Circulating) @@ -651,6 +662,13 @@ pub fn process_get_slot(rpc_client: &RpcClient, config: &CliConfig) -> ProcessRe Ok(slot.to_string()) } +pub fn process_get_block_height(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult { + let epoch_info: CliEpochInfo = rpc_client + .get_epoch_info_with_commitment(config.commitment)? + .into(); + Ok(epoch_info.epoch_info.block_height.to_string()) +} + pub fn parse_show_block_production(matches: &ArgMatches<'_>) -> Result { let epoch = value_t!(matches, "epoch", Epoch).ok(); let slot_limit = value_t!(matches, "slot_limit", u64).ok();