-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add framework for converting XDR structures to JSON #249
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shaptic
force-pushed
the
json-response-format
branch
from
July 17, 2024 02:43
3928422
to
a143442
Compare
Shaptic
force-pushed
the
json-response-format
branch
from
July 17, 2024 02:49
a143442
to
37c8e92
Compare
… into json-response-format
Shaptic
force-pushed
the
json-response-format
branch
from
August 5, 2024 22:57
e8553c4
to
1ef0940
Compare
Shaptic
force-pushed
the
json-response-format
branch
from
August 6, 2024 00:03
fb4239e
to
641c06f
Compare
Shaptic
force-pushed
the
json-response-format
branch
2 times, most recently
from
August 6, 2024 06:46
07799d4
to
5ce8937
Compare
Shaptic
force-pushed
the
json-response-format
branch
from
August 6, 2024 17:07
c7f2086
to
ae2897a
Compare
tamirms
reviewed
Aug 9, 2024
tamirms
reviewed
Aug 9, 2024
tamirms
reviewed
Aug 9, 2024
tamirms
approved these changes
Aug 9, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Shaptic
force-pushed
the
json-response-format
branch
from
August 12, 2024 20:36
11b6aa3
to
2ae24b3
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
This PR adds support for bsae64-encoded XDR fields to instead be returned as unpacked JSON objects.
New Request Parameter
We introduce a new, optional parameter to all endpoints with XDR outputs:
When omitted, the behavior does not change and we encode fields as base64.
New Response Fields
There are new field names for the JSONified versions of XDR structures. Any field with an
Xdr
suffix (e.g.,resultXdr
ingetTransaction()
) will be replaced with one that has aJson
suffix (e.g.,resultJson
) that is a JSON object verbosely and completely describing the XDR structure.Certain XDR-encoded fields do not have an
Xdr
suffix, but those also have a*Json
equivalent and are listed below:topic
->topicJson
,value
->valueJson
key
->keyJson
,xdr
->dataJson
xdr
->entryJson
transactionData
,events
,results.auth
,restorePreamble.transactionData
,stateChanges.key|before|after
all have aJson
suffix, andresults.xdr
is nowresults.returnValueJson
Notes for reviewers
lib.rs
has the Rust code to perform the XDR -> JSON conversion viastellar_xdr
.xdr_json.h
just has the header definitions to define what is accessible from Go -> Rust.conversion.go
has the actual binding invocation:convertAnyBytes
is the one that does the low-level Go -> C/FFI -> Rust workTransactionToJSON
is an isolated way to see how the conversion is done for a transaction structureget_transaction.go
. Each one of these has three sets of changes:Json
(serialized) andJSON
(Golang) suffix with a 1:1 mapping to their corresponding base64-encoded fields that should always be ajson.RawMessage
.switch
statement in the handler that uses the newxdr2json
package (i.e.conversion.go
) to convert XDR structures to JSON.Why
Closes #124.
Known Limitations
Remaining Items
getTransaction
getTransactions
getLedgerEntry
getLedgerEntries
getEvents
sendTransaction
simulateTransaction
Alternative Implementations
Would it be possible to extend
xdrgen
to actually have.JSON()
-like methods attached? This would be a significant lift there, since it'd need to do the Go <-> Rust FFI, but the calling code would be far cleaner and we'd get JSON output "for free" across any Golang project that usedstellar/go/xdr
...