@ -1,4 +1,5 @@
|
||||
use crate::{
|
||||
cli_output::{CliAccount, OutputFormat},
|
||||
cluster_query::*,
|
||||
display::{println_name_value, println_signers},
|
||||
nonce::{self, *},
|
||||
@ -21,6 +22,7 @@ use solana_clap_utils::{
|
||||
use solana_client::{
|
||||
client_error::{ClientErrorKind, Result as ClientResult},
|
||||
rpc_client::RpcClient,
|
||||
rpc_response::{RpcAccount, RpcKeyedAccount},
|
||||
};
|
||||
#[cfg(not(test))]
|
||||
use solana_faucet::faucet::request_airdrop_transaction;
|
||||
@ -472,6 +474,7 @@ pub struct CliConfig<'a> {
|
||||
pub keypair_path: String,
|
||||
pub rpc_client: Option<RpcClient>,
|
||||
pub verbose: bool,
|
||||
pub output_format: OutputFormat,
|
||||
}
|
||||
|
||||
impl CliConfig<'_> {
|
||||
@ -563,6 +566,7 @@ impl Default for CliConfig<'_> {
|
||||
keypair_path: Self::default_keypair_path(),
|
||||
rpc_client: None,
|
||||
verbose: false,
|
||||
output_format: OutputFormat::Display,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1179,31 +1183,33 @@ fn process_confirm(rpc_client: &RpcClient, signature: &Signature) -> ProcessResu
|
||||
|
||||
fn process_show_account(
|
||||
rpc_client: &RpcClient,
|
||||
_config: &CliConfig,
|
||||
config: &CliConfig,
|
||||
account_pubkey: &Pubkey,
|
||||
output_file: &Option<String>,
|
||||
use_lamports_unit: bool,
|
||||
) -> ProcessResult {
|
||||
let account = rpc_client.get_account(account_pubkey)?;
|
||||
let data = account.data.clone();
|
||||
let cli_account = CliAccount {
|
||||
keyed_account: RpcKeyedAccount {
|
||||
pubkey: account_pubkey.to_string(),
|
||||
account: RpcAccount::encode(account),
|
||||
},
|
||||
use_lamports_unit,
|
||||
};
|
||||
|
||||
println!();
|
||||
println_name_value("Public Key:", &account_pubkey.to_string());
|
||||
println_name_value(
|
||||
"Balance:",
|
||||
&build_balance_message(account.lamports, use_lamports_unit, true),
|
||||
);
|
||||
println_name_value("Owner:", &account.owner.to_string());
|
||||
println_name_value("Executable:", &account.executable.to_string());
|
||||
println_name_value("Rent Epoch:", &account.rent_epoch.to_string());
|
||||
config.output_format.formatted_print(&cli_account);
|
||||
|
||||
if let Some(output_file) = output_file {
|
||||
let mut f = File::create(output_file)?;
|
||||
f.write_all(&account.data)?;
|
||||
println!();
|
||||
println!("Wrote account data to {}", output_file);
|
||||
} else if !account.data.is_empty() {
|
||||
use pretty_hex::*;
|
||||
println!("{:?}", account.data.hex_dump());
|
||||
if config.output_format == OutputFormat::Display {
|
||||
if let Some(output_file) = output_file {
|
||||
let mut f = File::create(output_file)?;
|
||||
f.write_all(&data)?;
|
||||
println!();
|
||||
println!("Wrote account data to {}", output_file);
|
||||
} else if !data.is_empty() {
|
||||
use pretty_hex::*;
|
||||
println!("{:?}", data.hex_dump());
|
||||
}
|
||||
}
|
||||
|
||||
Ok("".to_string())
|
||||
@ -1577,7 +1583,7 @@ fn process_witness(
|
||||
}
|
||||
|
||||
pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||
if config.verbose {
|
||||
if config.verbose && config.output_format == OutputFormat::Display {
|
||||
println_name_value("RPC URL:", &config.json_rpc_url);
|
||||
println_name_value("Default Signer Path:", &config.keypair_path);
|
||||
if config.keypair_path.starts_with("usb://") {
|
||||
@ -1622,7 +1628,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||
CliCommand::GetBlockTime { slot } => process_get_block_time(&rpc_client, *slot),
|
||||
CliCommand::GetGenesisHash => process_get_genesis_hash(&rpc_client),
|
||||
CliCommand::GetEpochInfo { commitment_config } => {
|
||||
process_get_epoch_info(&rpc_client, *commitment_config)
|
||||
process_get_epoch_info(&rpc_client, config, *commitment_config)
|
||||
}
|
||||
CliCommand::GetEpoch { commitment_config } => {
|
||||
process_get_epoch(&rpc_client, *commitment_config)
|
||||
@ -1662,13 +1668,14 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||
vote_account_pubkeys,
|
||||
} => process_show_stakes(
|
||||
&rpc_client,
|
||||
config,
|
||||
*use_lamports_unit,
|
||||
vote_account_pubkeys.as_deref(),
|
||||
),
|
||||
CliCommand::ShowValidators {
|
||||
use_lamports_unit,
|
||||
commitment_config,
|
||||
} => process_show_validators(&rpc_client, *use_lamports_unit, *commitment_config),
|
||||
} => process_show_validators(&rpc_client, config, *use_lamports_unit, *commitment_config),
|
||||
|
||||
// Nonce Commands
|
||||
|
||||
@ -1711,7 +1718,12 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||
CliCommand::ShowNonceAccount {
|
||||
nonce_account_pubkey,
|
||||
use_lamports_unit,
|
||||
} => process_show_nonce_account(&rpc_client, &nonce_account_pubkey, *use_lamports_unit),
|
||||
} => process_show_nonce_account(
|
||||
&rpc_client,
|
||||
config,
|
||||
&nonce_account_pubkey,
|
||||
*use_lamports_unit,
|
||||
),
|
||||
// Withdraw lamports from a nonce account
|
||||
CliCommand::WithdrawFromNonceAccount {
|
||||
nonce_account,
|
||||
@ -1940,7 +1952,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||
|
||||
// Return all or single validator info
|
||||
CliCommand::GetValidatorInfo(info_pubkey) => {
|
||||
process_get_validator_info(&rpc_client, *info_pubkey)
|
||||
process_get_validator_info(&rpc_client, config, *info_pubkey)
|
||||
}
|
||||
// Publish validator info
|
||||
CliCommand::SetValidatorInfo {
|
||||
@ -2532,7 +2544,7 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, '
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("output_file")
|
||||
.long("output")
|
||||
.long("output-file")
|
||||
.short("o")
|
||||
.value_name("FILEPATH")
|
||||
.takes_value(true)
|
||||
|
Reference in New Issue
Block a user