diff --git a/src/permissions/mod.rs b/src/permissions/mod.rs index 30fdb04..a045f16 100644 --- a/src/permissions/mod.rs +++ b/src/permissions/mod.rs @@ -1,5 +1,8 @@ +mod private; mod superadmin; pub use crate::permissions::superadmin::{ ensure_super_admin, is_super_admin, not_super_admin_error, }; + +pub use crate::permissions::private::{ensure_private, not_self_contract_error}; diff --git a/src/permissions/private.rs b/src/permissions/private.rs new file mode 100644 index 0000000..644cfa4 --- /dev/null +++ b/src/permissions/private.rs @@ -0,0 +1,16 @@ +use cosmwasm_std::{Addr, Env}; +use cosmwasm_std::{StdError, StdResult}; + +const ERR_NOT_SELF_CONTRACT: &str = "[FET_ERR_NOT_SELF] Sender is not a self contract."; + +pub fn ensure_private(env: &Env, address: &Addr) -> StdResult<()> { + if env.contract.address != address { + return Err(not_self_contract_error()); + } + + Ok(()) +} + +pub fn not_self_contract_error() -> StdError { + StdError::generic_err(ERR_NOT_SELF_CONTRACT) +} diff --git a/src/permissions/superadmin.rs b/src/permissions/superadmin.rs index 36fa09c..a4e00de 100644 --- a/src/permissions/superadmin.rs +++ b/src/permissions/superadmin.rs @@ -3,7 +3,7 @@ use cosmwasm_std::{StdError, StdResult}; const ERR_NOT_SUPER_ADMIN: &str = "[FET_ERR_NOT_SUPER_ADMIN] Sender is not a super-admin."; -// Check if the address is admin of the contract, everyone cannot be admin of the contract +// Check if the address is admin of the contract pub fn is_super_admin(deps: &Deps, env: &Env, address: &Addr) -> StdResult { // Check if the address is specified (opposite of the Everyone case) if let Some(admin_address) = deps