diff --git a/cli/src/cli.rs b/cli/src/cli.rs index ec3d6cec8f..13dfa441b0 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, }, @@ -586,6 +589,7 @@ pub fn parse_command( command: CliCommand::GetGenesisHash, signers: vec![], }), + ("epoch", Some(matches)) => parse_get_epoch(matches), ("slot", Some(matches)) => parse_get_slot(matches), ("total-supply", Some(matches)) => parse_total_supply(matches), ("transaction-count", Some(matches)) => parse_get_transaction_count(matches), @@ -1602,6 +1606,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 f6739be68c..a24e78a80d 100644 --- a/cli/src/cluster_query.rs +++ b/cli/src/cluster_query.rs @@ -119,6 +119,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("total-supply").about("Get total number of SOL") .arg( @@ -338,6 +349,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_total_supply(matches: &ArgMatches<'_>) -> Result { let commitment_config = if matches.is_present("confirmed") { CommitmentConfig::default() @@ -617,6 +640,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(); @@ -1330,6 +1361,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_total_supply = test_commands .clone() .get_matches_from(vec!["test", "total-supply"]);