Skip to main content

stellar_xdr/generated/
muxed_ed25519_account.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// MuxedEd25519Account is an XDR Struct defined as:
5///
6/// ```text
7/// struct MuxedEd25519Account
8/// {
9///     uint64 id;
10///     uint256 ed25519;
11/// };
12/// ```
13///
14#[cfg_attr(feature = "alloc", derive(Default))]
15#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
16#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
17#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
18#[cfg_attr(
19    all(feature = "serde", feature = "alloc"),
20    derive(serde_with::SerializeDisplay)
21)]
22pub struct MuxedEd25519Account {
23    pub id: u64,
24    pub ed25519: Uint256,
25}
26
27impl ReadXdr for MuxedEd25519Account {
28    #[cfg(feature = "std")]
29    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
30        r.with_limited_depth(|r| {
31            Ok(Self {
32                id: u64::read_xdr(r)?,
33                ed25519: Uint256::read_xdr(r)?,
34            })
35        })
36    }
37}
38
39impl WriteXdr for MuxedEd25519Account {
40    #[cfg(feature = "std")]
41    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
42        w.with_limited_depth(|w| {
43            self.id.write_xdr(w)?;
44            self.ed25519.write_xdr(w)?;
45            Ok(())
46        })
47    }
48}
49#[cfg(all(feature = "serde", feature = "alloc"))]
50impl<'de> serde::Deserialize<'de> for MuxedEd25519Account {
51    fn deserialize<D>(deserializer: D) -> core::result::Result<Self, D::Error>
52    where
53        D: serde::Deserializer<'de>,
54    {
55        use serde::Deserialize;
56        #[derive(Deserialize)]
57        struct MuxedEd25519Account {
58            id: u64,
59            ed25519: Uint256,
60        }
61        #[derive(Deserialize)]
62        #[serde(untagged)]
63        enum MuxedEd25519AccountOrString<'a> {
64            Str(&'a str),
65            String(String),
66            MuxedEd25519Account(MuxedEd25519Account),
67        }
68        match MuxedEd25519AccountOrString::deserialize(deserializer)? {
69            MuxedEd25519AccountOrString::Str(s) => s.parse().map_err(serde::de::Error::custom),
70            MuxedEd25519AccountOrString::String(s) => s.parse().map_err(serde::de::Error::custom),
71            MuxedEd25519AccountOrString::MuxedEd25519Account(MuxedEd25519Account {
72                id,
73                ed25519,
74            }) => Ok(self::MuxedEd25519Account { id, ed25519 }),
75        }
76    }
77}