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 instance module to cosmos style #1653

Merged
merged 6 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
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