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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ require (
github.com/imdario/mergo v0.3.11
github.com/improbable-eng/grpc-web v0.13.0
github.com/jpillora/chisel v1.7.3
github.com/kr/pretty v0.1.0
github.com/manifoldco/promptui v0.8.0
github.com/mattn/go-zglob v0.0.3
github.com/mwitkow/grpc-proxy v0.0.0-20181017164139-0f1106ef9c76
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package msgs
package module

import (
"fmt"
"go/ast"
"go/parser"
"go/token"
Expand Down Expand Up @@ -32,7 +33,28 @@ func newRequirements() requirements {
// Msgs is a module import path-sdk msgs pair.
type Msgs map[string][]string

// Discover discovers and returns pairs of module import paths and their types that implements sdk.Msg.
// Module keeps metadata about a Cosmos SDK module.
type Module struct {
// Name of the module.
Name string

// TypesImportPath is the Go import path of the types pkg of the module.
TypesImportPath string

// Msg is a list of sdk.Msg implementation of the module.
Msgs []Msg
}

// Msg keeps metadata about an sdk.Msg implementation.
type Msg struct {
// Name of the type.
Name string

// URI of the type.
URI string
}

// Discover discovers and returns modules and their types that implements sdk.Msg.
// sourcePath is the root path of an sdk blockchain.
//
// discovery algorithm make use of proto definitions to discover modules inside the blockchain.
Expand All @@ -42,7 +64,7 @@ type Msgs map[string][]string
// for a more opinionated check:
// - go/types.Implements() might be utilized and as needed.
// - instead of just comparing method names, their full signatures can be compared.
func Discover(sourcePath string) (Msgs, error) {
func Discover(sourcePath string) ([]Module, error) {
// find out base Go import path of the blockchain.
gm, err := gomodule.ParseAt(sourcePath)
if err != nil {
Expand All @@ -56,21 +78,41 @@ func Discover(sourcePath string) (Msgs, error) {
return nil, err
}

msgs := make(Msgs)
var modules []Module

for _, xproto := range xprotopkgs {
rxpath := strings.TrimPrefix(xproto.GoImportName, bpath)
xpath := filepath.Join(sourcePath, rxpath)
var (
rxpath = strings.TrimPrefix(xproto.GoImportName, bpath)
xpath = filepath.Join(sourcePath, rxpath)
)

xmsgs, err := DiscoverModule(xpath)
if err != nil {
return nil, err
}

msgs[xproto.GoImportName] = xmsgs
var msgs []Msg

for _, xmsg := range xmsgs {
msgs = append(msgs, Msg{
Name: xmsg,
URI: fmt.Sprintf("%s.%s", xproto.Name, xmsg),
})
}

var (
spname = strings.Split(xproto.Name, ".")
m = Module{
Name: spname[len(spname)-1],
TypesImportPath: xproto.GoImportName,
Msgs: msgs,
}
)

modules = append(modules, m)
}

return msgs, nil
return modules, nil
}

// DiscoverModule discovers sdk messages defined in a module that resides under modulePath.
Expand Down
30 changes: 30 additions & 0 deletions starport/pkg/cosmosanalysis/module/module_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package module

import (
"github.com/kr/pretty"
)

func ExampleDiscover() {
pretty.Println(Discover("/home/ilker/Documents/code/src/github.com/tendermint/starport/local_test/moon"))
// outputs:
// []msgs.Module{
// {
// Name: "moon",
// TypesImportPath: "github.com/ilker/moon/x/moon/types",
// Msgs: {
// {Name:"MsgUpdateUser", URI:"ilker.moon.moon.MsgUpdateUser"},
// {Name:"MsgDeleteUser", URI:"ilker.moon.moon.MsgDeleteUser"},
// {Name:"MsgCreateUser", URI:"ilker.moon.moon.MsgCreateUser"},
// },
// },
// {
// Name: "elips",
// TypesImportPath: "github.com/ilker/moon/x/elips/types",
// Msgs: {
// {Name:"MsgCreateBlog", URI:"ilker.moon.elips.MsgCreateBlog"},
// {Name:"MsgUpdateBlog", URI:"ilker.moon.elips.MsgUpdateBlog"},
// {Name:"MsgDeleteBlog", URI:"ilker.moon.elips.MsgDeleteBlog"},
// },
// },
// } nil
}
11 changes: 0 additions & 11 deletions starport/pkg/cosmosanalysis/msgs/msgs_test.go

This file was deleted.