Expand description
Validation guards for Hopper programs.
These functions define the “sentence structure” of Hopper handlers. They support the canonical authored flow:
Validate -> Load -> Mutate -> Emit
Each guard reads as a clear, auditable assertion. Functions return
ProgramResult (i.e. Result<(), ProgramError>) so they compose
naturally with ?.
ⓘ
use hopper::prelude::*;
fn deposit(ctx: &Context, amount: u64) -> ProgramResult {
let authority = ctx.account(0)?;
let vault = ctx.account(1)?;
require_signer(authority)?;
require_writable(vault)?;
require_disc(vault, 1)?;
require_owner(vault, ctx.program_id)?;
let state = vault.load_mut::<VaultState>()?;
// ...
Ok(())
}Functions§
- require
- Require a boolean condition, returning
errif false. - require_
address - Require that the account has the given address.
- require_
data_ len - Require the account has at least
min_lenbytes of data. - require_
disc - Require the account has the given discriminator byte.
- require_
eq - Require two values to be equal.
- require_
gt - Require a > b.
- require_
gte - Require a >= b.
- require_
has_ data - Require the account has non-empty data.
- require_
keys_ eq - Require two addresses to be equal.
- require_
keys_ neq - Require two addresses to be different.
- require_
layout - Require the account passes a full layout contract check (disc + version + layout_id).
- require_
neq - Require two values to be different.
- require_
owner - Require that the account is owned by the given program.
- require_
payer - Require both signer and writable (common payer pattern).
- require_
signer - Require that the account signed the transaction.
- require_
unique_ 2 - Require that
naccounts are different (pairwise uniqueness, up to 6). - require_
unique_ 3 - Require 3 accounts are pairwise unique.
- require_
version - Require the account’s version byte matches the layout contract’s VERSION.
- require_
writable - Require that the account is writable.