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

wip(keeper): implement json primitive return #2949

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

gfanton
Copy link
Member

@gfanton gfanton commented Oct 14, 2024

Yet another JSON PR 🎉

This is a simpler implementation of the JSON keeper result that introduces JSON primitive results in keeper MsgCall and MsgQuery result. To maintain backward compatibility, it's not enabled by default, and you have to specify the format in the request.

The result will be returned in the form of a parsable JSON array.

Currently, it will resolve types as follows:

  • PrimitiveKind -> raw value
  • Error/Stringer -> execute and return result
  • Object -> <oid:type> as string
  • Other -> <type> as string

This PR also adds a small utility command in gnokey called jquery that outputs a parsable JSON response. This command is flagged as experimental, as are all JSON features present in the handler/keeper.

Screenshot 2025-01-09 at 10 31 49

TODOs

  • Probably more tests
  • Need approval on how we represent object
Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

Signed-off-by: gfanton <[email protected]>
Signed-off-by: gfanton <[email protected]>
Signed-off-by: gfanton <[email protected]>
@github-actions github-actions bot added 🧾 package/realm Tag used for new Realms or Packages. 📦 🤖 gnovm Issues or PRs gnovm related 📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ gno.land Issues or PRs gno.land package related labels Oct 14, 2024
Copy link

codecov bot commented Oct 14, 2024

Codecov Report

Attention: Patch coverage is 60.00000% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
gnovm/pkg/gnolang/values.go 0.00% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Member

@thehowl thehowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall approach LGTM, let's roll with only supporting primitive types for now

gno.land/pkg/sdk/vm/keeper.go Outdated Show resolved Hide resolved
gno.land/pkg/sdk/vm/msgs.go Outdated Show resolved Hide resolved
gnovm/pkg/gnolang/values.go Show resolved Hide resolved
tm2/pkg/bft/abci/types/types.go Outdated Show resolved Hide resolved
QueryRender = "qrender"
QueryFuncs = "qfuncs"
QueryEval = "qeval"
QueryEvalJSON = "qeval/json" // EXPERIMENTAL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I prefer a single call with a flag to specify the format.
Any other opinions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A solution could be to have "qeval" data as a marshaled MsgEval, but that would break the current behavior of qeval until the current behavior is set as a fallback if unmarshal MsgEval fail.
I'm hesitating; it would probably give more flexibility, but qeval/json is really more straightforward.

wdyt?

Copy link
Member Author

@gfanton gfanton Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. After some attempts with url.Url using a query to parse the JSON flag or employing \n as a flag separator, I found it problematic and difficult to escape. This issue arises when users include ? or \n within the expression's arguments. In my opinion, we should use qeval/json as it looks like the most straightforward method to handle this for now, given the current implementation of the handler.

A possible compromise is to check the json part of vm/qeval/json within the queryEval function, allowing the right part of the path to serve as a flag.

Copy link
Member Author

@gfanton gfanton Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moul I've ended up going with the path query flag; see the queryEval function. We can probably set another separator than / to distinguish between the specific path and the flag. However, having this as a distinct sub-path does especially chock me.

gno.land/pkg/sdk/vm/keeper.go Outdated Show resolved Hide resolved
gno.land/pkg/sdk/vm/keeper.go Outdated Show resolved Hide resolved
@Kouteki Kouteki added the in focus Core team is prioritizing this work label Nov 15, 2024
@Kouteki Kouteki added this to the 🚀 Mainnet launch milestone Nov 22, 2024
@Gno2D2
Copy link
Collaborator

Gno2D2 commented Jan 9, 2025

🛠 PR Checks Summary

All Automated Checks passed. ✅

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

🟢 Maintainers must be able to edit this pull request (more info)

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 The pull request was created from a fork (head branch repo: gfanton/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission

Signed-off-by: gfanton <[email protected]>
Signed-off-by: gfanton <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in focus Core team is prioritizing this work 📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ gno.land Issues or PRs gno.land package related 📦 🤖 gnovm Issues or PRs gnovm related 🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: No status
Status: No status
Status: In Progress
Development

Successfully merging this pull request may close these issues.

5 participants