Add block-height subcommand

This commit is contained in:
Michael Vines
2020-07-22 08:36:12 -07:00
parent 2adfe3f199
commit 50c92e3a94
3 changed files with 26 additions and 1 deletions

View File

@ -198,6 +198,7 @@ pub enum CliCommand {
GetEpochInfo, GetEpochInfo,
GetGenesisHash, GetGenesisHash,
GetSlot, GetSlot,
GetBlockHeight,
GetTransactionCount, GetTransactionCount,
LargestAccounts { LargestAccounts {
filter: Option<RpcLargestAccountsFilter>, filter: Option<RpcLargestAccountsFilter>,
@ -638,6 +639,7 @@ pub fn parse_command(
}), }),
("epoch", Some(matches)) => parse_get_epoch(matches), ("epoch", Some(matches)) => parse_get_epoch(matches),
("slot", Some(matches)) => parse_get_slot(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), ("largest-accounts", Some(matches)) => parse_largest_accounts(matches),
("supply", Some(matches)) => parse_supply(matches), ("supply", Some(matches)) => parse_supply(matches),
("total-supply", Some(matches)) => parse_total_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::GetEpochInfo => process_get_epoch_info(&rpc_client, config),
CliCommand::GetGenesisHash => process_get_genesis_hash(&rpc_client), CliCommand::GetGenesisHash => process_get_genesis_hash(&rpc_client),
CliCommand::GetSlot => process_get_slot(&rpc_client, config), CliCommand::GetSlot => process_get_slot(&rpc_client, config),
CliCommand::GetBlockHeight => process_get_block_height(&rpc_client, config),
CliCommand::LargestAccounts { filter } => { CliCommand::LargestAccounts { filter } => {
process_largest_accounts(&rpc_client, config, filter.clone()) process_largest_accounts(&rpc_client, config, filter.clone())
} }

View File

@ -206,7 +206,11 @@ impl From<EpochInfo> for CliEpochInfo {
impl fmt::Display for CliEpochInfo { impl fmt::Display for CliEpochInfo {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln!(f)?; 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, "Slot:", &self.epoch_info.absolute_slot.to_string())?;
writeln_name_value(f, "Epoch:", &self.epoch_info.epoch.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; let start_slot = self.epoch_info.absolute_slot - self.epoch_info.slot_index;

View File

@ -115,6 +115,10 @@ impl ClusterQuerySubCommands for App<'_, '_> {
.alias("get-slot") .alias("get-slot")
.arg(commitment_arg()), .arg(commitment_arg()),
) )
.subcommand(
SubCommand::with_name("block-height").about("Get current block height")
.arg(commitment_arg()),
)
.subcommand( .subcommand(
SubCommand::with_name("epoch").about("Get current epoch") SubCommand::with_name("epoch").about("Get current epoch")
.arg(commitment_arg()), .arg(commitment_arg()),
@ -362,6 +366,13 @@ pub fn parse_get_slot(_matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliEr
}) })
} }
pub fn parse_get_block_height(_matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
Ok(CliCommandInfo {
command: CliCommand::GetBlockHeight,
signers: vec![],
})
}
pub fn parse_largest_accounts(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> { pub fn parse_largest_accounts(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
let filter = if matches.is_present("circulating") { let filter = if matches.is_present("circulating") {
Some(RpcLargestAccountsFilter::Circulating) Some(RpcLargestAccountsFilter::Circulating)
@ -651,6 +662,13 @@ pub fn process_get_slot(rpc_client: &RpcClient, config: &CliConfig) -> ProcessRe
Ok(slot.to_string()) 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<CliCommandInfo, CliError> { pub fn parse_show_block_production(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
let epoch = value_t!(matches, "epoch", Epoch).ok(); let epoch = value_t!(matches, "epoch", Epoch).ok();
let slot_limit = value_t!(matches, "slot_limit", u64).ok(); let slot_limit = value_t!(matches, "slot_limit", u64).ok();