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