Skip to content

Commit

Permalink
x:ibc: remove alias.go usage (#6429)
Browse files Browse the repository at this point in the history
* x:ibc: remove alias.go usage

* Replace ibc24host with ibchost
  • Loading branch information
dauTT authored Jun 13, 2020
1 parent 1783f5e commit 560398c
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 70 deletions.
16 changes: 9 additions & 7 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
transfer "github.com/cosmos/cosmos-sdk/x/ibc-transfer"
ibcclient "github.com/cosmos/cosmos-sdk/x/ibc/02-client"
port "github.com/cosmos/cosmos-sdk/x/ibc/05-port"
ibchost "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
ibckeeper "github.com/cosmos/cosmos-sdk/x/ibc/keeper"
"github.com/cosmos/cosmos-sdk/x/mint"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
Expand Down Expand Up @@ -134,7 +136,7 @@ type SimApp struct {
CrisisKeeper crisis.Keeper
UpgradeKeeper upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
IBCKeeper *ibc.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
EvidenceKeeper evidence.Keeper
TransferKeeper transfer.Keeper

Expand Down Expand Up @@ -165,7 +167,7 @@ func NewSimApp(
keys := sdk.NewKVStoreKeys(
auth.StoreKey, bank.StoreKey, stakingtypes.StoreKey,
minttypes.StoreKey, distr.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, ibc.StoreKey, upgradetypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey,
evidence.StoreKey, transfer.StoreKey, capability.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -198,7 +200,7 @@ func NewSimApp(

// add capability keeper and ScopeToModule for ibc module
app.CapabilityKeeper = capability.NewKeeper(appCodec, keys[capability.StoreKey], memKeys[capability.MemStoreKey])
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibc.ModuleName)
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(transfer.ModuleName)

// add keepers
Expand Down Expand Up @@ -247,8 +249,8 @@ func NewSimApp(
// Create IBC Keeper
// TODO: remove amino codec dependency once Tendermint version is upgraded with
// protobuf changes
app.IBCKeeper = ibc.NewKeeper(
app.cdc, appCodec, keys[ibc.StoreKey], app.StakingKeeper, scopedIBCKeeper,
app.IBCKeeper = ibckeeper.NewKeeper(
app.cdc, appCodec, keys[ibchost.StoreKey], app.StakingKeeper, scopedIBCKeeper,
)

// Create Transfer Keepers
Expand Down Expand Up @@ -300,7 +302,7 @@ func NewSimApp(
// NOTE: staking module is required if HistoricalEntries param > 0
app.mm.SetOrderBeginBlockers(
upgradetypes.ModuleName, minttypes.ModuleName, distr.ModuleName, slashingtypes.ModuleName,
evidence.ModuleName, stakingtypes.ModuleName, ibc.ModuleName,
evidence.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName,
)
app.mm.SetOrderEndBlockers(crisis.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName)

Expand All @@ -312,7 +314,7 @@ func NewSimApp(
app.mm.SetOrderInitGenesis(
capability.ModuleName, auth.ModuleName, distr.ModuleName, stakingtypes.ModuleName, bank.ModuleName,
slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisis.ModuleName,
ibc.ModuleName, genutiltypes.ModuleName, evidence.ModuleName, transfer.ModuleName,
ibchost.ModuleName, genutiltypes.ModuleName, evidence.ModuleName, transfer.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
Expand Down
4 changes: 2 additions & 2 deletions simapp/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/evidence"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/ibc"
transfer "github.com/cosmos/cosmos-sdk/x/ibc-transfer"
ibchost "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/cosmos-sdk/x/simulation"
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestAppImportExport(t *testing.T) {
{app.keys[govtypes.StoreKey], newApp.keys[govtypes.StoreKey], [][]byte{}},
{app.keys[evidence.StoreKey], newApp.keys[evidence.StoreKey], [][]byte{}},
{app.keys[capability.StoreKey], newApp.keys[capability.StoreKey], [][]byte{}},
{app.keys[ibc.StoreKey], newApp.keys[ibc.StoreKey], [][]byte{}},
{app.keys[ibchost.StoreKey], newApp.keys[ibchost.StoreKey], [][]byte{}},
{app.keys[transfer.StoreKey], newApp.keys[transfer.StoreKey], [][]byte{}},
}

Expand Down
33 changes: 0 additions & 33 deletions x/ibc/alias.go

This file was deleted.

8 changes: 5 additions & 3 deletions x/ibc/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ import (
client "github.com/cosmos/cosmos-sdk/x/ibc/02-client"
connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection"
channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel"
"github.com/cosmos/cosmos-sdk/x/ibc/keeper"
"github.com/cosmos/cosmos-sdk/x/ibc/types"
)

// InitGenesis initializes the ibc state from a provided genesis
// state.
func InitGenesis(ctx sdk.Context, k Keeper, createLocalhost bool, gs GenesisState) {
func InitGenesis(ctx sdk.Context, k keeper.Keeper, createLocalhost bool, gs types.GenesisState) {
client.InitGenesis(ctx, k.ClientKeeper, gs.ClientGenesis)
connection.InitGenesis(ctx, k.ConnectionKeeper, gs.ConnectionGenesis)
channel.InitGenesis(ctx, k.ChannelKeeper, gs.ChannelGenesis)
}

// ExportGenesis returns the ibc exported genesis.
func ExportGenesis(ctx sdk.Context, k Keeper) GenesisState {
return GenesisState{
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState {
return types.GenesisState{
ClientGenesis: client.ExportGenesis(ctx, k.ClientKeeper),
ConnectionGenesis: connection.ExportGenesis(ctx, k.ConnectionKeeper),
ChannelGenesis: channel.ExportGenesis(ctx, k.ChannelKeeper),
Expand Down
14 changes: 7 additions & 7 deletions x/ibc/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ibc_test
import (
lite "github.com/tendermint/tendermint/lite2"

"github.com/cosmos/cosmos-sdk/x/ibc"
client "github.com/cosmos/cosmos-sdk/x/ibc/02-client"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection"
Expand All @@ -12,22 +11,23 @@ import (
localhosttypes "github.com/cosmos/cosmos-sdk/x/ibc/09-localhost/types"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
"github.com/cosmos/cosmos-sdk/x/ibc/types"
)

func (suite *IBCTestSuite) TestValidateGenesis() {
testCases := []struct {
name string
genState ibc.GenesisState
genState types.GenesisState
expPass bool
}{
{
name: "default",
genState: ibc.DefaultGenesisState(),
genState: types.DefaultGenesisState(),
expPass: true,
},
{
name: "valid genesis",
genState: ibc.GenesisState{
genState: types.GenesisState{
ClientGenesis: client.NewGenesisState(
[]exported.ClientState{
ibctmtypes.NewClientState(clientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header, commitmenttypes.GetSDKSpecs()),
Expand Down Expand Up @@ -83,7 +83,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
},
{
name: "invalid client genesis",
genState: ibc.GenesisState{
genState: types.GenesisState{
ClientGenesis: client.NewGenesisState(
[]exported.ClientState{
ibctmtypes.NewClientState(clientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header, commitmenttypes.GetSDKSpecs()),
Expand All @@ -98,7 +98,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
},
{
name: "invalid connection genesis",
genState: ibc.GenesisState{
genState: types.GenesisState{
ClientGenesis: client.DefaultGenesisState(),
ConnectionGenesis: connection.NewGenesisState(
[]connection.End{
Expand All @@ -113,7 +113,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
},
{
name: "invalid channel genesis",
genState: ibc.GenesisState{
genState: types.GenesisState{
ClientGenesis: client.DefaultGenesisState(),
ConnectionGenesis: connection.DefaultGenesisState(),
ChannelGenesis: channel.GenesisState{
Expand Down
3 changes: 2 additions & 1 deletion x/ibc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection"
channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel"
port "github.com/cosmos/cosmos-sdk/x/ibc/05-port"
"github.com/cosmos/cosmos-sdk/x/ibc/keeper"
)

// NewHandler defines the IBC handler
func NewHandler(k Keeper) sdk.Handler {
func NewHandler(k keeper.Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
ctx = ctx.WithEventManager(sdk.NewEventManager())

Expand Down
36 changes: 19 additions & 17 deletions x/ibc/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import (
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
"github.com/cosmos/cosmos-sdk/x/ibc/client/cli"
"github.com/cosmos/cosmos-sdk/x/ibc/client/rest"
"github.com/cosmos/cosmos-sdk/x/ibc/keeper"
"github.com/cosmos/cosmos-sdk/x/ibc/simulation"
"github.com/cosmos/cosmos-sdk/x/ibc/types"
)

var (
Expand All @@ -42,64 +44,64 @@ func (AppModuleBasic) Name() string {

// RegisterCodec registers the ibc module's types for the given codec.
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
RegisterCodec(cdc)
types.RegisterCodec(cdc)
}

// DefaultGenesis returns default genesis state as raw bytes for the ibc
// module.
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage {
return cdc.MustMarshalJSON(DefaultGenesisState())
return cdc.MustMarshalJSON(types.DefaultGenesisState())
}

// ValidateGenesis performs genesis state validation for the ibc module.
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error {
var gs GenesisState
var gs types.GenesisState
if err := cdc.UnmarshalJSON(bz, &gs); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err)
return fmt.Errorf("failed to unmarshal %s genesis state: %w", host.ModuleName, err)
}

return gs.Validate()
}

// RegisterRESTRoutes registers the REST routes for the ibc module.
func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {
rest.RegisterRoutes(clientCtx, rtr, StoreKey)
rest.RegisterRoutes(clientCtx, rtr, host.StoreKey)
}

// GetTxCmd returns the root tx command for the ibc module.
func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command {
return cli.GetTxCmd(StoreKey, clientCtx.Codec)
return cli.GetTxCmd(host.StoreKey, clientCtx.Codec)
}

// GetQueryCmd returns no root query command for the ibc module.
func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command {
return cli.GetQueryCmd(QuerierRoute, clientCtx.Codec)
return cli.GetQueryCmd(host.QuerierRoute, clientCtx.Codec)
}

// RegisterInterfaceTypes registers module concrete types into protobuf Any.
func (AppModuleBasic) RegisterInterfaceTypes(registry cdctypes.InterfaceRegistry) {
RegisterInterfaces(registry)
types.RegisterInterfaces(registry)
}

// AppModule implements an application module for the ibc module.
type AppModule struct {
AppModuleBasic
keeper *Keeper
keeper *keeper.Keeper

// create localhost by default
createLocalhost bool
}

// NewAppModule creates a new AppModule object
func NewAppModule(k *Keeper) AppModule {
func NewAppModule(k *keeper.Keeper) AppModule {
return AppModule{
keeper: k,
}
}

// Name returns the ibc module's name.
func (AppModule) Name() string {
return ModuleName
return host.ModuleName
}

// RegisterInvariants registers the ibc module invariants.
Expand All @@ -109,28 +111,28 @@ func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {

// Route returns the message routing key for the ibc module.
func (am AppModule) Route() sdk.Route {
return sdk.NewRoute(RouterKey, NewHandler(*am.keeper))
return sdk.NewRoute(host.RouterKey, NewHandler(*am.keeper))
}

// QuerierRoute returns the ibc module's querier route name.
func (AppModule) QuerierRoute() string {
return QuerierRoute
return host.QuerierRoute
}

// NewQuerierHandler returns the ibc module sdk.Querier.
func (am AppModule) NewQuerierHandler() sdk.Querier {
return NewQuerier(*am.keeper)
return keeper.NewQuerier(*am.keeper)
}

func (am AppModule) RegisterQueryService(grpc.Server) {}

// InitGenesis performs genesis initialization for the ibc module. It returns
// no validator updates.
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, bz json.RawMessage) []abci.ValidatorUpdate {
var gs GenesisState
var gs types.GenesisState
err := cdc.UnmarshalJSON(bz, &gs)
if err != nil {
panic(fmt.Sprintf("failed to unmarshal %s genesis state: %s", ModuleName, err))
panic(fmt.Sprintf("failed to unmarshal %s genesis state: %s", host.ModuleName, err))
}
InitGenesis(ctx, *am.keeper, am.createLocalhost, gs)
return []abci.ValidatorUpdate{}
Expand Down Expand Up @@ -174,7 +176,7 @@ func (AppModule) RandomizedParams(_ *rand.Rand) []simtypes.ParamChange {

// RegisterStoreDecoder registers a decoder for ibc module's types
func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
sdr[StoreKey] = simulation.NewDecodeStore(am.keeper.Codecs())
sdr[host.StoreKey] = simulation.NewDecodeStore(am.keeper.Codecs())
}

// WeightedOperations returns the all the ibc module operations with their respective weights.
Expand Down

0 comments on commit 560398c

Please sign in to comment.