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
Context<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: boolToken CPI authors must pair every raw invocation with the
matching *Checked builder (which carries the decimals: u8
byte the SPL Token program validates against the mint).
Handlers that do their own SPL plumbing read this back to
decide whether the signer + owner invariants are already
upheld elsewhere.
allow_unsafe: boolPermit unsafe { ... } blocks inside handler bodies. When
false the program macro wraps each handler in
#[deny(unsafe_code)] so the compiler rejects any raw pointer
detour.
Implementations§
Source§impl HopperProgramPolicy
impl HopperProgramPolicy
Sourcepub const SEALED: Self
pub const SEALED: Self
Strict + token checks + no unsafe in handlers. The zero-escape
mode for programs that never want to drop to raw pointers.
Sourcepub const RAW: Self
pub const RAW: Self
Every lever disengaged. Pinocchio-parity throughput with responsibility pushed to the handler author.
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.
Trait Implementations§
Source§impl Clone for HopperProgramPolicy
impl Clone for HopperProgramPolicy
Source§fn clone(&self) -> HopperProgramPolicy
fn clone(&self) -> HopperProgramPolicy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more