Skip to content

Commit

Permalink
Refactor cosmos module
Browse files Browse the repository at this point in the history
- create cosmos module client
- removed sdk packages
- create runner/builder and event/publisher packages
- remove orchestrator tests & mocks
  • Loading branch information
krhubert committed Feb 15, 2020
1 parent 3f17b27 commit bc2b445
Show file tree
Hide file tree
Showing 37 changed files with 615 additions and 1,250 deletions.
1 change: 0 additions & 1 deletion Dockerfile.tools
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ RUN go mod download

RUN go install github.com/golang/protobuf/protoc-gen-go
RUN go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc
RUN go install github.com/vektra/mockery/.../

# verify that mesg-dev container is being used.
ENV MESG_DEV true
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all build build-cmd-cosmos changelog check-version clean clean-build clean-docker dep dev dev-mon dev-start dev-stop docker-build docker-dev docker-publish docker-publish-dev docker-tools genesis lint mock protobuf test
.PHONY: all build build-cmd-cosmos changelog check-version clean clean-build clean-docker dep dev dev-mon dev-start dev-stop docker-build docker-dev docker-publish docker-publish-dev docker-tools genesis lint protobuf test

MAJOR_VERSION := $(shell echo $(version) | cut -d . -f 1)
MINOR_VERSION := $(shell echo $(version) | cut -d . -f 1-2)
Expand Down Expand Up @@ -67,9 +67,6 @@ test: dep
lint:
golangci-lint run

mock: docker-tools
docker run --rm -v $(PWD):/project mesg/tools:local ./scripts/build-mocks.sh

protobuf: docker-tools
docker run --rm -v $(PWD):/project mesg/tools:local ./scripts/build-proto.sh

Expand Down
28 changes: 15 additions & 13 deletions core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/mesg-foundation/engine/config"
"github.com/mesg-foundation/engine/container"
"github.com/mesg-foundation/engine/cosmos"
"github.com/mesg-foundation/engine/event/publisher"
"github.com/mesg-foundation/engine/ext/xerrors"
"github.com/mesg-foundation/engine/ext/xnet"
"github.com/mesg-foundation/engine/ext/xrand"
Expand All @@ -25,8 +26,7 @@ import (
"github.com/mesg-foundation/engine/logger"
"github.com/mesg-foundation/engine/orchestrator"
"github.com/mesg-foundation/engine/protobuf/api"
enginesdk "github.com/mesg-foundation/engine/sdk"
runnersdk "github.com/mesg-foundation/engine/sdk/runner"
"github.com/mesg-foundation/engine/runner/builder"
"github.com/mesg-foundation/engine/server/grpc"
"github.com/mesg-foundation/engine/version"
"github.com/sirupsen/logrus"
Expand All @@ -35,8 +35,8 @@ import (
db "github.com/tendermint/tm-db"
)

func stopRunningServices(sdk *enginesdk.SDK, address string) error {
runners, err := sdk.Runner.List(&runnersdk.Filter{Address: address})
func stopRunningServices(mc *cosmos.ModuleClient, b *builder.Builder, address string) error {
runners, err := mc.ListRunner(&cosmos.FilterRunner{Address: address})
if err != nil {
return err
}
Expand All @@ -49,7 +49,7 @@ func stopRunningServices(sdk *enginesdk.SDK, address string) error {
for _, instance := range runners {
go func(hash hash.Hash) {
defer wg.Done()
err := sdk.Runner.Delete(&api.DeleteRunnerRequest{
err := b.Delete(&api.DeleteRunnerRequest{
Hash: hash,
DeleteData: false,
})
Expand Down Expand Up @@ -128,9 +128,6 @@ func main() {
// init logger.
logger.Init(cfg.Log.Format, cfg.Log.Level, cfg.Log.ForceColors)

// init basicManager
// basicManager := enginesdk.NewBasicManager()

// init tendermint logger
tendermintLogger := logger.TendermintLogger()

Expand Down Expand Up @@ -182,8 +179,13 @@ func main() {
logrus.WithField("module", "main").Fatalln(err)
}

// init sdk
sdk := enginesdk.New(client, kb, container, cfg.Name, strconv.Itoa(port), cfg.IpfsEndpoint)
mc := cosmos.NewModuleClient(client)

// init runner builder
b := builder.New(mc, container, cfg.Name, strconv.Itoa(port), cfg.IpfsEndpoint)

// init event publiserh
ep := publisher.New(mc)

// start tendermint node
logrus.WithField("module", "main").WithField("seeds", cfg.Tendermint.Config.P2P.Seeds).Info("starting tendermint node")
Expand All @@ -192,7 +194,7 @@ func main() {
}

// init gRPC server.
server := grpc.New(sdk, cfg, client)
server := grpc.New(mc, ep, b)

logrus.WithField("module", "main").Infof("starting MESG Engine version %s", version.Version)

Expand All @@ -203,7 +205,7 @@ func main() {
}()

logrus.WithField("module", "main").Info("starting process engine")
s := orchestrator.New(sdk.Event, sdk.Execution, sdk.Process, sdk.Runner)
s := orchestrator.New(mc, ep)
go func() {
if err := s.Start(); err != nil {
logrus.WithField("module", "main").Fatalln(err)
Expand Down Expand Up @@ -244,7 +246,7 @@ func main() {
}

logrus.WithField("module", "main").Info("stopping running services")
if err := stopRunningServices(sdk, acc.GetAddress().String()); err != nil {
if err := stopRunningServices(mc, b, acc.GetAddress().String()); err != nil {
logrus.WithField("module", "main").Fatalln(err)
}

Expand Down
17 changes: 0 additions & 17 deletions cosmos/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,6 @@ func (c *Client) QueryJSON(path string, qdata, ptr interface{}) error {
return c.cdc.UnmarshalJSON(result, ptr)
}

// Query is abci.query wrapper with errors check and decode data.
func (c *Client) Query(path string, qdata, ptr interface{}) error {
var data []byte
if !xreflect.IsNil(qdata) {
b, err := c.cdc.MarshalBinaryBare(qdata)
if err != nil {
return err
}
data = b
}
result, _, err := c.QueryWithData(path, data)
if err != nil {
return err
}
return c.cdc.UnmarshalBinaryBare(result, ptr)
}

// QueryWithData performs a query to a Tendermint node with the provided path
// and a data payload. It returns the result and height of the query upon success
// or an error if the query fails.
Expand Down
Loading

0 comments on commit bc2b445

Please sign in to comment.