multiversx_sc_meta_lib/abi_json/
esdt_attribute_abi_json.rs

1use std::collections::BTreeMap;
2
3use multiversx_sc::abi::EsdtAttributeAbi;
4use serde::{Deserialize, Serialize};
5
6use super::{
7    convert_type_descriptions_to_json, empty_type_description_container, EsdtAttributeJson,
8    TypeDescriptionJson,
9};
10
11/// Represents an entire ESDT attribute ABI file. The type descriptions only show up here.
12#[derive(Serialize, Deserialize)]
13#[serde(rename_all = "camelCase")]
14pub struct EsdtAttributeAbiJson {
15    pub esdt_attribute: EsdtAttributeJson,
16
17    #[serde(default)]
18    #[serde(skip_serializing_if = "BTreeMap::is_empty")]
19    pub types: BTreeMap<String, TypeDescriptionJson>,
20}
21
22impl EsdtAttributeAbiJson {
23    pub fn new(attr: &EsdtAttributeAbi) -> Self {
24        EsdtAttributeAbiJson {
25            esdt_attribute: EsdtAttributeJson::from(attr),
26            types: convert_type_descriptions_to_json(&attr.type_descriptions),
27        }
28    }
29}
30
31impl From<&EsdtAttributeAbiJson> for EsdtAttributeAbi {
32    fn from(abi_json: &EsdtAttributeAbiJson) -> Self {
33        EsdtAttributeAbi {
34            ticker: abi_json.esdt_attribute.ticker.clone(),
35            ty: abi_json.esdt_attribute.ty.clone(),
36            type_descriptions: empty_type_description_container(), // TODO: @Laur should recursively call convert_json_to_type_descriptions
37        }
38    }
39}