Crate light_instruction_decoder_derive

Crate light_instruction_decoder_derive 

Source
Expand description

Derive macros for InstructionDecoder implementations

This crate provides two macros:

  1. #[derive(InstructionDecoder)] - For instruction enums (native programs)
  2. #[instruction_decoder] - Attribute macro for Anchor program modules

The attribute macro extracts function names from the program module and generates an instruction enum with #[derive(InstructionDecoder)] applied.

§Enhanced InstructionDecoder for Anchor Programs

The derive macro supports an enhanced mode that references Anchor-generated types for account names and parameter decoding:

use light_instruction_decoder_derive::InstructionDecoder;

#[derive(InstructionDecoder)]
#[instruction_decoder(
    program_id = "MyProgram111111111111111111111111111111111",
    program_name = "My Program"
)]
pub enum MyInstruction {
    #[instruction_decoder(accounts = CreateRecord, params = CreateRecordParams)]
    CreateRecord,

    #[instruction_decoder(accounts = UpdateRecord)]
    UpdateRecord,
}

This generates a decoder that:

  • Gets account names from <AccountsType<'_>>::ACCOUNT_NAMES
  • Decodes instruction data using ParamsType::try_from_slice() with Debug output

Attribute Macros§

instruction_decoder
Attribute macro for generating InstructionDecoder from Anchor program modules.

Derive Macros§

InstructionDecoder
Derives an InstructionDecoder implementation for an Anchor instruction enum.