cosmwasm_std/query/
bank.rs1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use crate::Coin;
5
6use crate::prelude::*;
7#[cfg(feature = "cosmwasm_1_3")]
8use crate::PageRequest;
9use crate::{Binary, DenomMetadata};
10
11use super::query_response::QueryResponseType;
12
13#[non_exhaustive]
14#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
15#[serde(rename_all = "snake_case")]
16pub enum BankQuery {
17 #[cfg(feature = "cosmwasm_1_1")]
21 Supply { denom: String },
22 Balance { address: String, denom: String },
25 AllBalances { address: String },
29 #[cfg(feature = "cosmwasm_1_3")]
32 DenomMetadata { denom: String },
33 #[cfg(feature = "cosmwasm_1_3")]
36 AllDenomMetadata { pagination: Option<PageRequest> },
37}
38
39#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
40#[serde(rename_all = "snake_case")]
41#[non_exhaustive]
42pub struct SupplyResponse {
43 pub amount: Coin,
46}
47
48impl_response_constructor!(SupplyResponse, amount: Coin);
49
50impl QueryResponseType for SupplyResponse {}
51
52#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
53#[serde(rename_all = "snake_case")]
54#[non_exhaustive]
55pub struct BalanceResponse {
56 pub amount: Coin,
59}
60
61impl_response_constructor!(BalanceResponse, amount: Coin);
62
63impl QueryResponseType for BalanceResponse {}
64
65#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
66#[serde(rename_all = "snake_case")]
67#[non_exhaustive]
68pub struct AllBalanceResponse {
69 pub amount: Vec<Coin>,
71}
72
73impl_response_constructor!(AllBalanceResponse, amount: Vec<Coin>);
74
75impl QueryResponseType for AllBalanceResponse {}
76
77#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
78#[serde(rename_all = "snake_case")]
79#[non_exhaustive]
80pub struct DenomMetadataResponse {
81 pub metadata: DenomMetadata,
83}
84
85impl_response_constructor!(DenomMetadataResponse, metadata: DenomMetadata);
86
87impl QueryResponseType for DenomMetadataResponse {}
88
89#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
90#[serde(rename_all = "snake_case")]
91#[non_exhaustive]
92pub struct AllDenomMetadataResponse {
93 pub metadata: Vec<DenomMetadata>,
95 pub next_key: Option<Binary>,
96}
97
98impl_response_constructor!(
99 AllDenomMetadataResponse,
100 metadata: Vec<DenomMetadata>,
101 next_key: Option<Binary>
102);
103
104impl QueryResponseType for AllDenomMetadataResponse {}
105
106#[cfg(test)]
107mod tests {
108 use super::*;
109
110 #[test]
111 fn private_constructor_works() {
112 let response = AllBalanceResponse::new(vec![Coin::new(1234u128, "uatom")]);
113 assert_eq!(
114 response,
115 AllBalanceResponse {
116 amount: vec![Coin::new(1234u128, "uatom")]
117 }
118 );
119 }
120}