Skip to content

Commit

Permalink
Filter stakes by withdrawer (#25939)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
godmodegalactus authored Jun 17, 2022
1 parent 2866ca4 commit 7d54807
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
3 changes: 3 additions & 0 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
38 changes: 33 additions & 5 deletions cli/src/cluster_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -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![],
})
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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())?;
Expand Down

0 comments on commit 7d54807

Please sign in to comment.