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

Refactor ownership module to cosmos style #1651

Merged
merged 5 commits into from
Feb 12, 2020
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
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ issues:
- "ineffective break statement. Did you mean to break out of the outer loop"

exclude-rules:
- path: x/xvalidator/validator.go
- path: ext/xvalidator/validator.go
linters:
- golint
text: "exported var Translator should have its own declaration"
Expand Down
14 changes: 7 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import (
"github.com/mesg-foundation/engine/cosmos"
executionsdk "github.com/mesg-foundation/engine/sdk/execution"
instancesdk "github.com/mesg-foundation/engine/sdk/instance"
ownershipsdk "github.com/mesg-foundation/engine/sdk/ownership"
processsdk "github.com/mesg-foundation/engine/sdk/process"
runnersdk "github.com/mesg-foundation/engine/sdk/runner"
servicesdk "github.com/mesg-foundation/engine/sdk/service"
"github.com/mesg-foundation/engine/x/ownership"
)

const appName = "engine"
Expand All @@ -59,7 +59,7 @@ var (
supply.AppModuleBasic{},

// Engine's AppModuleBasic
cosmos.NewAppModuleBasic(ownershipsdk.ModuleName),
ownership.AppModuleBasic{},
cosmos.NewAppModuleBasic(servicesdk.ModuleName),
cosmos.NewAppModuleBasic(instancesdk.ModuleName),
cosmos.NewAppModuleBasic(runnersdk.ModuleName),
Expand Down Expand Up @@ -115,7 +115,7 @@ type NewApp struct {
paramsKeeper params.Keeper

// Engine's keepers
ownershipKeeper *ownershipsdk.Keeper
ownershipKeeper ownership.Keeper
serviceKeeper *servicesdk.Keeper
instanceKeeper *instancesdk.Keeper
runnerKeeper *runnersdk.Keeper
Expand Down Expand Up @@ -155,7 +155,7 @@ func NewInitApp(
params.StoreKey,

// Engine's module keys
ownershipsdk.ModuleName,
ownership.ModuleName,
servicesdk.ModuleName,
instancesdk.ModuleName,
runnersdk.ModuleName,
Expand Down Expand Up @@ -242,7 +242,7 @@ func NewInitApp(
)

// Engine's module keepers
app.ownershipKeeper = ownershipsdk.NewKeeper(keys[ownershipsdk.ModuleName])
app.ownershipKeeper = ownership.NewKeeper(app.cdc, keys[ownership.StoreKey])
app.serviceKeeper = servicesdk.NewKeeper(keys[servicesdk.ModuleName], app.ownershipKeeper)
app.instanceKeeper = instancesdk.NewKeeper(keys[instancesdk.ModuleName])
app.runnerKeeper = runnersdk.NewKeeper(keys[runnersdk.ModuleName], app.instanceKeeper)
Expand All @@ -260,7 +260,7 @@ func NewInitApp(
slashing.NewAppModule(app.slashingKeeper, app.accountKeeper, app.stakingKeeper),

// Engine's modules
ownershipsdk.NewModule(app.ownershipKeeper),
ownership.NewAppModule(app.ownershipKeeper),
servicesdk.NewModule(app.serviceKeeper),
instancesdk.NewModule(app.instanceKeeper),
runnersdk.NewModule(app.runnerKeeper),
Expand All @@ -287,7 +287,7 @@ func NewInitApp(
slashing.ModuleName,

// Engine's modules
ownershipsdk.ModuleName,
ownership.ModuleName,
servicesdk.ModuleName,
instancesdk.ModuleName,
runnersdk.ModuleName,
Expand Down
10 changes: 5 additions & 5 deletions core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import (
"github.com/mesg-foundation/engine/config"
"github.com/mesg-foundation/engine/container"
"github.com/mesg-foundation/engine/cosmos"
"github.com/mesg-foundation/engine/ext/xerrors"
"github.com/mesg-foundation/engine/ext/xnet"
"github.com/mesg-foundation/engine/ext/xrand"
"github.com/mesg-foundation/engine/ext/xsignal"
"github.com/mesg-foundation/engine/hash"
"github.com/mesg-foundation/engine/logger"
"github.com/mesg-foundation/engine/orchestrator"
Expand All @@ -25,10 +29,6 @@ import (
runnersdk "github.com/mesg-foundation/engine/sdk/runner"
"github.com/mesg-foundation/engine/server/grpc"
"github.com/mesg-foundation/engine/version"
"github.com/mesg-foundation/engine/x/xerrors"
"github.com/mesg-foundation/engine/x/xnet"
"github.com/mesg-foundation/engine/x/xrand"
"github.com/mesg-foundation/engine/x/xsignal"
"github.com/sirupsen/logrus"
rpcserver "github.com/tendermint/tendermint/rpc/lib/server"
tmtypes "github.com/tendermint/tendermint/types"
Expand Down Expand Up @@ -191,7 +191,7 @@ func main() {
}

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

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

Expand Down
22 changes: 20 additions & 2 deletions cosmos/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
authExported "github.com/cosmos/cosmos-sdk/x/auth/exported"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/mesg-foundation/engine/codec"
"github.com/mesg-foundation/engine/ext/xreflect"
"github.com/mesg-foundation/engine/ext/xstrings"
"github.com/mesg-foundation/engine/hash"
"github.com/mesg-foundation/engine/x/xreflect"
"github.com/mesg-foundation/engine/x/xstrings"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/node"
rpcclient "github.com/tendermint/tendermint/rpc/client"
Expand Down Expand Up @@ -55,6 +55,24 @@ func NewClient(node *node.Node, kb keys.Keybase, chainID, accName, accPassword,
}, nil
}

// QueryJSON is abci.query wrapper with errors check and decode data.
func (c *Client) QueryJSON(path string, qdata, ptr interface{}) error {
krhubert marked this conversation as resolved.
Show resolved Hide resolved
var data []byte
if !xreflect.IsNil(qdata) {
b, err := codec.MarshalJSON(qdata)
if err != nil {
return err
}
data = b
}

result, _, err := c.QueryWithData(path, data)
if err != nil {
return err
}
return codec.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
Expand Down
2 changes: 1 addition & 1 deletion e2e/testdata/test-complex-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"os"
"time"

"github.com/mesg-foundation/engine/ext/xsignal"
"github.com/mesg-foundation/engine/hash"
pb "github.com/mesg-foundation/engine/protobuf/api"
"github.com/mesg-foundation/engine/x/xsignal"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion x/xvalidator/validator.go → ext/xvalidator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
cosmostypes "github.com/cosmos/cosmos-sdk/types"
"github.com/go-playground/locales/en"
ut "github.com/go-playground/universal-translator"
"github.com/mesg-foundation/engine/ext/xnet"
"github.com/mesg-foundation/engine/hash"
"github.com/mesg-foundation/engine/x/xnet"
validator "gopkg.in/go-playground/validator.v9"
en_translations "gopkg.in/go-playground/validator.v9/translations/en"
)
Expand Down
2 changes: 1 addition & 1 deletion protobuf/api/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
fmt "fmt"

execution "github.com/mesg-foundation/engine/execution"
"github.com/mesg-foundation/engine/x/xstrings"
"github.com/mesg-foundation/engine/ext/xstrings"
)

// Validate checks if given filter is valid and returns error.
Expand Down
2 changes: 1 addition & 1 deletion sdk/execution/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
cosmoserrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/mesg-foundation/engine/codec"
"github.com/mesg-foundation/engine/cosmos"
"github.com/mesg-foundation/engine/ext/xvalidator"
"github.com/mesg-foundation/engine/protobuf/api"
"github.com/mesg-foundation/engine/x/xvalidator"
)

// msgCreateExecution defines a state transition to create a execution.
Expand Down
97 changes: 0 additions & 97 deletions sdk/ownership/keeper.go

This file was deleted.

37 changes: 0 additions & 37 deletions sdk/ownership/module.go

This file was deleted.

28 changes: 0 additions & 28 deletions sdk/ownership/sdk.go

This file was deleted.

10 changes: 5 additions & 5 deletions sdk/process/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import (
cosmostypes "github.com/cosmos/cosmos-sdk/types"
"github.com/mesg-foundation/engine/codec"
"github.com/mesg-foundation/engine/hash"
"github.com/mesg-foundation/engine/ownership"
ownershippb "github.com/mesg-foundation/engine/ownership"
krhubert marked this conversation as resolved.
Show resolved Hide resolved
"github.com/mesg-foundation/engine/process"
instancesdk "github.com/mesg-foundation/engine/sdk/instance"
ownershipsdk "github.com/mesg-foundation/engine/sdk/ownership"
"github.com/mesg-foundation/engine/x/ownership"
)

// Keeper is the service keeper.
type Keeper struct {
storeKey *cosmostypes.KVStoreKey
ownershipKeeper *ownershipsdk.Keeper
ownershipKeeper ownership.Keeper
krhubert marked this conversation as resolved.
Show resolved Hide resolved
instanceKeeper *instancesdk.Keeper
}

// NewKeeper returns the keeper of the service sdk.
func NewKeeper(storeKey *cosmostypes.KVStoreKey, ownershipKeeper *ownershipsdk.Keeper, instanceKeeper *instancesdk.Keeper) *Keeper {
func NewKeeper(storeKey *cosmostypes.KVStoreKey, ownershipKeeper ownership.Keeper, instanceKeeper *instancesdk.Keeper) *Keeper {
return &Keeper{
storeKey: storeKey,
ownershipKeeper: ownershipKeeper,
Expand Down Expand Up @@ -63,7 +63,7 @@ func (k *Keeper) Create(req cosmostypes.Request, msg *msgCreateProcess) (*proces
return nil, err
}

if _, err := k.ownershipKeeper.Create(req, msg.Owner, p.Hash, ownership.Ownership_Process); err != nil {
if _, err := k.ownershipKeeper.Set(req, msg.Owner, p.Hash, ownershippb.Ownership_Process); err != nil {
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/process/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
cosmostypes "github.com/cosmos/cosmos-sdk/types"
cosmoserrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/mesg-foundation/engine/codec"
"github.com/mesg-foundation/engine/ext/xvalidator"
"github.com/mesg-foundation/engine/hash"
"github.com/mesg-foundation/engine/process"
"github.com/mesg-foundation/engine/protobuf/api"
"github.com/mesg-foundation/engine/x/xvalidator"
)

// msgCreateProcess defines a state transition to create a service.
Expand Down
Loading