Skip to content

Commit

Permalink
fix ibc templates for appwiring
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani committed Jun 21, 2023
1 parent 2c96082 commit d1eed93
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 70 deletions.
2 changes: 0 additions & 2 deletions ignite/templates/app/files/app/app.go.plush
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ func New(
depinject.Supply(
// supply the application options
appOpts,
// this line is used by starport scaffolding # stargate/app/supply

// ADVANCED CONFIGURATION

//
Expand Down
4 changes: 4 additions & 0 deletions ignite/templates/app/files/app/ibc.go.plush
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
solomachine "github.com/cosmos/ibc-go/v7/modules/light-clients/06-solomachine"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"

// this line is used by starport scaffolding # ibc/app/import
)

func (app *App) RegisterIBCModules() {
Expand Down Expand Up @@ -127,6 +129,8 @@ func (app *App) RegisterIBCModules() {
AddRoute(icacontrollertypes.SubModuleName, icaControllerIBCModule).
AddRoute(icahosttypes.SubModuleName, icaHostIBCModule)

// this line is used by starport scaffolding # ibc/app/module

app.IBCKeeper.SetRouter(ibcRouter)

// NOTE: Any module instantiated in the module manager that is later modified
Expand Down
1 change: 1 addition & 0 deletions ignite/templates/module/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package module
const (
PathAppModule = "app"
PathAppGo = "app/app.go"
PathIBCConfigGo = "app/ibc.go"
PathAppConfigGo = "app/app_config.go"
)
12 changes: 2 additions & 10 deletions ignite/templates/module/create/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,13 @@ func appModify(replacer placeholder.Replacer, opts *CreateOptions) genny.RunFn {
content = replacer.Replace(content, module.PlaceholderSgAppModuleBasic, replacement)

// Keeper declaration
var scopedKeeperDeclaration string
if opts.IsIBC {
// Scoped keeper declaration for IBC module
// We set this placeholder so it is modified by the IBC module scaffolder
scopedKeeperDeclaration = module.PlaceholderIBCAppScopedKeeperDeclaration
}
template = `%[3]v
%[4]vKeeper %[2]vmodulekeeper.Keeper
template = `%[2]vKeeper %[3]vmodulekeeper.Keeper
%[1]v`
replacement = fmt.Sprintf(
template,
module.PlaceholderSgAppKeeperDeclaration,
opts.ModuleName,
scopedKeeperDeclaration,
xstrings.Title(opts.ModuleName),
opts.ModuleName,
)
content = replacer.Replace(content, module.PlaceholderSgAppKeeperDeclaration, replacement)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"<%= modulePath %>/x/<%= moduleName %>/types"
)

func <%= title(moduleName) %>Keeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
func <%= title(moduleName) %>Keeper(t testing.TB) (keeper.Keeper, sdk.Context) {
storeKey := sdk.NewKVStoreKey(types.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)

Expand Down
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"
"github.com/cosmos/ibc-go/v7/modules/core/exported"<% } %>
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,9 +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) { %>ChannelKeeper types.ChannelKeeper
PortKeeper types.PortKeeper
ScopedKeeper exported.ScopedKeeper<% } %>
<%= if (isIBC) { %> CapabilityKeeper *capabilitykeeper.Keeper
// IBCKeeper *ibckeeper.Keeper<% } %>
}

type <%= title(moduleName) %>Outputs struct {
Expand All @@ -211,15 +211,15 @@ func ProvideModule(in <%= title(moduleName) %>Inputs) <%= title(moduleName) %>Ou
if in.Config.Authority != "" {
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
}

<%= if (isIBC) { %>scopedVoteKeeper := in.CapabilityKeeper.ScopeToModule(types.ModuleName)<% } %>
k := keeper.NewKeeper(
in.Cdc,
in.KvStoreKey,
in.MemStoreKey,
authority.String(), <%= if (isIBC) { %>
in.ChannelKeeper,
in.PortKeeper,
in.ScopedKeeper,<% } %><%= for (dependency) in dependencies { %>
in.IBCKeeper.ChannelKeeper,
&in.IBCKeeper.PortKeeper,
scopedVoteKeeper,<% } %><%= for (dependency) in dependencies { %>
in.<%= dependency.KeeperName() %>,<% } %>
)
m := NewAppModule(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func TestGenesis(t *testing.T) {
}

k, ctx := keepertest.<%= title(moduleName) %>Keeper(t)
<%= moduleName %>.InitGenesis(ctx, *k, genesisState)
got := <%= moduleName %>.ExportGenesis(ctx, *k)
<%= moduleName %>.InitGenesis(ctx, k, genesisState)
got := <%= moduleName %>.ExportGenesis(ctx, k)
require.NotNil(t, got)

nullify.Fill(&genesisState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (<%= moduleName %>PortKeeper) BindPort(ctx sdk.Context, portID string) *cap



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

storeKey := sdk.NewKVStoreKey(types.StoreKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func setupMsgServer(t testing.TB) (types.MsgServer, context.Context) {
k, ctx := keepertest.<%= title(moduleName) %>Keeper(t)
return keeper.NewMsgServerImpl(*k), sdk.WrapSDKContext(ctx)
return keeper.NewMsgServerImpl(k), sdk.WrapSDKContext(ctx)
}

func TestMsgServer(t *testing.T) {
Expand Down
61 changes: 22 additions & 39 deletions ignite/templates/module/create/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,57 +181,40 @@ PortID = "%[1]v"`

func appIBCModify(replacer placeholder.Replacer, opts *CreateOptions) genny.RunFn {
return func(r *genny.Runner) error {
path := filepath.Join(opts.AppPath, module.PathAppGo)
path := filepath.Join(opts.AppPath, module.PathIBCConfigGo)
f, err := r.Disk.Find(path)
if err != nil {
return err
}

// Import
templateImport := `%[2]vmodule "%[3]v/x/%[2]v"
%[2]vmoduletypes "%[3]v/x/%[2]v/types"
%[1]v`
replacementImport := fmt.Sprintf(templateImport, module.PlaceholderIBCImport, opts.ModuleName, opts.ModulePath)
content := replacer.Replace(f.String(), module.PlaceholderIBCImport, replacementImport)

// create IBC module
templateIBCModule := `%[2]vIBCModule := %[2]vmodule.NewIBCModule(app.%[3]vKeeper)
templateIBCModule := `%[2]vIBCModule := ibcfee.NewIBCMiddleware(%[2]vmodule.NewIBCModule(app.%[3]vKeeper), app.IBCFeeKeeper)
ibcRouter.AddRoute(%[2]vmoduletypes.ModuleName, %[2]vIBCModule)
%[1]v`
replacementIBCModule := fmt.Sprintf(
templateIBCModule,
module.PlaceholderSgAppKeeperDefinition,
opts.ModuleName,
xstrings.Title(opts.ModuleName),
)
content := replacer.Replace(f.String(), module.PlaceholderSgAppKeeperDefinition, replacementIBCModule)

// Add route to IBC router
templateRouter := `ibcRouter.AddRoute(%[2]vmoduletypes.ModuleName, %[2]vIBCModule)
%[1]v`
replacementRouter := fmt.Sprintf(
templateRouter,
module.PlaceholderIBCAppRouter,
opts.ModuleName,
)
content = replacer.Replace(content, module.PlaceholderIBCAppRouter, replacementRouter)

// Scoped keeper declaration for the module
templateScopedKeeperDeclaration := `Scoped%[1]vKeeper capabilitykeeper.ScopedKeeper`
replacementScopedKeeperDeclaration := fmt.Sprintf(templateScopedKeeperDeclaration, xstrings.Title(opts.ModuleName))
content = replacer.Replace(content, module.PlaceholderIBCAppScopedKeeperDeclaration, replacementScopedKeeperDeclaration)

// Scoped keeper definition
templateScopedKeeperDefinition := `scoped%[1]vKeeper := app.CapabilityKeeper.ScopeToModule(%[2]vmoduletypes.ModuleName)
app.Scoped%[1]vKeeper = scoped%[1]vKeeper`
replacementScopedKeeperDefinition := fmt.Sprintf(
templateScopedKeeperDefinition,
xstrings.Title(opts.ModuleName),
module.PlaceholderIBCNewModule,
opts.ModuleName,
)
content = replacer.Replace(content, module.PlaceholderIBCAppScopedKeeperDefinition, replacementScopedKeeperDefinition)

// New argument passed to the module keeper
templateKeeperArgument := `app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
scoped%[1]vKeeper,`
replacementKeeperArgument := fmt.Sprintf(
templateKeeperArgument,
xstrings.Title(opts.ModuleName),
)
content = replacer.Replace(content, module.PlaceholderIBCAppKeeperArgument, replacementKeeperArgument)
content = replacer.Replace(content, module.PlaceholderIBCNewModule, replacementIBCModule)

// // New argument passed to the module keeper
// templateKeeperArgument := `app.IBCKeeper.ChannelKeeper,
//&app.IBCKeeper.PortKeeper,
//scoped%[1]vKeeper,`
// replacementKeeperArgument := fmt.Sprintf(
// templateKeeperArgument,
// xstrings.Title(opts.ModuleName),
// )
// content = replacer.Replace(content, module.PlaceholderIBCAppKeeperArgument, replacementKeeperArgument)

newFile := genny.NewFileS(path, content)
return r.File(newFile)
Expand Down
10 changes: 4 additions & 6 deletions ignite/templates/module/placeholders.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ const (
PlaceholderSgAppModuleConfig = "// this line is used by starport scaffolding # stargate/app/moduleConfig"

// Placeholders IBC
PlaceholderIBCKeysName = "// this line is used by starport scaffolding # ibc/keys/name"
PlaceholderIBCKeysPort = "// this line is used by starport scaffolding # ibc/keys/port"
PlaceholderIBCAppScopedKeeperDeclaration = "// this line is used by starport scaffolding # ibc/app/scopedKeeper/declaration"
PlaceholderIBCAppScopedKeeperDefinition = "// this line is used by starport scaffolding # ibc/app/scopedKeeper/definition"
PlaceholderIBCAppKeeperArgument = "// this line is used by starport scaffolding # ibc/app/keeper/argument"
PlaceholderIBCAppRouter = "// this line is used by starport scaffolding # ibc/app/router"
PlaceholderIBCImport = "// this line is used by starport scaffolding # ibc/app/import"
PlaceholderIBCKeysName = "// this line is used by starport scaffolding # ibc/keys/name"
PlaceholderIBCKeysPort = "// this line is used by starport scaffolding # ibc/keys/port"
PlaceholderIBCNewModule = "// this line is used by starport scaffolding # ibc/app/module"

// Genesis test
PlaceholderTypesGenesisTestcase = "// this line is used by starport scaffolding # types/genesis/testcase"
Expand Down

0 comments on commit d1eed93

Please sign in to comment.