metaplex-foundation / shank

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

feat: shank main lib exposing proc macros #7

Closed thlorenz closed 2 years ago

thlorenz commented 2 years ago

This change properly integrates the Instruction and Account derive attributes into the compiler expand workflow in order to generate compile errors in case they are incorrectly specified.

Example Compiler Error Output:

use shank::{ShankAccount, ShankInstruction};

#[derive(ShankInstruction)]
pub enum InstructionInvalidAccountName {
    #[account(0, naame = "creator", sig)]
    CreateThing,
}

#[derive(ShankInstruction)]
pub enum InstructionInvalidConfig {
    #[account(0, name = "creator", sizzle)]
    CreateThing,
}

#[derive(ShankInstruction)]
pub enum InstructionInvalidAccountIdx {
    #[account(1, name = "creator", sig)]
    CreateThing,
}

#[derive(ShankAccount)]
pub enum EnumAccount {}
error: Only desc/description or name can be assigned strings
 --> src/lib.rs:7:18
  |
7 |     #[account(0, naame = "creator", sig)]
  |                  ^^^^^

error: Invalid/unknown account meta configuration
  --> src/lib.rs:13:36
   |
13 |     #[account(0, name = "creator", sizzle)]
   |                                    ^^^^^^

error: Account index 1 does not match its position 0
  --> src/lib.rs:19:7
   |
19 |     #[account(1, name = "creator", sig)]
   |       ^^^^^^^

error: ShankAccount can only be derived for structs
  --> src/lib.rs:23:10
   |
23 | #[derive(ShankAccount)]
   |          ^^^^^^^^^^^^
   |

As part of this more tests were added ensuring that errors propagate as expected. Some cleanup is part of this as well.