Skip to content

Commit 5e05483

Browse files
committed
Add new grpc query
1 parent 35c5470 commit 5e05483

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/std/src/query/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use schemars::JsonSchema;
22
use serde::{Deserialize, Serialize};
33

44
use crate::prelude::*;
5-
#[cfg(feature = "stargate")]
65
use crate::Binary;
76
use crate::Empty;
87

@@ -63,6 +62,22 @@ pub enum QueryRequest<C> {
6362
#[cfg(feature = "stargate")]
6463
Ibc(IbcQuery),
6564
Wasm(WasmQuery),
65+
Grpc(GrpcQuery),
66+
}
67+
68+
/// Queries the chain using a grpc query.
69+
/// This allows to query information that is not exposed in our API.
70+
/// The chain needs to whitelist the supported queries.
71+
/// The drawback of this query is that you have to handle the protobuf encoding and decoding yourself.
72+
///
73+
/// The returned data is protobuf encoded. The protobuf type depends on the query.
74+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
75+
pub struct GrpcQuery {
76+
/// The fully qualified service path used for routing,
77+
/// eg. "custom/cosmos_sdk.x.bank.v1.Query/QueryBalance"
78+
path: String,
79+
/// The expected protobuf message type (not any), binary encoded
80+
data: Binary,
6681
}
6782

6883
/// A trait that is required to avoid conflicts with other query types like BankQuery and WasmQuery

packages/std/src/testing/mock.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,9 @@ impl<C: CustomQuery + DeserializeOwned> MockQuerier<C> {
605605
QueryRequest::Stargate { .. } => SystemResult::Err(SystemError::UnsupportedRequest {
606606
kind: "Stargate".to_string(),
607607
}),
608+
QueryRequest::Grpc(_) => SystemResult::Err(SystemError::UnsupportedRequest {
609+
kind: "GRPC".to_string(),
610+
}),
608611
#[cfg(feature = "stargate")]
609612
QueryRequest::Ibc(msg) => self.ibc.query(msg),
610613
}

0 commit comments

Comments
 (0)