1#![doc = include_str!("../README.md")]
2#![cfg_attr(target_arch = "wasm32", no_std)]
3
4#[cfg(not(target_arch = "wasm32"))]
5extern crate std;
6
7pub use xrpl_macros::blob;
9pub use xrpl_macros::currency;
10pub use xrpl_macros::hash256;
11pub use xrpl_macros::pubkey;
12pub use xrpl_macros::r_address;
13pub use xrpl_macros::smart_contract;
14pub use xrpl_macros::smart_escrow;
15
16pub mod core;
17pub mod ctx;
18pub mod fields;
19pub mod host;
20pub mod sfield;
21pub(crate) mod tx_flags;
22pub mod types;
23
24#[cfg(doc)]
31#[doc = include_str!("../docs/comprehensive-guide.md")]
32pub mod guide {}
33
34#[cfg(target_arch = "wasm32")]
37#[panic_handler]
38fn panic(_info: &::core::panic::PanicInfo) -> ! {
39 ::core::arch::wasm32::unreachable();
42}
43
44#[inline(always)]
45fn hex_char_to_nibble(c: u8) -> Option<u8> {
46 #[cfg(target_arch = "wasm32")]
48 {
49 if c >= b'0' && c <= b'9' {
51 Some(c - b'0')
52 } else if c >= b'a' && c <= b'f' {
53 Some(c - b'a' + 10)
54 } else if c >= b'A' && c <= b'F' {
55 Some(c - b'A' + 10)
56 } else {
57 None
58 }
59 }
60 #[cfg(not(target_arch = "wasm32"))]
61 {
62 match c {
65 b'0'..=b'9' => Some(c - b'0'),
66 b'a'..=b'f' => Some(c - b'a' + 10),
67 b'A'..=b'F' => Some(c - b'A' + 10),
68 _ => None,
69 }
70 }
71}
72
73#[inline(always)]
86pub fn decode_hex_32(hex: &[u8; 64]) -> Option<[u8; 32]> {
87 let mut out = [0u8; 32];
88
89 macro_rules! decode_byte {
91 ($i:expr) => {{
92 let high = hex_char_to_nibble(hex[$i * 2])?;
93 let low = hex_char_to_nibble(hex[$i * 2 + 1])?;
94 out[$i] = (high << 4) | low;
95 }};
96 }
97
98 decode_byte!(0);
99 decode_byte!(1);
100 decode_byte!(2);
101 decode_byte!(3);
102 decode_byte!(4);
103 decode_byte!(5);
104 decode_byte!(6);
105 decode_byte!(7);
106 decode_byte!(8);
107 decode_byte!(9);
108 decode_byte!(10);
109 decode_byte!(11);
110 decode_byte!(12);
111 decode_byte!(13);
112 decode_byte!(14);
113 decode_byte!(15);
114 decode_byte!(16);
115 decode_byte!(17);
116 decode_byte!(18);
117 decode_byte!(19);
118 decode_byte!(20);
119 decode_byte!(21);
120 decode_byte!(22);
121 decode_byte!(23);
122 decode_byte!(24);
123 decode_byte!(25);
124 decode_byte!(26);
125 decode_byte!(27);
126 decode_byte!(28);
127 decode_byte!(29);
128 decode_byte!(30);
129 decode_byte!(31);
130
131 Some(out)
132}
133
134#[inline(always)]
147pub fn decode_hex_20(hex: &[u8; 40]) -> Option<[u8; 20]> {
148 let mut out = [0u8; 20];
149
150 macro_rules! decode_byte {
152 ($i:expr) => {{
153 let high = hex_char_to_nibble(hex[$i * 2])?;
154 let low = hex_char_to_nibble(hex[$i * 2 + 1])?;
155 out[$i] = (high << 4) | low;
156 }};
157 }
158
159 decode_byte!(0);
160 decode_byte!(1);
161 decode_byte!(2);
162 decode_byte!(3);
163 decode_byte!(4);
164 decode_byte!(5);
165 decode_byte!(6);
166 decode_byte!(7);
167 decode_byte!(8);
168 decode_byte!(9);
169 decode_byte!(10);
170 decode_byte!(11);
171 decode_byte!(12);
172 decode_byte!(13);
173 decode_byte!(14);
174 decode_byte!(15);
175 decode_byte!(16);
176 decode_byte!(17);
177 decode_byte!(18);
178 decode_byte!(19);
179
180 Some(out)
181}