Skip to content

Commit

Permalink
fix ibckeeper injection
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani committed Jun 22, 2023
1 parent fe7bf5f commit 592eb87
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 38 deletions.
9 changes: 8 additions & 1 deletion ignite/templates/app/files/app/app.go.plush
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ func New(
depinject.Supply(
// supply the application options
appOpts,
// supply ibc keeper getter for the IBC modules
app.GetIBCeKeeper,

// ADVANCED CONFIGURATION
//
Expand Down Expand Up @@ -302,7 +304,7 @@ func New(
app.App = appBuilder.Build(logger, db, traceStore, baseAppOptions...)

// Register legacy modules
app.RegisterIBCModules()
app.registerIBCModules()

// load state streaming if enabled
if _, _, err := streaming.LoadStreamingServices(app.App.BaseApp, appOpts, app.appCodec, logger, app.kvStoreKeys()); err != nil {
Expand Down Expand Up @@ -429,6 +431,11 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig
docs.RegisterOpenAPIService(Name, apiSvr.Router)
}

// GetIBCeKeeper returns the IBC keeper
func (app *App) GetIBCeKeeper() *ibckeeper.Keeper {
return app.IBCKeeper
}

// GetMaccPerms returns a copy of the module account permissions
//
// NOTE: This is solely to be used for testing purposes.
Expand Down
4 changes: 1 addition & 3 deletions ignite/templates/app/files/app/ibc.go.plush
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
// this line is used by starport scaffolding # ibc/app/import
)

func (app *App) RegisterIBCModules() {
func (app *App) registerIBCModules() {
// set up non depinject support modules store keys
app.keys = sdk.NewKVStoreKeys(
ibcexported.StoreKey,
Expand Down Expand Up @@ -161,6 +161,4 @@ func (app *App) RegisterIBCModules() {
app.ScopedIBCTransferKeeper = scopedIBCTransferKeeper
app.ScopedICAHostKeeper = scopedICAHostKeeper
app.ScopedICAControllerKeeper = scopedICAControllerKeeper

app.ModuleManager.RegisterInvariants(app.CrisisKeeper)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (k msgServer) <%= queryName.UpperCamel %>Data(goCtx context.Context, msg *t
ctx := sdk.UnwrapSDKContext(goCtx)

sourcePort := types.PortID
sourceChannelEnd, found := k.channelKeeper.GetChannel(ctx, sourcePort, msg.SourceChannel)
sourceChannelEnd, found := k.ibcKeeperFn().ChannelKeeper.GetChannel(ctx, sourcePort, msg.SourceChannel)
if !found {
return nil, sdkerrors.Wrapf(
sdkerrors.ErrUnknownRequest,
Expand All @@ -33,7 +33,7 @@ func (k msgServer) <%= queryName.UpperCamel %>Data(goCtx context.Context, msg *t
destinationChannel := sourceChannelEnd.GetCounterparty().GetChannelID()

// get the next sequence
sequence, found := k.channelKeeper.GetNextSequenceSend(ctx, sourcePort, msg.SourceChannel)
sequence, found := k.ibcKeeperFn().ChannelKeeper.GetNextSequenceSend(ctx, sourcePort, msg.SourceChannel)
if !found {
return nil, sdkerrors.Wrapf(
channeltypes.ErrSequenceSendNotFound,
Expand Down Expand Up @@ -64,5 +64,5 @@ func (k msgServer) <%= queryName.UpperCamel %>Data(goCtx context.Context, msg *t
return sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, "cannot marshal the packet: " + err.Error())
}

return k.channelKeeper.SendPacket(ctx, channelCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, packetBytes)
return k.ibcKeeperFn().ChannelKeeper.SendPacket(ctx, channelCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, packetBytes)
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (k Keeper) Transmit<%= packetName.UpperCamel %>Packet(
return 0, sdkerrors.Wrapf(sdkerrors.ErrJSONMarshal, "cannot marshal the packet: %w", err)
}

return k.channelKeeper.SendPacket(ctx, channelCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, packetBytes)
return k.ibcKeeperFn().ChannelKeeper.SendPacket(ctx, channelCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, packetBytes)
}

// OnRecv<%= packetName.UpperCamel %>Packet processes packet reception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
"github.com/cosmos/ibc-go/v7/modules/core/exported"<% } %>
"github.com/cosmos/ibc-go/v7/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"<% } %>

"<%= modulePath %>/x/<%= moduleName %>/types"
)
Expand All @@ -26,8 +27,7 @@ type (
// should be the x/gov module account.
authority string
<%= if (isIBC) { %>
channelKeeper types.ChannelKeeper
portKeeper types.PortKeeper
ibcKeeperFn func() *ibckeeper.Keeper
scopedKeeper exported.ScopedKeeper<% } %>
<%= for (dependency) in dependencies { %>
<%= toVariableName(dependency.KeeperName()) %> types.<%= dependency.KeeperName() %><% } %>
Expand All @@ -38,9 +38,8 @@ func NewKeeper(
cdc codec.BinaryCodec,
storeKey,
memKey storetypes.StoreKey,
authority string,
<%= if (isIBC) { %>channelKeeper types.ChannelKeeper,
portKeeper types.PortKeeper,
authority string,<%= if (isIBC) { %>
ibcKeeperFn func() *ibckeeper.Keeper,
scopedKeeper exported.ScopedKeeper,<% } %>
<%= for (dependency) in dependencies { %>
<%= toVariableName(dependency.KeeperName()) %> types.<%= dependency.KeeperName() %>,<% } %>
Expand All @@ -53,10 +52,8 @@ func NewKeeper(
cdc: cdc,
storeKey: storeKey,
memKey: memKey,
authority: authority,
<%= if (isIBC) { %>
channelKeeper: channelKeeper,
portKeeper: portKeeper,
authority: authority,<%= if (isIBC) { %>
ibcKeeperFn: ibcKeeperFn,
scopedKeeper: scopedKeeper,<% } %>
<%= for (dependency) in dependencies { %>
<%= toVariableName(dependency.KeeperName()) %>: <%= toVariableName(dependency.KeeperName()) %>,<% } %>
Expand Down Expand Up @@ -84,7 +81,7 @@ func (k Keeper) ChanCloseInit(ctx sdk.Context, portID, channelID string) error {
if !ok {
return sdkerrors.Wrapf(channeltypes.ErrChannelCapabilityNotFound, "could not retrieve channel capability at: %s", capName)
}
return k.channelKeeper.ChanCloseInit(ctx, portID, channelID, chanCap)
return k.ibcKeeperFn().ChannelKeeper.ChanCloseInit(ctx, portID, channelID, chanCap)
}

// IsBound checks if the IBC app module is already bound to the desired port
Expand All @@ -96,7 +93,7 @@ func (k Keeper) IsBound(ctx sdk.Context, portID string) bool {
// BindPort defines a wrapper function for the port Keeper's function in
// order to expose it to module's InitGenesis function
func (k Keeper) BindPort(ctx sdk.Context, portID string) error {
cap := k.portKeeper.BindPort(ctx, portID)
cap := k.ibcKeeperFn().PortKeeper.BindPort(ctx, portID)
return k.ClaimCapability(ctx, cap, host.PortPath(portID))
}

Expand Down Expand Up @@ -126,13 +123,4 @@ func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability
// ScopedKeeper returns the ScopedKeeper
func (k Keeper) ScopedKeeper() exported.ScopedKeeper {
return k.scopedKeeper
}

// SetIBCKeepers set IBCKeepers for Keeper
func (k Keeper) SetIBCKeepers(
channelKeeper types.ChannelKeeper,
portKeeper types.PortKeeper,
) {
k.channelKeeper = channelKeeper
k.portKeeper = portKeeper
}<% } %>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import (
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
<%= if (isIBC) { %>porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"<% } %>
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"<% } %>

// this line is used by starport scaffolding # 1

Expand Down Expand Up @@ -193,7 +194,8 @@ type <%= title(moduleName) %>Inputs struct {
BankKeeper types.BankKeeper<%= for (dependency) in dependencies { %><%= if (dependency.Name != "Bank" && dependency.Name != "Account") { %>
<%= dependency.KeeperName() %> types.<%= dependency.KeeperName() %><% } %><% } %>

<%= if (isIBC) { %> CapabilityKeeper *capabilitykeeper.Keeper<% } %>
<%= if (isIBC) { %> CapabilityKeeper *capabilitykeeper.Keeper
IBCKeeperFn func() *ibckeeper.Keeper<% } %>
}

type <%= title(moduleName) %>Outputs struct {
Expand All @@ -215,8 +217,7 @@ func ProvideModule(in <%= title(moduleName) %>Inputs) <%= title(moduleName) %>Ou
in.KvStoreKey,
in.MemStoreKey,
authority.String(), <%= if (isIBC) { %>
nil,
nil,
in.IBCKeeperFn,
scopedVoteKeeper,<% } %><%= for (dependency) in dependencies { %>
in.<%= dependency.KeeperName() %>,<% } %>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ func (<%= moduleName %>PortKeeper) BindPort(ctx sdk.Context, portID string) *cap
return &capabilitytypes.Capability{}
}



func <%= title(moduleName) %>Keeper(t testing.TB) (keeper.Keeper, sdk.Context) {
logger := log.NewNopLogger()

Expand All @@ -81,8 +79,9 @@ func <%= title(moduleName) %>Keeper(t testing.TB) (keeper.Keeper, sdk.Context) {
storeKey,
memStoreKey,
authority.String(),
<%= moduleName %>ChannelKeeper{},
<%= moduleName %>PortKeeper{},
func() *ibckeeper.Keeper {
return &ibckeeper.Keeper{}
},
capabilityKeeper.ScopeToModule("<%= title(moduleName) %>ScopedKeeper"),<%= for (dependency) in dependencies { %>
nil,<% } %>
)
Expand Down
1 change: 0 additions & 1 deletion ignite/templates/module/create/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ func appIBCModify(replacer placeholder.Replacer, opts *CreateOptions) genny.RunF
// create IBC module
templateIBCModule := `%[2]vIBCModule := ibcfee.NewIBCMiddleware(%[2]vmodule.NewIBCModule(app.%[3]vKeeper), app.IBCFeeKeeper)
ibcRouter.AddRoute(%[2]vmoduletypes.ModuleName, %[2]vIBCModule)
app.%[3]vKeeper.SetIBCKeepers(app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper)
%[1]v`
replacementIBCModule := fmt.Sprintf(
templateIBCModule,
Expand Down

0 comments on commit 592eb87

Please sign in to comment.