js-stellar-base icon indicating copy to clipboard operation
js-stellar-base copied to clipboard

Allow people to generate transactions from JSON

Open morleyzhi opened this issue 6 years ago • 3 comments

Instead of using TransactionBuilder to imperatively add stuff to transactions, generate this all from a static JSON object.

morleyzhi avatar Feb 08 '19 22:02 morleyzhi

You guys might be interested by the JSON format I use as an intermediate representation in cosmic-lib: example

I thing the steps to make something like this standard are:

  1. Define a syntax for parameterized transactions - This doesn't need to be JSON-specific but rather a key-value tree abstraction from which JSON format can get derived, but also other key-value formats if the need arise.
  2. Get this validated as a SEP.
  3. Derive the XDR<->JSON implementation from that SEP.

There's also @stanford-scs txRep, which guarantees an exact convertibility between XDR and human-readable format.

IIRC the discussion, there are various corner cases such as a parameter being undefined vs 0 that would defeat backward conversion of the simplified format I use.

I did not switch to txRep because I found it too verbose for my use case - but maybe it is possible to come up with some sort of synthesis that retains advantages of both formats.

Anyway, I think my point here is that it would be good to start by write an generic standard that can be shared across implementations before adding this feature into stellar-base JS.

MisterTicot avatar Aug 28 '19 12:08 MisterTicot

@MisterTicot btw, I have a POC here https://github.com/abuiles/json-xdr which you could play with, you can use that library to convert between JSON and XDR. See this file for examples on how to use it with Stellar https://github.com/abuiles/json-xdr/blob/master/src/integration.test.ts

abuiles avatar Aug 28 '19 14:08 abuiles

As part of our work building Soroban we've built a solid and round-trippable JSON representation for XDR in the Rust library that we're using in some second line features (i.e. not frontline features with a backwards compatibility guarantee). I think it would be really interesting if we're able to reflect identically that JSON representation in a JavaScript implementation, or any other implementation for that matter.

leighmcculloch avatar Jun 16 '23 05:06 leighmcculloch