Add CLI to get stake minimum delegation (#26645)
This commit is contained in:
parent
cbb74a190f
commit
8105b761ed
|
@ -416,6 +416,9 @@ pub enum CliCommand {
|
||||||
derived_address_seed: Option<String>,
|
derived_address_seed: Option<String>,
|
||||||
derived_address_program_id: Option<Pubkey>,
|
derived_address_program_id: Option<Pubkey>,
|
||||||
},
|
},
|
||||||
|
StakeMinimumDelegation {
|
||||||
|
use_lamports_unit: bool,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
|
@ -706,6 +709,7 @@ pub fn parse_command(
|
||||||
}
|
}
|
||||||
("stake-account", Some(matches)) => parse_show_stake_account(matches, wallet_manager),
|
("stake-account", Some(matches)) => parse_show_stake_account(matches, wallet_manager),
|
||||||
("stake-history", Some(matches)) => parse_show_stake_history(matches),
|
("stake-history", Some(matches)) => parse_show_stake_history(matches),
|
||||||
|
("stake-minimum-delegation", Some(matches)) => parse_stake_minimum_delegation(matches),
|
||||||
// Validator Info Commands
|
// Validator Info Commands
|
||||||
("validator-info", Some(matches)) => match matches.subcommand() {
|
("validator-info", Some(matches)) => match matches.subcommand() {
|
||||||
("publish", Some(matches)) => {
|
("publish", Some(matches)) => {
|
||||||
|
@ -1301,6 +1305,9 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||||
seed.as_ref(),
|
seed.as_ref(),
|
||||||
*fee_payer,
|
*fee_payer,
|
||||||
),
|
),
|
||||||
|
CliCommand::StakeMinimumDelegation { use_lamports_unit } => {
|
||||||
|
process_stake_minimum_delegation(&rpc_client, config, *use_lamports_unit)
|
||||||
|
}
|
||||||
|
|
||||||
// Validator Info Commands
|
// Validator Info Commands
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ use {
|
||||||
ArgConstant,
|
ArgConstant,
|
||||||
},
|
},
|
||||||
solana_cli_output::{
|
solana_cli_output::{
|
||||||
return_signers_with_config, CliEpochReward, CliStakeHistory, CliStakeHistoryEntry,
|
self, return_signers_with_config, CliEpochReward, CliStakeHistory, CliStakeHistoryEntry,
|
||||||
CliStakeState, CliStakeType, OutputFormat, ReturnSignersConfig,
|
CliStakeState, CliStakeType, OutputFormat, ReturnSignersConfig,
|
||||||
},
|
},
|
||||||
solana_client::{
|
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")
|
.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)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn process_create_stake_account(
|
pub fn process_create_stake_account(
|
||||||
rpc_client: &RpcClient,
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use {
|
use {
|
||||||
|
|
|
@ -1982,3 +1982,18 @@ fn test_stake_checked_instructions() {
|
||||||
assert_eq!(current_lockup.epoch, lockup.epoch.unwrap());
|
assert_eq!(current_lockup.epoch, lockup.epoch.unwrap());
|
||||||
assert_eq!(current_lockup.custodian, custodian_pubkey);
|
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(..)));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue