metaplex-foundation / shank

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

Consider support Rust type aliases for single arguments #24

Open samuelvanderwaal opened 2 years ago

samuelvanderwaal commented 2 years ago

For instructions with single arguments we should discuss/consider supporting Rust type aliases so something like this:

pub struct SetCollectionSizeArgs {
    pub size: u64
}

#[account(0, writable, name="collection_metadata", desc="Collection Metadata account")]
#[account(1, signer, writable, name="collection_authority", desc="Collection Update authority")]
#[account(2, name="collection_mint", desc="Mint of the Collection")]
SetCollectionSize(SetCollectionSizeArgs),

could be

type Size = u64;

#[account(0, writable, name="collection_metadata", desc="Collection Metadata account")]
#[account(1, signer, writable, name="collection_authority", desc="Collection Update authority")]
#[account(2, name="collection_mint", desc="Mint of the Collection")]
SetCollectionSize(Size),

Alternately, accept a primitive Rust type directly and generate a common-sense name, e.g. SetCollectionSizeArg:

#[account(0, writable, name="collection_metadata", desc="Collection Metadata account")]
#[account(1, signer, writable, name="collection_authority", desc="Collection Update authority")]
#[account(2, name="collection_mint", desc="Mint of the Collection")]
SetCollectionSize(u64),

Getting this down to track the issue and I will try to add more details later.