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
28#[derive(Serialize, Deserialize)]
29pub struct EventAbiJson {
30    #[serde(default)]
31    #[serde(skip_serializing_if = "Vec::is_empty")]
32    pub docs: Vec<String>,
33    pub identifier: String,
34    pub inputs: Vec<EventInputAbiJson>,
35}
36
37impl From<&EventAbi> for EventAbiJson {
38    fn from(abi: &EventAbi) -> Self {
39        EventAbiJson {
40            docs: abi.docs.iter().map(|d| d.to_string()).collect(),
41            identifier: abi.identifier.to_string(),
42            inputs: abi.inputs.iter().map(EventInputAbiJson::from).collect(),
43        }
44    }
45}