Add stargate support to wasm querier plugins
This commit is contained in:
@@ -346,14 +346,12 @@ func NewWasmApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b
|
||||
)
|
||||
app.evidenceKeeper = *evidenceKeeper
|
||||
|
||||
// just re-use the full router - do we want to limit this more?
|
||||
var wasmRouter = bApp.Router()
|
||||
wasmDir := filepath.Join(homePath, "wasm")
|
||||
|
||||
wasmConfig, err := wasm.ReadWasmConfig(appOpts)
|
||||
if err != nil {
|
||||
panic("error while reading wasm config: " + err.Error())
|
||||
}
|
||||
|
||||
// The last arguments can contain custom message handlers, and custom query handlers,
|
||||
// if we want to allow any custom callbacks
|
||||
supportedFeatures := "staking,stargate"
|
||||
@@ -368,7 +366,8 @@ func NewWasmApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b
|
||||
app.ibcKeeper.ChannelKeeper,
|
||||
&app.ibcKeeper.PortKeeper,
|
||||
scopedWasmKeeper,
|
||||
wasmRouter,
|
||||
app.Router(),
|
||||
app.GRPCQueryRouter(),
|
||||
wasmDir,
|
||||
wasmConfig,
|
||||
supportedFeatures,
|
||||
|
||||
@@ -616,7 +616,7 @@ func setupKeeper(t *testing.T) (*Keeper, sdk.Context, []sdk.StoreKey) {
|
||||
wasmConfig := wasmTypes.DefaultWasmConfig()
|
||||
pk := paramskeeper.NewKeeper(encodingConfig.Marshaler, encodingConfig.Amino, keyParams, tkeyParams)
|
||||
|
||||
srcKeeper := NewKeeper(encodingConfig.Marshaler, keyWasm, pk.Subspace(wasmTypes.DefaultParamspace), authkeeper.AccountKeeper{}, nil, stakingkeeper.Keeper{}, distributionkeeper.Keeper{}, nil, nil, nil, nil, tempDir, wasmConfig, SupportedFeatures, nil, nil)
|
||||
srcKeeper := NewKeeper(encodingConfig.Marshaler, keyWasm, pk.Subspace(wasmTypes.DefaultParamspace), authkeeper.AccountKeeper{}, nil, stakingkeeper.Keeper{}, distributionkeeper.Keeper{}, nil, nil, nil, nil, nil, tempDir, wasmConfig, SupportedFeatures, nil, nil)
|
||||
return &srcKeeper, ctx, []sdk.StoreKey{keyWasm, keyParams}
|
||||
}
|
||||
|
||||
|
||||
@@ -88,6 +88,7 @@ func NewKeeper(
|
||||
portKeeper types.PortKeeper,
|
||||
capabilityKeeper types.CapabilityKeeper,
|
||||
router sdk.Router,
|
||||
queryRouter GRPCQueryRouter,
|
||||
homeDir string,
|
||||
wasmConfig types.WasmConfig,
|
||||
supportedFeatures string,
|
||||
@@ -120,7 +121,7 @@ func NewKeeper(
|
||||
authZPolicy: DefaultAuthorizationPolicy{},
|
||||
paramSpace: paramSpace,
|
||||
}
|
||||
keeper.queryPlugins = DefaultQueryPlugins(bankKeeper, stakingKeeper, distKeeper, &keeper).Merge(customPlugins)
|
||||
keeper.queryPlugins = DefaultQueryPlugins(bankKeeper, stakingKeeper, distKeeper, queryRouter, &keeper).Merge(customPlugins)
|
||||
for _, o := range opts {
|
||||
o.apply(&keeper)
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ func TestConstructorOptions(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
"tempDir",
|
||||
types.DefaultWasmConfig(),
|
||||
SupportedFeatures,
|
||||
|
||||
@@ -2,6 +2,7 @@ package keeper
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
)
|
||||
|
||||
type QueryHandler struct {
|
||||
@@ -18,6 +20,18 @@ type QueryHandler struct {
|
||||
Plugins QueryPlugins
|
||||
}
|
||||
|
||||
// -- interfaces from baseapp - so we can use the GPRQueryRouter --
|
||||
|
||||
// GRPCQueryHandler defines a function type which handles ABCI Query requests
|
||||
// using gRPC
|
||||
type GRPCQueryHandler = func(ctx sdk.Context, req abci.RequestQuery) (abci.ResponseQuery, error)
|
||||
|
||||
type GRPCQueryRouter interface {
|
||||
Route(path string) GRPCQueryHandler
|
||||
}
|
||||
|
||||
// -- end baseapp interfaces --
|
||||
|
||||
var _ wasmvmtypes.Querier = QueryHandler{}
|
||||
|
||||
func (q QueryHandler) Query(request wasmvmtypes.QueryRequest, gasLimit uint64) ([]byte, error) {
|
||||
@@ -63,12 +77,12 @@ type QueryPlugins struct {
|
||||
Wasm func(ctx sdk.Context, request *wasmvmtypes.WasmQuery) ([]byte, error)
|
||||
}
|
||||
|
||||
func DefaultQueryPlugins(bank bankkeeper.ViewKeeper, staking stakingkeeper.Keeper, distKeeper distributionkeeper.Keeper, wasm *Keeper) QueryPlugins {
|
||||
func DefaultQueryPlugins(bank bankkeeper.ViewKeeper, staking stakingkeeper.Keeper, distKeeper distributionkeeper.Keeper, queryRouter GRPCQueryRouter, wasm *Keeper) QueryPlugins {
|
||||
return QueryPlugins{
|
||||
Bank: BankQuerier(bank),
|
||||
Custom: NoCustomQuerier,
|
||||
Staking: StakingQuerier(staking, distKeeper),
|
||||
Stargate: StargateQuerier,
|
||||
Stargate: StargateQuerier(queryRouter),
|
||||
Wasm: WasmQuerier(wasm),
|
||||
}
|
||||
}
|
||||
@@ -132,8 +146,22 @@ func NoCustomQuerier(sdk.Context, json.RawMessage) ([]byte, error) {
|
||||
return nil, wasmvmtypes.UnsupportedRequest{Kind: "custom"}
|
||||
}
|
||||
|
||||
func StargateQuerier(ctx sdk.Context, msg *wasmvmtypes.StargateQuery) ([]byte, error) {
|
||||
return nil, wasmvmtypes.UnsupportedRequest{Kind: "custom"}
|
||||
func StargateQuerier(queryRouter GRPCQueryRouter) func(ctx sdk.Context, request *wasmvmtypes.StargateQuery) ([]byte, error) {
|
||||
return func(ctx sdk.Context, msg *wasmvmtypes.StargateQuery) ([]byte, error) {
|
||||
route := queryRouter.Route(msg.Path)
|
||||
if route == nil {
|
||||
return nil, wasmvmtypes.UnsupportedRequest{Kind: fmt.Sprintf("No route to query '%s'", msg.Path)}
|
||||
}
|
||||
req := abci.RequestQuery{
|
||||
Data: msg.Data,
|
||||
Path: msg.Path,
|
||||
}
|
||||
res, err := route(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res.Value, nil
|
||||
}
|
||||
}
|
||||
|
||||
func StakingQuerier(keeper stakingkeeper.Keeper, distKeeper distributionkeeper.Keeper) func(ctx sdk.Context, request *wasmvmtypes.StakingQuery) ([]byte, error) {
|
||||
|
||||
@@ -255,6 +255,11 @@ func CreateTestInput(t *testing.T, isCheckTx bool, supportedFeatures string, enc
|
||||
dh := distribution.NewHandler(distKeeper)
|
||||
router.AddRoute(sdk.NewRoute(distributiontypes.RouterKey, dh))
|
||||
|
||||
querier := baseapp.NewGRPCQueryRouter()
|
||||
banktypes.RegisterQueryServer(querier, bankKeeper)
|
||||
stakingtypes.RegisterQueryServer(querier, stakingkeeper.Querier{Keeper: stakingKeeper})
|
||||
distributiontypes.RegisterQueryServer(querier, distKeeper)
|
||||
|
||||
// Load default wasm config
|
||||
wasmConfig := types.DefaultWasmConfig()
|
||||
|
||||
@@ -270,6 +275,7 @@ func CreateTestInput(t *testing.T, isCheckTx bool, supportedFeatures string, enc
|
||||
&ibcKeeper.PortKeeper,
|
||||
scopedWasmKeeper,
|
||||
router,
|
||||
querier,
|
||||
tempDir,
|
||||
wasmConfig,
|
||||
supportedFeatures,
|
||||
|
||||
Reference in New Issue
Block a user