multiversx_sc_meta_lib/abi_json/
event_abi_json.rs

1use multiversx_sc::abi::*;
2use serde::{Deserialize, Serialize};
3
4#[derive(Serialize, Deserialize)]
5pub struct EventInputAbiJson {
6    #[serde(rename = "name")]
7    pub arg_name: String,
8
9    #[serde(rename = "type")]
10    pub type_name: String,
11
12    /// Bool that is only serialized when true
13    #[serde(default)]
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub indexed: Option<bool>,
16}
17
18impl From<&EventInputAbi> for EventInputAbiJson {
19    fn from(abi: &EventInputAbi) -> Self {
20        EventInputAbiJson {
21            arg_name: abi.arg_name.to_string(),
22            type_name: abi.type_name.clone(),
23            indexed: if abi.indexed { Some(true) } else { None },
24        }
25    }
26}
27
28impl From<&EventInputAbiJson> for EventInputAbi {
29    fn from(abi: &EventInputAbiJson) -> Self {
30        EventInputAbi {
31            arg_name: abi.arg_name.to_string(),
32            type_name: abi.type_name.clone(),
33            indexed: abi.indexed.unwrap_or(false),
34        }
35    }
36}
37
38impl From<EventInputAbiJson> for EventInputAbi {
39    fn from(abi: EventInputAbiJson) -> Self {
40        EventInputAbi::from(&abi)
41    }
42}
43
44#[derive(Serialize, Deserialize)]
45pub struct EventAbiJson {
46    #[serde(default)]
47    #[serde(skip_serializing_if = "Vec::is_empty")]
48    pub docs: Vec<String>,
49    pub identifier: String,
50    pub inputs: Vec<EventInputAbiJson>,
51}
52
53impl From<&EventAbi> for EventAbiJson {
54    fn from(abi: &EventAbi) -> Self {
55        EventAbiJson {
56            docs: abi.docs.iter().map(|d| d.to_string()).collect(),
57            identifier: abi.identifier.to_string(),
58            inputs: abi.inputs.iter().map(EventInputAbiJson::from).collect(),
59        }
60    }
61}
62
63impl From<&EventAbiJson> for EventAbi {
64    fn from(abi: &EventAbiJson) -> Self {
65        EventAbi {
66            docs: abi.docs.iter().map(|d| d.to_string()).collect(),
67            identifier: abi.identifier.to_string(),
68            inputs: abi.inputs.iter().map(EventInputAbi::from).collect(),
69        }
70    }
71}
72
73impl From<EventAbiJson> for EventAbi {
74    fn from(abi: EventAbiJson) -> Self {
75        EventAbi::from(&abi)
76    }
77}