#[light_program]Expand description
Auto-discovering Light program macro that reads external module files.
This macro automatically discovers #[light_account(init)] fields in Accounts structs by reading external module files. No explicit type list needed!
It also automatically wraps instruction handlers that use Light Accounts
structs with light_pre_init/light_finalize logic - no separate attribute needed!
Usage:
ⓘ
#[light_program]
#[program]
pub mod my_program {
pub mod instruction_accounts; // Macro reads this file!
pub mod state;
use instruction_accounts::*;
use state::*;
pub fn create_user(ctx: Context<CreateUser>, params: Params) -> Result<()> {
// Your business logic
}
}The macro:
- Scans the crate’s
src/directory for#[derive(Accounts)]structs - Extracts seeds from
#[account(seeds = [...])]on#[light_account(init)]fields - Auto-wraps instruction handlers that use those Accounts structs
- Generates all necessary types, enums, and instruction handlers
Seeds are declared ONCE in Anchor attributes - no duplication!