Trait near_contract_tools::pause::Pause
source · 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§
sourcefn slot_paused() -> Slot<bool>
fn slot_paused() -> Slot<bool>
Storage slot for pause state
sourcefn set_is_paused(&mut self, is_paused: bool)
fn set_is_paused(&mut self, is_paused: bool)
Force the contract pause state in a particular direction. Does not emit events or check the current pause state.
sourcefn pause(&mut self)
fn pause(&mut self)
Pauses the contract if it is currently unpaused, panics otherwise.
Emits a PauseEvent::Pause
event.
sourcefn unpause(&mut self)
fn unpause(&mut self)
Unpauses the contract if it is currently paused, panics otherwise.
Emits a PauseEvent::Unpause
event.
sourcefn require_paused()
fn require_paused()
Rejects if the contract is unpaused
sourcefn require_unpaused()
fn require_unpaused()
Rejects if the contract is paused