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

feat: wasmbinding schema #ntrn-327 #597

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,6 @@ check-proto-format:
$(DOCKER) run --rm -v $(CURDIR):/workspace \
--workdir /workspace $(PROTO_FORMATTER_IMAGE) \
format proto -d --exit-code

gen-wasmbinding-json: build
$(BUILDDIR)/neutrond gen-wasmbinding-schema
87 changes: 87 additions & 0 deletions cmd/neutrond/genwasmbindingschema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package main

import (
"encoding/json"
"fmt"
"os"

"github.com/invopop/jsonschema"
"github.com/spf13/cobra"

"github.com/neutron-org/neutron/v4/wasmbinding/bindings"
)

const (
schemaFolder = "wasmbinding/schema/"
packageName = "github.com/neutron-org/neutron/v4"
prefix = ""
indent = " "
queryFile = "query.json"
msgFile = "msg.json"
queryResponsesFile = "query_responses.json"
msgResponsesFile = "msg_responses.json"
)

func genWasmbindingSchemaCmd() *cobra.Command {
txCmd := &cobra.Command{
Use: "gen-wasmbinding-schema",
Short: "Generates wasmbinding json schema for NeutronQuery and NeutronMsg",
Args: cobra.ExactArgs(0),
RunE: func(_ *cobra.Command, _ []string) error {
r := new(jsonschema.Reflector)
if err := r.AddGoComments(packageName, "./"); err != nil {
return fmt.Errorf("failed to add comments: %w", err)
}

// query
if err := generateJsonToFile(r, &bindings.NeutronQuery{}, queryFile); err != nil {
return fmt.Errorf("failed to generate query: %w", err)
}
// msg
if err := generateJsonToFile(r, &bindings.NeutronMsg{}, msgFile); err != nil {
return fmt.Errorf("failed to generate msg: %w", err)
}
// query responses
if err := generateJsonToFile(r, &bindings.NeutronQueryResponse{}, queryResponsesFile); err != nil {
return fmt.Errorf("failed to generate query response: %w", err)
}
// msg responses
if err := generateJsonToFile(r, &bindings.NeutronMsgResponse{}, msgResponsesFile); err != nil {
return fmt.Errorf("failed to generate query response: %w", err)
}

fmt.Println("wasmbinding json schema generated successfully")

return nil
},
}

return txCmd
}

func generateJsonToFile(r *jsonschema.Reflector, reflected any, filename string) error {

Check failure on line 62 in cmd/neutrond/genwasmbindingschema.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: func generateJsonToFile should be generateJSONToFile (revive)
querySchema := r.Reflect(reflected)
queryJSON, err := json.MarshalIndent(querySchema, prefix, indent)
if err != nil {
return fmt.Errorf("failed to create jsonschema: %w", err)
}
if err := writeToFile(queryJSON, schemaFolder+filename); err != nil {
return fmt.Errorf("failed to write json schema to a file: %w", err)
}
return err
}

func writeToFile(bts []byte, filepath string) error {
file, err := os.Create(filepath)
if err != nil {
return fmt.Errorf("failed to create file with path=%s: %w", filepath, err)
}

defer file.Close()

_, err = file.Write(bts)
if err != nil {
return fmt.Errorf("failed to write file: %w", err)
}
return nil
}
1 change: 1 addition & 0 deletions cmd/neutrond/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
tmcli.NewCompletionCmd(rootCmd, true),
debugCmd,
ConfigCmd(),
genWasmbindingSchemaCmd(),
)

ac := appCreator{
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0
github.com/hashicorp/go-metrics v0.5.3
github.com/iancoleman/orderedmap v0.3.0
github.com/invopop/jsonschema v0.12.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.19.1
github.com/rs/zerolog v1.32.0
Expand Down Expand Up @@ -106,6 +107,7 @@ require (
github.com/DataDog/zstd v1.5.5 // indirect
github.com/GeertJohan/go.rice v1.0.3 // indirect
github.com/aws/aws-sdk-go v1.44.224 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
Expand Down Expand Up @@ -193,6 +195,7 @@ require (
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/linxGnu/grocksdb v1.8.14 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand Down Expand Up @@ -223,6 +226,7 @@ require (
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tidwall/btree v1.7.0 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
go.etcd.io/bbolt v1.3.8 // indirect
Expand Down
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX
github.com/aws/aws-sdk-go v1.44.224 h1:09CiaaF35nRmxrzWZ2uRq5v6Ghg/d2RiPjZnSgtt+RQ=
github.com/aws/aws-sdk-go v1.44.224/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
Expand Down Expand Up @@ -801,6 +803,8 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI=
github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus=
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
Expand All @@ -815,6 +819,7 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfC
github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U=
github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
Expand Down Expand Up @@ -872,6 +877,8 @@ github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0Q
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
Expand Down Expand Up @@ -1185,6 +1192,8 @@ github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs=
github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g=
github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
Expand Down
10 changes: 10 additions & 0 deletions wasmbinding/bindings/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ type NeutronMsg struct {
Dex *Dex `json:"dex,omitempty"`
}

type NeutronMsgResponse struct {
RegisterInterchainAccountResponse *RegisterInterchainAccountResponse `json:"register_interchain_account_response,omitempty"`
RegisterInterchainQueryResponse *RegisterInterchainQueryResponse `json:"register_interchain_query_response,omitempty"`
RemoveInterchainQueryResponse *RemoveInterchainQueryResponse `json:"remove_interchain_query_response,omitempty"`
UpdateInterchainQueryResponse *UpdateInterchainQueryResponse `json:"update_interchain_query_response,omitempty"`
AddScheduleResponse *AddScheduleResponse `json:"add_schedule_response,omitempty"`
RemoveScheduleResponse *RemoveScheduleResponse `json:"remove_schedule_response,omitempty"`
ResubmitFailureResponse *ResubmitFailureResponse `json:"resubmit_failure_response,omitempty"`
}

// SubmitTx submits interchain transaction on a remote chain.
type SubmitTx struct {
ConnectionId string `json:"connection_id"`
Expand Down
13 changes: 13 additions & 0 deletions wasmbinding/bindings/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@ type QueryRegisteredQueryRequest struct {

/* Responses */

type NeutronQueryResponse struct {
QueryRegisteredQueryResponse *QueryRegisteredQueryResponse `json:"query_registered_query_response,omitempty"`
QueryRegisteredQueriesResponse *QueryRegisteredQueriesResponse `json:"query_registered_queries_response,omitempty"`
QueryTotalBurnedNeutronsAmountResponse *QueryTotalBurnedNeutronsAmountResponse `json:"query_total_burned_neutrons_amount_response,omitempty"`
QueryMinIbcFeeResponse *QueryMinIbcFeeResponse `json:"query_min_ibc_fee_response,omitempty"`
QueryInterchainAccountAddressResponse *QueryInterchainAccountAddressResponse `json:"query_interchain_account_address_response,omitempty"`
QueryRegisteredQueryResultResponse *QueryRegisteredQueryResultResponse `json:"query_registered_query_result_response,omitempty"`
BeforeSendHookResponse *BeforeSendHookResponse `json:"before_send_hook_response,omitempty"`
DenomAdminResponse *DenomAdminResponse `json:"denom_admin_response,omitempty"`
FullDenomResponse *FullDenomResponse `json:"full_denom_response,omitempty"`
FailuresResponse *FailuresResponse `json:"failures_response,omitempty"`
}

type QueryRegisteredQueryResponse struct {
RegisteredQuery *RegisteredQuery `json:"registered_query,omitempty"`
}
Expand Down
Loading
Loading