Skip to main content

xrpl/models/transactions/
exceptions.rs

1use crate::{
2    core::exceptions::XRPLCoreException,
3    models::transactions::{account_set::AccountSetFlag, payment::PaymentFlag},
4};
5use alloc::string::String;
6use thiserror_no_std::Error;
7
8#[derive(Debug, PartialEq, Error)]
9pub enum XRPLTransactionException {
10    #[error("{0}")]
11    XRPLAccountSetError(#[from] XRPLAccountSetException),
12    #[error("{0}")]
13    XRPLClawbackError(#[from] XRPLClawbackException),
14    #[error("{0}")]
15    XRPLDIDSetError(#[from] XRPLDIDSetException),
16    #[error("{0}")]
17    XRPLNFTokenCancelOfferError(#[from] XRPLNFTokenCancelOfferException),
18    #[error("{0}")]
19    XRPLNFTokenCreateOfferError(#[from] XRPLNFTokenCreateOfferException),
20    #[error("{0}")]
21    XRPLPaymentError(#[from] XRPLPaymentException),
22    #[error("{0}")]
23    XRPLSignerListSetError(#[from] XRPLSignerListSetException),
24    #[error("{0}")]
25    XRPLXChainClaimError(#[from] XRPLXChainClaimException),
26    #[error("{0}")]
27    XRPLXChainCreateBridgeError(#[from] XRPLXChainCreateBridgeException),
28    #[error("{0}")]
29    XRPLXChainCreateClaimIDError(#[from] XRPLXChainCreateClaimIDException),
30    #[error("{0}")]
31    XRPLXChainModifyBridgeError(#[from] XRPLXChainModifyBridgeException),
32    #[error("{0}")]
33    XRPLAMMCreateError(#[from] XRPLAMMCreateException),
34    #[error("{0}")]
35    XRPLCoreError(#[from] XRPLCoreException),
36    #[error("The transaction must be signed")]
37    TxMustBeSigned,
38}
39
40#[cfg(feature = "std")]
41impl alloc::error::Error for XRPLTransactionException {}
42
43#[derive(Debug, PartialEq, Error)]
44pub enum XRPLTransactionFieldException {
45    #[error("There is no transaction common field `{0:?}`")]
46    InvalidCommonField(String),
47    #[error("There is no account field named `{0:?}`")]
48    UnknownAccountField(String),
49}
50
51#[derive(Debug, PartialEq, Error)]
52pub enum XRPLAccountSetException {
53    /// A field can only be defined if a transaction flag is set.
54    #[error("For the field `{field:?}` to be defined it is required to set the flag `{flag:?}`")]
55    FieldRequiresFlag { field: String, flag: AccountSetFlag },
56    /// An account set flag can only be set if a field is defined.
57    #[error("For the flag `{flag:?}` to be set it is required to define the field `{field:?}`")]
58    FlagRequiresField { flag: AccountSetFlag, field: String },
59    /// Am account set flag can not be set and unset at the same time.
60    #[error("A flag cannot be set and unset at the same time (found {found:?})")]
61    SetAndUnsetSameFlag { found: AccountSetFlag },
62    /// A field was defined and an account set flag that is required for that field was unset.
63    #[error(
64        "The field `{field:?}` cannot be defined if its required flag `{flag:?}` is being unset"
65    )]
66    SetFieldWhenUnsetRequiredFlag { field: String, flag: AccountSetFlag },
67}
68
69#[cfg(feature = "std")]
70impl alloc::error::Error for XRPLAccountSetException {}
71
72#[derive(Debug, Clone, PartialEq, Eq, Error)]
73pub enum XRPLNFTokenCancelOfferException {
74    /// A collection was defined to be empty.
75    #[error("The value of the field `{field:?}` is not allowed to be empty (type `{r#type:?}`). If the field is optional, define it to be `None`")]
76    CollectionEmpty { field: String, r#type: String },
77}
78
79#[cfg(feature = "std")]
80impl alloc::error::Error for XRPLNFTokenCancelOfferException {}
81
82#[derive(Debug, Clone, PartialEq, Eq, Error)]
83pub enum XRPLNFTokenCreateOfferException {
84    /// An optional value must be defined in a certain context.
85    #[error("The optional field `{field:?}` is required to be defined for {context:?}")]
86    OptionRequired { field: String, context: String },
87    /// An optional value is not allowed to be defined in a certain context.
88    #[error("The optional field `{field:?}` is not allowed to be defined for {context:?}")]
89    IllegalOption { field: String, context: String },
90}
91
92#[cfg(feature = "std")]
93impl alloc::error::Error for XRPLNFTokenCreateOfferException {}
94
95#[derive(Debug, Clone, PartialEq, Eq, Error)]
96pub enum XRPLPaymentException {
97    /// An optional value must be defined in a certain context.
98    #[error("The optional field `{field:?}` is required to be defined for {context:?}")]
99    OptionRequired { field: String, context: String },
100    /// An optional value is not allowed to be defined in a certain context.
101    #[error("The optional field `{field:?}` is not allowed to be defined for {context:?}")]
102    IllegalOption { field: String, context: String },
103    /// A fields value is not allowed to be the same as another fields value, in a certain context.
104    #[error("The value of the field `{field1:?}` is not allowed to be the same as the value of the field `{field2:?}`, for {context:?}")]
105    ValueEqualsValueInContext {
106        field1: String,
107        field2: String,
108        context: String,
109    },
110    /// An account set flag can only be set if a field is defined.
111    #[error("For the flag `{flag:?}` to be set it is required to define the field `{field:?}`")]
112    FlagRequiresField { flag: PaymentFlag, field: String },
113}
114
115#[cfg(feature = "std")]
116impl alloc::error::Error for XRPLPaymentException {}
117
118#[derive(Debug, Clone, PartialEq, Eq, Error)]
119#[non_exhaustive]
120pub enum XRPLSignerListSetException {
121    /// A field was defined that another field definition would delete.
122    #[error("The value of the field `{field1:?}` can not be defined with the field `{field2:?}` because it would cause the deletion of `{field1:?}`")]
123    ValueCausesValueDeletion { field1: String, field2: String },
124    /// A field is expected to have a certain value to be deleted.
125    #[error("The field `{field:?}` has the wrong value to be deleted (expected {expected:?}, found {found:?})")]
126    InvalidValueForValueDeletion {
127        field: String,
128        expected: u32,
129        found: u32,
130    },
131    /// A collection has too few items in it.
132    #[error(
133        "The value of the field `{field:?}` has too few items in it (min {min:?}, found {found:?})"
134    )]
135    CollectionTooFewItems {
136        field: String,
137        min: usize,
138        found: usize,
139    },
140    /// A collection has too many items in it.
141    #[error("The value of the field `{field:?}` has too many items in it (max {max:?}, found {found:?})")]
142    CollectionTooManyItems {
143        field: String,
144        max: usize,
145        found: usize,
146    },
147    /// A collection is not allowed to have duplicates in it.
148    #[error("The value of the field `{field:?}` has a duplicate in it (found {found:?})")]
149    CollectionItemDuplicate { field: String, found: String },
150    /// A collection contains an invalid value.
151    #[error("The field `{field:?}` contains an invalid value (found {found:?})")]
152    CollectionInvalidItem { field: String, found: String },
153    #[error("The field `signer_quorum` must be below or equal to the sum of `signer_weight` in `signer_entries` (max {max}, found {found})")]
154    SignerQuorumExceedsSignerWeight { max: u32, found: u32 },
155}
156
157#[cfg(feature = "std")]
158impl alloc::error::Error for XRPLSignerListSetException {}
159
160#[derive(Debug, Clone, PartialEq, Eq, Error)]
161#[non_exhaustive]
162pub enum XRPLXChainClaimException {
163    #[error("`amount` must match either `locking_chain_issue` or `issuing_chain_issue`")]
164    AmountMismatch,
165}
166
167#[cfg(feature = "std")]
168impl alloc::error::Error for XRPLXChainClaimException {}
169
170#[derive(Debug, Clone, PartialEq, Eq, Error)]
171#[non_exhaustive]
172pub enum XRPLXChainCreateBridgeException {
173    #[error("Cannot have the same door accounts on the locking and issuing chain")]
174    SameDoorAccounts,
175    #[error(
176        "The `account` field must either match the `locking_chain_door` or `issuing_chain_door`"
177    )]
178    AccountDoorMismatch,
179    #[error("Bridge must be XRP-XRP or IOU-IOU")]
180    CrossCurrencyBridgeNotAllowed,
181    #[error("Cannot have MinAccountCreateAmount if bridge is IOU-IOU")]
182    MinAccountCreateAmountForIOU,
183    #[error("`signature_reward` must be numeric")]
184    SignatureRewartMustBeNumberic,
185    #[error("`min_account_create_amount` must be numeric")]
186    MinAccountCreateAmountMustBeNumberic,
187}
188
189#[cfg(feature = "std")]
190impl alloc::error::Error for XRPLXChainCreateBridgeException {}
191
192#[derive(Debug, Clone, PartialEq, Eq, Error)]
193#[non_exhaustive]
194pub enum XRPLXChainCreateClaimIDException {
195    #[error("`other_chain_source` must be a valid XRPL address")]
196    OtherChainSourceIsInvalid,
197}
198
199#[cfg(feature = "std")]
200impl alloc::error::Error for XRPLXChainCreateClaimIDException {}
201
202#[derive(Debug, Clone, PartialEq, Eq, Error)]
203#[non_exhaustive]
204pub enum XRPLXChainModifyBridgeException {
205    #[error("Must either change `signature_reward`, change `min_account_create_amount`, or clear `min_account_create_amount`")]
206    MustChangeOrClear,
207    #[error("`account` must be either `locking_chain_door` or `issuing_chain_door`")]
208    AccountDoorMismatch,
209    #[error("Cannot have MinAccountCreateAmount if bridge is IOU-IOU")]
210    CannotHaveMinAccountCreateAmount,
211}
212
213#[derive(Debug, Clone, PartialEq, Eq, Error)]
214pub enum XRPLAMMCreateException {
215    #[error("The trading fee must be between 0 and {max:?} (found {found:?})")]
216    TradingFeeOutOfRange { max: u16, found: u16 },
217}
218
219#[cfg(feature = "std")]
220impl alloc::error::Error for XRPLAMMCreateException {}
221
222#[derive(Debug, Clone, PartialEq, Eq, Error)]
223pub enum XRPLDIDSetException {
224    #[error("Must have at least one of `data`, `did_document`, and `uri`")]
225    MustHaveAtLeastOneField,
226    #[error("At least one of the fields `data`, `did_document`, and `uri` must have a length greater than zero")]
227    AtLeastOneFieldMustBeNonEmpty,
228    #[error("The field `{field:?}` must be hex-encoded")]
229    InvalidFieldHex { field: String },
230    #[error("The field `{field:?}` must be <= {max} characters (found {found})")]
231    FieldTooLong {
232        field: String,
233        max: usize,
234        found: usize,
235    },
236    #[error("The field `{field:?}` must be hex-encoded and must be <= 512 characters (found {found_length})")]
237    InvalidFieldHexAndTooLong { field: String, found_length: usize },
238}
239
240#[cfg(feature = "std")]
241impl alloc::error::Error for XRPLDIDSetException {}
242
243#[derive(Debug, PartialEq, Error)]
244pub enum XRPLClawbackException {
245    #[error("Clawback amount must not be XRP — only issued currencies can be clawed back")]
246    AmountMustNotBeXRP,
247    #[error("The `holder` field must not be present for standard issued-currency (IOU) clawback")]
248    HolderMustNotBePresentForIOU,
249    #[error(
250        "For IOU clawback, `amount.issuer` must be the holder's address and must differ from `Account`"
251    )]
252    IssuerMustNotEqualAccount,
253    #[error("The `holder` field is required for MPT clawback")]
254    HolderRequiredForMPT,
255    #[error("The `holder` field must not equal the transaction `Account` (no self-clawback)")]
256    HolderMustNotEqualAccount,
257}
258
259#[cfg(feature = "std")]
260impl alloc::error::Error for XRPLClawbackException {}