diff --git a/simapp/app.go b/simapp/app.go index 8b090a74f..325fde488 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -31,6 +31,8 @@ import ( 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" + ibctransferkeeper "github.com/cosmos/cosmos-sdk/x/ibc-transfer/keeper" + ibctransfertypes "github.com/cosmos/cosmos-sdk/x/ibc-transfer/types" 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" @@ -95,7 +97,7 @@ var ( stakingtypes.BondedPoolName: {auth.Burner, auth.Staking}, stakingtypes.NotBondedPoolName: {auth.Burner, auth.Staking}, govtypes.ModuleName: {auth.Burner}, - transfer.ModuleName: {auth.Minter, auth.Burner}, + ibctransfertypes.ModuleName: {auth.Minter, auth.Burner}, } // module accounts that are allowed to receive tokens @@ -138,7 +140,7 @@ type SimApp struct { ParamsKeeper paramskeeper.Keeper 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 + TransferKeeper ibctransferkeeper.Keeper // make scoped keepers public for test purposes ScopedIBCKeeper capability.ScopedKeeper @@ -168,7 +170,7 @@ func NewSimApp( auth.StoreKey, bank.StoreKey, stakingtypes.StoreKey, minttypes.StoreKey, distr.StoreKey, slashingtypes.StoreKey, govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, - evidence.StoreKey, transfer.StoreKey, capability.StoreKey, + evidence.StoreKey, ibctransfertypes.StoreKey, capability.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) memKeys := sdk.NewMemoryStoreKeys(capability.MemStoreKey) @@ -201,7 +203,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(ibchost.ModuleName) - scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(transfer.ModuleName) + scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) // add keepers app.AccountKeeper = auth.NewAccountKeeper( @@ -254,8 +256,8 @@ func NewSimApp( ) // Create Transfer Keepers - app.TransferKeeper = transfer.NewKeeper( - appCodec, keys[transfer.StoreKey], + app.TransferKeeper = ibctransferkeeper.NewKeeper( + appCodec, keys[ibctransfertypes.StoreKey], app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, scopedTransferKeeper, ) @@ -263,7 +265,7 @@ func NewSimApp( // Create static IBC router, add transfer route, then set and seal it ibcRouter := port.NewRouter() - ibcRouter.AddRoute(transfer.ModuleName, transferModule) + ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferModule) app.IBCKeeper.SetRouter(ibcRouter) // create evidence keeper with router @@ -314,7 +316,7 @@ func NewSimApp( app.mm.SetOrderInitGenesis( capability.ModuleName, auth.ModuleName, distr.ModuleName, stakingtypes.ModuleName, bank.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisis.ModuleName, - ibchost.ModuleName, genutiltypes.ModuleName, evidence.ModuleName, transfer.ModuleName, + ibchost.ModuleName, genutiltypes.ModuleName, evidence.ModuleName, ibctransfertypes.ModuleName, ) app.mm.RegisterInvariants(&app.CrisisKeeper) diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 48a6ec1c5..e6254c0a4 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -23,7 +23,7 @@ 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" - transfer "github.com/cosmos/cosmos-sdk/x/ibc-transfer" + ibctransfertypes "github.com/cosmos/cosmos-sdk/x/ibc-transfer/types" 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" @@ -163,7 +163,7 @@ func TestAppImportExport(t *testing.T) { {app.keys[evidence.StoreKey], newApp.keys[evidence.StoreKey], [][]byte{}}, {app.keys[capability.StoreKey], newApp.keys[capability.StoreKey], [][]byte{}}, {app.keys[ibchost.StoreKey], newApp.keys[ibchost.StoreKey], [][]byte{}}, - {app.keys[transfer.StoreKey], newApp.keys[transfer.StoreKey], [][]byte{}}, + {app.keys[ibctransfertypes.StoreKey], newApp.keys[ibctransfertypes.StoreKey], [][]byte{}}, } for _, skp := range storeKeysPrefixes { diff --git a/x/ibc-transfer/alias.go b/x/ibc-transfer/alias.go deleted file mode 100644 index 8a882d31a..000000000 --- a/x/ibc-transfer/alias.go +++ /dev/null @@ -1,51 +0,0 @@ -package transfer - -// autogenerated code using github.com/rigelrozanski/multitool -// aliases generated for the following subdirectories: -// ALIASGEN: github.com/cosmos/cosmos-sdk/x/ibc-transfer/keeper -// ALIASGEN: github.com/cosmos/cosmos-sdk/x/ibc-transfer/types - -import ( - "github.com/cosmos/cosmos-sdk/x/ibc-transfer/keeper" - "github.com/cosmos/cosmos-sdk/x/ibc-transfer/types" -) - -const ( - EventTypeTimeout = types.EventTypeTimeout - EventTypePacket = types.EventTypePacket - EventTypeChannelClose = types.EventTypeChannelClose - AttributeKeyReceiver = types.AttributeKeyReceiver - AttributeKeyValue = types.AttributeKeyValue - AttributeKeyRefundReceiver = types.AttributeKeyRefundReceiver - AttributeKeyRefundValue = types.AttributeKeyRefundValue - AttributeKeyAckSuccess = types.AttributeKeyAckSuccess - AttributeKeyAckError = types.AttributeKeyAckError - ModuleName = types.ModuleName - StoreKey = types.StoreKey - RouterKey = types.RouterKey - QuerierRoute = types.QuerierRoute -) - -var ( - // functions aliases - NewKeeper = keeper.NewKeeper - RegisterCodec = types.RegisterCodec - GetEscrowAddress = types.GetEscrowAddress - GetDenomPrefix = types.GetDenomPrefix - NewMsgTransfer = types.NewMsgTransfer - RegisterInterfaces = types.RegisterInterfaces - - // variable aliases - ModuleCdc = types.ModuleCdc -) - -type ( - Keeper = keeper.Keeper - BankKeeper = types.BankKeeper - ChannelKeeper = types.ChannelKeeper - ClientKeeper = types.ClientKeeper - ConnectionKeeper = types.ConnectionKeeper - FungibleTokenPacketData = types.FungibleTokenPacketData - FungibleTokenPacketAcknowledgement = types.FungibleTokenPacketAcknowledgement - MsgTransfer = types.MsgTransfer -) diff --git a/x/ibc-transfer/genesis.go b/x/ibc-transfer/genesis.go index ad6120ab5..99aaa4ea9 100644 --- a/x/ibc-transfer/genesis.go +++ b/x/ibc-transfer/genesis.go @@ -4,11 +4,12 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/ibc-transfer/keeper" "github.com/cosmos/cosmos-sdk/x/ibc-transfer/types" ) // InitGenesis binds to portid from genesis state -func InitGenesis(ctx sdk.Context, keeper Keeper, state types.GenesisState) { +func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, state types.GenesisState) { keeper.SetPort(ctx, state.PortID) // Only try to bind to port if it is not already bound, since we may already own @@ -25,12 +26,12 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, state types.GenesisState) { // check if the module account exists moduleAcc := keeper.GetTransferAccount(ctx) if moduleAcc == nil { - panic(fmt.Sprintf("%s module account has not been set", ModuleName)) + panic(fmt.Sprintf("%s module account has not been set", types.ModuleName)) } } // ExportGenesis exports transfer module's portID into its geneis state -func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState { +func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) types.GenesisState { return types.GenesisState{ PortID: keeper.GetPort(ctx), } diff --git a/x/ibc-transfer/handler.go b/x/ibc-transfer/handler.go index f1e51547e..6699faa33 100644 --- a/x/ibc-transfer/handler.go +++ b/x/ibc-transfer/handler.go @@ -3,15 +3,17 @@ package transfer import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/ibc-transfer/keeper" + "github.com/cosmos/cosmos-sdk/x/ibc-transfer/types" ) // NewHandler returns sdk.Handler for IBC token transfer module messages -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()) switch msg := msg.(type) { - case *MsgTransfer: + case *types.MsgTransfer: return handleMsgTransfer(ctx, k, msg) default: return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized ICS-20 transfer message type: %T", msg) @@ -20,7 +22,7 @@ func NewHandler(k Keeper) sdk.Handler { } // See createOutgoingPacket in spec:https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#packet-relay -func handleMsgTransfer(ctx sdk.Context, k Keeper, msg *MsgTransfer) (*sdk.Result, error) { +func handleMsgTransfer(ctx sdk.Context, k keeper.Keeper, msg *types.MsgTransfer) (*sdk.Result, error) { if err := k.SendTransfer( ctx, msg.SourcePort, msg.SourceChannel, msg.Amount, msg.Sender, msg.Receiver, msg.TimeoutHeight, msg.TimeoutTimestamp, ); err != nil { @@ -32,9 +34,9 @@ func handleMsgTransfer(ctx sdk.Context, k Keeper, msg *MsgTransfer) (*sdk.Result ctx.EventManager().EmitEvent( sdk.NewEvent( sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, ModuleName), + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender.String()), - sdk.NewAttribute(AttributeKeyReceiver, msg.Receiver), + sdk.NewAttribute(types.AttributeKeyReceiver, msg.Receiver), ), ) diff --git a/x/ibc-transfer/handler_test.go b/x/ibc-transfer/handler_test.go index 767735594..350e76e65 100644 --- a/x/ibc-transfer/handler_test.go +++ b/x/ibc-transfer/handler_test.go @@ -79,7 +79,7 @@ func (suite *HandlerTestSuite) TestHandleMsgTransfer() { suite.Require().Nil(err, "transfer module could not claim capability") ctx := suite.chainA.GetContext() - msg := transfer.NewMsgTransfer(testPort1, testChannel1, testPrefixedCoins2, testAddr1, testAddr2.String(), 110, 0) + msg := types.NewMsgTransfer(testPort1, testChannel1, testPrefixedCoins2, testAddr1, testAddr2.String(), 110, 0) res, err := handler(ctx, msg) suite.Require().Error(err) suite.Require().Nil(res, "%+v", res) // channel does not exist @@ -105,14 +105,14 @@ func (suite *HandlerTestSuite) TestHandleMsgTransfer() { suite.Require().NotNil(res, "%+v", res) // successfully executed // test when the source is false - msg = transfer.NewMsgTransfer(testPort1, testChannel1, testPrefixedCoins2, testAddr1, testAddr2.String(), 110, 0) + msg = types.NewMsgTransfer(testPort1, testChannel1, testPrefixedCoins2, testAddr1, testAddr2.String(), 110, 0) _ = suite.chainA.App.BankKeeper.SetBalances(ctx, testAddr1, testPrefixedCoins2) res, err = handler(ctx, msg) suite.Require().Error(err) suite.Require().Nil(res, "%+v", res) // incorrect denom prefix - msg = transfer.NewMsgTransfer(testPort1, testChannel1, testPrefixedCoins1, testAddr1, testAddr2.String(), 110, 0) + msg = types.NewMsgTransfer(testPort1, testChannel1, testPrefixedCoins1, testAddr1, testAddr2.String(), 110, 0) suite.chainA.App.BankKeeper.SetSupply(ctx, bank.NewSupply(testPrefixedCoins1)) _ = suite.chainA.App.BankKeeper.SetBalances(ctx, testAddr1, testPrefixedCoins1) diff --git a/x/ibc-transfer/module.go b/x/ibc-transfer/module.go index 4b162310d..e308c1134 100644 --- a/x/ibc-transfer/module.go +++ b/x/ibc-transfer/module.go @@ -22,6 +22,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/capability" "github.com/cosmos/cosmos-sdk/x/ibc-transfer/client/cli" "github.com/cosmos/cosmos-sdk/x/ibc-transfer/client/rest" + "github.com/cosmos/cosmos-sdk/x/ibc-transfer/keeper" "github.com/cosmos/cosmos-sdk/x/ibc-transfer/simulation" "github.com/cosmos/cosmos-sdk/x/ibc-transfer/types" channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel" @@ -42,12 +43,12 @@ type AppModuleBasic struct{} // Name implements AppModuleBasic interface func (AppModuleBasic) Name() string { - return ModuleName + return types.ModuleName } // RegisterCodec implements AppModuleBasic interface func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { - RegisterCodec(cdc) + types.RegisterCodec(cdc) } // DefaultGenesis returns default genesis state as raw bytes for the ibc @@ -60,7 +61,7 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { 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", types.ModuleName, err) } return gs.Validate() @@ -78,22 +79,22 @@ func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command { // GetQueryCmd implements AppModuleBasic interface func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command { - return cli.GetQueryCmd(clientCtx.Codec, QuerierRoute) + return cli.GetQueryCmd(clientCtx.Codec, types.QuerierRoute) } // RegisterInterfaceTypes registers module concrete types into protobuf Any. func (AppModuleBasic) RegisterInterfaceTypes(registry cdctypes.InterfaceRegistry) { - RegisterInterfaces(registry) + types.RegisterInterfaces(registry) } // AppModule represents the AppModule for this module type AppModule struct { AppModuleBasic - keeper Keeper + keeper keeper.Keeper } // NewAppModule creates a new 20-transfer module -func NewAppModule(k Keeper) AppModule { +func NewAppModule(k keeper.Keeper) AppModule { return AppModule{ keeper: k, } @@ -106,12 +107,12 @@ func (AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { // Route implements the AppModule interface func (am AppModule) Route() sdk.Route { - return sdk.NewRoute(RouterKey, NewHandler(am.keeper)) + return sdk.NewRoute(types.RouterKey, NewHandler(am.keeper)) } // QuerierRoute implements the AppModule interface func (AppModule) QuerierRoute() string { - return QuerierRoute + return types.QuerierRoute } // NewQuerierHandler implements the AppModule interface @@ -285,16 +286,16 @@ func (am AppModule) OnRecvPacket( ctx sdk.Context, packet channeltypes.Packet, ) (*sdk.Result, []byte, error) { - var data FungibleTokenPacketData + var data types.FungibleTokenPacketData if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil { return nil, nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error()) } - acknowledgement := FungibleTokenPacketAcknowledgement{ + acknowledgement := types.FungibleTokenPacketAcknowledgement{ Success: true, Error: "", } if err := am.keeper.OnRecvPacket(ctx, packet, data); err != nil { - acknowledgement = FungibleTokenPacketAcknowledgement{ + acknowledgement = types.FungibleTokenPacketAcknowledgement{ Success: false, Error: err.Error(), } @@ -302,10 +303,10 @@ func (am AppModule) OnRecvPacket( ctx.EventManager().EmitEvent( sdk.NewEvent( - EventTypePacket, - sdk.NewAttribute(sdk.AttributeKeyModule, ModuleName), - sdk.NewAttribute(AttributeKeyReceiver, data.Receiver), - sdk.NewAttribute(AttributeKeyValue, data.Amount.String()), + types.EventTypePacket, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(types.AttributeKeyReceiver, data.Receiver), + sdk.NewAttribute(types.AttributeKeyValue, data.Amount.String()), ), ) @@ -319,11 +320,11 @@ func (am AppModule) OnAcknowledgementPacket( packet channeltypes.Packet, acknowledgement []byte, ) (*sdk.Result, error) { - var ack FungibleTokenPacketAcknowledgement + var ack types.FungibleTokenPacketAcknowledgement if err := types.ModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil { return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet acknowledgement: %v", err) } - var data FungibleTokenPacketData + var data types.FungibleTokenPacketData if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil { return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error()) } @@ -334,19 +335,19 @@ func (am AppModule) OnAcknowledgementPacket( ctx.EventManager().EmitEvent( sdk.NewEvent( - EventTypePacket, - sdk.NewAttribute(sdk.AttributeKeyModule, ModuleName), - sdk.NewAttribute(AttributeKeyReceiver, data.Receiver), - sdk.NewAttribute(AttributeKeyValue, data.Amount.String()), - sdk.NewAttribute(AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success)), + types.EventTypePacket, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(types.AttributeKeyReceiver, data.Receiver), + sdk.NewAttribute(types.AttributeKeyValue, data.Amount.String()), + sdk.NewAttribute(types.AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success)), ), ) if !ack.Success { ctx.EventManager().EmitEvent( sdk.NewEvent( - EventTypePacket, - sdk.NewAttribute(AttributeKeyAckError, ack.Error), + types.EventTypePacket, + sdk.NewAttribute(types.AttributeKeyAckError, ack.Error), ), ) } @@ -360,7 +361,7 @@ func (am AppModule) OnTimeoutPacket( ctx sdk.Context, packet channeltypes.Packet, ) (*sdk.Result, error) { - var data FungibleTokenPacketData + var data types.FungibleTokenPacketData if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil { return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error()) } @@ -371,10 +372,10 @@ func (am AppModule) OnTimeoutPacket( ctx.EventManager().EmitEvent( sdk.NewEvent( - EventTypeTimeout, - sdk.NewAttribute(AttributeKeyRefundReceiver, data.Sender), - sdk.NewAttribute(AttributeKeyRefundValue, data.Amount.String()), - sdk.NewAttribute(sdk.AttributeKeyModule, ModuleName), + types.EventTypeTimeout, + sdk.NewAttribute(types.AttributeKeyRefundReceiver, data.Sender), + sdk.NewAttribute(types.AttributeKeyRefundValue, data.Amount.String()), + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), ), )