diff --git a/x/marketmap/keeper/msg_server.go b/x/marketmap/keeper/msg_server.go index 960bfdf6b..2de7a18ec 100644 --- a/x/marketmap/keeper/msg_server.go +++ b/x/marketmap/keeper/msg_server.go @@ -283,6 +283,10 @@ func (ms msgServer) RemoveMarkets( ctx.Logger().Info(fmt.Sprintf("deleted market %s", market)) deletedMarkets = append(deletedMarkets, market) } + + if err := ms.k.hooks.AfterMarketRemoved(ctx, market); err != nil { + return nil, fmt.Errorf("unable to run market removal hook: %w", err) + } } // check if the resulting state is valid: it may not be valid if the removed market is used as a normalization pair diff --git a/x/marketmap/types/hooks.go b/x/marketmap/types/hooks.go index 90b70c769..276d55591 100644 --- a/x/marketmap/types/hooks.go +++ b/x/marketmap/types/hooks.go @@ -16,7 +16,7 @@ type MarketMapHooks interface { AfterMarketGenesis(ctx sdk.Context, tickers map[string]Market) error // AfterMarketRemoved is called after a market is removed. - AfterMarketRemoved(ctx sdk.Context, market Market) error + AfterMarketRemoved(ctx sdk.Context, key string) error } var _ MarketMapHooks = &MultiMarketMapHooks{} @@ -58,9 +58,9 @@ func (mh MultiMarketMapHooks) AfterMarketGenesis(ctx sdk.Context, markets map[st } // AfterMarketRemoved calls all AfterMarketRemoved hooks registered to the MultiMarketMapHooks. -func (mh MultiMarketMapHooks) AfterMarketRemoved(ctx sdk.Context, market Market) error { +func (mh MultiMarketMapHooks) AfterMarketRemoved(ctx sdk.Context, key string) error { for i := range mh { - if err := mh[i].AfterMarketRemoved(ctx, market); err != nil { + if err := mh[i].AfterMarketRemoved(ctx, key); err != nil { return err } } @@ -88,6 +88,6 @@ func (n *NoopMarketMapHooks) AfterMarketGenesis(_ sdk.Context, _ map[string]Mark return nil } -func (n *NoopMarketMapHooks) AfterMarketRemoved(_ sdk.Context, _ Market) error { +func (n *NoopMarketMapHooks) AfterMarketRemoved(_ sdk.Context, _ string) error { return nil } diff --git a/x/marketmap/types/mocks/MarketMapHooks.go b/x/marketmap/types/mocks/MarketMapHooks.go index 20661e446..e09a523f0 100644 --- a/x/marketmap/types/mocks/MarketMapHooks.go +++ b/x/marketmap/types/mocks/MarketMapHooks.go @@ -117,17 +117,17 @@ func (_c *MarketMapHooks_AfterMarketGenesis_Call) RunAndReturn(run func(types.Co return _c } -// AfterMarketRemoved provides a mock function with given fields: ctx, market -func (_m *MarketMapHooks) AfterMarketRemoved(ctx types.Context, market marketmaptypes.Market) error { - ret := _m.Called(ctx, market) +// AfterMarketRemoved provides a mock function with given fields: ctx, key +func (_m *MarketMapHooks) AfterMarketRemoved(ctx types.Context, key string) error { + ret := _m.Called(ctx, key) if len(ret) == 0 { panic("no return value specified for AfterMarketRemoved") } var r0 error - if rf, ok := ret.Get(0).(func(types.Context, marketmaptypes.Market) error); ok { - r0 = rf(ctx, market) + if rf, ok := ret.Get(0).(func(types.Context, string) error); ok { + r0 = rf(ctx, key) } else { r0 = ret.Error(0) } @@ -142,14 +142,14 @@ type MarketMapHooks_AfterMarketRemoved_Call struct { // AfterMarketRemoved is a helper method to define mock.On call // - ctx types.Context -// - market marketmaptypes.Market -func (_e *MarketMapHooks_Expecter) AfterMarketRemoved(ctx interface{}, market interface{}) *MarketMapHooks_AfterMarketRemoved_Call { - return &MarketMapHooks_AfterMarketRemoved_Call{Call: _e.mock.On("AfterMarketRemoved", ctx, market)} +// - key string +func (_e *MarketMapHooks_Expecter) AfterMarketRemoved(ctx interface{}, key interface{}) *MarketMapHooks_AfterMarketRemoved_Call { + return &MarketMapHooks_AfterMarketRemoved_Call{Call: _e.mock.On("AfterMarketRemoved", ctx, key)} } -func (_c *MarketMapHooks_AfterMarketRemoved_Call) Run(run func(ctx types.Context, market marketmaptypes.Market)) *MarketMapHooks_AfterMarketRemoved_Call { +func (_c *MarketMapHooks_AfterMarketRemoved_Call) Run(run func(ctx types.Context, key string)) *MarketMapHooks_AfterMarketRemoved_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(types.Context), args[1].(marketmaptypes.Market)) + run(args[0].(types.Context), args[1].(string)) }) return _c } @@ -159,7 +159,7 @@ func (_c *MarketMapHooks_AfterMarketRemoved_Call) Return(_a0 error) *MarketMapHo return _c } -func (_c *MarketMapHooks_AfterMarketRemoved_Call) RunAndReturn(run func(types.Context, marketmaptypes.Market) error) *MarketMapHooks_AfterMarketRemoved_Call { +func (_c *MarketMapHooks_AfterMarketRemoved_Call) RunAndReturn(run func(types.Context, string) error) *MarketMapHooks_AfterMarketRemoved_Call { _c.Call.Return(run) return _c } diff --git a/x/oracle/keeper/hooks.go b/x/oracle/keeper/hooks.go index d228b425a..e962af2af 100644 --- a/x/oracle/keeper/hooks.go +++ b/x/oracle/keeper/hooks.go @@ -49,7 +49,8 @@ func (h Hooks) AfterMarketGenesis(ctx sdk.Context, markets map[string]marketmapt // AfterMarketRemoved is the marketmap hook for x/oracle that is run after a market is removed in // the marketmap. -func (h Hooks) AfterMarketRemoved(ctx sdk.Context, market marketmaptypes.Market) error { - ctx.Logger().Info(fmt.Sprintf("market %s removed. retaining x/oracle state if it exists", market.Ticker.String())) +func (h Hooks) AfterMarketRemoved(ctx sdk.Context, key string) error { + ctx.Logger().Info(fmt.Sprintf("market %s removed. retaining x/oracle state if it exists", key)) + return nil }