pub struct HopperProgramPolicy {
pub strict: bool,
pub enforce_token_checks: bool,
pub allow_unsafe: bool,
}Expand description
Program-level safety policy emitted by #[hopper::program(...)].
Each field is a compile-time lever. The const value ends up inlined at every call site the program evaluates it from, so the branches fold away when a lever is known to be on or off at compile time.
Fields§
§strict: boolProgram-level intent marker: handlers in this program run under Hopper’s full enforcement envelope.
The actual per-handler behaviour is controlled by the
handler’s context parameter type. A handler typed as
Ctx<MyAccounts> always runs MyAccounts::bind(ctx)?
(which chains into validate(ctx)?) regardless of policy. A
handler typed as &mut Context<'_> always receives the
context raw. strict = true is the documentation contract
that every handler in the module opts into the typed form;
strict = false signals the author intends to use raw
contexts and accepts the responsibility of calling
validate() manually where needed.
The flag is read back by callers at compile time
(HOPPER_PROGRAM_POLICY.strict) to specialize code paths that
depend on whether the enforcement envelope is active.
enforce_token_checks: boolAuthor-maintained token-check intent. The macro records this flag without inserting or removing checks from CPI calls. Explicit strict methods on TransferChecked, BurnChecked, and ApproveChecked check the token owner field; their direct variants also require signer privilege. Signed strict variants accept PDA seeds, whose signing authority is validated during CPI rather than requiring an incoming signer flag.
allow_unsafe: boolPermit unsafe { ... } blocks inside handler bodies. When
false the program macro wraps each handler in
#[deny(unsafe_code)]. The lint covers that handler item, not called
helpers or dependencies, and ordinary Rust lint override rules apply.
Implementations§
Source§impl HopperProgramPolicy
impl HopperProgramPolicy
Sourcepub const STRICT: Self
pub const STRICT: Self
Typed-validation and token-check intent enabled; unsafe code permitted. The shipping default. Handler types and helper calls determine checks.
Sourcepub const SEALED: Self
pub const SEALED: Self
STRICT intent plus a default unsafe-code denial on handler items. This does not audit unsafe implementations in called helpers.
Sourcepub const RAW: Self
pub const RAW: Self
Typed-validation and token-check intent disabled; unsafe code permitted. Typed handlers still bind. Raw handlers own their explicit validation.
Sourcepub const fn default_policy() -> Self
pub const fn default_policy() -> Self
The shipping default, identical to HopperProgramPolicy::STRICT.
Exposed as a const fn so downstream macro expansion can
reach it from const context without an intermediate binding.