Skip to main content

hopper_emit_cpi

Macro hopper_emit_cpi 

Source
macro_rules! hopper_emit_cpi {
    ( $program_id:expr, $event_authority:expr, $bump:expr, $event:expr ) => { ... };
}
Expand description

Emit a Hopper event via self-CPI for reliable indexing.

Wraps cpi_event::encode_event_cpi and a call into the active backend’s invoke_signed so indexers see the event as an inner instruction in the transaction metadata. Logs truncate; inner instructions do not. Anchor’s emit_cpi! solves the same problem with the same trick; Hopper’s lives in pure Rust so it works under no_std and any of the three backends.

§Required program plumbing

The caller must declare a sentinel handler so the runtime routes the self-CPI somewhere:

#[instruction(discriminator = [0xE0, 0x1E])]
fn __hopper_event_sink(_ctx: &mut Context<'_>) -> ProgramResult {
    Ok(())
}

And a PDA named event_authority seeded with [b"__hopper_event_authority"] so the CPI has a signer.

§Usage

hopper_emit_cpi!(
    ctx.program_id(),
    event_authority: &AccountView,
    event_authority_bump: u8,
    Deposited { amount, depositor }
);

Expands to: build instruction bytes, invoke_signed with the event_authority PDA as the signer. One CPI, bounded stack allocation, zero heap.