Skip to content

Commit

Permalink
Add CLI to get stake minimum delegation (solana-labs#26645)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored Jul 21, 2022
1 parent cbb74a1 commit 8105b76
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
7 changes: 7 additions & 0 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ pub enum CliCommand {
derived_address_seed: Option<String>,
derived_address_program_id: Option<Pubkey>,
},
StakeMinimumDelegation {
use_lamports_unit: bool,
},
}

#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -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)) => {
Expand Down Expand Up @@ -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

Expand Down
36 changes: 35 additions & 1 deletion cli/src/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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")
)
)
}
}

Expand Down Expand Up @@ -1195,6 +1205,16 @@ pub fn parse_show_stake_history(matches: &ArgMatches<'_>) -> Result<CliCommandIn
})
}

pub fn parse_stake_minimum_delegation(
matches: &ArgMatches<'_>,
) -> Result<CliCommandInfo, CliError> {
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,
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions cli/tests/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..)));
}

0 comments on commit 8105b76

Please sign in to comment.