-
Notifications
You must be signed in to change notification settings - Fork 2
/
execute.rs
61 lines (54 loc) · 1.86 KB
/
execute.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, DepsMut, MessageInfo, Response};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::{errors::RbacError, Role};
#[cw_serde]
pub enum RbacExecuteMsg {
Grant { address: Addr },
Revoke { address: Addr },
Transfer { to: Addr },
}
impl<'a> Role<'a> {
pub fn handle_execute(
&self,
deps: DepsMut,
info: MessageInfo,
msg: RbacExecuteMsg,
) -> Result<Response, RbacError> {
match msg {
RbacExecuteMsg::Grant { address } => {
self.grant(deps.storage, address.clone())?;
Ok(Response::new().add_attributes(vec![
("action", "grant"),
("role", self.name),
("address", address.as_str()),
]))
}
RbacExecuteMsg::Revoke { address } => {
self.revoke(deps.storage, address.clone())?;
Ok(Response::new().add_attributes(vec![
("action", "revoke"),
("role", self.name),
("address", address.as_str()),
]))
}
RbacExecuteMsg::Transfer { to } => {
self.check(deps.storage, &info.sender)?;
self.revoke(deps.storage, info.sender.clone())?;
self.grant(deps.storage, to.clone())?;
Ok(Response::new()
.add_attributes(vec![
("action", "revoke"),
("role", self.name),
("address", info.sender.as_str()),
])
.add_attributes(vec![
("action", "grant"),
("role", self.name),
("address", to.as_str()),
]))
}
}
}
}