1use alloc::string::String;
2use thiserror_no_std::Error;
3
4use crate::{utils::exceptions::ISOCodeException, XRPLSerdeJsonError};
5
6use super::{
7 addresscodec::exceptions::XRPLAddressCodecException,
8 binarycodec::{
9 exceptions::XRPLBinaryCodecException,
10 types::exceptions::{
11 XRPLHashException, XRPLSerializeArrayException, XRPLSerializeMapException,
12 XRPLTypeException, XRPLVectorException, XRPLXChainBridgeException,
13 },
14 },
15 keypairs::exceptions::XRPLKeypairsException,
16};
17
18pub type XRPLCoreResult<T, E = XRPLCoreException> = core::result::Result<T, E>;
19
20#[derive(Debug, PartialEq, Error)]
21#[non_exhaustive]
22pub enum XRPLCoreException {
23 #[error("XRPL Address Codec error: {0}")]
24 XRPLAddressCodecError(#[from] XRPLAddressCodecException),
25 #[error("XRPL Binary Codec error: {0}")]
26 XRPLBinaryCodecError(#[from] XRPLBinaryCodecException),
27 #[error("XRPL Keypairs error: {0}")]
28 XRPLKeypairsError(#[from] XRPLKeypairsException),
29 #[error("serde_json error: {0}")]
30 SerdeJsonError(#[from] XRPLSerdeJsonError),
31 #[error("XRPL utils error: {0}")]
32 XRPLUtilsError(String), #[error("From hex error: {0}")]
34 FromHexError(#[from] hex::FromHexError),
35 #[error("ISO code error: {0}")]
36 ISOCodeError(#[from] ISOCodeException),
37 #[error("Base58 error: {0}")]
38 Bs58Error(#[from] bs58::decode::Error),
39}
40
41impl From<XRPLTypeException> for XRPLCoreException {
42 fn from(error: XRPLTypeException) -> Self {
43 XRPLCoreException::XRPLBinaryCodecError(XRPLBinaryCodecException::XRPLTypeError(error))
44 }
45}
46
47impl From<XRPLSerializeArrayException> for XRPLCoreException {
48 fn from(error: XRPLSerializeArrayException) -> Self {
49 XRPLCoreException::XRPLBinaryCodecError(XRPLBinaryCodecException::XRPLTypeError(
50 XRPLTypeException::XRPLSerializeArrayException(error),
51 ))
52 }
53}
54
55impl From<XRPLSerializeMapException> for XRPLCoreException {
56 fn from(error: XRPLSerializeMapException) -> Self {
57 XRPLCoreException::XRPLBinaryCodecError(XRPLBinaryCodecException::XRPLTypeError(
58 XRPLTypeException::XRPLSerializeMapException(error),
59 ))
60 }
61}
62
63impl From<XRPLXChainBridgeException> for XRPLCoreException {
64 fn from(error: XRPLXChainBridgeException) -> Self {
65 XRPLCoreException::XRPLBinaryCodecError(XRPLBinaryCodecException::XRPLTypeError(
66 XRPLTypeException::XRPLXChainBridgeError(error),
67 ))
68 }
69}
70
71impl From<XRPLHashException> for XRPLCoreException {
72 fn from(error: XRPLHashException) -> Self {
73 XRPLCoreException::XRPLBinaryCodecError(XRPLBinaryCodecException::XRPLTypeError(
74 XRPLTypeException::XRPLHashError(error),
75 ))
76 }
77}
78
79impl From<XRPLVectorException> for XRPLCoreException {
80 fn from(error: XRPLVectorException) -> Self {
81 XRPLCoreException::XRPLBinaryCodecError(XRPLBinaryCodecException::XRPLTypeError(
82 XRPLTypeException::XRPLVectorError(error),
83 ))
84 }
85}
86
87#[cfg(feature = "std")]
88impl alloc::error::Error for XRPLCoreException {}