metaplex-foundation / shank

Extracts IDL from Solana Rust contracts
https://docs.rs/crate/shank_macro/latest
118 stars 23 forks source link

feat: parse instructions with and without args #3

Closed thlorenz closed 2 years ago

thlorenz commented 2 years ago

This PR adds ability to parse Instruction enums, i.e. of this form:

#[derive(ShankInstruction)]
pub enum Instruction {
    #[account(0, name = "creator", sig)]
    #[account(1, name = "thing", mut)]
    CreateThing(SomeArgs),
    #[account(name = "creator", sig)]
    CloseThing(Option<u8>),
}

It extracts the accounts array with the relevant configs as well as instruction args.

As part of this a generic Enum parser was included.

NOTE: that for now all instructions are expected to be part of an instruction enum as shown in the example.

NOTE: the name of the enum, i.e. Instruction is not included in the naming, thus two enums with the same variants would cause naming conflicts (this is since we only expect one Instruction enum per program)