1use alloc::string::String;
4use thiserror_no_std::Error;
5
6#[cfg(feature = "models")]
7use crate::models::XRPLModelException;
8use crate::{core::exceptions::XRPLCoreException, XRPLSerdeJsonError};
9
10pub type XRPLUtilsResult<T, E = XRPLUtilsException> = core::result::Result<T, E>;
11
12#[derive(Debug, PartialEq, Error)]
13#[non_exhaustive]
14pub enum XRPLUtilsException {
15 #[error("XRPL Time Range error: {0}")]
16 XRPLTimeRangeError(#[from] XRPLTimeRangeException),
17 #[error("XRP Range error: {0}")]
18 XRPRangeError(#[from] XRPRangeException),
19 #[error("XRPL NFT ID error: {0}")]
20 XRPLNFTIdError(#[from] XRPLNFTIdException),
21 #[error("XRPL Core error: {0}")]
22 XRPLCoreError(#[from] XRPLCoreException),
23 #[cfg(feature = "models")]
24 #[error("XRPL Model error: {0}")]
25 XRPLModelError(#[from] XRPLModelException),
26 #[error("XRPL Txn Parser error: {0}")]
27 XRPLTxnParserError(#[from] XRPLTxnParserException),
28 #[error("XRPL XChain Claim ID error: {0}")]
29 XRPLXChainClaimIdError(#[from] XRPLXChainClaimIdException),
30 #[error("ISO Code error: {0}")]
31 ISOCodeError(#[from] ISOCodeException),
32 #[error("Decimal error: {0}")]
33 DecimalError(#[from] rust_decimal::Error),
34 #[error("BigDecimal error: {0}")]
35 BigDecimalError(#[from] bigdecimal::ParseBigDecimalError),
36 #[error("serde_json error: {0}")]
37 SerdeJsonError(#[from] XRPLSerdeJsonError),
38 #[error("From Hex error: {0}")]
39 FromHexError(#[from] hex::FromHexError),
40 #[error("ParseInt error: {0}")]
41 ParseIntError(#[from] core::num::ParseIntError),
42 #[error("Invalid UTF-8")]
43 Utf8Error,
44}
45
46#[derive(Debug, Clone, PartialEq, Error)]
47#[non_exhaustive]
48pub enum XRPLTimeRangeException {
49 #[error("Invalid time before epoch (min: {min} found: {found})")]
50 InvalidTimeBeforeEpoch { min: i64, found: i64 },
51 #[error("Invalid time after epoch (max: {max} found: {found})")]
52 UnexpectedTimeOverflow { max: i64, found: i64 },
53 #[error("Invalid local time")]
54 InvalidLocalTime,
55}
56
57#[derive(Debug, Clone, PartialEq, Error)]
58#[non_exhaustive]
59pub enum XRPRangeException {
60 #[error("Invalid XRP amount")]
61 InvalidXRPAmount,
62 #[error("Invalid Issued Currency amount")]
63 InvalidICAmount,
64 #[error("Invalid value contains decimal")]
65 InvalidValueContainsDecimal,
66 #[error("Invalid XRP amount too small (min: {min} found: {found})")]
67 InvalidXRPAmountTooSmall { min: String, found: String },
68 #[error("Invalid XRP amount too large (max: {max} found: {found})")]
69 InvalidXRPAmountTooLarge { max: u64, found: String },
70 #[error("Invalid Issued Currency precision too small (min: {min} found: {found})")]
71 InvalidICPrecisionTooSmall { min: i32, found: i32 },
72 #[error("Invalid Issued Currency precision too large (max: {max} found: {found})")]
73 InvalidICPrecisionTooLarge { max: i32, found: i32 },
74 #[error("Invalid Drops amount too large (max: {max} found: {found})")]
75 InvalidDropsAmountTooLarge { max: String, found: String },
76 #[error("Invalid Issued Currency serialization length (expected: {expected} found: {found})")]
77 InvalidICSerializationLength { expected: usize, found: usize },
78 #[error("Invalid Issued Currency amount overflow (max: {max} found: {found})")]
79 UnexpectedICAmountOverflow { max: usize, found: usize },
80}
81
82#[derive(Debug, Clone, PartialEq, Error)]
83#[non_exhaustive]
84pub enum XRPLNFTIdException {
85 #[error("Invalid NFT ID length (expected: {expected} found: {found})")]
86 InvalidNFTIdLength { expected: usize, found: usize },
87}
88
89#[derive(Debug, Clone, PartialEq, Error)]
90#[non_exhaustive]
91pub enum XRPLXChainClaimIdException {
92 #[error("No XChainOwnedClaimID created")]
93 NoXChainOwnedClaimID,
94}
95
96#[cfg(feature = "std")]
97impl alloc::error::Error for XRPLXChainClaimIdException {}
98
99#[derive(Debug, Clone, PartialEq, Error)]
100#[non_exhaustive]
101pub enum XRPLTxnParserException {
102 #[error("Missing field: {0}")]
103 MissingField(&'static str),
104}
105
106#[cfg(feature = "std")]
107impl alloc::error::Error for XRPLTxnParserException {}
108
109#[derive(Debug, Clone, PartialEq, Error)]
110#[non_exhaustive]
111pub enum ISOCodeException {
112 #[error("Invalid ISO code")]
113 InvalidISOCode,
114 #[error("Invalid ISO length")]
115 InvalidISOLength,
116 #[error("Invalid XRP bytes")]
117 InvalidXRPBytes,
118 #[error("Invalid Currency representation")]
119 UnsupportedCurrencyRepresentation,
120}
121
122impl From<core::str::Utf8Error> for XRPLUtilsException {
123 fn from(_: core::str::Utf8Error) -> Self {
124 XRPLUtilsException::Utf8Error
125 }
126}
127
128impl From<serde_json::Error> for XRPLUtilsException {
129 fn from(error: serde_json::Error) -> Self {
130 XRPLUtilsException::SerdeJsonError(error.into())
131 }
132}
133
134#[cfg(feature = "std")]
135impl alloc::error::Error for XRPLTimeRangeException {}
136
137#[cfg(feature = "std")]
138impl alloc::error::Error for XRPRangeException {}
139
140#[cfg(feature = "std")]
141impl alloc::error::Error for ISOCodeException {}
142
143#[cfg(feature = "std")]
144impl alloc::error::Error for XRPLUtilsException {}