prov_cosmwasm_std/query/
mod.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4#[cfg(feature = "stargate")]
5use crate::Binary;
6use crate::Empty;
7
8mod bank;
9mod ibc;
10mod staking;
11mod stargate;
12mod wasm;
13
14pub use bank::{AllBalanceResponse, BalanceResponse, BankQuery};
15#[cfg(feature = "stargate")]
16pub use ibc::{ChannelResponse, IbcQuery, ListChannelsResponse, PortIdResponse};
17#[cfg(feature = "staking")]
18pub use staking::{
19    AllDelegationsResponse, AllValidatorsResponse, BondedDenomResponse, Delegation,
20    DelegationResponse, FullDelegation, StakingQuery, Validator, ValidatorResponse,
21};
22#[cfg(feature = "stargate")]
23pub use stargate::StargateResponse;
24pub use wasm::{ContractInfoResponse, WasmQuery};
25
26#[non_exhaustive]
27#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
28#[serde(rename_all = "snake_case")]
29pub enum QueryRequest<C> {
30    Bank(BankQuery),
31    Custom(C),
32    #[cfg(feature = "staking")]
33    Staking(StakingQuery),
34    /// A Stargate query encoded the same way as abci_query, with path and protobuf encoded Data.
35    /// The format is defined in [ADR-21](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-021-protobuf-query-encoding.md)
36    /// The response is also protobuf encoded. The caller is responsible for compiling the proper protobuf definitions
37    #[cfg(feature = "stargate")]
38    Stargate {
39        /// this is the fully qualified service path used for routing,
40        /// eg. custom/cosmos_sdk.x.bank.v1.Query/QueryBalance
41        path: String,
42        /// this is the expected protobuf message type (not any), binary encoded
43        data: Binary,
44    },
45    #[cfg(feature = "stargate")]
46    Ibc(IbcQuery),
47    Wasm(WasmQuery),
48}
49
50/// A trait that is required to avoid conflicts with other query types like BankQuery and WasmQuery
51/// in generic implementations.
52/// You need to implement it in your custom query type.
53///
54/// # Examples
55///
56/// ```
57/// # use prov_cosmwasm_std::CustomQuery;
58/// # use schemars::JsonSchema;
59/// # use serde::{Deserialize, Serialize};
60/// #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
61/// #[serde(rename_all = "snake_case")]
62/// pub enum MyCustomQuery {
63///     Ping {},
64///     Capitalized { text: String },
65/// }
66///
67/// impl CustomQuery for MyCustomQuery {}
68/// ```
69pub trait CustomQuery: Serialize + Clone {}
70// We require `Clone` because `Clone` in `QueryRequest<C>` is only derived for
71// `C: Clone` and we want consistent behaviour for all `QueryRequest<C>`
72
73impl CustomQuery for Empty {}
74
75impl<C: CustomQuery> From<BankQuery> for QueryRequest<C> {
76    fn from(msg: BankQuery) -> Self {
77        QueryRequest::Bank(msg)
78    }
79}
80
81impl<C: CustomQuery> From<C> for QueryRequest<C> {
82    fn from(msg: C) -> Self {
83        QueryRequest::Custom(msg)
84    }
85}
86
87#[cfg(feature = "staking")]
88impl<C: CustomQuery> From<StakingQuery> for QueryRequest<C> {
89    fn from(msg: StakingQuery) -> Self {
90        QueryRequest::Staking(msg)
91    }
92}
93
94impl<C: CustomQuery> From<WasmQuery> for QueryRequest<C> {
95    fn from(msg: WasmQuery) -> Self {
96        QueryRequest::Wasm(msg)
97    }
98}
99
100#[cfg(feature = "stargate")]
101impl<C: CustomQuery> From<IbcQuery> for QueryRequest<C> {
102    fn from(msg: IbcQuery) -> Self {
103        QueryRequest::Ibc(msg)
104    }
105}