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(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
16#[serde(rename_all = "snake_case")]
17pub enum BankQuery {
18 #[cfg(feature = "cosmwasm_1_1")]
22 Supply { denom: String },
23 Balance { address: String, denom: String },
26 #[cfg(feature = "cosmwasm_1_3")]
29 DenomMetadata { denom: String },
30 #[cfg(feature = "cosmwasm_1_3")]
33 AllDenomMetadata { pagination: Option<PageRequest> },
34}
35
36#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
37#[serde(rename_all = "snake_case")]
38#[non_exhaustive]
39pub struct SupplyResponse {
40 pub amount: Coin,
43}
44
45impl_hidden_constructor!(SupplyResponse, amount: Coin);
46
47impl QueryResponseType for SupplyResponse {}
48
49#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
50#[serde(rename_all = "snake_case")]
51#[non_exhaustive]
52pub struct BalanceResponse {
53 pub amount: Coin,
56}
57
58impl_hidden_constructor!(BalanceResponse, amount: Coin);
59
60impl QueryResponseType for BalanceResponse {}
61
62#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
63#[serde(rename_all = "snake_case")]
64#[non_exhaustive]
65pub struct DenomMetadataResponse {
66 pub metadata: DenomMetadata,
68}
69
70impl_hidden_constructor!(DenomMetadataResponse, metadata: DenomMetadata);
71
72impl QueryResponseType for DenomMetadataResponse {}
73
74#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
75#[serde(rename_all = "snake_case")]
76#[non_exhaustive]
77pub struct AllDenomMetadataResponse {
78 pub metadata: Vec<DenomMetadata>,
80 pub next_key: Option<Binary>,
81}
82
83impl_hidden_constructor!(
84 AllDenomMetadataResponse,
85 metadata: Vec<DenomMetadata>,
86 next_key: Option<Binary>
87);
88
89impl QueryResponseType for AllDenomMetadataResponse {}
90
91#[cfg(test)]
92mod tests {
93 use super::*;
94
95 #[test]
96 fn private_constructor_works() {
97 let response = BalanceResponse::new(Coin::new(1234u128, "uatom"));
98 assert_eq!(
99 response,
100 BalanceResponse {
101 amount: Coin::new(1234u128, "uatom")
102 }
103 );
104 }
105}