1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use crate::prelude::*;
5use crate::{Addr, Coin, Decimal};
6
7use super::query_response::QueryResponseType;
8
9#[non_exhaustive]
10#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
11#[serde(rename_all = "snake_case")]
12pub enum StakingQuery {
13 BondedDenom {},
15 AllDelegations { delegator: String },
17 Delegation {
20 delegator: String,
21 validator: String,
22 },
23 AllValidators {},
27 Validator {
32 address: String,
34 },
35}
36
37#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
39#[serde(rename_all = "snake_case")]
40#[non_exhaustive]
41pub struct BondedDenomResponse {
42 pub denom: String,
43}
44
45impl QueryResponseType for BondedDenomResponse {}
46
47impl_response_constructor!(BondedDenomResponse, denom: String);
48
49#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
51#[serde(rename_all = "snake_case")]
52#[non_exhaustive]
53pub struct AllDelegationsResponse {
54 pub delegations: Vec<Delegation>,
55}
56
57impl QueryResponseType for AllDelegationsResponse {}
58
59impl_response_constructor!(AllDelegationsResponse, delegations: Vec<Delegation>);
60
61#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
65#[non_exhaustive]
66pub struct Delegation {
67 pub delegator: Addr,
68 pub validator: String,
70 pub amount: Coin,
72}
73
74impl_response_constructor!(Delegation, delegator: Addr, validator: String, amount: Coin);
75
76impl From<FullDelegation> for Delegation {
77 fn from(full: FullDelegation) -> Self {
78 Delegation {
79 delegator: full.delegator,
80 validator: full.validator,
81 amount: full.amount,
82 }
83 }
84}
85
86#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
88#[serde(rename_all = "snake_case")]
89#[non_exhaustive]
90pub struct DelegationResponse {
91 pub delegation: Option<FullDelegation>,
92}
93
94impl QueryResponseType for DelegationResponse {}
95
96impl_response_constructor!(DelegationResponse, delegation: Option<FullDelegation>);
97
98#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
103#[non_exhaustive]
104pub struct FullDelegation {
105 pub delegator: Addr,
106 pub validator: String,
108 pub amount: Coin,
110 pub can_redelegate: Coin,
114 pub accumulated_rewards: Vec<Coin>,
116}
117
118impl_response_constructor!(
119 FullDelegation,
120 delegator: Addr,
121 validator: String,
122 amount: Coin,
123 can_redelegate: Coin,
124 accumulated_rewards: Vec<Coin>
125);
126
127impl FullDelegation {
128 pub fn create(
133 delegator: Addr,
134 validator: String,
135 amount: Coin,
136 can_redelegate: Coin,
137 accumulated_rewards: Vec<Coin>,
138 ) -> Self {
139 Self {
140 delegator,
141 validator,
142 amount,
143 can_redelegate,
144 accumulated_rewards,
145 }
146 }
147}
148
149#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
151#[non_exhaustive]
152pub struct AllValidatorsResponse {
153 pub validators: Vec<Validator>,
154}
155
156impl QueryResponseType for AllValidatorsResponse {}
157
158impl_response_constructor!(AllValidatorsResponse, validators: Vec<Validator>);
159
160#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
162#[non_exhaustive]
163pub struct ValidatorResponse {
164 pub validator: Option<Validator>,
165}
166
167impl QueryResponseType for ValidatorResponse {}
168
169impl_response_constructor!(ValidatorResponse, validator: Option<Validator>);
170
171#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
173#[non_exhaustive]
174pub struct Validator {
175 pub address: String,
182 pub commission: Decimal,
183 pub max_commission: Decimal,
184 pub max_change_rate: Decimal,
186}
187
188impl_response_constructor!(
189 Validator,
190 address: String,
191 commission: Decimal,
192 max_commission: Decimal,
193 max_change_rate: Decimal
194);
195
196impl Validator {
197 pub fn create(
202 address: String,
203 commission: Decimal,
204 max_commission: Decimal,
205 max_change_rate: Decimal,
206 ) -> Self {
207 Self {
208 address,
209 commission,
210 max_commission,
211 max_change_rate,
212 }
213 }
214}