Struct cw_controllers::Admin
source · pub struct Admin<'a>(_);
Implementations§
source§impl<'a> Admin<'a>
impl<'a> Admin<'a>
pub const fn new(namespace: &'a str) -> Self
sourcepub fn set<Q: CustomQuery>(
&self,
deps: DepsMut<'_, Q>,
admin: Option<Addr>
) -> StdResult<()>
pub fn set<Q: CustomQuery>(
&self,
deps: DepsMut<'_, Q>,
admin: Option<Addr>
) -> StdResult<()>
Examples found in repository?
src/admin.rs (line 89)
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
pub fn execute_update_admin<C, Q: CustomQuery>(
&self,
deps: DepsMut<Q>,
info: MessageInfo,
new_admin: Option<Addr>,
) -> Result<Response<C>, AdminError>
where
C: Clone + fmt::Debug + PartialEq + JsonSchema,
{
self.assert_admin(deps.as_ref(), &info.sender)?;
let admin_str = match new_admin.as_ref() {
Some(admin) => admin.to_string(),
None => "None".to_string(),
};
let attributes = vec![
attr("action", "update_admin"),
attr("admin", admin_str),
attr("sender", info.sender),
];
self.set(deps, new_admin)?;
Ok(Response::new().add_attributes(attributes))
}
sourcepub fn is_admin<Q: CustomQuery>(
&self,
deps: Deps<'_, Q>,
caller: &Addr
) -> StdResult<bool>
pub fn is_admin<Q: CustomQuery>(
&self,
deps: Deps<'_, Q>,
caller: &Addr
) -> StdResult<bool>
Returns Ok(true) if this is an admin, Ok(false) if not and an Error if we hit an error with Api or Storage usage
sourcepub fn assert_admin<Q: CustomQuery>(
&self,
deps: Deps<'_, Q>,
caller: &Addr
) -> Result<(), AdminError>
pub fn assert_admin<Q: CustomQuery>(
&self,
deps: Deps<'_, Q>,
caller: &Addr
) -> Result<(), AdminError>
Like is_admin but returns AdminError::NotAdmin if not admin. Helper for a nice one-line auth check.
Examples found in repository?
src/hooks.rs (line 87)
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
pub fn execute_add_hook<C, Q: CustomQuery>(
&self,
admin: &Admin,
deps: DepsMut<Q>,
info: MessageInfo,
addr: Addr,
) -> Result<Response<C>, HookError>
where
C: Clone + fmt::Debug + PartialEq + JsonSchema,
{
admin.assert_admin(deps.as_ref(), &info.sender)?;
self.add_hook(deps.storage, addr.clone())?;
let attributes = vec![
attr("action", "add_hook"),
attr("hook", addr),
attr("sender", info.sender),
];
Ok(Response::new().add_attributes(attributes))
}
pub fn execute_remove_hook<C, Q: CustomQuery>(
&self,
admin: &Admin,
deps: DepsMut<Q>,
info: MessageInfo,
addr: Addr,
) -> Result<Response<C>, HookError>
where
C: Clone + fmt::Debug + PartialEq + JsonSchema,
{
admin.assert_admin(deps.as_ref(), &info.sender)?;
self.remove_hook(deps.storage, addr.clone())?;
let attributes = vec![
attr("action", "remove_hook"),
attr("hook", addr),
attr("sender", info.sender),
];
Ok(Response::new().add_attributes(attributes))
}
More examples
src/admin.rs (line 77)
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
pub fn execute_update_admin<C, Q: CustomQuery>(
&self,
deps: DepsMut<Q>,
info: MessageInfo,
new_admin: Option<Addr>,
) -> Result<Response<C>, AdminError>
where
C: Clone + fmt::Debug + PartialEq + JsonSchema,
{
self.assert_admin(deps.as_ref(), &info.sender)?;
let admin_str = match new_admin.as_ref() {
Some(admin) => admin.to_string(),
None => "None".to_string(),
};
let attributes = vec![
attr("action", "update_admin"),
attr("admin", admin_str),
attr("sender", info.sender),
];
self.set(deps, new_admin)?;
Ok(Response::new().add_attributes(attributes))
}