cudos_cosmwasm/
query.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use cosmwasm_std::CustomQuery;
5
6// implement custom query
7impl CustomQuery for CudosQuery {}
8
9/// CudosQuery is defines available query datas
10#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
11#[serde(rename_all = "snake_case")]
12pub enum CudosQuery {
13    QueryDenomById {
14        denom_id: String,
15    },
16    QueryDenomByName {
17        denom_name: String,
18    },
19    QueryDenomBySymbol {
20        denom_symbol: String,
21    },
22    QueryDenoms {
23        pagination: Option<PaginationRequest>,
24    },
25    QueryCollection {
26        denom_id: String,
27        pagination: Option<PaginationRequest>,
28    },
29    QuerySupply {
30        denom_id: String,
31    },
32    QueryOwner {
33        denom_id: Option<String>,
34        address: String,
35        pagination: Option<PaginationRequest>,
36    },
37    QueryToken {
38        denom_id: String,
39        token_id: String,
40    },
41    QueryApprovals {
42        denom_id: String,
43        token_id: String,
44    },
45    QueryApprovedForAll {
46        owner_address: String,
47        operator_address: String,
48    },
49}
50
51#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
52pub struct QueryApprovalsResponse {
53    pub approved_addresses: Vec<String>,
54}
55
56#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
57pub struct QueryApprovedForAllResponse {
58    pub is_approved: bool,
59}
60
61#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
62pub struct OwnerCollectionResponse {
63    owner: Owner,
64    pub pagination: Option<PageResponse>,
65}
66
67#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
68pub struct Owner {
69    address: String,
70    id_collections: Vec<IDCollection>,
71}
72
73#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
74pub struct IDCollection {
75    denom_id: String,
76    token_ids: Vec<String>,
77}
78
79#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
80pub struct SupplyResponse {
81    amount: u64,
82}
83
84#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
85pub struct DenomResponse {
86    pub denom: Denom,
87}
88
89#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
90pub struct DenomsResponse {
91    pub denoms: Option<Vec<Denom>>,
92    pub pagination: Option<PageResponse>,
93}
94
95#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, JsonSchema)]
96pub struct Denom {
97    pub id: String,
98    pub name: String,
99    pub schema: Option<String>,
100    pub creator: String,
101}
102
103#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, JsonSchema)]
104pub struct CollectionResponse {
105    pub collection: Option<Collection>,
106    pub pagination: Option<PageResponse>,
107}
108
109#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
110pub struct PaginationRequest {
111    // key is a value returned in PageResponse.next_key to begin
112	// querying the next page most efficiently. Only one of offset or key
113	// should be set.
114	pub key: Option<String>,
115	// offset is a numeric offset that can be used when key is unavailable.
116	// It is less efficient than using key. Only one of offset or key should
117	// be set.
118	pub offset: Option<u64>,
119	// limit is the total number of results to be returned in the result page.
120	// If left empty it will default to a value to be set by each app.
121	pub limit: Option<u64>,
122	// count_total is set to true  to indicate that the result set should include
123	// a count of the total number of items available for pagination in UIs.
124	// count_total is only respected when offset is used. It is ignored when key
125	// is set.
126	pub count_total: Option<bool>,
127	// reverse is set to true if results are to be returned in the descending order.
128	//
129	// Since: cosmos-sdk 0.43
130	pub reverse: Option<bool>,
131}
132
133#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
134pub struct PageResponse {
135    pub next_key: Option<String>,
136    pub total: Option<u64>,
137}
138
139#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, JsonSchema)]
140pub struct Collection {
141    pub denom: Denom,
142    pub nfts: Option<Vec<NFT>>,
143}
144
145#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, JsonSchema)]
146pub struct NFT {
147    pub id: String,
148    pub name: Option<String>,
149    pub uri: Option<String>,
150    pub data: Option<String>,
151    pub owner: String,
152    pub approved_addresses: Option<Vec<String>>,
153}
154
155#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, JsonSchema)]
156pub struct QueryNFTResponse {
157    pub nft: NFT,
158}