Skip to main content

stellar_xdr/generated/
manage_buy_offer_op.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// ManageBuyOfferOp is an XDR Struct defined as:
5///
6/// ```text
7/// struct ManageBuyOfferOp
8/// {
9///     Asset selling;
10///     Asset buying;
11///     int64 buyAmount; // amount being bought. if set to 0, delete the offer
12///     Price price;     // price of thing being bought in terms of what you are
13///                      // selling
14///
15///     // 0=create a new offer, otherwise edit an existing offer
16///     int64 offerID;
17/// };
18/// ```
19///
20#[cfg_attr(feature = "alloc", derive(Default))]
21#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
22#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
23#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
24#[cfg_attr(
25    all(feature = "serde", feature = "alloc"),
26    serde_with::serde_as,
27    derive(serde::Serialize, serde::Deserialize),
28    serde(rename_all = "snake_case")
29)]
30#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
31pub struct ManageBuyOfferOp {
32    pub selling: Asset,
33    pub buying: Asset,
34    #[cfg_attr(
35        all(feature = "serde", feature = "alloc"),
36        serde_as(as = "NumberOrString")
37    )]
38    pub buy_amount: i64,
39    pub price: Price,
40    #[cfg_attr(
41        all(feature = "serde", feature = "alloc"),
42        serde_as(as = "NumberOrString")
43    )]
44    pub offer_id: i64,
45}
46
47impl ReadXdr for ManageBuyOfferOp {
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                selling: Asset::read_xdr(r)?,
53                buying: Asset::read_xdr(r)?,
54                buy_amount: i64::read_xdr(r)?,
55                price: Price::read_xdr(r)?,
56                offer_id: i64::read_xdr(r)?,
57            })
58        })
59    }
60}
61
62impl WriteXdr for ManageBuyOfferOp {
63    #[cfg(feature = "std")]
64    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
65        w.with_limited_depth(|w| {
66            self.selling.write_xdr(w)?;
67            self.buying.write_xdr(w)?;
68            self.buy_amount.write_xdr(w)?;
69            self.price.write_xdr(w)?;
70            self.offer_id.write_xdr(w)?;
71            Ok(())
72        })
73    }
74}