-
Notifications
You must be signed in to change notification settings - Fork 410
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
Using custom any resolver to StargateQuerier
#1454
Comments
This is only a smaller point of the whole problem, but please note that in https://protobuf.dev/programming-guides/proto3/#json the flattening of the |
@webmaster128 Thanks for the reference! I see and fixed the content. |
Changing the response encoding would be a breaking change for existing contracts. We can not simply do this without a lot of communication and coordination work. I do see your use case but the query plugin provides an extension point to set your own Stargate query handler and use that with your community. Our default is The |
@alpe I think it the best solution for my usecase. Thanks for the wonderful solution! |
## Description After discussing with wasmd team, the best way to have custom wasm any for desmos-bindings is injecting a custom any resolver to the codec. CosmWasm/wasmd#1454 (comment) This PR creates a custom `InterfaceRegistry` with a custom any resolver function `Resolve` in order to have a custom any JSON encoding in base64 for our contract SDK. As a result, we can use `wasmd` directly without forking it. In the other word, it moves the logic of [this commit](https://github.com/desmos-labs/wasmd/commit/b7700dfcc403b58c9702f0c45f4016b9668a287e) into Desmos. <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://docs.cosmos.network/v0.44/building-modules/intro.html) - [ ] included the necessary unit and integration [tests](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
Context
Currently
StargateQuerier
is using default any resolver provided by codec.Codec, which unpacksAny
type to the underlying structure then builds the JSON message for wasmvm. That makes parsing the proto message difficult since parsing underlying structure intoAny
requires a custom decoder inside contract.The definition of default codec any resolver can be traced here:
https://github.com/cosmos/cosmos-sdk/blob/13e61bd0c5c7950d137bbdfb171f95d87179ed29/codec/proto_codec.go#L148
https://github.com/cosmos/cosmos-sdk/blob/13e61bd0c5c7950d137bbdfb171f95d87179ed29/codec/json.go#L16
For example, Desmos profiles is a
Any
proto message, the json pass to wasmvm is:Instead of a
Any
JSON can be easily deserializedAs a result, it is not easy to deserialize the
Any
structure in Rust like:Solution
The solution can be implementing a custom any resolver to unpack to
Any
JSON without underlying structure, it would be like the following commit, then theAny
deserialization will be easy in contract side:https://github.com/desmos-labs/wasmd/commit/b7700dfcc403b58c9702f0c45f4016b9668a287e
What do you think? I can create a pull request if you think it is worth to do.
Edited: 05:00 UTC +0, June 20, 2023
The text was updated successfully, but these errors were encountered: