Skip to content
Merged
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
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Bug Fixes

- [#4686](https://github.com/ignite/cli/pull/4686) Filter discovered protos to only messages.

## [`v29.0.0-rc.1`](https://github.com/ignite/cli/releases/tag/v29.0.0-rc.1)

### Features
Expand Down
9 changes: 0 additions & 9 deletions ignite/pkg/cosmosanalysis/module/message.go

This file was deleted.

87 changes: 29 additions & 58 deletions ignite/pkg/cosmosanalysis/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,25 +208,6 @@ func RootGoImportPath(importPath string) string {
return importPath
}

func extractRelPath(pkgGoImportPath, baseGoPath string) (string, error) {
// Remove the import prefix to get the relative path
if strings.HasPrefix(pkgGoImportPath, baseGoPath) {
return strings.TrimPrefix(pkgGoImportPath, baseGoPath), nil
}

// When the import path prefix defined by the proto package
// doesn't match the base Go import path it means that the
// latter might have a version suffix and the former doesn't.
if p, v := path.Split(baseGoPath); semver.IsValid(v) {
// Use the import path without the version as prefix
p = strings.TrimRight(p, "/")

return strings.TrimPrefix(pkgGoImportPath, p), nil
}

return "", errors.Errorf("proto go import %s is not relative to %s", pkgGoImportPath, baseGoPath)
}

// discover discovers and sdk module by a proto pkg.
func (d *moduleDiscoverer) discover(pkg protoanalysis.Package) (Module, error) {
// Check if the proto package services are implemented
Expand All @@ -235,19 +216,7 @@ func (d *moduleDiscoverer) discover(pkg protoanalysis.Package) (Module, error) {
return Module{}, err
}

pkgRelPath, err := extractRelPath(pkg.GoImportPath(), d.basegopath)
if err != nil {
return Module{}, err
}

// Find the `sdk.Msg` interface implementation
pkgPath := filepath.Join(d.sourcePath, pkgRelPath)
msgs, err := cosmosanalysis.FindImplementation(pkgPath, messageImplementation)
if err != nil {
return Module{}, err
}

if len(pkg.Services)+len(msgs) == 0 {
if len(pkg.Services) == 0 {
return Module{}, nil
}

Expand All @@ -257,22 +226,6 @@ func (d *moduleDiscoverer) discover(pkg protoanalysis.Package) (Module, error) {
Pkg: pkg,
}

for _, msg := range msgs {
pkgmsg, err := pkg.MessageByName(msg)
if err != nil {
// no msg found in the proto defs corresponds to discovered sdk message.
// if it cannot be found, nothing to worry about, this means that it is used
// only internally and not open for actual use.
continue
}

m.Msgs = append(m.Msgs, Msg{
Name: msg,
URI: fmt.Sprintf("%s.%s", pkg.Name, msg),
FilePath: pkgmsg.Path,
})
}

// isType whether if protomsg can be added as an any Type to Module.
isType := func(protomsg protoanalysis.Message) bool {
// do not use GenesisState type.
Expand Down Expand Up @@ -315,19 +268,37 @@ func (d *moduleDiscoverer) discover(pkg protoanalysis.Package) (Module, error) {
})
}

// fill queries.
// fill queries & messages.
for _, s := range pkg.Services {
for _, q := range s.RPCFuncs {
if len(q.HTTPRules) == 0 {
continue
}
switch s.Name {
case "Msg":
pkgmsg, err := pkg.MessageByName(q.RequestType)
if err != nil {
// no msg found in the proto defs corresponds to discovered sdk message.
// if it cannot be found, nothing to worry about, this means that it is used
// only internally and not open for actual use.
continue
}

m.HTTPQueries = append(m.HTTPQueries, HTTPQuery{
Name: q.Name,
FullName: s.Name + q.Name,
Rules: q.HTTPRules,
Paginated: q.Paginated,
})
m.Msgs = append(m.Msgs, Msg{
Name: q.RequestType,
URI: fmt.Sprintf("%s.%s", pkg.Name, q.RequestType),
FilePath: pkgmsg.Path,
})
case "Query":
// no http rules means this query is not exposed as a REST endpoint.
if len(q.HTTPRules) == 0 {
continue
}

m.HTTPQueries = append(m.HTTPQueries, HTTPQuery{
Name: q.Name,
FullName: s.Name + q.Name,
Rules: q.HTTPRules,
Paginated: q.Paginated,
})
}
}
}

Expand Down
60 changes: 59 additions & 1 deletion ignite/pkg/cosmosanalysis/module/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,38 @@ func newModule(relChainPath, goImportPath string) module.Module {
},
GoImportName: "github.com/tendermint/planet/x/mars/types",
Messages: []protoanalysis.Message{
{
Name: "MsgMyMessageRequest",
Path: filepath.Join(relChainPath, "proto/planet/mars/mars.proto"),
HighestFieldNumber: 1,
Fields: map[string]string{
"mytypefield": "string",
},
},
{
Name: "MsgMyMessageResponse",
Path: filepath.Join(relChainPath, "proto/planet/mars/mars.proto"),
HighestFieldNumber: 1,
Fields: map[string]string{
"mytypefield": "string",
},
},
{
Name: "MsgBarRequest",
Path: filepath.Join(relChainPath, "proto/planet/mars/mars.proto"),
HighestFieldNumber: 1,
Fields: map[string]string{
"mytypefield": "string",
},
},
{
Name: "MsgBarResponse",
Path: filepath.Join(relChainPath, "proto/planet/mars/mars.proto"),
HighestFieldNumber: 1,
Fields: map[string]string{
"mytypefield": "string",
},
},
{
Name: "QueryMyQueryRequest",
Path: filepath.Join(relChainPath, "proto/planet/mars/mars.proto"),
Expand Down Expand Up @@ -58,6 +90,21 @@ func newModule(relChainPath, goImportPath string) module.Module {
},
},
Services: []protoanalysis.Service{
{
Name: "Msg",
RPCFuncs: []protoanalysis.RPCFunc{
{
Name: "MyMessage",
RequestType: "MsgMyMessageRequest",
ReturnsType: "MsgMyMessageResponse",
},
{
Name: "Bar",
RequestType: "MsgBarRequest",
ReturnsType: "MsgBarResponse",
},
},
},
{
Name: "Query",
RPCFuncs: []protoanalysis.RPCFunc{
Expand Down Expand Up @@ -89,7 +136,18 @@ func newModule(relChainPath, goImportPath string) module.Module {
},
},
},
Msgs: []module.Msg(nil),
Msgs: []module.Msg{
{
Name: "MsgMyMessageRequest",
URI: "tendermint.planet.mars.MsgMyMessageRequest",
FilePath: filepath.Join(relChainPath, "proto/planet/mars/mars.proto"),
},
{
Name: "MsgBarRequest",
URI: "tendermint.planet.mars.MsgBarRequest",
FilePath: filepath.Join(relChainPath, "proto/planet/mars/mars.proto"),
},
},
HTTPQueries: []module.HTTPQuery{
{
Name: "MyQuery",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,35 @@ import "cosmos/base/query/v1beta1/pagination.proto";
import "google/api/annotations.proto";
option go_package = "github.com/tendermint/planet/x/mars/types";

service Msg {
rpc MyMessage(MsgMyMessageRequest) returns (MsgMyMessageResponse);

rpc Bar(MsgBarRequest) returns (MsgBarResponse);
}

message MsgMyMessageRequest {
string mytypefield = 1;
}

message MsgMyMessageResponse {
string mytypefield = 1;
}

message MsgBarRequest {
string mytypefield = 1;
}

message MsgBarResponse {
string mytypefield = 1;
}

service Query {
rpc MyQuery(QueryMyQueryRequest) returns (QueryMyQueryResponse) {
option (google.api.http).get = "/tendermint/mars/withoutmsg/my_query/{mytypefield}";
option (google.api.http).get = "/tendermint/mars/my_query/{mytypefield}";
}

rpc Foo(QueryFooRequest) returns (QueryFooResponse) {
option (google.api.http).get = "/tendermint/mars/withoutmsg/foo/";
option (google.api.http).get = "/tendermint/mars/foo/";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,35 @@ import "cosmos/base/query/v1beta1/pagination.proto";
import "google/api/annotations.proto";
option go_package = "github.com/tendermint/planet/x/mars/types";

service Msg {
rpc MyMessage(MsgMyMessageRequest) returns (MsgMyMessageResponse);

rpc Bar(MsgBarRequest) returns (MsgBarResponse);
}

message MsgMyMessageRequest {
string mytypefield = 1;
}

message MsgMyMessageResponse {
string mytypefield = 1;
}

message MsgBarRequest {
string mytypefield = 1;
}

message MsgBarResponse {
string mytypefield = 1;
}

service Query {
rpc MyQuery(QueryMyQueryRequest) returns (QueryMyQueryResponse) {
option (google.api.http).get = "/tendermint/mars/withoutmsg/my_query/{mytypefield}";
option (google.api.http).get = "/tendermint/mars/my_query/{mytypefield}";
}

rpc Foo(QueryFooRequest) returns (QueryFooResponse) {
option (google.api.http).get = "/tendermint/mars/withoutmsg/foo/";
option (google.api.http).get = "/tendermint/mars/foo/";
}
}

Expand Down