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:
parent
2866ca4b1c
commit
7d54807da0
|
@ -103,6 +103,7 @@ pub enum CliCommand {
|
||||||
ShowStakes {
|
ShowStakes {
|
||||||
use_lamports_unit: bool,
|
use_lamports_unit: bool,
|
||||||
vote_account_pubkeys: Option<Vec<Pubkey>>,
|
vote_account_pubkeys: Option<Vec<Pubkey>>,
|
||||||
|
withdraw_authority: Option<Pubkey>,
|
||||||
},
|
},
|
||||||
ShowValidators {
|
ShowValidators {
|
||||||
use_lamports_unit: bool,
|
use_lamports_unit: bool,
|
||||||
|
@ -904,11 +905,13 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||||
CliCommand::ShowStakes {
|
CliCommand::ShowStakes {
|
||||||
use_lamports_unit,
|
use_lamports_unit,
|
||||||
vote_account_pubkeys,
|
vote_account_pubkeys,
|
||||||
|
withdraw_authority,
|
||||||
} => process_show_stakes(
|
} => process_show_stakes(
|
||||||
&rpc_client,
|
&rpc_client,
|
||||||
config,
|
config,
|
||||||
*use_lamports_unit,
|
*use_lamports_unit,
|
||||||
vote_account_pubkeys.as_deref(),
|
vote_account_pubkeys.as_deref(),
|
||||||
|
withdraw_authority.as_ref(),
|
||||||
),
|
),
|
||||||
CliCommand::WaitForMaxStake { max_stake_percent } => {
|
CliCommand::WaitForMaxStake { max_stake_percent } => {
|
||||||
process_wait_for_max_stake(&rpc_client, config, *max_stake_percent)
|
process_wait_for_max_stake(&rpc_client, config, *max_stake_percent)
|
||||||
|
|
|
@ -328,6 +328,12 @@ impl ClusterQuerySubCommands for App<'_, '_> {
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("stakes")
|
SubCommand::with_name("stakes")
|
||||||
.about("Show stake account information")
|
.about("Show stake account information")
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("lamports")
|
||||||
|
.long("lamports")
|
||||||
|
.takes_value(false)
|
||||||
|
.help("Display balance in lamports instead of SOL"),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
pubkey!(Arg::with_name("vote_account_pubkeys")
|
pubkey!(Arg::with_name("vote_account_pubkeys")
|
||||||
.index(1)
|
.index(1)
|
||||||
|
@ -336,10 +342,10 @@ impl ClusterQuerySubCommands for App<'_, '_> {
|
||||||
"Only show stake accounts delegated to the provided vote accounts. "),
|
"Only show stake accounts delegated to the provided vote accounts. "),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("lamports")
|
pubkey!(Arg::with_name("withdraw_authority")
|
||||||
.long("lamports")
|
.value_name("PUBKEY")
|
||||||
.takes_value(false)
|
.long("withdraw-authority"),
|
||||||
.help("Display balance in lamports instead of SOL"),
|
"Only show stake accounts with the provided withdraw authority. "),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
|
@ -624,11 +630,12 @@ pub fn parse_show_stakes(
|
||||||
let use_lamports_unit = matches.is_present("lamports");
|
let use_lamports_unit = matches.is_present("lamports");
|
||||||
let vote_account_pubkeys =
|
let vote_account_pubkeys =
|
||||||
pubkeys_of_multiple_signers(matches, "vote_account_pubkeys", wallet_manager)?;
|
pubkeys_of_multiple_signers(matches, "vote_account_pubkeys", wallet_manager)?;
|
||||||
|
let withdraw_authority = pubkey_of(matches, "withdraw_authority");
|
||||||
Ok(CliCommandInfo {
|
Ok(CliCommandInfo {
|
||||||
command: CliCommand::ShowStakes {
|
command: CliCommand::ShowStakes {
|
||||||
use_lamports_unit,
|
use_lamports_unit,
|
||||||
vote_account_pubkeys,
|
vote_account_pubkeys,
|
||||||
|
withdraw_authority,
|
||||||
},
|
},
|
||||||
signers: vec![],
|
signers: vec![],
|
||||||
})
|
})
|
||||||
|
@ -1749,6 +1756,7 @@ pub fn process_show_stakes(
|
||||||
config: &CliConfig,
|
config: &CliConfig,
|
||||||
use_lamports_unit: bool,
|
use_lamports_unit: bool,
|
||||||
vote_account_pubkeys: Option<&[Pubkey]>,
|
vote_account_pubkeys: Option<&[Pubkey]>,
|
||||||
|
withdraw_authority_pubkey: Option<&Pubkey>,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
use crate::stake::build_stake_state;
|
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
|
let all_stake_accounts = rpc_client
|
||||||
.get_program_accounts_with_config(&stake::program::id(), program_accounts_config)?;
|
.get_program_accounts_with_config(&stake::program::id(), program_accounts_config)?;
|
||||||
let stake_history_account = rpc_client.get_account(&stake_history::id())?;
|
let stake_history_account = rpc_client.get_account(&stake_history::id())?;
|
||||||
|
|
Loading…
Reference in New Issue