Skip to content

Commit b14e902

Browse files
authored
Merge pull request #1973 from CosmWasm/1966-grpc-query
Add `QueryRequest::Grpc`
2 parents d912030 + 2d8baa9 commit b14e902

File tree

8 files changed

+66
-7
lines changed

8 files changed

+66
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ and this project adheres to
7272
- cosmwasm-std: Make `IbcReceiveResponse::acknowledgement` optional and add
7373
`IbcReceiveResponse::without_ack` constructor. ([#1892])
7474
- cosmwasm-std: Add `std` feature and make it a default feature. ([#1971])
75+
- cosmwasm-std: Add `QueryRequest::Grpc` and deprecate `QueryRequest::Stargate`.
76+
([#1973])
7577

7678
[#1874]: https://github.com/CosmWasm/cosmwasm/pull/1874
7779
[#1876]: https://github.com/CosmWasm/cosmwasm/pull/1876
@@ -91,6 +93,7 @@ and this project adheres to
9193
[#1949]: https://github.com/CosmWasm/cosmwasm/pull/1949
9294
[#1967]: https://github.com/CosmWasm/cosmwasm/pull/1967
9395
[#1971]: https://github.com/CosmWasm/cosmwasm/pull/1971
96+
[#1973]: https://github.com/CosmWasm/cosmwasm/pull/1973
9497

9598
### Removed
9699

MIGRATING.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,23 @@ major releases of `cosmwasm`. Note that you can also view the
189189
+};
190190
```
191191

192+
- If you were using `QueryRequest::Stargate`, you might want to enable the
193+
`cosmwasm_2_0` cargo feature and migrate to `QueryRequest::Grpc` instead.
194+
While the stargate query sometimes returns protobuf encoded data and sometimes
195+
JSON encoded data, depending on the chain, the gRPC query always returns
196+
protobuf encoded data.
197+
198+
```diff
199+
-deps.querier.query(&QueryRequest::Stargate {
200+
- path: "/service.Path/ServiceMethod".to_string(),
201+
- data: Binary::new(b"DATA"),
202+
-})?;
203+
+deps.querier.query(&QueryRequest::Grpc(GrpcQuery {
204+
+ path: "/service.Path/ServiceMethod".to_string(),
205+
+ data: Binary::new(b"DATA"),
206+
+}))?;
207+
```
208+
192209
## 1.4.x -> 1.5.0
193210

194211
- Update `cosmwasm-*` dependencies in Cargo.toml (skip the ones you don't use):

contracts/reflect/schema/raw/query.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@
470470
},
471471
{
472472
"description": "A Stargate query 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.",
473+
"deprecated": true,
473474
"type": "object",
474475
"required": [
475476
"stargate"
@@ -491,7 +492,7 @@
491492
]
492493
},
493494
"path": {
494-
"description": "this is the fully qualified service path used for routing, eg. custom/cosmos_sdk.x.bank.v1.Query/QueryBalance",
495+
"description": "this is the fully qualified service path used for routing, eg. \"/cosmos_sdk.x.bank.v1.Query/QueryBalance\"",
495496
"type": "string"
496497
}
497498
}

contracts/reflect/schema/reflect.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,7 @@
14731473
},
14741474
{
14751475
"description": "A Stargate query 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.",
1476+
"deprecated": true,
14761477
"type": "object",
14771478
"required": [
14781479
"stargate"
@@ -1494,7 +1495,7 @@
14941495
]
14951496
},
14961497
"path": {
1497-
"description": "this is the fully qualified service path used for routing, eg. custom/cosmos_sdk.x.bank.v1.Query/QueryBalance",
1498+
"description": "this is the fully qualified service path used for routing, eg. \"/cosmos_sdk.x.bank.v1.Query/QueryBalance\"",
14981499
"type": "string"
14991500
}
15001501
}

docs/CAPABILITIES-BUILT-IN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ might define others.
2323
`DistributionQuery::DelegationTotalRewards` and
2424
`DistributionQuery::DelegatorValidators` queries. Only chains running CosmWasm
2525
`1.4.0` or higher support this.
26-
- `cosmwasm_2_0` enables `CosmosMsg::Any`. Only chains running CosmWasm `2.0.0`
27-
or higher support this.
26+
- `cosmwasm_2_0` enables `CosmosMsg::Any` and `QueryRequest::Grpc`. Only chains
27+
running CosmWasm `2.0.0` or higher support this.

packages/std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ cosmwasm_1_3 = ["cosmwasm_1_2"]
4747
# It requires the host blockchain to run CosmWasm `1.4.0` or higher.
4848
cosmwasm_1_4 = ["cosmwasm_1_3"]
4949
# This enables functionality that is only available on 2.0 chains.
50-
# It adds `CosmosMsg::Any`, replacing `CosmosMsg::Stargate`.
50+
# It adds `CosmosMsg::Any`, replacing `CosmosMsg::Stargate`. It also adds `QueryRequest::Grpc`.
5151
cosmwasm_2_0 = ["cosmwasm_1_4"]
5252

5353
[dependencies]

packages/std/src/query/mod.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
// needed because the derive macros on QueryRequest use the deprecated `Stargate` variant
2+
#![allow(deprecated)]
3+
14
use schemars::JsonSchema;
25
use serde::{Deserialize, Serialize};
36

47
use crate::prelude::*;
5-
#[cfg(feature = "stargate")]
68
use crate::Binary;
79
use crate::Empty;
810

@@ -53,16 +55,39 @@ pub enum QueryRequest<C> {
5355
/// The response is protobuf encoded data directly without a JSON response wrapper.
5456
/// The caller is responsible for compiling the proper protobuf definitions for both requests and responses.
5557
#[cfg(feature = "stargate")]
58+
#[deprecated = "Please use the GrpcQuery instead"]
5659
Stargate {
5760
/// this is the fully qualified service path used for routing,
58-
/// eg. custom/cosmos_sdk.x.bank.v1.Query/QueryBalance
61+
/// eg. "/cosmos_sdk.x.bank.v1.Query/QueryBalance"
5962
path: String,
6063
/// this is the expected protobuf message type (not any), binary encoded
6164
data: Binary,
6265
},
6366
#[cfg(feature = "stargate")]
6467
Ibc(IbcQuery),
6568
Wasm(WasmQuery),
69+
#[cfg(feature = "cosmwasm_2_0")]
70+
Grpc(GrpcQuery),
71+
}
72+
73+
/// Queries the chain using a grpc query.
74+
/// This allows to query information that is not exposed in our API.
75+
/// The chain needs to allowlist the supported queries.
76+
/// The drawback of this query is that you have to handle the protobuf encoding and decoding yourself.
77+
///
78+
/// The returned data is protobuf encoded. The protobuf type depends on the query.
79+
///
80+
/// To find the path, as well as the request and response types,
81+
/// you can query the chain's gRPC endpoint using a tool like
82+
/// [grpcurl](https://github.com/fullstorydev/grpcurl).
83+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
84+
pub struct GrpcQuery {
85+
/// The fully qualified endpoint path used for routing.
86+
/// It follows the format `/service_path/method_name`,
87+
/// eg. "/cosmos.authz.v1beta1.Query/Grants"
88+
pub path: String,
89+
/// The expected protobuf message type (not [Any](https://protobuf.dev/programming-guides/proto3/#any)), binary encoded
90+
pub data: Binary,
6691
}
6792

6893
/// A trait that is required to avoid conflicts with other query types like BankQuery and WasmQuery
@@ -115,6 +140,13 @@ impl<C: CustomQuery> From<WasmQuery> for QueryRequest<C> {
115140
}
116141
}
117142

143+
#[cfg(feature = "cosmwasm_2_0")]
144+
impl<C: CustomQuery> From<GrpcQuery> for QueryRequest<C> {
145+
fn from(msg: GrpcQuery) -> Self {
146+
QueryRequest::Grpc(msg)
147+
}
148+
}
149+
118150
#[cfg(feature = "stargate")]
119151
impl<C: CustomQuery> From<IbcQuery> for QueryRequest<C> {
120152
fn from(msg: IbcQuery) -> Self {

packages/std/src/testing/mock.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,9 +602,14 @@ impl<C: CustomQuery + DeserializeOwned> MockQuerier<C> {
602602
}
603603
QueryRequest::Wasm(msg) => self.wasm.query(msg),
604604
#[cfg(feature = "stargate")]
605+
#[allow(deprecated)]
605606
QueryRequest::Stargate { .. } => SystemResult::Err(SystemError::UnsupportedRequest {
606607
kind: "Stargate".to_string(),
607608
}),
609+
#[cfg(feature = "cosmwasm_2_0")]
610+
QueryRequest::Grpc(_) => SystemResult::Err(SystemError::UnsupportedRequest {
611+
kind: "GRPC".to_string(),
612+
}),
608613
#[cfg(feature = "stargate")]
609614
QueryRequest::Ibc(msg) => self.ibc.query(msg),
610615
}

0 commit comments

Comments
 (0)