Filter stakes by withdrawer (#25939)

* Add a new argument to stake cli to filter stakes by withdrawer

* some fix on compilation errors

* fixing rust format

* defining withdrawer in cli arguments

* changes after review.

* minor changes after review
This commit is contained in:
godmodegalactus 2022-06-17 21:52:23 +02:00 committed by GitHub
parent 2866ca4b1c
commit 7d54807da0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 5 deletions

View File

@ -103,6 +103,7 @@ pub enum CliCommand {
ShowStakes {
use_lamports_unit: bool,
vote_account_pubkeys: Option<Vec<Pubkey>>,
withdraw_authority: Option<Pubkey>,
},
ShowValidators {
use_lamports_unit: bool,
@ -904,11 +905,13 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
CliCommand::ShowStakes {
use_lamports_unit,
vote_account_pubkeys,
withdraw_authority,
} => process_show_stakes(
&rpc_client,
config,
*use_lamports_unit,
vote_account_pubkeys.as_deref(),
withdraw_authority.as_ref(),
),
CliCommand::WaitForMaxStake { max_stake_percent } => {
process_wait_for_max_stake(&rpc_client, config, *max_stake_percent)

View File

@ -328,6 +328,12 @@ impl ClusterQuerySubCommands for App<'_, '_> {
.subcommand(
SubCommand::with_name("stakes")
.about("Show stake account information")
.arg(
Arg::with_name("lamports")
.long("lamports")
.takes_value(false)
.help("Display balance in lamports instead of SOL"),
)
.arg(
pubkey!(Arg::with_name("vote_account_pubkeys")
.index(1)
@ -336,10 +342,10 @@ impl ClusterQuerySubCommands for App<'_, '_> {
"Only show stake accounts delegated to the provided vote accounts. "),
)
.arg(
Arg::with_name("lamports")
.long("lamports")
.takes_value(false)
.help("Display balance in lamports instead of SOL"),
pubkey!(Arg::with_name("withdraw_authority")
.value_name("PUBKEY")
.long("withdraw-authority"),
"Only show stake accounts with the provided withdraw authority. "),
),
)
.subcommand(
@ -624,11 +630,12 @@ pub fn parse_show_stakes(
let use_lamports_unit = matches.is_present("lamports");
let vote_account_pubkeys =
pubkeys_of_multiple_signers(matches, "vote_account_pubkeys", wallet_manager)?;
let withdraw_authority = pubkey_of(matches, "withdraw_authority");
Ok(CliCommandInfo {
command: CliCommand::ShowStakes {
use_lamports_unit,
vote_account_pubkeys,
withdraw_authority,
},
signers: vec![],
})
@ -1749,6 +1756,7 @@ pub fn process_show_stakes(
config: &CliConfig,
use_lamports_unit: bool,
vote_account_pubkeys: Option<&[Pubkey]>,
withdraw_authority_pubkey: Option<&Pubkey>,
) -> ProcessResult {
use crate::stake::build_stake_state;
@ -1786,6 +1794,26 @@ pub fn process_show_stakes(
]);
}
}
if let Some(withdraw_authority_pubkey) = withdraw_authority_pubkey {
// withdrawer filter
let withdrawer_filter = vec![rpc_filter::RpcFilterType::Memcmp(rpc_filter::Memcmp {
offset: 44,
bytes: rpc_filter::MemcmpEncodedBytes::Base58(withdraw_authority_pubkey.to_string()),
encoding: Some(rpc_filter::MemcmpEncoding::Binary),
})];
match program_accounts_config.filters {
Some(filters) => {
// filter by withdrawer
program_accounts_config.filters = Some([filters, withdrawer_filter].concat())
}
None => {
program_accounts_config.filters = Some(withdrawer_filter);
}
}
}
let all_stake_accounts = rpc_client
.get_program_accounts_with_config(&stake::program::id(), program_accounts_config)?;
let stake_history_account = rpc_client.get_account(&stake_history::id())?;