Skip to main content

stellar_xdr/generated/
offer_entry.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// OfferEntry is an XDR Struct defined as:
5///
6/// ```text
7/// struct OfferEntry
8/// {
9///     AccountID sellerID;
10///     int64 offerID;
11///     Asset selling; // A
12///     Asset buying;  // B
13///     int64 amount;  // amount of A
14///
15///     /* price for this offer:
16///         price of A in terms of B
17///         price=AmountB/AmountA=priceNumerator/priceDenominator
18///         price is after fees
19///     */
20///     Price price;
21///     uint32 flags; // see OfferEntryFlags
22///
23///     // reserved for future use
24///     union switch (int v)
25///     {
26///     case 0:
27///         void;
28///     }
29///     ext;
30/// };
31/// ```
32///
33#[cfg_attr(feature = "alloc", derive(Default))]
34#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
35#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
36#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
37#[cfg_attr(
38    all(feature = "serde", feature = "alloc"),
39    serde_with::serde_as,
40    derive(serde::Serialize, serde::Deserialize),
41    serde(rename_all = "snake_case")
42)]
43#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
44pub struct OfferEntry {
45    pub seller_id: AccountId,
46    #[cfg_attr(
47        all(feature = "serde", feature = "alloc"),
48        serde_as(as = "NumberOrString")
49    )]
50    pub offer_id: i64,
51    pub selling: Asset,
52    pub buying: Asset,
53    #[cfg_attr(
54        all(feature = "serde", feature = "alloc"),
55        serde_as(as = "NumberOrString")
56    )]
57    pub amount: i64,
58    pub price: Price,
59    pub flags: u32,
60    pub ext: OfferEntryExt,
61}
62
63impl ReadXdr for OfferEntry {
64    #[cfg(feature = "std")]
65    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
66        r.with_limited_depth(|r| {
67            Ok(Self {
68                seller_id: AccountId::read_xdr(r)?,
69                offer_id: i64::read_xdr(r)?,
70                selling: Asset::read_xdr(r)?,
71                buying: Asset::read_xdr(r)?,
72                amount: i64::read_xdr(r)?,
73                price: Price::read_xdr(r)?,
74                flags: u32::read_xdr(r)?,
75                ext: OfferEntryExt::read_xdr(r)?,
76            })
77        })
78    }
79}
80
81impl WriteXdr for OfferEntry {
82    #[cfg(feature = "std")]
83    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
84        w.with_limited_depth(|w| {
85            self.seller_id.write_xdr(w)?;
86            self.offer_id.write_xdr(w)?;
87            self.selling.write_xdr(w)?;
88            self.buying.write_xdr(w)?;
89            self.amount.write_xdr(w)?;
90            self.price.write_xdr(w)?;
91            self.flags.write_xdr(w)?;
92            self.ext.write_xdr(w)?;
93            Ok(())
94        })
95    }
96}