CLI: Limit `stake-history` output by default
This commit is contained in:
parent
97f6b090b9
commit
f91de6a84d
|
@ -257,6 +257,7 @@ pub enum CliCommand {
|
||||||
},
|
},
|
||||||
ShowStakeHistory {
|
ShowStakeHistory {
|
||||||
use_lamports_unit: bool,
|
use_lamports_unit: bool,
|
||||||
|
limit_results: usize,
|
||||||
},
|
},
|
||||||
ShowStakeAccount {
|
ShowStakeAccount {
|
||||||
pubkey: Pubkey,
|
pubkey: Pubkey,
|
||||||
|
@ -1661,9 +1662,10 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||||
*use_lamports_unit,
|
*use_lamports_unit,
|
||||||
*with_rewards,
|
*with_rewards,
|
||||||
),
|
),
|
||||||
CliCommand::ShowStakeHistory { use_lamports_unit } => {
|
CliCommand::ShowStakeHistory {
|
||||||
process_show_stake_history(&rpc_client, config, *use_lamports_unit)
|
use_lamports_unit,
|
||||||
}
|
limit_results,
|
||||||
|
} => process_show_stake_history(&rpc_client, config, *use_lamports_unit, *limit_results),
|
||||||
CliCommand::StakeAuthorize {
|
CliCommand::StakeAuthorize {
|
||||||
stake_account_pubkey,
|
stake_account_pubkey,
|
||||||
ref new_authorizations,
|
ref new_authorizations,
|
||||||
|
|
|
@ -21,7 +21,7 @@ use solana_clap_utils::{
|
||||||
};
|
};
|
||||||
use solana_cli_output::{
|
use solana_cli_output::{
|
||||||
return_signers_with_config, CliEpochReward, CliStakeHistory, CliStakeHistoryEntry,
|
return_signers_with_config, CliEpochReward, CliStakeHistory, CliStakeHistoryEntry,
|
||||||
CliStakeState, CliStakeType, ReturnSignersConfig,
|
CliStakeState, CliStakeType, OutputFormat, ReturnSignersConfig,
|
||||||
};
|
};
|
||||||
use solana_client::{
|
use solana_client::{
|
||||||
blockhash_query::BlockhashQuery, nonce_utils, rpc_client::RpcClient,
|
blockhash_query::BlockhashQuery, nonce_utils, rpc_client::RpcClient,
|
||||||
|
@ -438,6 +438,19 @@ impl StakeSubCommands for App<'_, '_> {
|
||||||
.takes_value(false)
|
.takes_value(false)
|
||||||
.help("Display balance in lamports instead of SOL")
|
.help("Display balance in lamports instead of SOL")
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("limit")
|
||||||
|
.long("limit")
|
||||||
|
.takes_value(true)
|
||||||
|
.value_name("NUM")
|
||||||
|
.default_value("10")
|
||||||
|
.validator(|s| {
|
||||||
|
s.parse::<usize>()
|
||||||
|
.map(|_| ())
|
||||||
|
.map_err(|e| e.to_string())
|
||||||
|
})
|
||||||
|
.help("Display NUM recent epochs worth of stake history in text mode. 0 for all")
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -896,8 +909,12 @@ pub fn parse_show_stake_account(
|
||||||
|
|
||||||
pub fn parse_show_stake_history(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
|
pub fn parse_show_stake_history(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
|
||||||
let use_lamports_unit = matches.is_present("lamports");
|
let use_lamports_unit = matches.is_present("lamports");
|
||||||
|
let limit_results = value_of(matches, "limit").unwrap();
|
||||||
Ok(CliCommandInfo {
|
Ok(CliCommandInfo {
|
||||||
command: CliCommand::ShowStakeHistory { use_lamports_unit },
|
command: CliCommand::ShowStakeHistory {
|
||||||
|
use_lamports_unit,
|
||||||
|
limit_results,
|
||||||
|
},
|
||||||
signers: vec![],
|
signers: vec![],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1846,6 +1863,7 @@ pub fn process_show_stake_history(
|
||||||
rpc_client: &RpcClient,
|
rpc_client: &RpcClient,
|
||||||
config: &CliConfig,
|
config: &CliConfig,
|
||||||
use_lamports_unit: bool,
|
use_lamports_unit: bool,
|
||||||
|
limit_results: usize,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let stake_history_account = rpc_client.get_account(&stake_history::id())?;
|
let stake_history_account = rpc_client.get_account(&stake_history::id())?;
|
||||||
let stake_history =
|
let stake_history =
|
||||||
|
@ -1853,8 +1871,18 @@ pub fn process_show_stake_history(
|
||||||
CliError::RpcRequestError("Failed to deserialize stake history".to_string())
|
CliError::RpcRequestError("Failed to deserialize stake history".to_string())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
let limit_results = match config.output_format {
|
||||||
|
OutputFormat::Json | OutputFormat::JsonCompact => std::usize::MAX,
|
||||||
|
_ => {
|
||||||
|
if limit_results == 0 {
|
||||||
|
std::usize::MAX
|
||||||
|
} else {
|
||||||
|
limit_results
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
let mut entries: Vec<CliStakeHistoryEntry> = vec![];
|
let mut entries: Vec<CliStakeHistoryEntry> = vec![];
|
||||||
for entry in stake_history.deref() {
|
for entry in stake_history.deref().iter().take(limit_results) {
|
||||||
entries.push(entry.into());
|
entries.push(entry.into());
|
||||||
}
|
}
|
||||||
let stake_history_output = CliStakeHistory {
|
let stake_history_output = CliStakeHistory {
|
||||||
|
|
Loading…
Reference in New Issue