1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use crate::{Addr, Coin, Decimal};
5
6use super::query_response::QueryResponseType;
7
8#[non_exhaustive]
9#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
10#[serde(rename_all = "snake_case")]
11pub enum StakingQuery {
12 BondedDenom {},
14 AllDelegations { delegator: String },
16 Delegation {
19 delegator: String,
20 validator: String,
21 },
22 AllValidators {},
26 Validator {
31 address: String,
33 },
34}
35
36#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
38#[serde(rename_all = "snake_case")]
39pub struct BondedDenomResponse {
40 pub denom: String,
41}
42
43impl QueryResponseType for BondedDenomResponse {}
44
45impl_response_constructor!(BondedDenomResponse, denom: String);
46
47#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
49#[serde(rename_all = "snake_case")]
50pub struct AllDelegationsResponse {
51 pub delegations: Vec<Delegation>,
52}
53
54impl QueryResponseType for AllDelegationsResponse {}
55
56impl_response_constructor!(AllDelegationsResponse, delegations: Vec<Delegation>);
57
58#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
62pub struct Delegation {
63 pub delegator: Addr,
64 pub validator: String,
66 pub amount: Coin,
68}
69
70impl From<FullDelegation> for Delegation {
71 fn from(full: FullDelegation) -> Self {
72 Delegation {
73 delegator: full.delegator,
74 validator: full.validator,
75 amount: full.amount,
76 }
77 }
78}
79
80#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
82#[serde(rename_all = "snake_case")]
83pub struct DelegationResponse {
84 pub delegation: Option<FullDelegation>,
85}
86
87impl QueryResponseType for DelegationResponse {}
88
89impl_response_constructor!(DelegationResponse, delegation: Option<FullDelegation>);
90
91#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
96pub struct FullDelegation {
97 pub delegator: Addr,
98 pub validator: String,
100 pub amount: Coin,
102 pub can_redelegate: Coin,
106 pub accumulated_rewards: Vec<Coin>,
108}
109
110#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
112pub struct AllValidatorsResponse {
113 pub validators: Vec<Validator>,
114}
115
116impl QueryResponseType for AllValidatorsResponse {}
117
118impl_response_constructor!(AllValidatorsResponse, validators: Vec<Validator>);
119
120#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
122pub struct ValidatorResponse {
123 pub validator: Option<Validator>,
124}
125
126impl QueryResponseType for ValidatorResponse {}
127
128impl_response_constructor!(ValidatorResponse, validator: Option<Validator>);
129
130#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
132pub struct Validator {
133 pub address: String,
140 pub commission: Decimal,
141 pub max_commission: Decimal,
142 pub max_change_rate: Decimal,
144}