Skip to content

Commit

Permalink
Use template to move ownership cosmos module to x/ dir
Browse files Browse the repository at this point in the history
  • Loading branch information
krhubert committed Feb 10, 2020
1 parent 78a9fe6 commit a0689a6
Show file tree
Hide file tree
Showing 31 changed files with 669 additions and 199 deletions.
15 changes: 8 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
"github.com/cosmos/cosmos-sdk/x/supply"
mesgcodec "github.com/mesg-foundation/engine/codec"
"github.com/mesg-foundation/engine/cosmos"
"github.com/mesg-foundation/engine/x/ownership"
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"
Expand Down Expand Up @@ -59,7 +59,7 @@ var (
supply.AppModuleBasic{},

// Engine's AppModuleBasic
cosmos.NewAppModuleBasic(ownershipsdk.ModuleName),
cosmos.NewAppModuleBasic(ownership.ModuleName),
cosmos.NewAppModuleBasic(servicesdk.ModuleName),
cosmos.NewAppModuleBasic(instancesdk.ModuleName),
cosmos.NewAppModuleBasic(runnersdk.ModuleName),
Expand All @@ -84,6 +84,7 @@ func MakeCodec() *codec.Codec {

ModuleBasics.RegisterCodec(mesgcodec.Codec)
vesting.RegisterCodec(mesgcodec.Codec)
ownership.RegisterCodec(mesgcodec.Codec)
// sdk.RegisterCodec(cdc)
// codec.RegisterCrypto(cdc)

Expand Down Expand Up @@ -115,7 +116,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 +156,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 +243,7 @@ func NewInitApp(
)

// Engine's module keepers
app.ownershipKeeper = ownershipsdk.NewKeeper(keys[ownershipsdk.ModuleName])
app.ownershipKeeper = ownership.NewKeeper(app.cdc, keys[ownership.ModuleName])
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 +261,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 +288,7 @@ func NewInitApp(
slashing.ModuleName,

// Engine's modules
ownershipsdk.ModuleName,
ownership.ModuleName,
servicesdk.ModuleName,
instancesdk.ModuleName,
runnersdk.ModuleName,
Expand Down
2 changes: 1 addition & 1 deletion core/main.go
Original file line number Diff line number Diff line change
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
20 changes: 19 additions & 1 deletion 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/hash"
"github.com/mesg-foundation/engine/ext/xreflect"
"github.com/mesg-foundation/engine/ext/xstrings"
"github.com/mesg-foundation/engine/hash"
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 {
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
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"
"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
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
4 changes: 0 additions & 4 deletions sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
eventsdk "github.com/mesg-foundation/engine/sdk/event"
executionsdk "github.com/mesg-foundation/engine/sdk/execution"
instancesdk "github.com/mesg-foundation/engine/sdk/instance"
ownershipsdk "github.com/mesg-foundation/engine/sdk/ownership"
processesdk "github.com/mesg-foundation/engine/sdk/process"
runnersdk "github.com/mesg-foundation/engine/sdk/runner"
servicesdk "github.com/mesg-foundation/engine/sdk/service"
Expand All @@ -20,15 +19,13 @@ type SDK struct {
Execution *executionsdk.SDK
Event *eventsdk.Event
Process *processesdk.SDK
Ownership *ownershipsdk.SDK
Runner *runnersdk.SDK
}

// New creates a new SDK with given options.
func New(client *cosmos.Client, kb *cosmos.Keybase, container container.Container, engineName, port, ipfsEndpoint string) *SDK {
ps := pubsub.New(0)
serviceSDK := servicesdk.New(client)
ownershipSDK := ownershipsdk.New(client)
instanceSDK := instancesdk.New(client)
runnerSDK := runnersdk.New(client, serviceSDK, instanceSDK, container, engineName, port, ipfsEndpoint)
processSDK := processesdk.New(client)
Expand All @@ -40,7 +37,6 @@ func New(client *cosmos.Client, kb *cosmos.Keybase, container container.Containe
Execution: executionSDK,
Event: eventSDK,
Process: processSDK,
Ownership: ownershipSDK,
Runner: runnerSDK,
}
}
16 changes: 8 additions & 8 deletions sdk/service/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ 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"
"github.com/mesg-foundation/engine/protobuf/api"
ownershipsdk "github.com/mesg-foundation/engine/sdk/ownership"
"github.com/mesg-foundation/engine/service"
"github.com/mesg-foundation/engine/service/validator"
"github.com/mesg-foundation/engine/x/ownership"
)

// Keeper holds the logic to read and write data.
type Keeper struct {
storeKey *cosmostypes.KVStoreKey
ownerships *ownershipsdk.Keeper
storeKey *cosmostypes.KVStoreKey
ownershipKeeper ownership.Keeper
}

// NewKeeper initialize a new keeper.
func NewKeeper(storeKey *cosmostypes.KVStoreKey, ownerships *ownershipsdk.Keeper) *Keeper {
func NewKeeper(storeKey *cosmostypes.KVStoreKey, ownershipKeeper ownership.Keeper) *Keeper {
return &Keeper{
storeKey: storeKey,
ownerships: ownerships,
storeKey: storeKey,
ownershipKeeper: ownershipKeeper,
}
}

Expand All @@ -48,7 +48,7 @@ func (k *Keeper) Create(request cosmostypes.Request, msg *msgCreateService) (*se
return nil, err
}

if _, err := k.ownerships.Create(request, msg.Owner, srv.Hash, ownership.Ownership_Service); err != nil {
if _, err := k.ownershipKeeper.Set(request, msg.Owner, srv.Hash, ownershippb.Ownership_Service); err != nil {
return nil, err
}

Expand Down
Loading

0 comments on commit a0689a6

Please sign in to comment.