Skip to main content

stellar_xdr/generated/
preconditions_v2.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// PreconditionsV2 is an XDR Struct defined as:
5///
6/// ```text
7/// struct PreconditionsV2
8/// {
9///     TimeBounds* timeBounds;
10///
11///     // Transaction only valid for ledger numbers n such that
12///     // minLedger <= n < maxLedger (if maxLedger == 0, then
13///     // only minLedger is checked)
14///     LedgerBounds* ledgerBounds;
15///
16///     // If NULL, only valid when sourceAccount's sequence number
17///     // is seqNum - 1.  Otherwise, valid when sourceAccount's
18///     // sequence number n satisfies minSeqNum <= n < tx.seqNum.
19///     // Note that after execution the account's sequence number
20///     // is always raised to tx.seqNum, and a transaction is not
21///     // valid if tx.seqNum is too high to ensure replay protection.
22///     SequenceNumber* minSeqNum;
23///
24///     // For the transaction to be valid, the current ledger time must
25///     // be at least minSeqAge greater than sourceAccount's seqTime.
26///     Duration minSeqAge;
27///
28///     // For the transaction to be valid, the current ledger number
29///     // must be at least minSeqLedgerGap greater than sourceAccount's
30///     // seqLedger.
31///     uint32 minSeqLedgerGap;
32///
33///     // For the transaction to be valid, there must be a signature
34///     // corresponding to every Signer in this array, even if the
35///     // signature is not otherwise required by the sourceAccount or
36///     // operations.
37///     SignerKey extraSigners<2>;
38/// };
39/// ```
40///
41#[cfg_attr(feature = "alloc", derive(Default))]
42#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
43#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
44#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
45#[cfg_attr(
46    all(feature = "serde", feature = "alloc"),
47    serde_with::serde_as,
48    derive(serde::Serialize, serde::Deserialize),
49    serde(rename_all = "snake_case")
50)]
51#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
52pub struct PreconditionsV2 {
53    pub time_bounds: Option<TimeBounds>,
54    pub ledger_bounds: Option<LedgerBounds>,
55    pub min_seq_num: Option<SequenceNumber>,
56    pub min_seq_age: Duration,
57    pub min_seq_ledger_gap: u32,
58    pub extra_signers: VecM<SignerKey, 2>,
59}
60
61impl ReadXdr for PreconditionsV2 {
62    #[cfg(feature = "std")]
63    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
64        r.with_limited_depth(|r| {
65            Ok(Self {
66                time_bounds: Option::<TimeBounds>::read_xdr(r)?,
67                ledger_bounds: Option::<LedgerBounds>::read_xdr(r)?,
68                min_seq_num: Option::<SequenceNumber>::read_xdr(r)?,
69                min_seq_age: Duration::read_xdr(r)?,
70                min_seq_ledger_gap: u32::read_xdr(r)?,
71                extra_signers: VecM::<SignerKey, 2>::read_xdr(r)?,
72            })
73        })
74    }
75}
76
77impl WriteXdr for PreconditionsV2 {
78    #[cfg(feature = "std")]
79    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
80        w.with_limited_depth(|w| {
81            self.time_bounds.write_xdr(w)?;
82            self.ledger_bounds.write_xdr(w)?;
83            self.min_seq_num.write_xdr(w)?;
84            self.min_seq_age.write_xdr(w)?;
85            self.min_seq_ledger_gap.write_xdr(w)?;
86            self.extra_signers.write_xdr(w)?;
87            Ok(())
88        })
89    }
90}