Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ syn = { version = "1.0.60", features = ["full", "extra-traits"] }
tar = "0.4.35"
toml = "0.7.6"
walkdir = "2.3.2"
pretty-hex = "0.4.1"
66 changes: 66 additions & 0 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,22 @@ pub enum Command {
#[clap(value_enum)]
shell: clap_complete::Shell,
},

/// Show the contents of the account
#[clap(alias = "account_new")]
Account_New {
///Account contents to show
#[clap(value_name = "ACCOUNT_ADDRESS")]
account_pubkey: String,

///Write the account data to this file
#[clap(short, long, value_name = "FILEPATH")]
output_file: Option<String>,

///Display balance in lamports instead of SOL
#[clap(long, action)]
lamports: bool,
},
}

#[derive(Debug, Parser)]
Expand Down Expand Up @@ -906,6 +922,11 @@ fn process_command(opts: Opts) -> Result<()> {
address,
idl,
} => account(&opts.cfg_override, account_type, address, idl),
Command::Account_New {
account_pubkey,
output_file,
lamports,
} => show_account(&opts.cfg_override, account_pubkey, output_file, lamports),
Command::Completions { shell } => {
clap_complete::generate(
shell,
Expand Down Expand Up @@ -2738,6 +2759,51 @@ fn account(
Ok(())
}

fn show_account(
cfg_override: &ConfigOverride,
account_pubkey: String,
output_file: Option<String>,
lamports: bool,
) -> Result<()> {
println!("show account");

// Convert address string into Pubkey
let pubkey: Pubkey = account_pubkey.parse()?;

// Pick the right cluster (same as in your `account` command)
let cluster = match &cfg_override.cluster {
Some(cluster) => cluster.clone(),
None => Config::discover(cfg_override)?
.map(|cfg| cfg.provider.cluster.clone())
.unwrap_or(Cluster::Localnet),
};

// Create RPC client and fetch account
let rpc_client = create_client(cluster.url());
let account = rpc_client.get_account(&pubkey)?;
let data = &account.data;

// Show balance
if lamports {
println!("Balance (lamports): {}", account.lamports);
} else {
println!(
"Balance (SOL): {}",
account.lamports as f64 / solana_sdk::native_token::LAMPORTS_PER_SOL as f64
);
}

// Handle writing or dumping account data
if let Some(output_file) = output_file {
let mut f = File::create(output_file.clone())?;
f.write_all(data)?;
println!("Wrote account data to {output_file}");
} else if !data.is_empty() {
use pretty_hex::*;
println!("{:?}", data.hex_dump());
}
Ok(())
}
// Deserializes user defined IDL types by munching the account data(recursively).
fn deserialize_idl_defined_type_to_json(
idl: &Idl,
Expand Down
Loading