pub trait Pause {
    fn root() -> Slot<()> { ... }
    fn slot_paused() -> Slot<bool> { ... }
    fn set_is_paused(&mut self, is_paused: bool) { ... }
    fn is_paused() -> bool { ... }
    fn pause(&mut self) { ... }
    fn unpause(&mut self) { ... }
    fn require_paused() { ... }
    fn require_unpaused() { ... }
}
Expand description

Internal-only interactions for a pausable contract

Examples

use near_sdk::near_bindgen;
use near_contract_tools::{pause::Pause, Pause};

#[derive(Pause)]
#[near_bindgen]
struct Contract {
    // ...
}

#[near_bindgen]
impl Contract {
    pub fn only_when_unpaused(&self) {
        Self::require_unpaused();
    }

    pub fn only_when_paused(&self) {
        Self::require_paused();
    }

    pub fn emergency_shutdown(&mut self) {
        self.pause();
    }

    pub fn emergency_shutdown_end(&mut self) {
        self.unpause();
    }
}

Provided Methods§

Storage root

Storage slot for pause state

Force the contract pause state in a particular direction. Does not emit events or check the current pause state.

Returns true if the contract is paused, false otherwise

Pauses the contract if it is currently unpaused, panics otherwise. Emits a PauseEvent::Pause event.

Unpauses the contract if it is currently paused, panics otherwise. Emits a PauseEvent::Unpause event.

Rejects if the contract is unpaused

Rejects if the contract is paused

Implementors§