stellar_xdr/generated/scp_statement.rs
1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// ScpStatement is an XDR Struct defined as:
5///
6/// ```text
7/// struct SCPStatement
8/// {
9/// NodeID nodeID; // v
10/// uint64 slotIndex; // i
11///
12/// union switch (SCPStatementType type)
13/// {
14/// case SCP_ST_PREPARE:
15/// struct
16/// {
17/// Hash quorumSetHash; // D
18/// SCPBallot ballot; // b
19/// SCPBallot* prepared; // p
20/// SCPBallot* preparedPrime; // p'
21/// uint32 nC; // c.n
22/// uint32 nH; // h.n
23/// } prepare;
24/// case SCP_ST_CONFIRM:
25/// struct
26/// {
27/// SCPBallot ballot; // b
28/// uint32 nPrepared; // p.n
29/// uint32 nCommit; // c.n
30/// uint32 nH; // h.n
31/// Hash quorumSetHash; // D
32/// } confirm;
33/// case SCP_ST_EXTERNALIZE:
34/// struct
35/// {
36/// SCPBallot commit; // c
37/// uint32 nH; // h.n
38/// Hash commitQuorumSetHash; // D used before EXTERNALIZE
39/// } externalize;
40/// case SCP_ST_NOMINATE:
41/// SCPNomination nominate;
42/// }
43/// pledges;
44/// };
45/// ```
46///
47#[cfg_attr(feature = "alloc", derive(Default))]
48#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
49#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
50#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
51#[cfg_attr(
52 all(feature = "serde", feature = "alloc"),
53 serde_with::serde_as,
54 derive(serde::Serialize, serde::Deserialize),
55 serde(rename_all = "snake_case")
56)]
57#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
58pub struct ScpStatement {
59 pub node_id: NodeId,
60 #[cfg_attr(
61 all(feature = "serde", feature = "alloc"),
62 serde_as(as = "NumberOrString")
63 )]
64 pub slot_index: u64,
65 pub pledges: ScpStatementPledges,
66}
67
68impl ReadXdr for ScpStatement {
69 #[cfg(feature = "std")]
70 fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
71 r.with_limited_depth(|r| {
72 Ok(Self {
73 node_id: NodeId::read_xdr(r)?,
74 slot_index: u64::read_xdr(r)?,
75 pledges: ScpStatementPledges::read_xdr(r)?,
76 })
77 })
78 }
79}
80
81impl WriteXdr for ScpStatement {
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.node_id.write_xdr(w)?;
86 self.slot_index.write_xdr(w)?;
87 self.pledges.write_xdr(w)?;
88 Ok(())
89 })
90 }
91}