Rpc: optionally filter getLargestAccounts by circulating/nonCirculating (#10007)
* Add circ/non-circ filter to getLargestAccounts * Plumb largest accounts into client and cli * Bump timeout toward CI flakiness * Update docs
This commit is contained in:
@ -26,6 +26,7 @@ use solana_clap_utils::{
|
||||
use solana_client::{
|
||||
client_error::{ClientErrorKind, Result as ClientResult},
|
||||
rpc_client::RpcClient,
|
||||
rpc_config::RpcLargestAccountsFilter,
|
||||
rpc_response::{RpcAccount, RpcKeyedAccount},
|
||||
};
|
||||
#[cfg(not(test))]
|
||||
@ -205,6 +206,10 @@ pub enum CliCommand {
|
||||
GetSlot {
|
||||
commitment_config: CommitmentConfig,
|
||||
},
|
||||
LargestAccounts {
|
||||
commitment_config: CommitmentConfig,
|
||||
filter: Option<RpcLargestAccountsFilter>,
|
||||
},
|
||||
Supply {
|
||||
commitment_config: CommitmentConfig,
|
||||
print_accounts: bool,
|
||||
@ -622,6 +627,7 @@ pub fn parse_command(
|
||||
}),
|
||||
("epoch", Some(matches)) => parse_get_epoch(matches),
|
||||
("slot", Some(matches)) => parse_get_slot(matches),
|
||||
("largest-accounts", Some(matches)) => parse_largest_accounts(matches),
|
||||
("supply", Some(matches)) => parse_supply(matches),
|
||||
("total-supply", Some(matches)) => parse_total_supply(matches),
|
||||
("transaction-count", Some(matches)) => parse_get_transaction_count(matches),
|
||||
@ -1707,6 +1713,10 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||
CliCommand::GetSlot { commitment_config } => {
|
||||
process_get_slot(&rpc_client, *commitment_config)
|
||||
}
|
||||
CliCommand::LargestAccounts {
|
||||
commitment_config,
|
||||
filter,
|
||||
} => process_largest_accounts(&rpc_client, config, *commitment_config, filter.clone()),
|
||||
CliCommand::Supply {
|
||||
commitment_config,
|
||||
print_accounts,
|
||||
|
@ -4,7 +4,9 @@ use console::{style, Emoji};
|
||||
use inflector::cases::titlecase::to_title_case;
|
||||
use serde::Serialize;
|
||||
use serde_json::{Map, Value};
|
||||
use solana_client::rpc_response::{RpcEpochInfo, RpcKeyedAccount, RpcSupply, RpcVoteAccountInfo};
|
||||
use solana_client::rpc_response::{
|
||||
RpcAccountBalance, RpcEpochInfo, RpcKeyedAccount, RpcSupply, RpcVoteAccountInfo,
|
||||
};
|
||||
use solana_sdk::{
|
||||
clock::{self, Epoch, Slot, UnixTimestamp},
|
||||
native_token::lamports_to_sol,
|
||||
@ -909,6 +911,30 @@ impl fmt::Display for CliSignature {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct CliAccountBalances {
|
||||
pub accounts: Vec<RpcAccountBalance>,
|
||||
}
|
||||
|
||||
impl fmt::Display for CliAccountBalances {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
writeln!(
|
||||
f,
|
||||
"{}",
|
||||
style(format!("{:<44} {}", "Address", "Balance",)).bold()
|
||||
)?;
|
||||
for account in &self.accounts {
|
||||
writeln!(
|
||||
f,
|
||||
"{:<44} {}",
|
||||
account.address,
|
||||
&format!("{} SOL", lamports_to_sol(account.lamports))
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct CliSupply {
|
||||
pub total: u64,
|
||||
|
@ -15,6 +15,7 @@ use solana_clap_utils::{
|
||||
use solana_client::{
|
||||
pubsub_client::{PubsubClient, SlotInfoMessage},
|
||||
rpc_client::RpcClient,
|
||||
rpc_config::{RpcLargestAccountsConfig, RpcLargestAccountsFilter},
|
||||
rpc_request::MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS_SLOT_RANGE,
|
||||
};
|
||||
use solana_remote_wallet::remote_wallet::RemoteWalletManager;
|
||||
@ -119,6 +120,23 @@ impl ClusterQuerySubCommands for App<'_, '_> {
|
||||
SubCommand::with_name("epoch").about("Get current epoch")
|
||||
.arg(commitment_arg()),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("largest-accounts").about("Get addresses of largest cluster accounts")
|
||||
.arg(
|
||||
Arg::with_name("circulating")
|
||||
.long("circulating")
|
||||
.takes_value(false)
|
||||
.help("Filter address list to only circulating accounts")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("non_circulating")
|
||||
.long("non-circulating")
|
||||
.takes_value(false)
|
||||
.conflicts_with("circulating")
|
||||
.help("Filter address list to only non-circulating accounts")
|
||||
)
|
||||
.arg(commitment_arg()),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("supply").about("Get information about the cluster supply of SOL")
|
||||
.arg(
|
||||
@ -352,6 +370,24 @@ pub fn parse_get_epoch(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliEr
|
||||
})
|
||||
}
|
||||
|
||||
pub fn parse_largest_accounts(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
|
||||
let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap();
|
||||
let filter = if matches.is_present("circulating") {
|
||||
Some(RpcLargestAccountsFilter::Circulating)
|
||||
} else if matches.is_present("non_circulating") {
|
||||
Some(RpcLargestAccountsFilter::NonCirculating)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
Ok(CliCommandInfo {
|
||||
command: CliCommand::LargestAccounts {
|
||||
commitment_config,
|
||||
filter,
|
||||
},
|
||||
signers: vec![],
|
||||
})
|
||||
}
|
||||
|
||||
pub fn parse_supply(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
|
||||
let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap();
|
||||
let print_accounts = matches.is_present("print_accounts");
|
||||
@ -815,6 +851,22 @@ pub fn process_show_block_production(
|
||||
Ok(config.output_format.formatted_string(&block_production))
|
||||
}
|
||||
|
||||
pub fn process_largest_accounts(
|
||||
rpc_client: &RpcClient,
|
||||
config: &CliConfig,
|
||||
commitment_config: CommitmentConfig,
|
||||
filter: Option<RpcLargestAccountsFilter>,
|
||||
) -> ProcessResult {
|
||||
let accounts = rpc_client
|
||||
.get_largest_accounts_with_config(RpcLargestAccountsConfig {
|
||||
commitment: Some(commitment_config),
|
||||
filter,
|
||||
})?
|
||||
.value;
|
||||
let largest_accounts = CliAccountBalances { accounts };
|
||||
Ok(config.output_format.formatted_string(&largest_accounts))
|
||||
}
|
||||
|
||||
pub fn process_supply(
|
||||
rpc_client: &RpcClient,
|
||||
config: &CliConfig,
|
||||
|
Reference in New Issue
Block a user