From 90e993fd9a0e7de75222ea18aae13e73b73a06ff Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 1 Apr 2020 22:29:18 -0700 Subject: [PATCH] Add epoch subcommand (#9249) (#9254) automerge --- cli/src/cli.rs | 7 +++++++ cli/src/cluster_query.rs | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 6805b778f5..a3a9e96a41 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -188,6 +188,9 @@ pub enum CliCommand { commitment_config: CommitmentConfig, }, GetGenesisHash, + GetEpoch { + commitment_config: CommitmentConfig, + }, GetSlot { commitment_config: CommitmentConfig, }, @@ -583,6 +586,7 @@ pub fn parse_command( command: CliCommand::GetGenesisHash, signers: vec![], }), + ("epoch", Some(matches)) => parse_get_epoch(matches), ("slot", Some(matches)) => parse_get_slot(matches), ("transaction-count", Some(matches)) => parse_get_transaction_count(matches), ("leader-schedule", Some(_matches)) => Ok(CliCommandInfo { @@ -1598,6 +1602,9 @@ pub fn process_command(config: &CliConfig) -> ProcessResult { CliCommand::GetEpochInfo { commitment_config } => { process_get_epoch_info(&rpc_client, *commitment_config) } + CliCommand::GetEpoch { commitment_config } => { + process_get_epoch(&rpc_client, *commitment_config) + } CliCommand::GetSlot { commitment_config } => { process_get_slot(&rpc_client, *commitment_config) } diff --git a/cli/src/cluster_query.rs b/cli/src/cluster_query.rs index b04cb35743..24f29c2929 100644 --- a/cli/src/cluster_query.rs +++ b/cli/src/cluster_query.rs @@ -117,6 +117,17 @@ impl ClusterQuerySubCommands for App<'_, '_> { ), ), ) + .subcommand( + SubCommand::with_name("epoch").about("Get current epoch") + .arg( + Arg::with_name("confirmed") + .long("confirmed") + .takes_value(false) + .help( + "Return epoch at maximum-lockout commitment level", + ), + ), + ) .subcommand( SubCommand::with_name("transaction-count").about("Get current transaction count") .alias("get-transaction-count") @@ -325,6 +336,18 @@ pub fn parse_get_slot(matches: &ArgMatches<'_>) -> Result) -> Result { + let commitment_config = if matches.is_present("confirmed") { + CommitmentConfig::default() + } else { + CommitmentConfig::recent() + }; + Ok(CliCommandInfo { + command: CliCommand::GetEpoch { commitment_config }, + signers: vec![], + }) +} + pub fn parse_get_transaction_count(matches: &ArgMatches<'_>) -> Result { let commitment_config = if matches.is_present("confirmed") { CommitmentConfig::default() @@ -575,6 +598,14 @@ pub fn process_get_slot( Ok(slot.to_string()) } +pub fn process_get_epoch( + rpc_client: &RpcClient, + commitment_config: CommitmentConfig, +) -> ProcessResult { + let epoch_info = rpc_client.get_epoch_info_with_commitment(commitment_config.clone())?; + Ok(epoch_info.epoch.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(); @@ -1280,6 +1311,19 @@ mod tests { } ); + let test_get_epoch = test_commands + .clone() + .get_matches_from(vec!["test", "epoch"]); + assert_eq!( + parse_command(&test_get_epoch, &default_keypair_file, None).unwrap(), + CliCommandInfo { + command: CliCommand::GetEpoch { + commitment_config: CommitmentConfig::recent(), + }, + signers: vec![], + } + ); + let test_transaction_count = test_commands .clone() .get_matches_from(vec!["test", "transaction-count"]);