numbat_wasm_module_pause/
lib.rs

1#![no_std]
2
3numbat_wasm::imports!();
4
5/// The module deals with temporarily pausing contract operations.
6/// It provides a flag that contracts can use to check if owner decided to pause the entire contract.
7/// Use the features module for more granular on/off switches.
8#[numbat_wasm::module]
9pub trait PauseModule {
10    #[view(isPaused)]
11    #[storage_get("pause_module:paused")]
12    fn is_paused(&self) -> bool;
13
14    fn not_paused(&self) -> bool {
15        !self.is_paused()
16    }
17
18    #[storage_set("pause_module:paused")]
19    fn set_paused(&self, paused: bool);
20
21    #[endpoint(pause)]
22    fn pause_endpoint(&self) -> SCResult<()> {
23        require!(
24            self.blockchain().get_caller() == self.blockchain().get_owner_address(),
25            "only owner allowed to pause contract"
26        );
27
28        self.set_paused(true);
29        // TODO: event
30        Ok(())
31    }
32
33    #[endpoint(unpause)]
34    fn unpause_endpoint(&self) -> SCResult<()> {
35        require!(
36            self.blockchain().get_caller() == self.blockchain().get_owner_address(),
37            "only owner allowed to unpause contract"
38        );
39
40        self.set_paused(false);
41        // TODO: event
42        Ok(())
43    }
44}