Skip to content

Commit

Permalink
Update Pausable to handle uninitialized storage
Browse files Browse the repository at this point in the history
  • Loading branch information
bitzoic committed Nov 13, 2023
1 parent a35fff0 commit 04e60a1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions libs/pausable/src/lib.sw
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub fn _unpause() {
#[storage(read)]
pub fn _is_paused() -> bool {
let paused_key = StorageKey::new(PAUSABLE, 0, PAUSABLE);
paused_key.read()
paused_key.try_read().unwrap_or(false)
}

/// Requires that the contract is in the paused state.
Expand All @@ -179,7 +179,12 @@ pub fn _is_paused() -> bool {
#[storage(read)]
pub fn require_paused() {
let paused_key = StorageKey::<bool>::new(PAUSABLE, 0, PAUSABLE);
require(paused_key.read(), PauseError::NotPaused);
require(
paused_key
.try_read()
.unwrap_or(false),
PauseError::NotPaused,
);
}

/// Requires that the contract is in the unpaused state.
Expand All @@ -206,5 +211,5 @@ pub fn require_paused() {
#[storage(read)]
pub fn require_not_paused() {
let paused_key = StorageKey::<bool>::new(PAUSABLE, 0, PAUSABLE);
require(!paused_key.read(), PauseError::Paused);
require(!paused_key.try_read().unwrap_or(false), PauseError::Paused);
}

0 comments on commit 04e60a1

Please sign in to comment.