Skip to content

Commit 1748805

Browse files
committed
feat(app): update application init
1 parent 3e47141 commit 1748805

File tree

1 file changed

+38
-26
lines changed

1 file changed

+38
-26
lines changed

app/app.go

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,25 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
ibccallbacks "github.com/cosmos/ibc-go/modules/apps/callbacks"
78
"io"
89
"io/fs"
910
"net/http"
1011
"os"
1112
"path/filepath"
12-
"slices"
1313
"sort"
1414

1515
"github.com/CosmWasm/wasmd/x/wasm"
1616
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
1717
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
18+
abci "github.com/cometbft/cometbft/abci/types"
19+
tmos "github.com/cometbft/cometbft/libs/os"
20+
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
1821
dbm "github.com/cosmos/cosmos-db"
1922
"github.com/cosmos/gogoproto/proto"
2023
"github.com/ignite/cli/ignite/pkg/openapiconsole"
2124
"github.com/prometheus/client_golang/prometheus"
2225
"github.com/spf13/cast"
23-
"google.golang.org/protobuf/reflect/protodesc"
24-
"google.golang.org/protobuf/types/descriptorpb"
25-
26-
abci "github.com/cometbft/cometbft/abci/types"
27-
tmos "github.com/cometbft/cometbft/libs/os"
28-
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
2926

3027
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
3128
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
@@ -486,13 +483,14 @@ func New(
486483
)
487484

488485
// Set legacy router for backwards compatibility with gov v1beta1
489-
app.GovKeeper.SetLegacyRouter(govRouter)
486+
govKeeper.SetLegacyRouter(govRouter)
490487

491488
app.GovKeeper = *govKeeper.SetHooks(
492489
govtypes.NewMultiGovHooks(
493490
// register the governance hooks
494491
),
495492
)
493+
496494
// Create IBC Keeper
497495
app.IBCKeeper = ibckeeper.NewKeeper(
498496
appCodec,
@@ -504,6 +502,16 @@ func New(
504502
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
505503
)
506504

505+
// IBC Fee Module keeper
506+
app.IBCFeeKeeper = ibcfeekeeper.NewKeeper(
507+
appCodec, keys[ibcfeetypes.StoreKey],
508+
app.IBCKeeper.ChannelKeeper, // may be replaced with IBC middleware
509+
app.IBCKeeper.ChannelKeeper,
510+
app.IBCKeeper.PortKeeper,
511+
app.AccountKeeper,
512+
app.BankKeeper,
513+
)
514+
507515
// Create Transfer Keepers
508516
app.TransferKeeper = ibctransferkeeper.NewKeeper(
509517
appCodec,
@@ -518,16 +526,6 @@ func New(
518526
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
519527
)
520528

521-
// IBC Fee Module keeper
522-
app.IBCFeeKeeper = ibcfeekeeper.NewKeeper(
523-
appCodec, keys[ibcfeetypes.StoreKey],
524-
app.IBCKeeper.ChannelKeeper, // may be replaced with IBC middleware
525-
app.IBCKeeper.ChannelKeeper,
526-
app.IBCKeeper.PortKeeper,
527-
app.AccountKeeper,
528-
app.BankKeeper,
529-
)
530-
531529
app.ICAHostKeeper = icahostkeeper.NewKeeper(
532530
appCodec,
533531
keys[icahosttypes.StoreKey],
@@ -540,6 +538,8 @@ func New(
540538
app.MsgServiceRouter(),
541539
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
542540
)
541+
// set grpc router for ica host
542+
app.ICAHostKeeper.WithQueryRouter(app.GRPCQueryRouter())
543543

544544
app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
545545
appCodec,
@@ -611,31 +611,43 @@ func New(
611611
wasmOpts...,
612612
)
613613

614-
// Create Transfer Stack
615-
var transferStack ibcporttypes.IBCModule
616-
transferStack = transfer.NewIBCModule(app.TransferKeeper)
617-
transferStack = ibcfee.NewIBCMiddleware(transferStack, app.IBCFeeKeeper)
614+
// Create fee enabled wasm ibc Stack
615+
var wasmStack ibcporttypes.IBCModule
616+
wasmStackIBCHandler := wasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper, app.IBCFeeKeeper)
617+
wasmStack = ibcfee.NewIBCMiddleware(wasmStackIBCHandler, app.IBCFeeKeeper)
618+
618619
// Create Interchain Accounts Stack
619620
// SendPacket, since it is originating from the application to core IBC:
620621
// icaAuthModuleKeeper.SendTx -> icaController.SendPacket -> fee.SendPacket -> channel.SendPacket
621622
var icaControllerStack ibcporttypes.IBCModule
623+
622624
// integration point for custom authentication modules
623625
//nolint:lll
624626
// see https://medium.com/the-interchain-foundation/ibc-go-v6-changes-to-interchain-accounts-and-how-it-impacts-your-chain-806c185300d7
625627
var noAuthzModule ibcporttypes.IBCModule
626628
icaControllerStack = icacontroller.NewIBCMiddleware(noAuthzModule, app.ICAControllerKeeper)
629+
icaControllerStack = icacontroller.NewIBCMiddleware(icaControllerStack, app.ICAControllerKeeper)
630+
icaControllerStack = ibccallbacks.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper, wasmStackIBCHandler, wasm.DefaultMaxIBCCallbackGas)
631+
icaICS4Wrapper := icaControllerStack.(ibcporttypes.ICS4Wrapper)
627632
icaControllerStack = ibcfee.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper)
628633

634+
// Since the callbacks middleware itself is an ics4wrapper, it needs to be passed to the ica controller keeper
635+
app.ICAControllerKeeper.WithICS4Wrapper(icaICS4Wrapper)
636+
629637
// RecvPacket, message that originates from core IBC and goes down to app, the flow is:
630638
// channel.RecvPacket -> fee.OnRecvPacket -> icaHost.OnRecvPacket
631639
var icaHostStack ibcporttypes.IBCModule
632640
icaHostStack = icahost.NewIBCModule(app.ICAHostKeeper)
633641
icaHostStack = ibcfee.NewIBCMiddleware(icaHostStack, app.IBCFeeKeeper)
634642

635-
// Create fee enabled wasm ibc Stack
636-
var wasmStack ibcporttypes.IBCModule
637-
wasmStack = wasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper, app.IBCFeeKeeper)
638-
wasmStack = ibcfee.NewIBCMiddleware(wasmStack, app.IBCFeeKeeper)
643+
// Create Transfer Stack
644+
var transferStack ibcporttypes.IBCModule
645+
transferStack = transfer.NewIBCModule(app.TransferKeeper)
646+
transferStack = ibccallbacks.NewIBCMiddleware(transferStack, app.IBCFeeKeeper, wasmStackIBCHandler, wasm.DefaultMaxIBCCallbackGas)
647+
transferICS4Wrapper := transferStack.(ibcporttypes.ICS4Wrapper)
648+
transferStack = ibcfee.NewIBCMiddleware(transferStack, app.IBCFeeKeeper)
649+
// Since the callbacks middleware itself is an ics4wrapper, it needs to be passed to the ica controller keeper
650+
app.TransferKeeper.WithICS4Wrapper(transferICS4Wrapper)
639651

640652
// Create static IBC router, add transfer route, then set and seal it
641653
ibcRouter := ibcporttypes.NewRouter()

0 commit comments

Comments
 (0)