xrpl_mithril_types/lib.rs
1#![doc(html_logo_url = "https://raw.githubusercontent.com/KyleWMiller/xrpl-mithril/main/assets/mithrilLogo.png")]
2//! Core protocol types for the XRP Ledger.
3//!
4//! This crate provides the fundamental types used throughout the XRPL protocol:
5//! accounts, amounts, currency codes, hashes, timestamps, and variable-length blobs.
6//!
7//! All types use the newtype pattern to prevent type confusion at compile time.
8//! Invalid states are unrepresentable — constructors validate inputs.
9//!
10//! # Examples
11//!
12//! Parsing an account address and constructing an XRP amount:
13//!
14//! ```
15//! use xrpl_types::{AccountId, XrpAmount};
16//!
17//! let account: AccountId = "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh".parse().unwrap();
18//! let amount = XrpAmount::from_drops(1_000_000).unwrap(); // 1 XRP
19//!
20//! assert_eq!(account.to_string(), "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh");
21//! assert_eq!(amount.drops(), 1_000_000);
22//! ```
23//!
24//! Building an issued currency amount:
25//!
26//! ```
27//! use xrpl_types::{AccountId, IssuedAmount, IssuedValue, CurrencyCode};
28//!
29//! let issuer: AccountId = "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh".parse().unwrap();
30//! let value = IssuedValue::from_decimal_string("1.5").unwrap();
31//! let currency = CurrencyCode::from_ascii("USD").unwrap();
32//!
33//! let amount = IssuedAmount { value, currency, issuer };
34//! assert_eq!(amount.value.to_decimal_string(), "1.5");
35//! ```
36//!
37//! Working with transaction and ledger hashes:
38//!
39//! ```
40//! use xrpl_types::Hash256;
41//!
42//! let hash = Hash256::from_hex(
43//! "C53ECF838647FA5A4C780377025FEC7999AB4182590510CA461444B207AB74A9"
44//! ).unwrap();
45//! assert_eq!(hash.as_bytes().len(), 32);
46//! ```
47
48#![forbid(unsafe_code)]
49
50pub mod account;
51pub mod amount;
52pub mod blob;
53pub mod currency;
54pub mod error;
55pub mod hash;
56pub mod serde_helpers;
57pub mod timestamp;
58
59pub use account::AccountId;
60pub use amount::{Amount, IssuedAmount, IssuedValue, MptAmount, XrpAmount};
61pub use blob::Blob;
62pub use currency::{CurrencyCode, Issue, MptIssuanceId};
63pub use error::TypeError;
64pub use hash::{Hash128, Hash160, Hash192, Hash256, UInt384, UInt512, UInt96};
65pub use timestamp::RippleTimestamp;