Skip to content

Commit

Permalink
add decode of raw account bytes (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelvanderwaal authored Jul 25, 2024
1 parent 258879c commit fda5923
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize>,

/// Optional end index
#[structopt(short, long)]
end: Option<usize>,
},
}

#[derive(Debug, StructOpt)]
Expand Down
12 changes: 12 additions & 0 deletions src/process_subcommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u8>()
.unwrap_or_else(|_| panic!("failed to parse {}", c))
Expand All @@ -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(())
}
Expand Down

0 comments on commit fda5923

Please sign in to comment.