diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cb05008d7..a50e5c53fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,8 @@ and this project adheres to - cosmwasm-std: Make `IbcReceiveResponse::acknowledgement` optional and add `IbcReceiveResponse::without_ack` constructor. ([#1892]) - cosmwasm-std: Add `std` feature and make it a default feature. ([#1971]) +- cosmwasm-std: Add `QueryRequest::Grpc` and deprecate `QueryRequest::Stargate`. + ([#1973]) [#1874]: https://github.com/CosmWasm/cosmwasm/pull/1874 [#1876]: https://github.com/CosmWasm/cosmwasm/pull/1876 @@ -91,6 +93,7 @@ and this project adheres to [#1949]: https://github.com/CosmWasm/cosmwasm/pull/1949 [#1967]: https://github.com/CosmWasm/cosmwasm/pull/1967 [#1971]: https://github.com/CosmWasm/cosmwasm/pull/1971 +[#1973]: https://github.com/CosmWasm/cosmwasm/pull/1973 ### Removed diff --git a/MIGRATING.md b/MIGRATING.md index d1dc8c6099..e13975ac2e 100644 --- a/MIGRATING.md +++ b/MIGRATING.md @@ -189,6 +189,23 @@ major releases of `cosmwasm`. Note that you can also view the +}; ``` +- If you were using `QueryRequest::Stargate`, you might want to enable the + `cosmwasm_2_0` cargo feature and migrate to `QueryRequest::Grpc` instead. + While the stargate query sometimes returns protobuf encoded data and sometimes + JSON encoded data, depending on the chain, the gRPC query always returns + protobuf encoded data. + + ```diff + -deps.querier.query(&QueryRequest::Stargate { + - path: "/service.Path/ServiceMethod".to_string(), + - data: Binary::new(b"DATA"), + -})?; + +deps.querier.query(&QueryRequest::Grpc(GrpcQuery { + + path: "/service.Path/ServiceMethod".to_string(), + + data: Binary::new(b"DATA"), + +}))?; + ``` + ## 1.4.x -> 1.5.0 - Update `cosmwasm-*` dependencies in Cargo.toml (skip the ones you don't use): diff --git a/contracts/reflect/schema/raw/query.json b/contracts/reflect/schema/raw/query.json index ef21990549..7c37f35326 100644 --- a/contracts/reflect/schema/raw/query.json +++ b/contracts/reflect/schema/raw/query.json @@ -470,6 +470,7 @@ }, { "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.", + "deprecated": true, "type": "object", "required": [ "stargate" @@ -491,7 +492,7 @@ ] }, "path": { - "description": "this is the fully qualified service path used for routing, eg. custom/cosmos_sdk.x.bank.v1.Query/QueryBalance", + "description": "this is the fully qualified service path used for routing, eg. \"/cosmos_sdk.x.bank.v1.Query/QueryBalance\"", "type": "string" } } diff --git a/contracts/reflect/schema/reflect.json b/contracts/reflect/schema/reflect.json index 05e8c7d4be..aaf5d1dea0 100644 --- a/contracts/reflect/schema/reflect.json +++ b/contracts/reflect/schema/reflect.json @@ -1473,6 +1473,7 @@ }, { "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.", + "deprecated": true, "type": "object", "required": [ "stargate" @@ -1494,7 +1495,7 @@ ] }, "path": { - "description": "this is the fully qualified service path used for routing, eg. custom/cosmos_sdk.x.bank.v1.Query/QueryBalance", + "description": "this is the fully qualified service path used for routing, eg. \"/cosmos_sdk.x.bank.v1.Query/QueryBalance\"", "type": "string" } } diff --git a/docs/CAPABILITIES-BUILT-IN.md b/docs/CAPABILITIES-BUILT-IN.md index 1d1313618d..b9c43bf19e 100644 --- a/docs/CAPABILITIES-BUILT-IN.md +++ b/docs/CAPABILITIES-BUILT-IN.md @@ -23,5 +23,5 @@ might define others. `DistributionQuery::DelegationTotalRewards` and `DistributionQuery::DelegatorValidators` queries. Only chains running CosmWasm `1.4.0` or higher support this. -- `cosmwasm_2_0` enables `CosmosMsg::Any`. Only chains running CosmWasm `2.0.0` - or higher support this. +- `cosmwasm_2_0` enables `CosmosMsg::Any` and `QueryRequest::Grpc`. Only chains + running CosmWasm `2.0.0` or higher support this. diff --git a/packages/std/Cargo.toml b/packages/std/Cargo.toml index 6dfdce060b..0e89233675 100644 --- a/packages/std/Cargo.toml +++ b/packages/std/Cargo.toml @@ -47,7 +47,7 @@ cosmwasm_1_3 = ["cosmwasm_1_2"] # It requires the host blockchain to run CosmWasm `1.4.0` or higher. cosmwasm_1_4 = ["cosmwasm_1_3"] # This enables functionality that is only available on 2.0 chains. -# It adds `CosmosMsg::Any`, replacing `CosmosMsg::Stargate`. +# It adds `CosmosMsg::Any`, replacing `CosmosMsg::Stargate`. It also adds `QueryRequest::Grpc`. cosmwasm_2_0 = ["cosmwasm_1_4"] [dependencies] diff --git a/packages/std/src/query/mod.rs b/packages/std/src/query/mod.rs index a6e0219c11..8082fdd44d 100644 --- a/packages/std/src/query/mod.rs +++ b/packages/std/src/query/mod.rs @@ -1,8 +1,10 @@ +// needed because the derive macros on QueryRequest use the deprecated `Stargate` variant +#![allow(deprecated)] + use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use crate::prelude::*; -#[cfg(feature = "stargate")] use crate::Binary; use crate::Empty; @@ -53,9 +55,10 @@ pub enum QueryRequest { /// 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. #[cfg(feature = "stargate")] + #[deprecated = "Please use the GrpcQuery instead"] Stargate { /// this is the fully qualified service path used for routing, - /// eg. custom/cosmos_sdk.x.bank.v1.Query/QueryBalance + /// eg. "/cosmos_sdk.x.bank.v1.Query/QueryBalance" path: String, /// this is the expected protobuf message type (not any), binary encoded data: Binary, @@ -63,6 +66,28 @@ pub enum QueryRequest { #[cfg(feature = "stargate")] Ibc(IbcQuery), Wasm(WasmQuery), + #[cfg(feature = "cosmwasm_2_0")] + Grpc(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 drawback of this query is that you have to handle the protobuf encoding and decoding yourself. +/// +/// The returned data is protobuf encoded. The protobuf type depends on the query. +/// +/// To find the path, as well as the request and response types, +/// you can query the chain's gRPC endpoint using a tool like +/// [grpcurl](https://github.com/fullstorydev/grpcurl). +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +pub struct GrpcQuery { + /// The fully qualified endpoint path used for routing. + /// It follows the format `/service_path/method_name`, + /// eg. "/cosmos.authz.v1beta1.Query/Grants" + pub path: String, + /// The expected protobuf message type (not [Any](https://protobuf.dev/programming-guides/proto3/#any)), binary encoded + pub data: Binary, } /// A trait that is required to avoid conflicts with other query types like BankQuery and WasmQuery @@ -115,6 +140,13 @@ impl From for QueryRequest { } } +#[cfg(feature = "cosmwasm_2_0")] +impl From for QueryRequest { + fn from(msg: GrpcQuery) -> Self { + QueryRequest::Grpc(msg) + } +} + #[cfg(feature = "stargate")] impl From for QueryRequest { fn from(msg: IbcQuery) -> Self { diff --git a/packages/std/src/testing/mock.rs b/packages/std/src/testing/mock.rs index dd3395daf0..b3bf55f28f 100644 --- a/packages/std/src/testing/mock.rs +++ b/packages/std/src/testing/mock.rs @@ -602,9 +602,14 @@ impl MockQuerier { } QueryRequest::Wasm(msg) => self.wasm.query(msg), #[cfg(feature = "stargate")] + #[allow(deprecated)] QueryRequest::Stargate { .. } => SystemResult::Err(SystemError::UnsupportedRequest { kind: "Stargate".to_string(), }), + #[cfg(feature = "cosmwasm_2_0")] + QueryRequest::Grpc(_) => SystemResult::Err(SystemError::UnsupportedRequest { + kind: "GRPC".to_string(), + }), #[cfg(feature = "stargate")] QueryRequest::Ibc(msg) => self.ibc.query(msg), }