Skip to content
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

adding support for json #83

Open
leejw51crypto opened this issue May 30, 2021 · 15 comments · May be fixed by #459
Open

adding support for json #83

leejw51crypto opened this issue May 30, 2021 · 15 comments · May be fixed by #459

Comments

@leejw51crypto
Copy link

leejw51crypto commented May 30, 2021

messages in the tx are encoded with protobuf,
need to know class first to decode by typeurl

if those messages can be parsed into serde_json, it would be easy to display
how about adding serde json support in compiling rust files from proto files?
(in prost)

@leejw51crypto leejw51crypto changed the title add support for json adding support for json May 30, 2021
@tony-iqlusion
Copy link
Member

We'd definitely like to add JSON support. Some complicating factors are a planned transition to "Proto JSON" from the previous "Amino JSON" was put on hiatus, or at least that's my understanding, but it may be out-of-date.

It'd be good to examine current and future strategies for JSON support in tendermint-rs so we can align with what they're doing, and ideally reuse some of their work:

informalsystems/tendermint-rs#654

@devashishdxt
Copy link
Contributor

devashishdxt commented May 27, 2022

@tony-iqlusion Can we use pbjson for this?

@tony-iqlusion
Copy link
Member

@devashishdxt unfortunately it seems like the JSON that's required (e.g. by ibc-rs/Hermes) differs from the standard Protobuf JSON, or at least that's my understanding.

See ample discussion on informalsystems/tendermint-rs#654

@scalalang2
Copy link

What if we add struct attributes ?
See this link : tokio-rs/prost#75 (comment)

@tony-iqlusion
Copy link
Member

If there's consensus that Cosmos SDK will eventually migrate to Protobuf JSON, then I'm fine with using something like pbjson like @devashishdxt recommended.

@hxrts
Copy link
Contributor

hxrts commented Oct 26, 2022

relevant cosmwasm discussion CosmWasm/cosmwasm#1448

@ewoolsey
Copy link

ewoolsey commented Dec 7, 2022

Any updates on this? I'm trying to build a cosmos-ledger library and running into a wall. I need to be ale to convert an Any into JSON to display on the ledger, and can't figure out how to move forwards.

@ewoolsey
Copy link

ewoolsey commented Dec 7, 2022

As a side note, is there currently any workaround I can use to get this functionality? I've been trying for an hour or two and I can't seem to come up with a way to get json from an Any, or any of the other message types for that matter.

@tony-iqlusion
Copy link
Member

Any contains a serialized proto, so you won't ever be able to just "convert it into JSON".

Instead you'll first need to convert it to the appropriate concrete type for a type_url, and then once you have an actual protobuf type, that type can potentially be serialized by pbjson.

Again, that's something we can potentially support, although AFAIK everything else is currently using the legacy Amino JSON so it won't provide interop. But it would work for your kind of use case, or if someone wanted to build a JSON RPC API.

@ewoolsey
Copy link

ewoolsey commented Dec 7, 2022

Yes sorry I wasn't completely clear, I don't need to convert to json for Any, but rather for all of types that are Msg. Even just #[derive(Serialize)] would work for my use case. Would it be useful to submit a PR with Serialize, Deserialize, derived on all of the Msg types in cosmrs? Could put it behind a feature gate as well.

@tony-iqlusion
Copy link
Member

No, we don't want to add a bespoke JSON format. It really needs to be pbjson or Amino JSON, and I would generally prefer not to support the latter except as a last resort if a Protobuf JSON migration upstream falls through as it will require a lot of manual work

@ewoolsey
Copy link

ewoolsey commented Dec 7, 2022

Gotcha, so am I stuck with re-deriving all the Msg structs myself? Or do you see another way for me to achieve that?

@tony-iqlusion
Copy link
Member

A PR adding pbjson support seems reasonable to me

@ewoolsey
Copy link

ewoolsey commented Dec 9, 2022

I have no experience with that library and I'm not really sure what that would entail. Which types in particular should pbjson be applied to? Would this just apply to the types in cosmrs? or are you talking about all the proto definitions?

@tony-iqlusion
Copy link
Member

It automatically builds serde-serializable structs for all types in the Protobuf schema, whose structure conforms to the Protobuf JSON Mapping

https://docs.rs/pbjson-build/latest/pbjson_build/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants