revive_solc_json_interface/standard_json/output/contract/
mod.rs

1//! The `solc --standard-json` output contract.
2
3pub mod evm;
4
5use std::collections::BTreeMap;
6use std::collections::BTreeSet;
7
8use serde::Deserialize;
9use serde::Serialize;
10
11use self::evm::EVM;
12
13/// The `solc --standard-json` output contract.
14#[derive(Debug, Default, Serialize, Deserialize, Clone)]
15#[serde(rename_all = "camelCase")]
16pub struct Contract {
17    /// The contract ABI.
18    #[serde(default, skip_serializing_if = "serde_json::Value::is_null")]
19    pub abi: serde_json::Value,
20    /// The contract metadata.
21    #[serde(default, skip_serializing_if = "serde_json::Value::is_null")]
22    pub metadata: serde_json::Value,
23    /// The contract developer documentation.
24    #[serde(default, skip_serializing_if = "serde_json::Value::is_null")]
25    pub devdoc: serde_json::Value,
26    /// The contract user documentation.
27    #[serde(default, skip_serializing_if = "serde_json::Value::is_null")]
28    pub userdoc: serde_json::Value,
29    /// The contract storage layout.
30    #[serde(default, skip_serializing_if = "serde_json::Value::is_null")]
31    pub storage_layout: serde_json::Value,
32    /// The contract storage layout.
33    #[serde(default, skip_serializing_if = "serde_json::Value::is_null")]
34    pub transient_storage_layout: serde_json::Value,
35    /// Contract's bytecode and related objects
36    #[serde(default, skip_serializing_if = "Option::is_none")]
37    pub evm: Option<EVM>,
38    /// The contract IR code.
39    #[serde(default, skip_serializing_if = "Option::is_none")]
40    pub ir: Option<String>,
41    /// The contract optimized IR code.
42    #[serde(default, skip_serializing_if = "String::is_empty")]
43    pub ir_optimized: String,
44    /// The contract PolkaVM bytecode hash.
45    #[serde(default, skip_serializing_if = "Option::is_none")]
46    pub hash: Option<String>,
47    /// Unlinked factory dependencies.
48    #[serde(default, skip_deserializing)]
49    pub factory_dependencies_unlinked: BTreeSet<String>,
50    /// The contract factory dependencies.
51    #[serde(default, skip_deserializing)]
52    pub factory_dependencies: BTreeMap<String, String>,
53    /// Missing linkable libraries.
54    #[serde(default, skip_deserializing)]
55    pub missing_libraries: BTreeSet<String>,
56    /// Binary object format.
57    #[serde(default, skip_deserializing)]
58    pub object_format: Option<revive_common::ObjectFormat>,
59}
60
61impl Contract {
62    /// Checks if all fields are unset or empty.
63    pub fn is_empty(&self) -> bool {
64        self.abi.is_null()
65            && self.storage_layout.is_null()
66            && self.transient_storage_layout.is_null()
67            && self.metadata.is_null()
68            && self.devdoc.is_null()
69            && self.userdoc.is_null()
70            && self.ir_optimized.is_empty()
71            && self.evm.is_none()
72            && self.hash.is_none()
73            && self.factory_dependencies_unlinked.is_empty()
74            && self.factory_dependencies.is_empty()
75            && self.missing_libraries.is_empty()
76    }
77}