Add CLI to get stake minimum delegation (#26645)

This commit is contained in:
Brooks Prumo 2022-07-21 07:23:18 -05:00 committed by GitHub
parent cbb74a190f
commit 8105b761ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 1 deletions

View File

@ -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)]
@ -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

View File

@ -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<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,
@ -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 {

View File

@ -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(..)));
}