Skip to content

Commit

Permalink
Merge pull request #1653 from mesg-foundation/refactor/cosmos-instanc…
Browse files Browse the repository at this point in the history
…e-module

Refactor/cosmos instance module
  • Loading branch information
Nicolas Mahé authored Feb 12, 2020
2 parents 1a55566 + 0564530 commit ee1f338
Show file tree
Hide file tree
Showing 32 changed files with 760 additions and 246 deletions.
14 changes: 7 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import (
mesgcodec "github.com/mesg-foundation/engine/codec"
"github.com/mesg-foundation/engine/cosmos"
executionsdk "github.com/mesg-foundation/engine/sdk/execution"
instancesdk "github.com/mesg-foundation/engine/sdk/instance"
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/instance"
"github.com/mesg-foundation/engine/x/ownership"
)

Expand Down Expand Up @@ -60,8 +60,8 @@ var (

// Engine's AppModuleBasic
ownership.AppModuleBasic{},
instance.AppModuleBasic{},
cosmos.NewAppModuleBasic(servicesdk.ModuleName),
cosmos.NewAppModuleBasic(instancesdk.ModuleName),
cosmos.NewAppModuleBasic(runnersdk.ModuleName),
cosmos.NewAppModuleBasic(executionsdk.ModuleName),
cosmos.NewAppModuleBasic(processsdk.ModuleName),
Expand Down Expand Up @@ -116,8 +116,8 @@ type NewApp struct {

// Engine's keepers
ownershipKeeper ownership.Keeper
instanceKeeper instance.Keeper
serviceKeeper *servicesdk.Keeper
instanceKeeper *instancesdk.Keeper
runnerKeeper *runnersdk.Keeper
processKeeper *processsdk.Keeper
executionKeeper *executionsdk.Keeper
Expand Down Expand Up @@ -156,8 +156,8 @@ func NewInitApp(

// Engine's module keys
ownership.ModuleName,
instance.ModuleName,
servicesdk.ModuleName,
instancesdk.ModuleName,
runnersdk.ModuleName,
executionsdk.ModuleName,
processsdk.ModuleName,
Expand Down Expand Up @@ -243,8 +243,8 @@ func NewInitApp(

// Engine's module keepers
app.ownershipKeeper = ownership.NewKeeper(app.cdc, keys[ownership.StoreKey])
app.instanceKeeper = instance.NewKeeper(app.cdc, keys[instance.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)
app.processKeeper = processsdk.NewKeeper(keys[processsdk.ModuleName], app.ownershipKeeper, app.instanceKeeper)
app.executionKeeper = executionsdk.NewKeeper(keys[executionsdk.ModuleName], app.serviceKeeper, app.instanceKeeper, app.runnerKeeper, app.processKeeper)
Expand All @@ -261,8 +261,8 @@ func NewInitApp(

// Engine's modules
ownership.NewAppModule(app.ownershipKeeper),
instance.NewAppModule(app.instanceKeeper),
servicesdk.NewModule(app.serviceKeeper),
instancesdk.NewModule(app.instanceKeeper),
runnersdk.NewModule(app.runnerKeeper),
executionsdk.NewModule(app.executionKeeper),
processsdk.NewModule(app.processKeeper),
Expand All @@ -288,8 +288,8 @@ func NewInitApp(

// Engine's modules
ownership.ModuleName,
instance.ModuleName,
servicesdk.ModuleName,
instancesdk.ModuleName,
runnersdk.ModuleName,
executionsdk.ModuleName,
processsdk.ModuleName,
Expand Down
26 changes: 15 additions & 11 deletions sdk/event/event.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package eventsdk

import (
"fmt"

"github.com/cskr/pubsub"
"github.com/mesg-foundation/engine/cosmos"
"github.com/mesg-foundation/engine/event"
"github.com/mesg-foundation/engine/hash"
instancepb "github.com/mesg-foundation/engine/instance"
"github.com/mesg-foundation/engine/protobuf/types"
instancesdk "github.com/mesg-foundation/engine/sdk/instance"
servicesdk "github.com/mesg-foundation/engine/sdk/service"
"github.com/mesg-foundation/engine/x/instance"
)

const (
Expand All @@ -16,30 +20,30 @@ const (

// Event exposes event APIs of MESG.
type Event struct {
ps *pubsub.PubSub
instance *instancesdk.SDK
service *servicesdk.SDK
ps *pubsub.PubSub
client *cosmos.Client
service *servicesdk.SDK
}

// New creates a new Event SDK with given options.
func New(ps *pubsub.PubSub, service *servicesdk.SDK, instance *instancesdk.SDK) *Event {
func New(ps *pubsub.PubSub, service *servicesdk.SDK, client *cosmos.Client) *Event {
return &Event{
ps: ps,
service: service,
instance: instance,
ps: ps,
client: client,
service: service,
}
}

// Create a MESG event eventKey with eventData for service token.
func (e *Event) Create(instanceHash hash.Hash, eventKey string, eventData *types.Struct) (*event.Event, error) {
event := event.Create(instanceHash, eventKey, eventData)

instance, err := e.instance.Get(event.InstanceHash)
if err != nil {
var inst instancepb.Instance
if err := e.client.QueryJSON(fmt.Sprintf("custom/%s/%s/%s", instance.QuerierRoute, instance.QueryGetInstance, event.InstanceHash), nil, &inst); err != nil {
return nil, err
}

service, err := e.service.Get(instance.ServiceHash)
service, err := e.service.Get(inst.ServiceHash)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions sdk/execution/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ import (
"github.com/mesg-foundation/engine/hash"
"github.com/mesg-foundation/engine/protobuf/api"
"github.com/mesg-foundation/engine/protobuf/types"
instancesdk "github.com/mesg-foundation/engine/sdk/instance"
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/instance"
)

// Keeper holds the logic to read and write data.
type Keeper struct {
storeKey *cosmostypes.KVStoreKey
serviceKeeper *servicesdk.Keeper
instanceKeeper *instancesdk.Keeper
instanceKeeper instance.Keeper
runnerKeeper *runnersdk.Keeper
processKeeper *processsdk.Keeper
}

// NewKeeper initialize a new keeper.
func NewKeeper(storeKey *cosmostypes.KVStoreKey, serviceKeeper *servicesdk.Keeper, instanceKeeper *instancesdk.Keeper, runnerKeeper *runnersdk.Keeper, processKeeper *processsdk.Keeper) *Keeper {
func NewKeeper(storeKey *cosmostypes.KVStoreKey, serviceKeeper *servicesdk.Keeper, instanceKeeper instance.Keeper, runnerKeeper *runnersdk.Keeper, processKeeper *processsdk.Keeper) *Keeper {
return &Keeper{
storeKey: storeKey,
serviceKeeper: serviceKeeper,
Expand Down
15 changes: 6 additions & 9 deletions sdk/execution/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/mesg-foundation/engine/execution"
"github.com/mesg-foundation/engine/hash"
"github.com/mesg-foundation/engine/protobuf/api"
instancesdk "github.com/mesg-foundation/engine/sdk/instance"
runnersdk "github.com/mesg-foundation/engine/sdk/runner"
servicesdk "github.com/mesg-foundation/engine/sdk/service"
)
Expand All @@ -16,18 +15,16 @@ import (
type SDK struct {
client *cosmos.Client

serviceSDK *servicesdk.SDK
instanceSDK *instancesdk.SDK
runnerSDK *runnersdk.SDK
serviceSDK *servicesdk.SDK
runnerSDK *runnersdk.SDK
}

// New returns the execution sdk.
func New(client *cosmos.Client, serviceSDK *servicesdk.SDK, instanceSDK *instancesdk.SDK, runnerSDK *runnersdk.SDK) *SDK {
func New(client *cosmos.Client, serviceSDK *servicesdk.SDK, runnerSDK *runnersdk.SDK) *SDK {
sdk := &SDK{
client: client,
serviceSDK: serviceSDK,
instanceSDK: instanceSDK,
runnerSDK: runnerSDK,
client: client,
serviceSDK: serviceSDK,
runnerSDK: runnerSDK,
}
return sdk
}
Expand Down
80 changes: 0 additions & 80 deletions sdk/instance/keeper.go

This file was deleted.

56 changes: 0 additions & 56 deletions sdk/instance/module.go

This file was deleted.

48 changes: 0 additions & 48 deletions sdk/instance/sdk.go

This file was deleted.

Loading

0 comments on commit ee1f338

Please sign in to comment.