Skip to main content

multiversx_sc/abi/
event_abi.rs

1use super::*;
2use alloc::{
3    string::{String, ToString},
4    vec::Vec,
5};
6
7#[derive(Clone, Debug)]
8pub struct EventInputAbi {
9    pub arg_name: String,
10    pub type_name: TypeName,
11    pub indexed: bool,
12}
13
14#[derive(Clone, Debug)]
15pub struct EventAbi {
16    pub docs: Vec<String>,
17    pub identifier: String,
18    pub inputs: Vec<EventInputAbi>,
19}
20
21impl EventAbi {
22    /// Used in code generation.
23    pub fn new(docs: &[&str], identifier: &str) -> Self {
24        EventAbi {
25            docs: docs.iter().map(|s| s.to_string()).collect(),
26            identifier: identifier.to_string(),
27            inputs: Vec::new(),
28        }
29    }
30
31    /// Used in code generation.
32    pub fn add_input<T: TypeAbi>(&mut self, arg_name: &str, indexed: bool) {
33        self.inputs.push(EventInputAbi {
34            arg_name: arg_name.to_string(),
35            type_name: T::type_name(),
36            indexed,
37        });
38    }
39}