metaplex-foundation / shank

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

feat: optional instruction acccounts defaulting to program_id #40

Closed thlorenz closed 1 year ago

thlorenz commented 1 year ago

Summary

This PR adds the default_optional_accounts instruction attribute that sets the strategy for code generators regarding how optional accounts should be included in the accounts array.

If it is present all accounts not provided should be set to the program_id instead of just being omitted (which is the default strategy).

Example

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

Related Issue in solita: https://github.com/metaplex-foundation/solita/issues/93 Related PR in solita: https://github.com/metaplex-foundation/solita/pull/94