#xdr #define #contract #set #type #codec #decoding

no-std bin+lib stellar-xdr

Stellar XDR types, encoding, and decoding

13 releases (stable)

new 22.1.0 Dec 12, 2024
22.0.0 Nov 5, 2024
22.0.0-rc.1.1 Oct 1, 2024
21.2.0 Jul 15, 2024
0.0.1 Jul 29, 2022

#788 in Magic Beans

Download history 3518/week @ 2024-08-28 3353/week @ 2024-09-04 3116/week @ 2024-09-11 2763/week @ 2024-09-18 2753/week @ 2024-09-25 2990/week @ 2024-10-02 3275/week @ 2024-10-09 2505/week @ 2024-10-16 3315/week @ 2024-10-23 3839/week @ 2024-10-30 5109/week @ 2024-11-06 4533/week @ 2024-11-13 4138/week @ 2024-11-20 3610/week @ 2024-11-27 4498/week @ 2024-12-04 5274/week @ 2024-12-11

18,260 downloads per month
Used in 80 crates (32 directly)

Apache-2.0

4.5MB
109K SLoC

stellar-xdr

Library and CLI containing types and functionality for working with Stellar XDR.

Types are generated from XDR definitions hosted at stellar/stellar-xdr using xdrgen.

Usage

Library

To use the library, include in your toml:

stellar-xdr = { version = "...", default-features = true, features = [] }

Features

The crate has several features, tiers of functionality, ancillary functionality, and channels of XDR.

Default features: std, curr.

Teirs of functionality:

  1. std – The std feature provides all functionality (types, encode, decode), and is the default feature set.
  2. alloc – The alloc feature uses Box and Vec types for recursive references and arrays, and is automatically enabled if the std feature is enabled. The default global allocator is used. Support for a custom allocator will be added in #39. No encode or decode capability exists, only types. Encode and decode capability will be added in #46.
  3. If std or alloc are not enabled recursive and array types requires static lifetime values. No encode or decode capability exists. Encode and decode capability will be added in #47.

Ancillary functionality:

  1. base64 – Enables support for base64 encoding and decoding.
  2. serde – Enables support for serializing and deserializing types with the serde crate.
  3. serde_json – Enables support for built-in functionality specifically for serde_json. Often not required to use the types with serde_json, and only necessary to use utility functions that depend on serde_json.
  4. arbitrary – Enables support for interop with the arbitrary crate.
  5. hex – Enables support for hex in string representations of some types. Automatically enabled when serde is enabled.
  6. schemars – Enables support for JSON Schema generation. (Experimental)

Features marked experimental may disappear at anytime, see breaking changes at anytime, or and may be minimal implementations instead of complete.

Channels of XDR:

  • curr – XDR types built from the stellar/stellar-xdr curr branch.
  • next – XDR types built from the stellar/stellar-xdr next branch.

If a single channel is enabled the types are available at the root of the crate. If multiple channels are enabled they are available in modules at the root of the crate.

CLI

To use the CLI:

cargo install --locked stellar-xdr --version ... --features cli

Examples

Parse a TransactionEnvelope:

stellar-xdr decode --type TransactionEnvelope << -
AAAAA...
-

Parse a ScSpecEntry stream from a contract:

stellar-xdr +next decode --type ScSpecEntry --input stream-base64 --output json-formatted << -
AAAAA...
-

Parse a BucketEntry framed stream from a bucket file:

stellar-xdr decode --type BucketEntry --input stream-framed --output json-formatted bucket.xdr

Dependencies

~0.7–2MB
~43K SLoC