Skip to main content

hopper_invariant

Macro hopper_invariant 

Source
macro_rules! hopper_invariant {
    ( $( $label:literal => $check:expr ),+ $(,)? ) => { ... };
}
Expand description

Invariant checking macro.

Defines a set of invariants for an instruction that run after mutation. Each invariant is a closure over account data that returns ProgramResult.

hopper_invariant! {
    "balance_conserved" => |vault: &Vault| {
        let bal = vault.balance.get();
        hopper_require!(bal <= MAX_SUPPLY, BalanceOverflow);
        Ok(())
    },
    "authority_unchanged" => |vault: &Vault, old: &Vault| {
        hopper_require!(vault.authority == old.authority, AuthorityChanged);
        Ok(())
    },
}

Generates an inline invariant runner that returns the first failure.