Skip to main content

hopper_constant

Attribute Macro hopper_constant 

Source
#[hopper_constant]
Expand description

Mark a pub const so it is surfaced in the Anchor IDL "constants" array.

Anchor-compatible surface for #[constant]. The original constant is preserved unchanged; alongside it a hidden __HOPPER_CONST_<NAME>: hopper_schema::ConstantDescriptor sibling is emitted, capturing the stringified type and initializer expression. Collect the descriptors into a slice and hand it to hopper_schema::AnchorIdlWithConstants (or AnchorIdlFromManifestWithConstants) when emitting the IDL.

§Example

#[hopper::constant]
pub const MAX_DEPOSIT: u64 = 1_000_000;

// A hidden sibling const is emitted:
// pub const __HOPPER_CONST_MAX_DEPOSIT: ConstantDescriptor = ...;

pub const PROGRAM_CONSTANTS: &[ConstantDescriptor] = &[__HOPPER_CONST_MAX_DEPOSIT];