Skip to content

Commit

Permalink
Add grpc queries support / whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolacy committed Nov 8, 2024
1 parent 14e6996 commit 5c1d623
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions demo/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
appparams "github.com/babylonlabs-io/babylon-sdk/demo/app/params"
appwasm "github.com/babylonlabs-io/babylon-sdk/demo/app/wasm"
abci "github.com/cometbft/cometbft/abci/types"
tmos "github.com/cometbft/cometbft/libs/os"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
Expand Down Expand Up @@ -492,6 +493,9 @@ func NewConsumerApp(
// add support for the custom queries
wasmkeeper.WithQueryHandlerDecorator(bbnkeeper.NewQueryDecorator(app.BabylonKeeper)),
)
// Add grpc query support for the whitelisted grpc queries
wasmOpts = append(wasmOpts, appwasm.RegisterGrpcQueries(bApp, appCodec)...)

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
availableCapabilities := AllCapabilities()
Expand Down
29 changes: 29 additions & 0 deletions demo/app/wasm/grpc_whitelist.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package wasm

import (
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
)

func RegisterGrpcQueries(bApp *baseapp.BaseApp, appCodec codec.Codec) []wasmkeeper.Option {
queryRouter := bApp.GRPCQueryRouter()
queryPluginOpt := wasmkeeper.WithQueryPlugins(
&wasmkeeper.QueryPlugins{
Stargate: wasmkeeper.AcceptListStargateQuerier(WhitelistedGrpcQuery(), queryRouter, appCodec),
Grpc: wasmkeeper.AcceptListGrpcQuerier(WhitelistedGrpcQuery(), queryRouter, appCodec),
})

return []wasmkeeper.Option{
queryPluginOpt,
}
}

// WhitelistedGrpcQuery returns the whitelisted Grpc queries
func WhitelistedGrpcQuery() wasmkeeper.AcceptedQueries {
return wasmkeeper.AcceptedQueries{
// mint
"/cosmos.mint.v1beta1.Query/Params": &minttypes.QueryParamsResponse{},
}
}

0 comments on commit 5c1d623

Please sign in to comment.