stellar_xdr/lib.rs
1#![forbid(unsafe_code)]
2#![cfg_attr(not(feature = "std"), no_std)]
3#![cfg_attr(docs, feature(doc_cfg))]
4// TODO: Remove these clippy doc comment allows after improving the
5// auto-generated docs.
6#![allow(clippy::tabs_in_doc_comments)]
7#![allow(clippy::doc_markdown)]
8#![allow(clippy::doc_lazy_continuation)]
9#![allow(unused_attributes)]
10
11//! Library and CLI containing types and functionality for working with Stellar
12//! XDR.
13//!
14//! Types are generated from XDR definitions hosted at [stellar/stellar-xdr]
15//! using the Rust XDR generator in `xdr-generator-rust/`.
16//!
17//! [stellar/stellar-xdr]: https://github.com/stellar/stellar-xdr
18//!
19//! ## Support
20//!
21//! The most recent stellar-xdr major release is supported with critical security fixes.
22//! Critical security issues may be backported to earlier versions if practical, but not guaranteed.
23//! General bugs are only fixed on, and new features are only added to, the latest major release.
24//!
25//! ## Usage
26//!
27//! ### Library
28//! To use the library, include in your toml:
29//!
30//! ```toml
31//! stellar-xdr = { version = "...", default-features = true, features = [] }
32//! ```
33//!
34//! #### Features
35//!
36//! The crate has several features, tiers of functionality, and ancillary
37//! functionality.
38//!
39//! Default features: `std`.
40//!
41//! Tiers of functionality:
42//!
43//! 1. `std` – The std feature provides all functionality (types, encode,
44//! decode), and is the default feature set.
45//! 2. `alloc` – The alloc feature uses `Box` and `Vec` types for recursive
46//! references and arrays, and is automatically enabled if the std feature is
47//! enabled. The default global allocator is used. Support for a custom
48//! allocator will be added in [#39]. No encode or decode capability exists,
49//! only types. Encode and decode capability will be added in [#46].
50//! 3. If std or alloc are not enabled recursive and array types requires static
51//! lifetime values. No encode or decode capability exists. Encode and decode
52//! capability will be added in [#47].
53//!
54//! [#39]: https://github.com/stellar/rs-stellar-xdr/issues/39
55//! [#46]: https://github.com/stellar/rs-stellar-xdr/issues/46
56//! [#47]: https://github.com/stellar/rs-stellar-xdr/issues/47
57//!
58//! Ancillary functionality:
59//!
60//! 1. `type_enum` – Enables the generated dynamic `Type` and `TypeVariant`
61//! APIs for runtime-selected XDR decoding, encoding, schema generation.
62//! 2. `base64` – Enables support for base64 encoding and decoding.
63//! 3. `serde` – Enables support for serializing and deserializing types with
64//! the serde crate.
65//! 4. `serde_json` – Enables support for built-in functionality specifically
66//! for serde_json. Often not required to use the types with serde_json, and
67//! only necessary to use utility functions that depend on serde_json.
68//! 5. `arbitrary` – Enables support for interop with the arbitrary crate.
69//! 6. `hex` – Enables support for hex in string representations of some types.
70//! Automatically enabled when serde is enabled.
71//! 7. `schemars` – Enables support for JSON Schema generation. (Experimental)
72//!
73//! Features marked experimental may disappear at anytime, see breaking changes
74//! at anytime, or and may be minimal implementations instead of complete.
75//!
76//! ### CLI
77//!
78//! To use the CLI:
79//!
80//! ```console
81//! cargo install --locked stellar-xdr --version ... --features cli
82//! ```
83//!
84//! #### Examples
85//!
86//! Parse a `TransactionEnvelope`:
87//! ```console
88//! stellar-xdr decode --type TransactionEnvelope << -
89//! AAAAA...
90//! -
91//! ```
92//!
93//! Parse a `ScSpecEntry` stream from a contract:
94//! ```console
95//! stellar-xdr decode --type ScSpecEntry --input stream-base64 --output json-formatted << -
96//! AAAAA...
97//! -
98//! ```
99//!
100//! Parse a `BucketEntry` framed stream from a bucket file:
101//! ```console
102//! stellar-xdr decode --type BucketEntry --input stream-framed --output json-formatted bucket.xdr
103//! ```
104
105#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
106#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
107pub struct Version<'a> {
108 pub pkg: &'a str,
109 pub rev: &'a str,
110 pub xdr: &'a str,
111 /// List of XDR feature flags enabled in this build.
112 #[cfg_attr(feature = "serde", serde(skip))]
113 pub features: &'a [&'a str],
114}
115pub const VERSION: Version = Version {
116 pkg: env!("CARGO_PKG_VERSION"),
117 rev: env!("GIT_REVISION"),
118 xdr: include_str!("../xdr-version"),
119 features: &[
120 #[cfg(feature = "test_feature")]
121 "test_feature",
122 #[cfg(feature = "cap_0084_muxed_contract")]
123 "cap_0084_muxed_contract",
124 ],
125};
126
127#[cfg(feature = "schemars")]
128pub mod schemars;
129
130#[allow(clippy::empty_line_after_doc_comments)]
131#[allow(clippy::derivable_impls, clippy::len_zero)]
132mod generated;
133mod ledgerkey;
134pub use generated::*;
135
136mod default;
137mod jsonschema;
138mod str;
139
140mod scval_conversions;
141pub use scval_conversions::*;
142mod account_conversions;
143mod transaction_conversions;
144
145mod scval_validations;
146pub use scval_validations::*;
147
148#[cfg(feature = "alloc")]
149mod scmap;
150
151mod tx_auths;
152mod tx_hash;
153
154#[cfg(feature = "cli")]
155pub mod cli;
156
157#[cfg(feature = "alloc")]
158pub(crate) mod num256;
159
160#[cfg(feature = "alloc")]
161pub(crate) mod num128;