elrond_wasm_derive/parse/attributes/
event_attr.rs

1use super::{attr_names::*, util::*};
2
3pub struct EventAttribute {
4    pub identifier: String,
5}
6
7impl EventAttribute {
8    pub fn parse(attr: &syn::Attribute) -> Option<Self> {
9        is_attr_one_string_arg(attr, ATTR_EVENT).map(|arg_str| EventAttribute {
10            identifier: arg_str,
11        })
12    }
13}
14
15pub struct LegacyEventAttribute {
16    pub identifier: Vec<u8>,
17}
18
19impl LegacyEventAttribute {
20    pub fn parse(attr: &syn::Attribute) -> Option<LegacyEventAttribute> {
21        match is_attr_one_string_arg(attr, ATTR_LEGACY_EVENT) {
22            None => None,
23            Some(event_str) => {
24                assert!(
25                    event_str.starts_with("0x"),
26                    "event id should start with '0x'"
27                );
28                assert!(
29                    event_str.len() == 64 + 2,
30                    "event id should be 64 characters long (32 bytes)"
31                );
32                let substr = &event_str[2..];
33                let result_str = substr.to_string();
34                match hex::decode(result_str) {
35                    Ok(v) => Some(LegacyEventAttribute { identifier: v }),
36                    Err(_) => panic!("could not parse event id"),
37                }
38            },
39        }
40    }
41}