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

x:ibc: remove alias.go usage #6429

Merged
merged 4 commits into from
Jun 13, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 9 additions & 7 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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"
"github.com/cosmos/cosmos-sdk/x/params"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
Expand Down Expand Up @@ -129,7 +131,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 @@ -160,7 +162,7 @@ func NewSimApp(
keys := sdk.NewKVStoreKeys(
auth.StoreKey, bank.StoreKey, stakingtypes.StoreKey,
mint.StoreKey, distr.StoreKey, slashingtypes.StoreKey,
gov.StoreKey, paramstypes.StoreKey, ibc.StoreKey, upgradetypes.StoreKey,
gov.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey,
evidence.StoreKey, transfer.StoreKey, capability.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -193,7 +195,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 @@ -242,8 +244,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 @@ -295,7 +297,7 @@ func NewSimApp(
// NOTE: staking module is required if HistoricalEntries param > 0
app.mm.SetOrderBeginBlockers(
upgradetypes.ModuleName, mint.ModuleName, distr.ModuleName, slashingtypes.ModuleName,
evidence.ModuleName, stakingtypes.ModuleName, ibc.ModuleName,
evidence.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName,
)
app.mm.SetOrderEndBlockers(crisis.ModuleName, gov.ModuleName, stakingtypes.ModuleName)

Expand All @@ -307,7 +309,7 @@ func NewSimApp(
app.mm.SetOrderInitGenesis(
capability.ModuleName, auth.ModuleName, distr.ModuleName, stakingtypes.ModuleName, bank.ModuleName,
slashingtypes.ModuleName, gov.ModuleName, mint.ModuleName, crisis.ModuleName,
ibc.ModuleName, genutil.ModuleName, evidence.ModuleName, transfer.ModuleName,
ibchost.ModuleName, genutil.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"
"github.com/cosmos/cosmos-sdk/x/gov"
"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"
"github.com/cosmos/cosmos-sdk/x/mint"
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[gov.StoreKey], newApp.keys[gov.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