From 82afd5298195c4cdb06aa692b461222c1b22fa94 Mon Sep 17 00:00:00 2001 From: dauTT <30392990+dauTT@users.noreply.github.com> Date: Wed, 10 Jun 2020 20:54:15 +0200 Subject: [PATCH] x/upgrade: remove alias.go usage (#6382) * x/upgrade: remove alias.go usage * Simplify code Co-authored-by: Alexander Bezobchuk Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- simapp/app.go | 12 +++++---- x/upgrade/abci.go | 3 ++- x/upgrade/abci_test.go | 58 ++++++++++++++++++++++-------------------- x/upgrade/alias.go | 40 ----------------------------- x/upgrade/handler.go | 12 +++++---- x/upgrade/module.go | 21 +++++++-------- 6 files changed, 57 insertions(+), 89 deletions(-) delete mode 100644 x/upgrade/alias.go diff --git a/simapp/app.go b/simapp/app.go index 7835fa2843..4ee634887b 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -38,6 +38,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/upgrade" upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" + upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) const appName = "SimApp" @@ -119,7 +121,7 @@ type SimApp struct { DistrKeeper distr.Keeper GovKeeper gov.Keeper CrisisKeeper crisis.Keeper - UpgradeKeeper upgrade.Keeper + UpgradeKeeper upgradekeeper.Keeper ParamsKeeper params.Keeper IBCKeeper *ibc.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly EvidenceKeeper evidence.Keeper @@ -152,7 +154,7 @@ func NewSimApp( keys := sdk.NewKVStoreKeys( auth.StoreKey, bank.StoreKey, staking.StoreKey, mint.StoreKey, distr.StoreKey, slashing.StoreKey, - gov.StoreKey, params.StoreKey, ibc.StoreKey, upgrade.StoreKey, + gov.StoreKey, params.StoreKey, ibc.StoreKey, upgradetypes.StoreKey, evidence.StoreKey, transfer.StoreKey, capability.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(params.TStoreKey) @@ -212,14 +214,14 @@ func NewSimApp( app.CrisisKeeper = crisis.NewKeeper( app.subspaces[crisis.ModuleName], invCheckPeriod, app.BankKeeper, auth.FeeCollectorName, ) - app.UpgradeKeeper = upgrade.NewKeeper(skipUpgradeHeights, keys[upgrade.StoreKey], appCodec, homePath) + app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath) // register the proposal types govRouter := gov.NewRouter() govRouter.AddRoute(gov.RouterKey, gov.ProposalHandler). AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)). AddRoute(distr.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)). - AddRoute(upgrade.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)) + AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)) app.GovKeeper = gov.NewKeeper( appCodec, keys[gov.StoreKey], app.subspaces[gov.ModuleName], app.AccountKeeper, app.BankKeeper, &stakingKeeper, govRouter, @@ -286,7 +288,7 @@ func NewSimApp( // CanWithdrawInvariant invariant. // NOTE: staking module is required if HistoricalEntries param > 0 app.mm.SetOrderBeginBlockers( - upgrade.ModuleName, mint.ModuleName, distr.ModuleName, slashing.ModuleName, + upgradetypes.ModuleName, mint.ModuleName, distr.ModuleName, slashing.ModuleName, evidence.ModuleName, staking.ModuleName, ibc.ModuleName, ) app.mm.SetOrderEndBlockers(crisis.ModuleName, gov.ModuleName, staking.ModuleName) diff --git a/x/upgrade/abci.go b/x/upgrade/abci.go index f5c6d6a348..c52220d05a 100644 --- a/x/upgrade/abci.go +++ b/x/upgrade/abci.go @@ -6,6 +6,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" ) // BeginBlock will check if there is a scheduled plan and if it is ready to be executed. @@ -16,7 +17,7 @@ import ( // The purpose is to ensure the binary is switched EXACTLY at the desired block, and to allow // a migration to be executed if needed upon this switch (migration defined in the new binary) // skipUpgradeHeightArray is a set of block heights for which the upgrade must be skipped -func BeginBlocker(k Keeper, ctx sdk.Context, _ abci.RequestBeginBlock) { +func BeginBlocker(k keeper.Keeper, ctx sdk.Context, _ abci.RequestBeginBlock) { plan, found := k.GetUpgradePlan(ctx) if !found { return diff --git a/x/upgrade/abci_test.go b/x/upgrade/abci_test.go index 131cdd7853..545b8ee262 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -22,11 +22,13 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/gov" "github.com/cosmos/cosmos-sdk/x/upgrade" + "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) type TestSuite struct { module module.AppModule - keeper upgrade.Keeper + keeper keeper.Keeper querier sdk.Querier handler gov.Handler ctx sdk.Context @@ -61,28 +63,28 @@ func setupTest(height int64, skip map[int64]bool) TestSuite { func TestRequireName(t *testing.T) { s := setupTest(10, map[int64]bool{}) - err := s.handler(s.ctx, &upgrade.SoftwareUpgradeProposal{Title: "prop", Plan: upgrade.Plan{}}) + err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{}}) require.NotNil(t, err) require.True(t, errors.Is(sdkerrors.ErrInvalidRequest, err), err) } func TestRequireFutureTime(t *testing.T) { s := setupTest(10, map[int64]bool{}) - err := s.handler(s.ctx, &upgrade.SoftwareUpgradeProposal{Title: "prop", Plan: upgrade.Plan{Name: "test", Time: s.ctx.BlockHeader().Time}}) + err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Time: s.ctx.BlockHeader().Time}}) require.NotNil(t, err) require.True(t, errors.Is(sdkerrors.ErrInvalidRequest, err), err) } func TestRequireFutureBlock(t *testing.T) { s := setupTest(10, map[int64]bool{}) - err := s.handler(s.ctx, &upgrade.SoftwareUpgradeProposal{Title: "prop", Plan: upgrade.Plan{Name: "test", Height: s.ctx.BlockHeight()}}) + err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Height: s.ctx.BlockHeight()}}) require.NotNil(t, err) require.True(t, errors.Is(sdkerrors.ErrInvalidRequest, err), err) } func TestCantSetBothTimeAndHeight(t *testing.T) { s := setupTest(10, map[int64]bool{}) - err := s.handler(s.ctx, &upgrade.SoftwareUpgradeProposal{Title: "prop", Plan: upgrade.Plan{Name: "test", Time: time.Now(), Height: s.ctx.BlockHeight() + 1}}) + err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Time: time.Now(), Height: s.ctx.BlockHeight() + 1}}) require.NotNil(t, err) require.True(t, errors.Is(sdkerrors.ErrInvalidRequest, err), err) } @@ -90,7 +92,7 @@ func TestCantSetBothTimeAndHeight(t *testing.T) { func TestDoTimeUpgrade(t *testing.T) { s := setupTest(10, map[int64]bool{}) t.Log("Verify can schedule an upgrade") - err := s.handler(s.ctx, &upgrade.SoftwareUpgradeProposal{Title: "prop", Plan: upgrade.Plan{Name: "test", Time: time.Now()}}) + err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Time: time.Now()}}) require.Nil(t, err) VerifyDoUpgrade(t) @@ -99,7 +101,7 @@ func TestDoTimeUpgrade(t *testing.T) { func TestDoHeightUpgrade(t *testing.T) { s := setupTest(10, map[int64]bool{}) t.Log("Verify can schedule an upgrade") - err := s.handler(s.ctx, &upgrade.SoftwareUpgradeProposal{Title: "prop", Plan: upgrade.Plan{Name: "test", Height: s.ctx.BlockHeight() + 1}}) + err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Height: s.ctx.BlockHeight() + 1}}) require.Nil(t, err) VerifyDoUpgrade(t) @@ -108,9 +110,9 @@ func TestDoHeightUpgrade(t *testing.T) { func TestCanOverwriteScheduleUpgrade(t *testing.T) { s := setupTest(10, map[int64]bool{}) t.Log("Can overwrite plan") - err := s.handler(s.ctx, &upgrade.SoftwareUpgradeProposal{Title: "prop", Plan: upgrade.Plan{Name: "bad_test", Height: s.ctx.BlockHeight() + 10}}) + err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "bad_test", Height: s.ctx.BlockHeight() + 10}}) require.Nil(t, err) - err = s.handler(s.ctx, &upgrade.SoftwareUpgradeProposal{Title: "prop", Plan: upgrade.Plan{Name: "test", Height: s.ctx.BlockHeight() + 1}}) + err = s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Height: s.ctx.BlockHeight() + 1}}) require.Nil(t, err) VerifyDoUpgrade(t) @@ -126,7 +128,7 @@ func VerifyDoUpgrade(t *testing.T) { }) t.Log("Verify that the upgrade can be successfully applied with a handler") - s.keeper.SetUpgradeHandler("test", func(ctx sdk.Context, plan upgrade.Plan) {}) + s.keeper.SetUpgradeHandler("test", func(ctx sdk.Context, plan types.Plan) {}) require.NotPanics(t, func() { s.module.BeginBlock(newCtx, req) }) @@ -142,7 +144,7 @@ func VerifyDoUpgradeWithCtx(t *testing.T, newCtx sdk.Context, proposalName strin }) t.Log("Verify that the upgrade can be successfully applied with a handler") - s.keeper.SetUpgradeHandler(proposalName, func(ctx sdk.Context, plan upgrade.Plan) {}) + s.keeper.SetUpgradeHandler(proposalName, func(ctx sdk.Context, plan types.Plan) {}) require.NotPanics(t, func() { s.module.BeginBlock(newCtx, req) }) @@ -154,7 +156,7 @@ func TestHaltIfTooNew(t *testing.T) { s := setupTest(10, map[int64]bool{}) t.Log("Verify that we don't panic with registered plan not in database at all") var called int - s.keeper.SetUpgradeHandler("future", func(ctx sdk.Context, plan upgrade.Plan) { called++ }) + s.keeper.SetUpgradeHandler("future", func(ctx sdk.Context, plan types.Plan) { called++ }) newCtx := s.ctx.WithBlockHeight(s.ctx.BlockHeight() + 1).WithBlockTime(time.Now()) req := abci.RequestBeginBlock{Header: newCtx.BlockHeader()} @@ -164,7 +166,7 @@ func TestHaltIfTooNew(t *testing.T) { require.Equal(t, 0, called) t.Log("Verify we panic if we have a registered handler ahead of time") - err := s.handler(s.ctx, &upgrade.SoftwareUpgradeProposal{Title: "prop", Plan: upgrade.Plan{Name: "future", Height: s.ctx.BlockHeight() + 3}}) + err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "future", Height: s.ctx.BlockHeight() + 3}}) require.NoError(t, err) require.Panics(t, func() { s.module.BeginBlock(newCtx, req) @@ -185,7 +187,7 @@ func TestHaltIfTooNew(t *testing.T) { func VerifyCleared(t *testing.T, newCtx sdk.Context) { t.Log("Verify that the upgrade plan has been cleared") - bz, err := s.querier(newCtx, []string{upgrade.QueryCurrent}, abci.RequestQuery{}) + bz, err := s.querier(newCtx, []string{types.QueryCurrent}, abci.RequestQuery{}) require.NoError(t, err) require.Nil(t, bz) } @@ -193,10 +195,10 @@ func VerifyCleared(t *testing.T, newCtx sdk.Context) { func TestCanClear(t *testing.T) { s := setupTest(10, map[int64]bool{}) t.Log("Verify upgrade is scheduled") - err := s.handler(s.ctx, &upgrade.SoftwareUpgradeProposal{Title: "prop", Plan: upgrade.Plan{Name: "test", Time: time.Now()}}) + err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Time: time.Now()}}) require.Nil(t, err) - err = s.handler(s.ctx, &upgrade.CancelSoftwareUpgradeProposal{Title: "cancel"}) + err = s.handler(s.ctx, &types.CancelSoftwareUpgradeProposal{Title: "cancel"}) require.Nil(t, err) VerifyCleared(t, s.ctx) @@ -204,11 +206,11 @@ func TestCanClear(t *testing.T) { func TestCantApplySameUpgradeTwice(t *testing.T) { s := setupTest(10, map[int64]bool{}) - err := s.handler(s.ctx, &upgrade.SoftwareUpgradeProposal{Title: "prop", Plan: upgrade.Plan{Name: "test", Time: time.Now()}}) + err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Time: time.Now()}}) require.Nil(t, err) VerifyDoUpgrade(t) t.Log("Verify an executed upgrade \"test\" can't be rescheduled") - err = s.handler(s.ctx, &upgrade.SoftwareUpgradeProposal{Title: "prop", Plan: upgrade.Plan{Name: "test", Time: time.Now()}}) + err = s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Time: time.Now()}}) require.NotNil(t, err) require.True(t, errors.Is(sdkerrors.ErrInvalidRequest, err), err) } @@ -228,11 +230,11 @@ func TestPlanStringer(t *testing.T) { require.Equal(t, `Upgrade Plan Name: test Time: 2020-01-01T00:00:00Z - Info: `, upgrade.Plan{Name: "test", Time: ti}.String()) + Info: `, types.Plan{Name: "test", Time: ti}.String()) require.Equal(t, `Upgrade Plan Name: test Height: 100 - Info: `, upgrade.Plan{Name: "test", Height: 100}.String()) + Info: `, types.Plan{Name: "test", Height: 100}.String()) } func VerifyNotDone(t *testing.T, newCtx sdk.Context, name string) { @@ -279,7 +281,7 @@ func TestSkipUpgradeSkippingAll(t *testing.T) { newCtx := s.ctx req := abci.RequestBeginBlock{Header: newCtx.BlockHeader()} - err := s.handler(s.ctx, &upgrade.SoftwareUpgradeProposal{Title: "prop", Plan: upgrade.Plan{Name: "test", Height: skipOne}}) + err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Height: skipOne}}) require.NoError(t, err) t.Log("Verify if skip upgrade flag clears upgrade plan in both cases") @@ -291,7 +293,7 @@ func TestSkipUpgradeSkippingAll(t *testing.T) { }) t.Log("Verify a second proposal also is being cleared") - err = s.handler(s.ctx, &upgrade.SoftwareUpgradeProposal{Title: "prop2", Plan: upgrade.Plan{Name: "test2", Height: skipTwo}}) + err = s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop2", Plan: types.Plan{Name: "test2", Height: skipTwo}}) require.NoError(t, err) newCtx = newCtx.WithBlockHeight(skipTwo) @@ -316,7 +318,7 @@ func TestUpgradeSkippingOne(t *testing.T) { newCtx := s.ctx req := abci.RequestBeginBlock{Header: newCtx.BlockHeader()} - err := s.handler(s.ctx, &upgrade.SoftwareUpgradeProposal{Title: "prop", Plan: upgrade.Plan{Name: "test", Height: skipOne}}) + err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Height: skipOne}}) require.Nil(t, err) t.Log("Verify if skip upgrade flag clears upgrade plan in one case and does upgrade on another") @@ -329,7 +331,7 @@ func TestUpgradeSkippingOne(t *testing.T) { }) t.Log("Verify the second proposal is not skipped") - err = s.handler(s.ctx, &upgrade.SoftwareUpgradeProposal{Title: "prop2", Plan: upgrade.Plan{Name: "test2", Height: skipTwo}}) + err = s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop2", Plan: types.Plan{Name: "test2", Height: skipTwo}}) require.Nil(t, err) // Setting block height of proposal test2 newCtx = newCtx.WithBlockHeight(skipTwo) @@ -351,7 +353,7 @@ func TestUpgradeSkippingOnlyTwo(t *testing.T) { newCtx := s.ctx req := abci.RequestBeginBlock{Header: newCtx.BlockHeader()} - err := s.handler(s.ctx, &upgrade.SoftwareUpgradeProposal{Title: "prop", Plan: upgrade.Plan{Name: "test", Height: skipOne}}) + err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Height: skipOne}}) require.Nil(t, err) t.Log("Verify if skip upgrade flag clears upgrade plan in both cases and does third upgrade") @@ -364,7 +366,7 @@ func TestUpgradeSkippingOnlyTwo(t *testing.T) { }) // A new proposal with height in skipUpgradeHeights - err = s.handler(s.ctx, &upgrade.SoftwareUpgradeProposal{Title: "prop2", Plan: upgrade.Plan{Name: "test2", Height: skipTwo}}) + err = s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop2", Plan: types.Plan{Name: "test2", Height: skipTwo}}) require.Nil(t, err) // Setting block height of proposal test2 newCtx = newCtx.WithBlockHeight(skipTwo) @@ -373,7 +375,7 @@ func TestUpgradeSkippingOnlyTwo(t *testing.T) { }) t.Log("Verify a new proposal is not skipped") - err = s.handler(s.ctx, &upgrade.SoftwareUpgradeProposal{Title: "prop3", Plan: upgrade.Plan{Name: "test3", Height: skipThree}}) + err = s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop3", Plan: types.Plan{Name: "test3", Height: skipThree}}) require.Nil(t, err) newCtx = newCtx.WithBlockHeight(skipThree) VerifyDoUpgradeWithCtx(t, newCtx, "test3") @@ -388,7 +390,7 @@ func TestUpgradeWithoutSkip(t *testing.T) { s := setupTest(10, map[int64]bool{}) newCtx := s.ctx.WithBlockHeight(s.ctx.BlockHeight() + 1).WithBlockTime(time.Now()) req := abci.RequestBeginBlock{Header: newCtx.BlockHeader()} - err := s.handler(s.ctx, &upgrade.SoftwareUpgradeProposal{Title: "prop", Plan: upgrade.Plan{Name: "test", Height: s.ctx.BlockHeight() + 1}}) + err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Height: s.ctx.BlockHeight() + 1}}) require.Nil(t, err) t.Log("Verify if upgrade happens without skip upgrade") require.Panics(t, func() { diff --git a/x/upgrade/alias.go b/x/upgrade/alias.go deleted file mode 100644 index 6e4fb09e5f..0000000000 --- a/x/upgrade/alias.go +++ /dev/null @@ -1,40 +0,0 @@ -package upgrade - -import ( - "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" - "github.com/cosmos/cosmos-sdk/x/upgrade/types" -) - -const ( - ModuleName = types.ModuleName - RouterKey = types.RouterKey - StoreKey = types.StoreKey - QuerierKey = types.QuerierKey - PlanByte = types.PlanByte - DoneByte = types.DoneByte - ProposalTypeSoftwareUpgrade = types.ProposalTypeSoftwareUpgrade - ProposalTypeCancelSoftwareUpgrade = types.ProposalTypeCancelSoftwareUpgrade - QueryCurrent = types.QueryCurrent - QueryApplied = types.QueryApplied -) - -var ( - // functions aliases - RegisterCodec = types.RegisterCodec - PlanKey = types.PlanKey - NewSoftwareUpgradeProposal = types.NewSoftwareUpgradeProposal - NewCancelSoftwareUpgradeProposal = types.NewCancelSoftwareUpgradeProposal - NewQueryAppliedParams = types.NewQueryAppliedParams - UpgradeStoreLoader = types.UpgradeStoreLoader - NewKeeper = keeper.NewKeeper - NewQuerier = keeper.NewQuerier -) - -type ( - UpgradeHandler = types.UpgradeHandler // nolint - Plan = types.Plan - SoftwareUpgradeProposal = types.SoftwareUpgradeProposal - CancelSoftwareUpgradeProposal = types.CancelSoftwareUpgradeProposal - QueryAppliedParams = types.QueryAppliedParams - Keeper = keeper.Keeper -) diff --git a/x/upgrade/handler.go b/x/upgrade/handler.go index d98d0a5da6..413217dc72 100644 --- a/x/upgrade/handler.go +++ b/x/upgrade/handler.go @@ -4,18 +4,20 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) // NewSoftwareUpgradeProposalHandler creates a governance handler to manage new proposal types. // It enables SoftwareUpgradeProposal to propose an Upgrade, and CancelSoftwareUpgradeProposal // to abort a previously voted upgrade. -func NewSoftwareUpgradeProposalHandler(k Keeper) govtypes.Handler { +func NewSoftwareUpgradeProposalHandler(k keeper.Keeper) govtypes.Handler { return func(ctx sdk.Context, content govtypes.Content) error { switch c := content.(type) { - case *SoftwareUpgradeProposal: + case *types.SoftwareUpgradeProposal: return handleSoftwareUpgradeProposal(ctx, k, c) - case *CancelSoftwareUpgradeProposal: + case *types.CancelSoftwareUpgradeProposal: return handleCancelSoftwareUpgradeProposal(ctx, k, c) default: @@ -24,11 +26,11 @@ func NewSoftwareUpgradeProposalHandler(k Keeper) govtypes.Handler { } } -func handleSoftwareUpgradeProposal(ctx sdk.Context, k Keeper, p *SoftwareUpgradeProposal) error { +func handleSoftwareUpgradeProposal(ctx sdk.Context, k keeper.Keeper, p *types.SoftwareUpgradeProposal) error { return k.ScheduleUpgrade(ctx, p.Plan) } -func handleCancelSoftwareUpgradeProposal(ctx sdk.Context, k Keeper, _ *CancelSoftwareUpgradeProposal) error { +func handleCancelSoftwareUpgradeProposal(ctx sdk.Context, k keeper.Keeper, _ *types.CancelSoftwareUpgradeProposal) error { k.ClearUpgradePlan(ctx) return nil } diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 6ef3c07a3d..93e034b35f 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -18,14 +18,15 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/upgrade/client/cli" "github.com/cosmos/cosmos-sdk/x/upgrade/client/rest" - types "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) // module codec var moduleCdc = codec.New() func init() { - RegisterCodec(moduleCdc) + types.RegisterCodec(moduleCdc) } var ( @@ -39,12 +40,12 @@ type AppModuleBasic struct{} // Name returns the ModuleName func (AppModuleBasic) Name() string { - return ModuleName + return types.ModuleName } // RegisterCodec registers the upgrade types on the amino codec func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { - RegisterCodec(cdc) + types.RegisterCodec(cdc) } // RegisterRESTRoutes registers all REST query handlers @@ -59,8 +60,8 @@ func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command { Short: "Querying commands for the upgrade module", } queryCmd.AddCommand(flags.GetCommands( - cli.GetPlanCmd(StoreKey, clientCtx.Codec), - cli.GetAppliedHeightCmd(StoreKey, clientCtx.Codec), + cli.GetPlanCmd(types.StoreKey, clientCtx.Codec), + cli.GetAppliedHeightCmd(types.StoreKey, clientCtx.Codec), )...) return queryCmd @@ -83,11 +84,11 @@ func (b AppModuleBasic) RegisterInterfaceTypes(registry codectypes.InterfaceRegi // AppModule implements the sdk.AppModule interface type AppModule struct { AppModuleBasic - keeper Keeper + keeper keeper.Keeper } // NewAppModule creates a new AppModule object -func NewAppModule(keeper Keeper) AppModule { +func NewAppModule(keeper keeper.Keeper) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{}, keeper: keeper, @@ -101,11 +102,11 @@ func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} func (AppModule) Route() *sdk.Route { return nil } // QuerierRoute returns the route we respond to for abci queries -func (AppModule) QuerierRoute() string { return QuerierKey } +func (AppModule) QuerierRoute() string { return types.QuerierKey } // NewQuerierHandler registers a query handler to respond to the module-specific queries func (am AppModule) NewQuerierHandler() sdk.Querier { - return NewQuerier(am.keeper) + return keeper.NewQuerier(am.keeper) } func (am AppModule) RegisterQueryService(grpc.Server) {}