Attribute Macro anchor_lang::event_cpi
source · #[event_cpi]
Available on crate feature
event-cpi
only.Expand description
An attribute macro to add necessary event CPI accounts to the given accounts struct.
Two accounts named event_authority
and program
will be appended to the list of accounts.
§Example
ⓘ
#[event_cpi]
#[derive(Accounts)]
pub struct MyInstruction<'info> {
pub signer: Signer<'info>,
}
The code above will be expanded to:
ⓘ
#[derive(Accounts)]
pub struct MyInstruction<'info> {
pub signer: Signer<'info>,
/// CHECK: Only the event authority can invoke self-CPI
#[account(seeds = [b"__event_authority"], bump)]
pub event_authority: AccountInfo<'info>,
/// CHECK: Self-CPI will fail if the program is not the current program
pub program: AccountInfo<'info>,
}
See emit_cpi!
for a full example.
Only available with event-cpi
feature enabled.