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