Skip to content

Commit

Permalink
refactor: use context.Context instead of sdk.Context for hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
RiccardoM committed Jun 6, 2024
1 parent 4f0ec34 commit b26fcab
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
7 changes: 4 additions & 3 deletions x/services/keeper/common_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper_test

import (
"context"
"testing"

"cosmossdk.io/log"
Expand Down Expand Up @@ -144,14 +145,14 @@ func newMockHooks() *mockHooks {
return &mockHooks{CalledMap: make(map[string]bool)}
}

func (m mockHooks) AfterServiceCreated(_ sdk.Context, _ uint32) {
func (m mockHooks) AfterServiceCreated(_ context.Context, _ uint32) {
m.CalledMap["AfterServiceCreated"] = true
}

func (m mockHooks) AfterServiceActivated(_ sdk.Context, _ uint32) {
func (m mockHooks) AfterServiceActivated(_ context.Context, _ uint32) {
m.CalledMap["AfterServiceActivated"] = true
}

func (m mockHooks) AfterServiceDeactivated(_ sdk.Context, _ uint32) {
func (m mockHooks) AfterServiceDeactivated(_ context.Context, _ uint32) {
m.CalledMap["AfterServiceDeactivated"] = true
}
8 changes: 4 additions & 4 deletions x/services/keeper/hooks.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"context"

"github.com/milkyway-labs/milkyway/x/services/types"
)
Expand All @@ -10,21 +10,21 @@ import (
var _ types.ServicesHooks = &Keeper{}

// AfterServiceCreated implements ServicesHooks
func (k *Keeper) AfterServiceCreated(ctx sdk.Context, avsID uint32) {
func (k *Keeper) AfterServiceCreated(ctx context.Context, avsID uint32) {
if k.hooks != nil {
k.hooks.AfterServiceCreated(ctx, avsID)
}
}

// AfterServiceActivated implements ServicesHooks
func (k *Keeper) AfterServiceActivated(ctx sdk.Context, avsID uint32) {
func (k *Keeper) AfterServiceActivated(ctx context.Context, avsID uint32) {
if k.hooks != nil {
k.hooks.AfterServiceActivated(ctx, avsID)
}
}

// AfterServiceDeactivated implements ServicesHooks
func (k *Keeper) AfterServiceDeactivated(ctx sdk.Context, avsID uint32) {
func (k *Keeper) AfterServiceDeactivated(ctx context.Context, avsID uint32) {
if k.hooks != nil {
k.hooks.AfterServiceDeactivated(ctx, avsID)
}
Expand Down
8 changes: 4 additions & 4 deletions x/services/testutil/hooks_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions x/services/types/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package types
// DONTCOVER

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"context"
)

// Event Hooks
Expand All @@ -14,13 +14,15 @@ import (

// ServicesHooks event hooks for services objects (noalias)
type ServicesHooks interface {
AfterServiceCreated(ctx sdk.Context, serviceID uint32) // Must be called after a service is created
AfterServiceActivated(ctx sdk.Context, serviceID uint32) // Must be called after a service is registered
AfterServiceDeactivated(ctx sdk.Context, serviceID uint32) // Must be called after a service is deregistered
AfterServiceCreated(ctx context.Context, serviceID uint32) // Must be called after a service is created
AfterServiceActivated(ctx context.Context, serviceID uint32) // Must be called after a service is registered
AfterServiceDeactivated(ctx context.Context, serviceID uint32) // Must be called after a service is deregistered
}

// --------------------------------------------------------------------------------------------------------------------

var _ ServicesHooks = MultiServicesHooks{}

// MultiServicesHooks combines multiple services hooks, all hook functions are run in array sequence
type MultiServicesHooks []ServicesHooks

Expand All @@ -30,21 +32,21 @@ func NewMultiServicesHooks(hooks ...ServicesHooks) MultiServicesHooks {
}

// AfterServiceCreated implements ServicesHooks
func (m MultiServicesHooks) AfterServiceCreated(ctx sdk.Context, serviceID uint32) {
func (m MultiServicesHooks) AfterServiceCreated(ctx context.Context, serviceID uint32) {
for _, hook := range m {
hook.AfterServiceCreated(ctx, serviceID)
}
}

// AfterServiceActivated implements ServicesHooks
func (m MultiServicesHooks) AfterServiceActivated(ctx sdk.Context, serviceID uint32) {
func (m MultiServicesHooks) AfterServiceActivated(ctx context.Context, serviceID uint32) {
for _, hook := range m {
hook.AfterServiceActivated(ctx, serviceID)
}
}

// AfterServiceDeactivated implements ServicesHooks
func (m MultiServicesHooks) AfterServiceDeactivated(ctx sdk.Context, serviceID uint32) {
func (m MultiServicesHooks) AfterServiceDeactivated(ctx context.Context, serviceID uint32) {
for _, hook := range m {
hook.AfterServiceDeactivated(ctx, serviceID)
}
Expand Down

0 comments on commit b26fcab

Please sign in to comment.