From 5c1d623ab58533f709862d963e9a0c6c4c0f5391 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Fri, 8 Nov 2024 10:47:18 +0700 Subject: [PATCH] Add grpc queries support / whitelist --- demo/app/app.go | 4 ++++ demo/app/wasm/grpc_whitelist.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 demo/app/wasm/grpc_whitelist.go diff --git a/demo/app/app.go b/demo/app/app.go index 156b232..6ba845d 100644 --- a/demo/app/app.go +++ b/demo/app/app.go @@ -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" @@ -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() diff --git a/demo/app/wasm/grpc_whitelist.go b/demo/app/wasm/grpc_whitelist.go new file mode 100644 index 0000000..9b4b342 --- /dev/null +++ b/demo/app/wasm/grpc_whitelist.go @@ -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{}, + } +}