Utilities
Pausable
Purpose
Allows contracts to be paused and unpaused by authorized accounts.
This utility contract can be used with any token standard (fungible, non-fungible, multi-token).
Design
To make it easier to spot when inspecting the code, we turned this simple functionality into a macro that can annotate your smart contract functions.
An example:
#[when_paused]
pub fn emergency_reset(e: &Env) {
e.storage().instance().set(&DataKey::Counter, &0);
}Which will expand into the below code:
pub fn emergency_reset(e: &Env) {
when_paused(e);
e.storage().instance().set(&DataKey::Counter, &0);
}Implementing Pausable Trait
#[contractimpl]
impl Pausable for ExampleContract {
fn paused(e: &Env) -> bool {
pausable::paused(e)
}
#[only_owner]
fn pause(e: &Env, _caller: Address) {
pausable::pause(e);
}
#[only_owner]
fn unpause(e: &Env, _caller: Address) {
pausable::unpause(e);
}
}