From 8105b761edc96e00ea44aa8bdb30d0953ac86c1e Mon Sep 17 00:00:00 2001 From: Brooks Prumo Date: Thu, 21 Jul 2022 07:23:18 -0500 Subject: [PATCH] Add CLI to get stake minimum delegation (#26645) --- cli/src/cli.rs | 7 +++++++ cli/src/stake.rs | 36 +++++++++++++++++++++++++++++++++++- cli/tests/stake.rs | 15 +++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 6e360dee0..d4e580d7e 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -416,6 +416,9 @@ pub enum CliCommand { derived_address_seed: Option, derived_address_program_id: Option, }, + StakeMinimumDelegation { + use_lamports_unit: bool, + }, } #[derive(Debug, PartialEq)] @@ -706,6 +709,7 @@ pub fn parse_command( } ("stake-account", Some(matches)) => parse_show_stake_account(matches, wallet_manager), ("stake-history", Some(matches)) => parse_show_stake_history(matches), + ("stake-minimum-delegation", Some(matches)) => parse_stake_minimum_delegation(matches), // Validator Info Commands ("validator-info", Some(matches)) => match matches.subcommand() { ("publish", Some(matches)) => { @@ -1301,6 +1305,9 @@ pub fn process_command(config: &CliConfig) -> ProcessResult { seed.as_ref(), *fee_payer, ), + CliCommand::StakeMinimumDelegation { use_lamports_unit } => { + process_stake_minimum_delegation(&rpc_client, config, *use_lamports_unit) + } // Validator Info Commands diff --git a/cli/src/stake.rs b/cli/src/stake.rs index f6a76f7e9..51686d66d 100644 --- a/cli/src/stake.rs +++ b/cli/src/stake.rs @@ -21,7 +21,7 @@ use { ArgConstant, }, solana_cli_output::{ - return_signers_with_config, CliEpochReward, CliStakeHistory, CliStakeHistoryEntry, + self, return_signers_with_config, CliEpochReward, CliStakeHistory, CliStakeHistoryEntry, CliStakeState, CliStakeType, OutputFormat, ReturnSignersConfig, }, solana_client::{ @@ -656,6 +656,16 @@ impl StakeSubCommands for App<'_, '_> { .help("Display NUM recent epochs worth of stake history in text mode. 0 for all") ) ) + .subcommand( + SubCommand::with_name("stake-minimum-delegation") + .about("Get the stake minimum delegation amount") + .arg( + Arg::with_name("lamports") + .long("lamports") + .takes_value(false) + .help("Display minimum delegation in lamports instead of SOL") + ) + ) } } @@ -1195,6 +1205,16 @@ pub fn parse_show_stake_history(matches: &ArgMatches<'_>) -> Result, +) -> Result { + let use_lamports_unit = matches.is_present("lamports"); + Ok(CliCommandInfo { + command: CliCommand::StakeMinimumDelegation { use_lamports_unit }, + signers: vec![], + }) +} + #[allow(clippy::too_many_arguments)] pub fn process_create_stake_account( rpc_client: &RpcClient, @@ -2501,6 +2521,20 @@ pub fn process_delegate_stake( } } +pub fn process_stake_minimum_delegation( + rpc_client: &RpcClient, + config: &CliConfig, + use_lamports_unit: bool, +) -> ProcessResult { + let stake_minimum_delegation = + rpc_client.get_stake_minimum_delegation_with_commitment(config.commitment)?; + Ok(solana_cli_output::display::build_balance_message( + stake_minimum_delegation, + use_lamports_unit, + true, + )) +} + #[cfg(test)] mod tests { use { diff --git a/cli/tests/stake.rs b/cli/tests/stake.rs index edcebd317..2fda3af9b 100644 --- a/cli/tests/stake.rs +++ b/cli/tests/stake.rs @@ -1982,3 +1982,18 @@ fn test_stake_checked_instructions() { assert_eq!(current_lockup.epoch, lockup.epoch.unwrap()); assert_eq!(current_lockup.custodian, custodian_pubkey); } + +#[test] +fn test_stake_minimum_delegation() { + let test_validator = + TestValidator::with_no_fees(Pubkey::new_unique(), None, SocketAddrSpace::Unspecified); + let mut config = CliConfig::recent_for_tests(); + config.json_rpc_url = test_validator.rpc_url(); + + config.command = CliCommand::StakeMinimumDelegation { + use_lamports_unit: true, + }; + + let result = process_command(&config); + assert!(matches!(result, Ok(..))); +}