|
| 1 | +// needed because the derive macros on QueryRequest use the deprecated `Stargate` variant |
| 2 | +#![allow(deprecated)] |
| 3 | + |
1 | 4 | use schemars::JsonSchema; |
2 | 5 | use serde::{Deserialize, Serialize}; |
3 | 6 |
|
4 | 7 | use crate::prelude::*; |
5 | | -#[cfg(feature = "stargate")] |
6 | 8 | use crate::Binary; |
7 | 9 | use crate::Empty; |
8 | 10 |
|
@@ -53,16 +55,39 @@ pub enum QueryRequest<C> { |
53 | 55 | /// The response is protobuf encoded data directly without a JSON response wrapper. |
54 | 56 | /// The caller is responsible for compiling the proper protobuf definitions for both requests and responses. |
55 | 57 | #[cfg(feature = "stargate")] |
| 58 | + #[deprecated = "Please use the GrpcQuery instead"] |
56 | 59 | Stargate { |
57 | 60 | /// 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" |
59 | 62 | path: String, |
60 | 63 | /// this is the expected protobuf message type (not any), binary encoded |
61 | 64 | data: Binary, |
62 | 65 | }, |
63 | 66 | #[cfg(feature = "stargate")] |
64 | 67 | Ibc(IbcQuery), |
65 | 68 | 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, |
66 | 91 | } |
67 | 92 |
|
68 | 93 | /// 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> { |
115 | 140 | } |
116 | 141 | } |
117 | 142 |
|
| 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 | + |
118 | 150 | #[cfg(feature = "stargate")] |
119 | 151 | impl<C: CustomQuery> From<IbcQuery> for QueryRequest<C> { |
120 | 152 | fn from(msg: IbcQuery) -> Self { |
|
0 commit comments