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 #[deprecated = "Returns a potentially unbound number of results. If you think you have a valid usecase, please open an issue."]
29 AllBalances { address: String },
30 #[cfg(feature = "cosmwasm_1_3")]
33 DenomMetadata { denom: String },
34 #[cfg(feature = "cosmwasm_1_3")]
37 AllDenomMetadata { pagination: Option<PageRequest> },
38}
39
40#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
41#[serde(rename_all = "snake_case")]
42#[non_exhaustive]
43pub struct SupplyResponse {
44 pub amount: Coin,
47}
48
49impl_response_constructor!(SupplyResponse, amount: Coin);
50
51impl QueryResponseType for SupplyResponse {}
52
53#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
54#[serde(rename_all = "snake_case")]
55#[non_exhaustive]
56pub struct BalanceResponse {
57 pub amount: Coin,
60}
61
62impl_response_constructor!(BalanceResponse, amount: Coin);
63
64impl QueryResponseType for BalanceResponse {}
65
66#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
67#[serde(rename_all = "snake_case")]
68#[non_exhaustive]
69pub struct AllBalanceResponse {
70 pub amount: Vec<Coin>,
72}
73
74impl_response_constructor!(AllBalanceResponse, amount: Vec<Coin>);
75
76impl QueryResponseType for AllBalanceResponse {}
77
78#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
79#[serde(rename_all = "snake_case")]
80#[non_exhaustive]
81pub struct DenomMetadataResponse {
82 pub metadata: DenomMetadata,
84}
85
86impl_response_constructor!(DenomMetadataResponse, metadata: DenomMetadata);
87
88impl QueryResponseType for DenomMetadataResponse {}
89
90#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
91#[serde(rename_all = "snake_case")]
92#[non_exhaustive]
93pub struct AllDenomMetadataResponse {
94 pub metadata: Vec<DenomMetadata>,
96 pub next_key: Option<Binary>,
97}
98
99impl_response_constructor!(
100 AllDenomMetadataResponse,
101 metadata: Vec<DenomMetadata>,
102 next_key: Option<Binary>
103);
104
105impl QueryResponseType for AllDenomMetadataResponse {}
106
107#[cfg(test)]
108mod tests {
109 use super::*;
110
111 #[test]
112 fn private_constructor_works() {
113 let response = AllBalanceResponse::new(vec![Coin::new(1234u128, "uatom")]);
114 assert_eq!(
115 response,
116 AllBalanceResponse {
117 amount: vec![Coin::new(1234u128, "uatom")]
118 }
119 );
120 }
121}