Skip to main content

stellar_xdr/generated/
sc_contract_instance.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// ScContractInstance is an XDR Struct defined as:
5///
6/// ```text
7/// struct SCContractInstance {
8///     ContractExecutable executable;
9///     SCMap* storage;
10/// };
11/// ```
12///
13#[cfg_attr(feature = "alloc", derive(Default))]
14#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
15#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
16#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
17#[cfg_attr(
18    all(feature = "serde", feature = "alloc"),
19    serde_with::serde_as,
20    derive(serde::Serialize, serde::Deserialize),
21    serde(rename_all = "snake_case")
22)]
23#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
24pub struct ScContractInstance {
25    pub executable: ContractExecutable,
26    pub storage: Option<ScMap>,
27}
28
29impl ReadXdr for ScContractInstance {
30    #[cfg(feature = "std")]
31    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
32        r.with_limited_depth(|r| {
33            Ok(Self {
34                executable: ContractExecutable::read_xdr(r)?,
35                storage: Option::<ScMap>::read_xdr(r)?,
36            })
37        })
38    }
39}
40
41impl WriteXdr for ScContractInstance {
42    #[cfg(feature = "std")]
43    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
44        w.with_limited_depth(|w| {
45            self.executable.write_xdr(w)?;
46            self.storage.write_xdr(w)?;
47            Ok(())
48        })
49    }
50}