partial-idl-parser

Crates.iopartial-idl-parser
lib.rspartial-idl-parser
version1.2.0
created_at2025-03-01 10:32:45.375594+00
updated_at2025-03-01 12:01:26.686644+00
descriptionA simple parser for anchor IDL without importing anchor types or causing build panics for WASM targets.
homepagehttps://github.com/JamiiDao
repositoryhttps://github.com/JamiiDao/SolanaWalletAdapter
max_upload_size
id1573672
size10,251
448-OG (448-OG)

documentation

README

Simple anchor IDL Parser

A simple parser for partial part of anchor IDL without importing anchor types or causing build panics for WASM targets.

It only parses the address of the program and the instructions containing the instruction name and the discriminant which are useful for the scope of the wallet-adapter templates.

Macro for creating a path to the IDL

the partial-idl-parser crate is used to read the IDL from the CARGO_WORKSPACE_DIR/target/temp.json file using a .cargo/config.toml in the root

[env]
CARGO_WORKSPACE_DIR = { value = "", relative = true }

Get the AnchorIdlPartialData data structure containing the IDL of an anchor example called temp

use partial_idl_parser::*;

const IDL: &str = get_idl!();

If the directory is different you can use idl_custom_path macro:

use partial_idl_parser::*;

const IDL: &str = idl_custom_path!("../../target/custom_idl_dir/idl.json");

The AnchorIdlPartialData

Parsed IDL is stored within a AnchorIdlPartialData struct.

fn foo() -> Result<(), serde_json::Error> {
    use partial_idl_parser::*;

    // Get the JSON IDL data
    const IDL_RAW_DATA: &str = idl_path!("temp");

    // Parse the JSON IDL
    let parsed_idl = AnchorIdlPartialData::parse(IDL_RAW_DATA)?;

    // Get program ID
    parsed_idl.program_id();


    // Get An Instruction by it's identifier assuming the instruction is
    // labeled by the name `initialize`
    parsed_idl.get_instruction("initialize");


    // Get the instruction discriminant assuming the instruction is
    // labeled by the name `initialize`
    parsed_idl.get_discriminant("initialize");

    Ok(())
}

LICENSE

MIT OR APACHE-2.0

Commit count: 239

cargo fmt