Skip to content

Commit

Permalink
add grpc querier for wasm (#2083)
Browse files Browse the repository at this point in the history
* add grpc querier encoder for wasm

* update changelog

* fix comment for GrpcQuerier
  • Loading branch information
kwtalley committed Jul 11, 2024
1 parent 641eba2 commit 6daebe5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Features

* Create a script for updating links in the spec docs to proto messages [#2068](https://github.com/provenance-io/provenance/pull/2068).
* Add grpc querier for cosmwasm 2.1.0 smart contracts [#2083](https://github.com/provenance-io/provenance/pull/2083).

### Improvements

Expand Down
26 changes: 26 additions & 0 deletions internal/provwasm/query_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func QueryPlugins(registry *QuerierRegistry, queryRouter baseapp.GRPCQueryRouter
return &wasmkeeper.QueryPlugins{
Custom: customPlugins(registry),
Stargate: StargateQuerier(queryRouter, stargateCdc),
Grpc: GrpcQuerier(queryRouter),
}
}

Expand Down Expand Up @@ -121,6 +122,31 @@ func StargateQuerier(queryRouter baseapp.GRPCQueryRouter, cdc codec.Codec) func(
}
}

// GrpcQuerier dispatches whitelisted queries and returns protobuf encoded responses
func GrpcQuerier(queryRouter baseapp.GRPCQueryRouter) func(ctx sdk.Context, request *wasmvmtypes.GrpcQuery) (proto.Message, error) {
return func(ctx sdk.Context, request *wasmvmtypes.GrpcQuery) (proto.Message, error) {
_, err := GetWhitelistedQuery(request.Path)
if err != nil {
return nil, err
}

route := queryRouter.Route(request.Path)
if route == nil {
return nil, wasmvmtypes.UnsupportedRequest{Kind: fmt.Sprintf("No route to query '%s'", request.Path)}
}

res, err := route(ctx, &abci.RequestQuery{
Data: request.Data,
Path: request.Path,
})
if err != nil {
return nil, err
}

return res, nil
}
}

// ConvertProtoToJsonMarshal unmarshals the given bytes into a proto message and then marshals it to json.
// This is done so that clients calling stargate queries do not need to define their own proto unmarshalers,
// being able to use response directly by json marshaling, which is supported in cosmwasm.
Expand Down

0 comments on commit 6daebe5

Please sign in to comment.