Skip to main content

xrpl/
lib.rs

1// Copyright 2021 589Labs Developers.
2// Licensed under the ISC License
3
4//! Utilities for interacting with the XRP Ledger.
5//!
6//! A pure Rust implementation for interacting with the XRP Ledger. The
7//! xrpl-rust crate simplifies the hardest parts of XRP Ledger interaction
8//! including serialization and transaction signing while providing idiomatic
9//! Rust functionality for XRP Ledger transactions and core server API
10//! (rippled) objects.
11//!
12//! # Quick Start
13//!
14//! TODO
15//!
16//! # The XRP Ledger
17//!
18//! For the user guide and further documentation, please read
19//! [XRP Ledger](https://xrpl.org/docs.html).
20#![cfg_attr(not(feature = "std"), no_std)]
21#![allow(dead_code)] // Remove eventually
22#![allow(clippy::result_large_err)]
23
24use ::core::fmt::Display;
25
26use alloc::string::{String, ToString};
27use thiserror_no_std::Error;
28
29#[cfg(not(feature = "std"))]
30extern crate alloc;
31#[cfg(feature = "std")]
32extern crate std as alloc;
33
34#[cfg(feature = "helpers")]
35pub mod account;
36// `asynch::exceptions` requires `models` for `XRPLModelException`; the rest of
37// `asynch` is gated internally on individual features.
38#[cfg(feature = "models")]
39pub mod asynch;
40#[cfg(feature = "cli")]
41pub mod cli;
42#[cfg(any(feature = "json-rpc", feature = "websocket"))]
43pub mod clients;
44pub mod constants;
45#[cfg(feature = "core")]
46pub mod core;
47#[cfg(feature = "helpers")]
48pub mod ledger;
49pub mod macros;
50#[cfg(feature = "models")]
51pub mod models;
52#[cfg(all(feature = "core", feature = "models", feature = "wallet"))]
53pub mod signing;
54#[cfg(feature = "helpers")]
55pub mod transaction;
56#[cfg(feature = "utils")]
57pub mod utils;
58#[cfg(feature = "wallet")]
59pub mod wallet;
60
61pub extern crate serde_json;
62
63#[cfg(feature = "models")]
64mod _serde;
65
66#[cfg(all(
67    feature = "helpers",
68    not(any(
69        feature = "tokio-rt",
70        feature = "embassy-rt",
71        feature = "actix-rt",
72        feature = "async-std-rt",
73        feature = "futures-rt",
74        feature = "smol-rt"
75    ))
76))]
77compile_error!("Cannot enable `helpers` without enabling a runtime feature (\"*-rt\"). This is required for sleeping between retries internally.");
78#[cfg(all(
79    feature = "helpers",
80    not(any(feature = "json-rpc", feature = "websocket",))
81))]
82compile_error!("Cannot enable `helpers` without enabling a client feature (\"json-rpc\", \"websocket\"). This is required for interacting with the XRP Ledger.");
83
84#[derive(Debug, Error)]
85pub enum XRPLSerdeJsonError {
86    SerdeJsonError(serde_json::Error),
87    InvalidNoneError(String),
88    UnexpectedValueType {
89        expected: String,
90        found: serde_json::Value,
91    },
92}
93
94impl Display for XRPLSerdeJsonError {
95    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
96        match self {
97            XRPLSerdeJsonError::SerdeJsonError(err) => write!(f, "{}", err),
98            XRPLSerdeJsonError::InvalidNoneError(err) => {
99                write!(f, "Invalid None value on field: {}", err)
100            }
101            XRPLSerdeJsonError::UnexpectedValueType { expected, found } => {
102                write!(
103                    f,
104                    "Unexpected value type (expected: {}, found: {})",
105                    expected, found
106                )
107            }
108        }
109    }
110}
111
112impl From<serde_json::Error> for XRPLSerdeJsonError {
113    fn from(err: serde_json::Error) -> Self {
114        XRPLSerdeJsonError::SerdeJsonError(err)
115    }
116}
117
118impl PartialEq for XRPLSerdeJsonError {
119    fn eq(&self, other: &Self) -> bool {
120        self.to_string() == other.to_string()
121    }
122}