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;
12use crate::utils::impl_hidden_constructor;
13
14#[non_exhaustive]
15#[derive(
16 Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier,
17)]
18#[serde(rename_all = "snake_case")]
19pub enum BankQuery {
20 #[cfg(feature = "cosmwasm_1_1")]
24 Supply { denom: String },
25 Balance { address: String, denom: String },
28 #[cfg(feature = "cosmwasm_1_3")]
31 DenomMetadata { denom: String },
32 #[cfg(feature = "cosmwasm_1_3")]
35 AllDenomMetadata { pagination: Option<PageRequest> },
36}
37
38#[derive(
39 Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier,
40)]
41#[serde(rename_all = "snake_case")]
42#[non_exhaustive]
43pub struct SupplyResponse {
44 pub amount: Coin,
47}
48
49impl_hidden_constructor!(SupplyResponse, amount: Coin);
50
51impl QueryResponseType for SupplyResponse {}
52
53#[derive(
54 Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier,
55)]
56#[serde(rename_all = "snake_case")]
57#[non_exhaustive]
58pub struct BalanceResponse {
59 pub amount: Coin,
62}
63
64impl_hidden_constructor!(BalanceResponse, amount: Coin);
65
66impl QueryResponseType for BalanceResponse {}
67
68#[derive(
69 Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier,
70)]
71#[serde(rename_all = "snake_case")]
72#[non_exhaustive]
73pub struct DenomMetadataResponse {
74 pub metadata: DenomMetadata,
76}
77
78impl_hidden_constructor!(DenomMetadataResponse, metadata: DenomMetadata);
79
80impl QueryResponseType for DenomMetadataResponse {}
81
82#[derive(
83 Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier,
84)]
85#[serde(rename_all = "snake_case")]
86#[non_exhaustive]
87pub struct AllDenomMetadataResponse {
88 pub metadata: Vec<DenomMetadata>,
90 pub next_key: Option<Binary>,
91}
92
93impl_hidden_constructor!(
94 AllDenomMetadataResponse,
95 metadata: Vec<DenomMetadata>,
96 next_key: Option<Binary>
97);
98
99impl QueryResponseType for AllDenomMetadataResponse {}
100
101#[cfg(test)]
102mod tests {
103 use super::*;
104
105 #[test]
106 fn private_constructor_works() {
107 let response = BalanceResponse::new(Coin::new(1234u128, "uatom"));
108 assert_eq!(
109 response,
110 BalanceResponse {
111 amount: Coin::new(1234u128, "uatom")
112 }
113 );
114 }
115}