Skip to content

Commit

Permalink
Merge pull request #510 from CosmWasm/grpc-query
Browse files Browse the repository at this point in the history
Add `GrpcQuery`
  • Loading branch information
chipshort authored Jan 31, 2024
2 parents dfd7f96 + c5d719f commit 1f22137
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions docs/MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
two `VM` instances operate on the same directory in parallel. This was
unsupported before already but now leads to an error early on. When doing
parallel testing, use a different directory for each instance.
- `QueryRequest.Grpc` was added. It is similar to `QueryRequest.Stargate` but
unlike that, it should always return protobuf encoded responses on all chains.
- `VM.StoreCode` now returns a `uint64` containing the gas cost in CosmWasm gas
and takes a gas limit as argument. This was previously calculated in wasmd.
The change brings consistency with the other functions that cause gas usage.
Expand Down
26 changes: 21 additions & 5 deletions types/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type QueryRequest struct {
Staking *StakingQuery `json:"staking,omitempty"`
Distribution *DistributionQuery `json:"distribution,omitempty"`
Stargate *StargateQuery `json:"stargate,omitempty"`
Grpc *GrpcQuery `json:"grpc,omitempty"`
Wasm *WasmQuery `json:"wasm,omitempty"`
}

Expand Down Expand Up @@ -435,14 +436,29 @@ type BondedDenomResponse struct {

// StargateQuery is encoded the same way as abci_query, with path and protobuf encoded request data.
// The format is defined in [ADR-21](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-021-protobuf-query-encoding.md).
// The response is protobuf encoded data directly without a JSON response wrapper.
// The caller is responsible for compiling the proper protobuf definitions for both requests and responses.
// The response is supposed to always be protobuf encoded data, but is JSON encoded on some chains.
// The caller is responsible for compiling the proper type definitions for both requests and responses.
type StargateQuery struct {
// this is the fully qualified service path used for routing,
// eg. custom/cosmos_sdk.x.bank.v1.Query/QueryBalance
// The expected protobuf message type (not [Any](https://protobuf.dev/programming-guides/proto3/#any)), binary encoded
Data []byte `json:"data"`
// The fully qualified endpoint path used for routing.
// It follows the format `/service_path/method_name`,
// eg. "/cosmos.authz.v1beta1.Query/Grants"
Path string `json:"path"`
// this is the expected protobuf message type (not any), binary encoded
}

// GrpcQuery queries the chain using a grpc query.
// This allows to query information that is not exposed in our API.
// The chain needs to allowlist the supported queries.
//
// The returned data is protobuf encoded. The protobuf type depends on the query.
type GrpcQuery struct {
// The expected protobuf message type (not [Any](https://protobuf.dev/programming-guides/proto3/#any)), binary encoded
Data []byte `json:"data"`
// The fully qualified endpoint path used for routing.
// It follows the format `/service_path/method_name`,
// eg. "/cosmos.authz.v1beta1.Query/Grants"
Path string `json:"path"`
}

type WasmQuery struct {
Expand Down

0 comments on commit 1f22137

Please sign in to comment.