Skip to content

Commit

Permalink
complete add router middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
vuong177 committed Apr 4, 2023
1 parent 8fe338f commit a169121
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
27 changes: 24 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ import (
icqkeeper "github.com/strangelove-ventures/async-icq/v7/keeper"
icqtypes "github.com/strangelove-ventures/async-icq/v7/types"

"github.com/strangelove-ventures/packet-forward-middleware/v7/router"
routerkeeper "github.com/strangelove-ventures/packet-forward-middleware/v7/router/keeper"
routertypes "github.com/strangelove-ventures/packet-forward-middleware/v7/router/types"

consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"

Expand Down Expand Up @@ -153,6 +157,7 @@ var (
vesting.AppModuleBasic{},
tendermint.AppModuleBasic{},
wasm.AppModuleBasic{},
router.AppModuleBasic{},
consensus.AppModuleBasic{},

// this line is used by starport scaffolding # stargate/app/moduleBasic
Expand Down Expand Up @@ -223,6 +228,7 @@ type BanksyApp struct {
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ConsensusParamsKeeper consensusparamkeeper.Keeper
// this line is used by starport scaffolding # stargate/app/keeperDeclaration
RouterKeeper *routerkeeper.Keeper

mm *module.Manager
sm *module.SimulationManager
Expand Down Expand Up @@ -256,7 +262,7 @@ func NewBanksyApp(
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, icqtypes.StoreKey, capabilitytypes.StoreKey, consensusparamtypes.StoreKey, wasmtypes.StoreKey,
crisistypes.StoreKey,
crisistypes.StoreKey, routertypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -339,8 +345,12 @@ func NewBanksyApp(
app.BankKeeper,
scopedTransferKeeper,
)

app.RouterKeeper = routerkeeper.NewKeeper(appCodec, keys[routertypes.StoreKey], app.GetSubspace(routertypes.ModuleName), app.TransferKeeper, app.IBCKeeper.ChannelKeeper, &app.DistrKeeper, app.BankKeeper, app.IBCKeeper.ChannelKeeper)

transferModule := transfer.NewAppModule(app.TransferKeeper)
transferIBCModule := transfer.NewIBCModule(app.TransferKeeper)
routerModule := router.NewAppModule(app.RouterKeeper)

app.ICQKeeper = icqkeeper.NewKeeper(
appCodec, keys[icqtypes.StoreKey], app.GetSubspace(icqtypes.ModuleName),
Expand All @@ -349,6 +359,13 @@ func NewBanksyApp(
)
icqModule := icq.NewAppModule(app.ICQKeeper)
icqIBCModule := icq.NewIBCModule(app.ICQKeeper)
ibcMiddlewareStack := router.NewIBCMiddleware(
transferIBCModule,
app.RouterKeeper,
0,
routerkeeper.DefaultForwardTransferPacketTimeoutTimestamp,
routerkeeper.DefaultRefundTransferPacketTimeoutTimestamp,
)

// Create evidence Keeper for to register the IBC light client misbehaviour evidence route
evidenceKeeper := evidencekeeper.NewKeeper(
Expand Down Expand Up @@ -379,7 +396,7 @@ func NewBanksyApp(
)

ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferIBCModule)
ibcRouter.AddRoute(ibctransfertypes.ModuleName, ibcMiddlewareStack)
ibcRouter.AddRoute(icqtypes.ModuleName, icqIBCModule)

// this line is used by starport scaffolding # ibc/app/router
Expand Down Expand Up @@ -417,7 +434,7 @@ func NewBanksyApp(
icqModule,
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
wasm.NewAppModule(app.WasmClientKeeper),

routerModule,
// this line is used by starport scaffolding # stargate/app/appModule
)

Expand All @@ -435,6 +452,7 @@ func NewBanksyApp(
vestingtypes.ModuleName,
ibchost.ModuleName,
ibctransfertypes.ModuleName,
routertypes.ModuleName,
icqtypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
Expand Down Expand Up @@ -464,6 +482,7 @@ func NewBanksyApp(
paramstypes.ModuleName,
upgradetypes.ModuleName,
ibchost.ModuleName,
routertypes.ModuleName,
ibctransfertypes.ModuleName,
icqtypes.ModuleName,
consensusparamtypes.ModuleName,
Expand Down Expand Up @@ -492,6 +511,7 @@ func NewBanksyApp(
upgradetypes.ModuleName,
ibctransfertypes.ModuleName,
icqtypes.ModuleName,
routertypes.ModuleName,
feegrant.ModuleName,
consensusparamtypes.ModuleName,
wasmtypes.ModuleName,
Expand Down Expand Up @@ -739,6 +759,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(stakingtypes.ModuleName)
paramsKeeper.Subspace(distrtypes.ModuleName)
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(routertypes.ModuleName).WithKeyTable(routertypes.ParamKeyTable())
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypesv1.ParamKeyTable()) //nolint:staticcheck
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/spf13/cast v1.5.0
github.com/spf13/cobra v1.6.1
github.com/strangelove-ventures/async-icq/v7 v7.0.0-20230317170414-3c3da64f93d4
github.com/strangelove-ventures/packet-forward-middleware/v7 v7.0.0-20230321175727-de5b28b4b6ca
)

require (
Expand Down Expand Up @@ -41,6 +42,7 @@ require (
github.com/hashicorp/go-getter v1.7.0 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/iancoleman/orderedmap v0.2.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
Expand Down Expand Up @@ -82,7 +84,7 @@ require (
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v0.20.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.1 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.2 // indirect
github.com/cosmos/rosetta-sdk-go v0.10.0 // indirect
github.com/creachadair/taskgroup v0.4.2 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ github.com/cosmos/ics23/go v0.9.1-0.20221207100636-b1abd8678aab h1:I9ialKTQo7248
github.com/cosmos/ics23/go v0.9.1-0.20221207100636-b1abd8678aab/go.mod h1:2CwqasX5dSD7Hbp/9b6lhK6BwoBDCBldx7gPKRukR60=
github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 h1:DdzS1m6o/pCqeZ8VOAit/gyATedRgjvkVI+UCrLpyuU=
github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76/go.mod h1:0mkLWIoZuQ7uBoospo5Q9zIpqq6rYCPJDSUdeCJvPM8=
github.com/cosmos/ledger-cosmos-go v0.12.1 h1:sMBxza5p/rNK/06nBSNmsI/WDqI0pVJFVNihy1Y984w=
github.com/cosmos/ledger-cosmos-go v0.12.1/go.mod h1:dhO6kj+Y+AHIOgAe4L9HL/6NDdyyth4q238I9yFpD2g=
github.com/cosmos/ledger-cosmos-go v0.12.2 h1:/XYaBlE2BJxtvpkHiBm97gFGSGmYGKunKyF3nNqAXZA=
github.com/cosmos/ledger-cosmos-go v0.12.2/go.mod h1:ZcqYgnfNJ6lAXe4HPtWgarNEY+B74i+2/8MhZw4ziiI=
github.com/cosmos/rosetta-sdk-go v0.10.0 h1:E5RhTruuoA7KTIXUcMicL76cffyeoyvNybzUGSKFTcM=
github.com/cosmos/rosetta-sdk-go v0.10.0/go.mod h1:SImAZkb96YbwvoRkzSMQB6noNJXFgWl/ENIznEoYQI4=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
Expand Down Expand Up @@ -614,6 +614,8 @@ github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0Jr
github.com/huandu/skiplist v1.2.0 h1:gox56QD77HzSC0w+Ws3MH3iie755GBJU1OER3h5VsYw=
github.com/huandu/skiplist v1.2.0/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXMrPiHF9w=
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
github.com/iancoleman/orderedmap v0.2.0 h1:sq1N/TFpYH++aViPcaKjys3bDClUEU7s5B+z6jq8pNA=
github.com/iancoleman/orderedmap v0.2.0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/improbable-eng/grpc-web v0.15.0 h1:BN+7z6uNXZ1tQGcNAuaU1YjsLTApzkjt2tzCixLaUPQ=
Expand Down Expand Up @@ -869,6 +871,8 @@ github.com/spf13/viper v1.15.0 h1:js3yy885G8xwJa6iOISGFwd+qlUo5AvyXb7CiihdtiU=
github.com/spf13/viper v1.15.0/go.mod h1:fFcTBJxvhhzSJiZy8n+PeW6t8l+KeT/uTARa0jHOQLA=
github.com/strangelove-ventures/ibc-go/v7 v7.0.0-20230327161923-eae575bf57cc h1:1vDhd5IjP1kdglSQ12DpOhUkwmUXBiE9NMwCj4yuVW8=
github.com/strangelove-ventures/ibc-go/v7 v7.0.0-20230327161923-eae575bf57cc/go.mod h1:ISHo/Qitjtvj2svGmttaZv03zVXmS+uqvUyF9kFqlI0=
github.com/strangelove-ventures/packet-forward-middleware/v7 v7.0.0-20230321175727-de5b28b4b6ca h1:UHShO7ZkPLUc/8bBf1WuXx8uh6XMUrePdBVcV2TZJc0=
github.com/strangelove-ventures/packet-forward-middleware/v7 v7.0.0-20230321175727-de5b28b4b6ca/go.mod h1:qu+hu9cpus1/noohdF+YPxBFYTS+p6mCgl7KMv2kHJU=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
Expand Down

0 comments on commit a169121

Please sign in to comment.