Skip to main content

xrpl/models/
mod.rs

1//! Top-level modules for the models package.
2//!
3//! Order of models:
4//! 1. Type of model
5//! 2. Required common fields in alphabetical order
6//! 3. Optional common fields in alphabetical order
7//! 4. Required specific fields in alphabetical order
8//! 5. Optional specific fields in alphabetical order
9
10#[cfg(feature = "models")]
11#[allow(clippy::too_many_arguments)]
12pub mod ledger;
13#[cfg(feature = "models")]
14#[allow(clippy::too_many_arguments)]
15pub mod requests;
16#[cfg(feature = "models")]
17#[allow(clippy::too_many_arguments)]
18pub mod results;
19#[cfg(feature = "models")]
20#[allow(clippy::too_many_arguments)]
21pub mod transactions;
22
23mod amount;
24mod credential_authorization;
25mod currency;
26mod exceptions;
27mod flag_collection;
28mod model;
29
30pub use amount::*;
31pub use credential_authorization::*;
32pub use currency::*;
33pub use exceptions::*;
34pub use flag_collection::*;
35pub use model::*;
36
37use alloc::borrow::Cow;
38use derive_new::new;
39use serde::{Deserialize, Serialize};
40
41/// A PathStep represents an individual step along a Path.
42#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Default, Clone, new)]
43#[serde(rename_all = "PascalCase")]
44pub struct PathStep<'a> {
45    account: Option<Cow<'a, str>>,
46    currency: Option<Cow<'a, str>>,
47    issuer: Option<Cow<'a, str>>,
48    r#type: Option<u8>,
49    type_hex: Option<Cow<'a, str>>,
50}
51
52impl<'a> PathStep<'a> {
53    /// Set the account field
54    pub fn with_account(mut self, account: Cow<'a, str>) -> Self {
55        self.account = Some(account);
56        self
57    }
58
59    /// Set the currency field
60    pub fn with_currency(mut self, currency: Cow<'a, str>) -> Self {
61        self.currency = Some(currency);
62        self
63    }
64
65    /// Set the issuer field
66    pub fn with_issuer(mut self, issuer: Cow<'a, str>) -> Self {
67        self.issuer = Some(issuer);
68        self
69    }
70
71    /// Set the type field
72    pub fn with_type(mut self, r#type: u8) -> Self {
73        self.r#type = Some(r#type);
74        self
75    }
76
77    /// Set the type_hex field
78    pub fn with_type_hex(mut self, type_hex: Cow<'a, str>) -> Self {
79        self.type_hex = Some(type_hex);
80        self
81    }
82}
83
84#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, derive_new::new)]
85#[serde(rename_all = "PascalCase")]
86pub struct XChainBridge<'a> {
87    pub issuing_chain_door: Cow<'a, str>,
88    pub issuing_chain_issue: Currency<'a>,
89    pub locking_chain_door: Cow<'a, str>,
90    pub locking_chain_issue: Currency<'a>,
91}
92
93/// For use with serde defaults.
94fn default_false() -> Option<bool> {
95    Some(false)
96}
97
98/// Trait for validating currencies in models. This is needed to use xrpl-rust-macros for deriving validation methods.
99/// This trait is implemented by models that contain fields of type `Amount`, `XRPAmount`, `IssuedCurrencyAmount`, `Currency`, `XRP`, or `IssuedCurrency`.
100/// It provides a method `validate_currencies` that checks if the provided values are valid according to the XRPL specifications.
101pub trait ValidateCurrencies {
102    fn validate_currencies(&self) -> crate::models::XRPLModelResult<()>;
103}