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
23use ::core::fmt::Display;
24
25use alloc::string::{String, ToString};
26use thiserror_no_std::Error;
27
28#[cfg(not(feature = "std"))]
29extern crate alloc;
30#[cfg(feature = "std")]
31extern crate std as alloc;
32
33#[cfg(feature = "helpers")]
34pub mod account;
35#[cfg(any(feature = "json-rpc", feature = "websocket", feature = "helpers"))]
36pub mod asynch;
37#[cfg(feature = "cli")]
38pub mod cli;
39#[cfg(any(feature = "json-rpc", feature = "websocket"))]
40pub mod clients;
41pub mod constants;
42#[cfg(feature = "core")]
43pub mod core;
44#[cfg(feature = "helpers")]
45pub mod ledger;
46pub mod macros;
47#[cfg(feature = "models")]
48pub mod models;
49#[cfg(feature = "helpers")]
50pub mod transaction;
51#[cfg(feature = "utils")]
52pub mod utils;
53#[cfg(feature = "wallet")]
54pub mod wallet;
55
56pub extern crate serde_json;
57
58#[cfg(feature = "models")]
59mod _serde;
60
61#[cfg(all(
62    feature = "helpers",
63    not(any(
64        feature = "tokio-rt",
65        feature = "embassy-rt",
66        feature = "actix-rt",
67        feature = "async-std-rt",
68        feature = "futures-rt",
69        feature = "smol-rt"
70    ))
71))]
72compile_error!("Cannot enable `helpers` without enabling a runtime feature (\"*-rt\"). This is required for sleeping between retries internally.");
73#[cfg(all(
74    feature = "helpers",
75    not(any(feature = "json-rpc", feature = "websocket",))
76))]
77compile_error!("Cannot enable `helpers` without enabling a client feature (\"json-rpc\", \"websocket\"). This is required for interacting with the XRP Ledger.");
78
79#[derive(Debug, Error)]
80pub enum XRPLSerdeJsonError {
81    SerdeJsonError(serde_json::Error),
82    InvalidNoneError(String),
83    UnexpectedValueType {
84        expected: String,
85        found: serde_json::Value,
86    },
87}
88
89impl Display for XRPLSerdeJsonError {
90    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
91        match self {
92            XRPLSerdeJsonError::SerdeJsonError(err) => write!(f, "{}", err),
93            XRPLSerdeJsonError::InvalidNoneError(err) => {
94                write!(f, "Invalid None value on field: {}", err)
95            }
96            XRPLSerdeJsonError::UnexpectedValueType { expected, found } => {
97                write!(
98                    f,
99                    "Unexpected value type (expected: {}, found: {})",
100                    expected, found
101                )
102            }
103        }
104    }
105}
106
107impl From<serde_json::Error> for XRPLSerdeJsonError {
108    fn from(err: serde_json::Error) -> Self {
109        XRPLSerdeJsonError::SerdeJsonError(err)
110    }
111}
112
113impl PartialEq for XRPLSerdeJsonError {
114    fn eq(&self, other: &Self) -> bool {
115        self.to_string() == other.to_string()
116    }
117}