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
62
63
use cosmwasm_std::{Attribute, Event, Response};
use std::string::ToString;
pub struct ResponseHelper;
impl ResponseHelper {
pub fn new_module(module: &str, action: &str) -> Response {
Response::new()
.add_attribute("name", "komple_framework")
.add_attribute("module", module)
.add_attribute("action", action)
}
pub fn new_permission(permission: &str, action: &str) -> Response {
Response::new()
.add_attribute("name", "komple_framework")
.add_attribute("permission", permission)
.add_attribute("action", action)
}
}
pub struct EventHelper {
event: Event,
}
impl EventHelper {
pub fn new(event_name: impl Into<String>) -> EventHelper {
Self {
event: Event::new(event_name),
}
}
pub fn check_add_attribute<T: ToString>(
&mut self,
check: &Option<T>,
key: &str,
value: impl Into<String>,
) -> EventHelper {
if check.is_none() {
return Self {
event: self.event.clone(),
};
};
Self {
event: self.get().add_attribute(key, value),
}
}
pub fn add_attribute(self, key: impl Into<String>, value: impl Into<String>) -> EventHelper {
Self {
event: self.get().add_attribute(key, value),
}
}
pub fn add_attributes(self, attributes: Vec<Attribute>) -> EventHelper {
Self {
event: self.get().add_attributes(attributes),
}
}
pub fn get(&self) -> Event {
self.event.clone()
}
}