js-stellar-base
js-stellar-base copied to clipboard
Allow people to generate transactions from JSON
Instead of using TransactionBuilder to imperatively add stuff to transactions, generate this all from a static JSON object.
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:
- 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.
- Get this validated as a SEP.
- 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 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
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.