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("XRPL MPTokenMetadata error: {0}")]
31 XRPLMPTokenMetadataError(#[from] XRPLMPTokenMetadataException),
32 #[error("ISO Code error: {0}")]
33 ISOCodeError(#[from] ISOCodeException),
34 #[error("Decimal error: {0}")]
35 DecimalError(#[from] rust_decimal::Error),
36 #[error("BigDecimal error: {0}")]
37 BigDecimalError(#[from] bigdecimal::ParseBigDecimalError),
38 #[error("serde_json error: {0}")]
39 SerdeJsonError(#[from] XRPLSerdeJsonError),
40 #[error("From Hex error: {0}")]
41 FromHexError(#[from] hex::FromHexError),
42 #[error("ParseInt error: {0}")]
43 ParseIntError(#[from] core::num::ParseIntError),
44 #[error("Invalid UTF-8")]
45 Utf8Error,
46}
47
48#[derive(Debug, Clone, PartialEq, Error)]
49#[non_exhaustive]
50pub enum XRPLTimeRangeException {
51 #[error("Invalid time before epoch (min: {min} found: {found})")]
52 InvalidTimeBeforeEpoch { min: i64, found: i64 },
53 #[error("Invalid time after epoch (max: {max} found: {found})")]
54 UnexpectedTimeOverflow { max: i64, found: i64 },
55 #[error("Invalid local time")]
56 InvalidLocalTime,
57}
58
59#[derive(Debug, Clone, PartialEq, Error)]
60#[non_exhaustive]
61pub enum XRPRangeException {
62 #[error("Invalid XRP amount")]
63 InvalidXRPAmount,
64 #[error("Invalid Issued Currency amount")]
65 InvalidICAmount,
66 #[error("Invalid value contains decimal")]
67 InvalidValueContainsDecimal,
68 #[error("Invalid XRP amount too small (min: {min} found: {found})")]
69 InvalidXRPAmountTooSmall { min: String, found: String },
70 #[error("Invalid XRP amount too large (max: {max} found: {found})")]
71 InvalidXRPAmountTooLarge { max: u64, found: String },
72 #[error("Invalid Issued Currency precision too small (min: {min} found: {found})")]
73 InvalidICPrecisionTooSmall { min: i32, found: i32 },
74 #[error("Invalid Issued Currency precision too large (max: {max} found: {found})")]
75 InvalidICPrecisionTooLarge { max: i32, found: i32 },
76 #[error("Invalid Drops amount too large (max: {max} found: {found})")]
77 InvalidDropsAmountTooLarge { max: String, found: String },
78 #[error("Invalid Issued Currency serialization length (expected: {expected} found: {found})")]
79 InvalidICSerializationLength { expected: usize, found: usize },
80 #[error("Invalid Issued Currency amount overflow (max: {max} found: {found})")]
81 UnexpectedICAmountOverflow { max: usize, found: usize },
82}
83
84#[derive(Debug, Clone, PartialEq, Error)]
85#[non_exhaustive]
86pub enum XRPLNFTIdException {
87 #[error("Invalid NFT ID length (expected: {expected} found: {found})")]
88 InvalidNFTIdLength { expected: usize, found: usize },
89}
90
91#[derive(Debug, Clone, PartialEq, Error)]
92#[non_exhaustive]
93pub enum XRPLXChainClaimIdException {
94 #[error("No XChainOwnedClaimID created")]
95 NoXChainOwnedClaimID,
96}
97
98#[cfg(feature = "std")]
99impl alloc::error::Error for XRPLXChainClaimIdException {}
100
101#[derive(Debug, Clone, PartialEq, Error)]
102#[non_exhaustive]
103pub enum XRPLMPTokenMetadataException {
104 #[error("MPTokenMetadata must be in hex format.")]
105 InvalidHex,
106 #[error("MPTokenMetadata must be a JSON object.")]
107 NotJsonObject,
108}
109
110#[cfg(feature = "std")]
111impl alloc::error::Error for XRPLMPTokenMetadataException {}
112
113#[derive(Debug, Clone, PartialEq, Error)]
114#[non_exhaustive]
115pub enum XRPLTxnParserException {
116 #[error("Missing field: {0}")]
117 MissingField(&'static str),
118}
119
120#[cfg(feature = "std")]
121impl alloc::error::Error for XRPLTxnParserException {}
122
123#[derive(Debug, Clone, PartialEq, Error)]
124#[non_exhaustive]
125pub enum ISOCodeException {
126 #[error("Invalid ISO code")]
127 InvalidISOCode,
128 #[error("Invalid ISO length")]
129 InvalidISOLength,
130 #[error("Invalid XRP bytes")]
131 InvalidXRPBytes,
132 #[error("Invalid Currency representation")]
133 UnsupportedCurrencyRepresentation,
134}
135
136impl From<core::str::Utf8Error> for XRPLUtilsException {
137 fn from(_: core::str::Utf8Error) -> Self {
138 XRPLUtilsException::Utf8Error
139 }
140}
141
142impl From<serde_json::Error> for XRPLUtilsException {
143 fn from(error: serde_json::Error) -> Self {
144 XRPLUtilsException::SerdeJsonError(error.into())
145 }
146}
147
148#[cfg(feature = "std")]
149impl alloc::error::Error for XRPLTimeRangeException {}
150
151#[cfg(feature = "std")]
152impl alloc::error::Error for XRPRangeException {}
153
154#[cfg(feature = "std")]
155impl alloc::error::Error for ISOCodeException {}
156
157#[cfg(feature = "std")]
158impl alloc::error::Error for XRPLUtilsException {}