#substrate #xdr #stellar

substrate-stellar-xdr

A coder/decoder of Stellar XDR types

15 releases

0.2.9 Jul 15, 2021
0.2.8 Jul 15, 2021
0.2.6 Jun 21, 2021
0.1.5 Jun 16, 2021

#17 in #xdr

Apache-2.0

335KB
8K SLoC

DEPRECATED

This crate is deprecated, it is now part of the Substrate Stellar SDK.

A coder/decoder of Stellar XDR types

This repository generates a Rust decoder and encoder of all XDR types used in Stellar. The code is generated via the Substrate Stellar XDR generator.

Usage

This is example code to decode and encode a Stellar transaction.

use substrate_stellar_xdr::{xdr, xdr_codec::XdrCodec};

const ENVELOPE: &str =
    "AAAAAgAAAAC9xFYU1gQJeH4apEfzJkMCsW5DL4GEWRpyVjQHOlWVzgAAAZA\
    CGsQoAAQytgAAAAAAAAAAAAAAAgAAAAAAAAADAAAAAVhMUEcAAAAAxxJMrxQQOx9raxDm3\
    lINsLvksi7tj1BCQXzWTtqigbgAAAAAAAAAAAbK5N8CprKDAExLQAAAAAAAAAAAAAAAAAA\
    AAAMAAAAAAAAAAVhMUEcAAAAAxxJMrxQQOx9raxDm3lINsLvksi7tj1BCQXzWTtqigbgAA\
    AAAlV2+xQAEaBMAJiWgAAAAAAAAAAAAAAAAAAAAATpVlc4AAABAaX11e1dGcDkXrFT5s3Q\
    N6x3v4kQqJ/1VIjqO00y6OStd70/aYiXR35e4289RvmBTudJ5Q05PaRsD8p1qa17VDQ==";

fn main() {
    let envelope = xdr::TransactionEnvelope::from_base64_xdr(ENVELOPE).unwrap();
    println!("{:#?}", envelope);
    assert_eq!(xdr, envelope.to_xdr());
}

All Stellar XDR types are defined in the module xdr. Each type implements the xdr_codex::XdrCodec trait, which defines the following two useful methods:

  • fn to_xdr(&self) -> Vec<u8>: encode as binary XDR
  • fn to_base64_xdr(&self) -> Vec<u8>: encode as XDR, afterwards encode result as base64
  • from_xdr<T: AsRef<[u8]>>(input: T) -> Result<Self, DecodeError>: decode binary XDR
  • from_base64_xdr<T: AsRef<[u8]>>(input: T) -> Result<Self, DecodeError>: decode as base64, then decode result as XDR

Features

  • all-types: when specified, will generate all types – otherwise only those types are generated that are in the dependency tree of the types TransactionEnvelope, TransactionResult, TransactionMeta, EnvelopeType and TransactionSignaturePayload

Dependencies

~250KB