Skip to main content

stellar_xdr/generated/
contract_event.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// ContractEvent is an XDR Struct defined as:
5///
6/// ```text
7/// struct ContractEvent
8/// {
9///     // We can use this to add more fields, or because it
10///     // is first, to change ContractEvent into a union.
11///     ExtensionPoint ext;
12///
13///     ContractID* contractID;
14///     ContractEventType type;
15///
16///     union switch (int v)
17///     {
18///     case 0:
19///         struct
20///         {
21///             SCVal topics<>;
22///             SCVal data;
23///         } v0;
24///     }
25///     body;
26/// };
27/// ```
28///
29#[cfg_attr(feature = "alloc", derive(Default))]
30#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
31#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
32#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
33#[cfg_attr(
34    all(feature = "serde", feature = "alloc"),
35    serde_with::serde_as,
36    derive(serde::Serialize, serde::Deserialize),
37    serde(rename_all = "snake_case")
38)]
39#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
40pub struct ContractEvent {
41    pub ext: ExtensionPoint,
42    pub contract_id: Option<ContractId>,
43    #[cfg_attr(
44        all(feature = "serde", feature = "alloc"),
45        serde(rename = "type", alias = "type_")
46    )]
47    #[cfg_attr(feature = "schemars", schemars(rename = "type"))]
48    pub type_: ContractEventType,
49    pub body: ContractEventBody,
50}
51
52impl ReadXdr for ContractEvent {
53    #[cfg(feature = "std")]
54    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
55        r.with_limited_depth(|r| {
56            Ok(Self {
57                ext: ExtensionPoint::read_xdr(r)?,
58                contract_id: Option::<ContractId>::read_xdr(r)?,
59                type_: ContractEventType::read_xdr(r)?,
60                body: ContractEventBody::read_xdr(r)?,
61            })
62        })
63    }
64}
65
66impl WriteXdr for ContractEvent {
67    #[cfg(feature = "std")]
68    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
69        w.with_limited_depth(|w| {
70            self.ext.write_xdr(w)?;
71            self.contract_id.write_xdr(w)?;
72            self.type_.write_xdr(w)?;
73            self.body.write_xdr(w)?;
74            Ok(())
75        })
76    }
77}