multiversx_sc/abi/
event_abi.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
use super::*;
use alloc::{
    string::{String, ToString},
    vec::Vec,
};

#[derive(Clone, Debug)]
pub struct EventInputAbi {
    pub arg_name: String,
    pub type_name: TypeName,
    pub indexed: bool,
}

#[derive(Clone, Debug)]
pub struct EventAbi {
    pub docs: Vec<String>,
    pub identifier: String,
    pub inputs: Vec<EventInputAbi>,
}

impl EventAbi {
    /// Used in code generation.
    pub fn new(docs: &[&str], identifier: &str) -> Self {
        EventAbi {
            docs: docs.iter().map(|s| s.to_string()).collect(),
            identifier: identifier.to_string(),
            inputs: Vec::new(),
        }
    }

    /// Used in code generation.
    pub fn add_input<T: TypeAbi>(&mut self, arg_name: &str, indexed: bool) {
        self.inputs.push(EventInputAbi {
            arg_name: arg_name.to_string(),
            type_name: T::type_name(),
            indexed,
        });
    }
}