Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
febo committed Oct 6, 2024
1 parent 2d6dd53 commit 3b061c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion include-idl-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum Commands {
Parse {
/// Read IDL from a solana program binary
path: PathBuf,
idl_type: IdlType
idl_type: IdlType,
},
}

Expand Down
18 changes: 10 additions & 8 deletions include-idl/src/parse.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#[cfg(feature = "parse")]
use {
flate2::bufread::ZlibDecoder, goblin::elf::Elf, serde_json::Value,
std::io::Read,
std::fmt, std::str::FromStr
flate2::bufread::ZlibDecoder, goblin::elf::Elf, serde_json::Value, std::fmt, std::io::Read,
std::str::FromStr,
};

#[derive(Clone, Debug)]
pub enum IdlType {
Anchor,
Kinobi
Kinobi,
}

impl fmt::Display for IdlType {
Expand All @@ -27,27 +26,30 @@ impl FromStr for IdlType {
match s.to_lowercase().as_str() {
"anchor" => Ok(IdlType::Anchor),
"kinobi" => Ok(IdlType::Kinobi),
_ => Err("Invalid IDL type")
_ => Err("Invalid IDL type"),
}
}
}

fn get_section_name(idl_type: IdlType) -> String {
match idl_type {
IdlType::Anchor => ".solana.idl".to_string(),
IdlType::Kinobi => ".kinobi.idl".to_string()
IdlType::Kinobi => ".kinobi.idl".to_string(),
}
}

pub fn parse_idl_from_program_binary(buffer: &[u8], idl_type: IdlType) -> goblin::error::Result<Value> {
pub fn parse_idl_from_program_binary(
buffer: &[u8],
idl_type: IdlType,
) -> goblin::error::Result<Value> {
let elf = Elf::parse(buffer)?;

let section_name = get_section_name(idl_type);

// Iterate over section headers and print information
for sh in &elf.section_headers {
let name = elf.shdr_strtab.get_at(sh.sh_name).unwrap_or("<invalid>");
if name == &section_name {
if name == section_name {
// Get offset of .solana.idl section data
let offset = sh.sh_offset as usize;

Expand Down

0 comments on commit 3b061c5

Please sign in to comment.