gnolang / gno

Gno: An interpreted, stack-based Go virtual machine to build succinct and composable apps + Gno.land: a blockchain for timeless code and fair open-source.
https://gno.land/
Other
880 stars 364 forks source link

[gnokey] Make output of queries follow JSON spec #2232

Open leohhhn opened 4 months ago

leohhhn commented 4 months ago

Description

To consolidate our returns on gnokey queries, I propose that we make them return JSON strings. Currently, most of them return values with no wrapping, such as this:

height: 0
data: gno.mod
wugnot.gno
z0_filetest.gno

One exception is vm/qfuncs, which returns a partly formatted JSON string:

❯ gnokey query vm/qfuncs --data "gno.land/r/demo/userbook" -remote https://rpc.gno.land:443
height: 0
data: [{"FuncName":"SignUp","Params":null,"Results":[{"Name":"_","Type":"string","Value":""}]},{"FuncName":"GetSignupsInRange","Params":[{"Name":"page","Type":"int","Value":""},{"Name":"pageSize","Type":"int","Value":""}],"Results":[{"Name":"_","Type":"[]gno.land/r/demo/userbook.Signup","Value":""},{"Name":"_","Type":"int","Value":""}]},{"FuncName":"Render","Params":[{"Name":"path","Type":"string","Value":""}],"Results":[{"Name":"_","Type":"string","Value":""}]}]

Would be great to wrap height & data properly, such as this:

{
  "height": 0,
  "data": [
    {
      "FuncName": "SignUp",
      "Params": null,
      "Results": [
        {
          "Name": "_",
          "Type": "string",
          "Value": ""
        }
      ]
    },
    {
      "FuncName": "GetSignupsInRange",
      "Params": [
        {
          "Name": "page",
          "Type": "int",
          "Value": ""
        },
        {
          "Name": "pageSize",
          "Type": "int",
          "Value": ""
        }
      ],
      "Results": [
        {
          "Name": "_",
          "Type": "[]gno.land/r/demo/userbook.Signup",
          "Value": ""
        },
        {
          "Name": "_",
          "Type": "int",
          "Value": ""
        }
      ]
    },
    {
      "FuncName": "Render",
      "Params": [
        {
          "Name": "path",
          "Type": "string",
          "Value": ""
        }
      ],
      "Results": [
        {
          "Name": "_",
          "Type": "string",
          "Value": ""
        }
      ]
    }
  ]
}
leohhhn commented 4 months ago

Additional thoughts: it would be great to unify the vm/qfuncs query with what DevX is doing with gnoschema, so we have a standard across the board.

I see this as a super useful quick and easy way to get the ABI of a realm, such as with this:

gnokey query vm/qfuncs --data "gno.land/r/demo/userbook" -remote https://rpc.gno.land:443 > abi.json

cc @salmad3 @ilgooz Let's have a discussion on defining the spec for this.

linhpn99 commented 4 months ago

https://github.com/gnolang/gno/pull/2249 hey @leohhhn , i made a PR to format this query response, wdyt ?

Kouteki commented 3 months ago

Relates to https://github.com/gnolang/gno/issues/2301