Crates.io | substrate-stellar-xdr |
lib.rs | substrate-stellar-xdr |
version | 0.2.9 |
source | src |
created_at | 2021-06-13 05:24:49.436719 |
updated_at | 2021-07-15 07:42:58.367463 |
description | A coder/decoder of Stellar XDR types |
homepage | |
repository | https://github.com/pendulum-chain/substrate-stellar-xdr-generator |
max_upload_size | |
id | 409490 |
size | 334,068 |
This crate is deprecated, it is now part of the Substrate Stellar SDK.
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.
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 XDRfn to_base64_xdr(&self) -> Vec<u8>
: encode as XDR, afterwards encode result as base64from_xdr<T: AsRef<[u8]>>(input: T) -> Result<Self, DecodeError>
: decode binary XDRfrom_base64_xdr<T: AsRef<[u8]>>(input: T) -> Result<Self, DecodeError>
: decode as base64, then decode result as XDRall-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