Skip to main content

pryzm_auth/
auth.rs

1use crate::error::AuthError;
2use crate::state::{ADMIN, PAUSED};
3use cosmwasm_std::{Addr, Deps, MessageInfo, Storage};
4
5pub fn set_admin(storage: &mut dyn Storage, address: &Addr) -> Result<(), AuthError> {
6    ADMIN.save(storage, address)?;
7    Ok(())
8}
9
10pub fn assert_admin(deps: &Deps, info: &MessageInfo) -> Result<(), AuthError> {
11    let admin = ADMIN.load(deps.storage)?;
12    if info.sender != admin {
13        return Err(AuthError::Unauthorized {});
14    }
15    Ok(())
16}
17
18pub fn assert_not_paused(deps: &Deps) -> Result<(), AuthError> {
19    if is_paused(deps)? {
20        return Err(AuthError::Paused {});
21    }
22    Ok(())
23}
24
25pub fn is_paused(deps: &Deps) -> Result<bool, AuthError> {
26    Ok(PAUSED.may_load(deps.storage)?.unwrap_or_default())
27}