From 19748b8907aa0c07600aef650b42b64de418d854 Mon Sep 17 00:00:00 2001 From: Samuel Vanderwaal Date: Wed, 17 Jul 2024 10:58:35 -0800 Subject: [PATCH] add decode of raw account bytes --- src/opt.rs | 13 +++++++++++++ src/process_subcommands.rs | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/opt.rs b/src/opt.rs index 2869162..47320a3 100644 --- a/src/opt.rs +++ b/src/opt.rs @@ -829,6 +829,19 @@ pub enum DecodeSubcommands { /// Pubkey pubkey: String, }, + /// Get Account's raw bytes + Account { + /// Account address + account: Pubkey, + + /// Optional start index + #[structopt(short, long)] + start: Option, + + /// Optional end index + #[structopt(short, long)] + end: Option, + }, } #[derive(Debug, StructOpt)] diff --git a/src/process_subcommands.rs b/src/process_subcommands.rs index 683802b..c868fef 100644 --- a/src/process_subcommands.rs +++ b/src/process_subcommands.rs @@ -454,6 +454,7 @@ pub fn process_decode(client: &RpcClient, commands: DecodeSubcommands) -> Result .trim_start_matches('[') .trim_end_matches(']') .split(',') + .map(|c| c.trim()) .map(|c| { c.parse::() .unwrap_or_else(|_| panic!("failed to parse {}", c)) @@ -463,6 +464,17 @@ pub fn process_decode(client: &RpcClient, commands: DecodeSubcommands) -> Result let array: [u8; 32] = key.try_into().map_err(|_| anyhow!("Invalid pubkey"))?; println!("{:?}", Pubkey::new_from_array(array)); } + DecodeSubcommands::Account { + account, + start, + end, + } => { + let account = client.get_account(&account)?; + let data = account.data; + let start = start.unwrap_or(0); + let end = end.unwrap_or(data.len()); + println!("{:?}", &data[start..end]); + } } Ok(()) }