Skip to content
This repository has been archived by the owner on Jul 15, 2021. It is now read-only.

Experimental generator for a Rust decoder and encoder of Stellar XDR types

Notifications You must be signed in to change notification settings

pendulum-chain/substrate-stellar-xdr-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DEPRECATED

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

Generator of Stellar XDR type Encoder/Decoder

This repository generates a Rust decoder and encoder of all XDR types used in Stellar. The generated crate is to be used with Substrate.

This generates the crate substrate-stellar-xdr on crates.io.

How to use

Requirements

NodeJs, NPM, Docker, Cargo (to publish)

Step 1: Generate Rust code

This downloads the latest version of Stellar XDR type specification and generates according Rust code

npm install
npm run build

How it works

  • downloads the Stellar XDR type specification from GitHub repository stellar/stellar-core
  • uses the Stellar's own parser to generate a JavaScript version of the XDR type specification
    • this runs in a Docker container, a local Ruby installation is not required
    • this code is in the folder x2JavaScript
  • executes the generated JavaScript code to generate the Rust code
    • this code is in the folder js-xdr
  • copy static Rust files to the generated Rust code to complete the crate
    • the static Rust files are in the folder static

Step 2: Publish crate

This requires cargo to publish the generated crate to crates.io.

Don't forget to update the version in static/Cargo.toml and to run npm build afterwards.

npm run publish

Tests

Run a simple test suite via npm run test. This requires to execute Step 1 (specified above) first.

Assumptions

  • this code assumes that the only way cycles in types can occur is if an enum or struct type directly references itself (no indirect cycles)
    • otherwise we need to have Box way too often and types get cluttered
    • this assumption is currently true as the only cycle occurs in the type ClaimPredicate – and that cycle is direct
    • this assumption might not hold true in the future anymore
      • in that case start to introduce Box everytime an enum or struct references a non-primitive type that is not wrapped into a Vec

About

Experimental generator for a Rust decoder and encoder of Stellar XDR types

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published