#![cfg(feature = "staking")]
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::{Addr, Coin, Decimal};
use super::query_response::QueryResponseType;
#[non_exhaustive]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum StakingQuery {
BondedDenom {},
AllDelegations { delegator: String },
Delegation {
delegator: String,
validator: String,
},
AllValidators {},
Validator {
address: String,
},
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct BondedDenomResponse {
pub denom: String,
}
impl QueryResponseType for BondedDenomResponse {}
impl_response_constructor!(BondedDenomResponse, denom: String);
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct AllDelegationsResponse {
pub delegations: Vec<Delegation>,
}
impl QueryResponseType for AllDelegationsResponse {}
impl_response_constructor!(AllDelegationsResponse, delegations: Vec<Delegation>);
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct Delegation {
pub delegator: Addr,
pub validator: String,
pub amount: Coin,
}
impl From<FullDelegation> for Delegation {
fn from(full: FullDelegation) -> Self {
Delegation {
delegator: full.delegator,
validator: full.validator,
amount: full.amount,
}
}
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct DelegationResponse {
pub delegation: Option<FullDelegation>,
}
impl QueryResponseType for DelegationResponse {}
impl_response_constructor!(DelegationResponse, delegation: Option<FullDelegation>);
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct FullDelegation {
pub delegator: Addr,
pub validator: String,
pub amount: Coin,
pub can_redelegate: Coin,
pub accumulated_rewards: Vec<Coin>,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct AllValidatorsResponse {
pub validators: Vec<Validator>,
}
impl QueryResponseType for AllValidatorsResponse {}
impl_response_constructor!(AllValidatorsResponse, validators: Vec<Validator>);
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct ValidatorResponse {
pub validator: Option<Validator>,
}
impl QueryResponseType for ValidatorResponse {}
impl_response_constructor!(ValidatorResponse, validator: Option<Validator>);
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct Validator {
pub address: String,
pub commission: Decimal,
pub max_commission: Decimal,
pub max_change_rate: Decimal,
}