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    pub type_: ContractEventType,
44    pub body: ContractEventBody,
45}
46
47impl ReadXdr for ContractEvent {
48    #[cfg(feature = "std")]
49    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
50        r.with_limited_depth(|r| {
51            Ok(Self {
52                ext: ExtensionPoint::read_xdr(r)?,
53                contract_id: Option::<ContractId>::read_xdr(r)?,
54                type_: ContractEventType::read_xdr(r)?,
55                body: ContractEventBody::read_xdr(r)?,
56            })
57        })
58    }
59}
60
61impl WriteXdr for ContractEvent {
62    #[cfg(feature = "std")]
63    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
64        w.with_limited_depth(|w| {
65            self.ext.write_xdr(w)?;
66            self.contract_id.write_xdr(w)?;
67            self.type_.write_xdr(w)?;
68            self.body.write_xdr(w)?;
69            Ok(())
70        })
71    }
72}