use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::prelude::*;
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")]
#[non_exhaustive]
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")]
#[non_exhaustive]
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)]
#[non_exhaustive]
pub struct Delegation {
pub delegator: Addr,
pub validator: String,
pub amount: Coin,
}
impl_response_constructor!(Delegation, delegator: Addr, validator: String, 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")]
#[non_exhaustive]
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)]
#[non_exhaustive]
pub struct FullDelegation {
pub delegator: Addr,
pub validator: String,
pub amount: Coin,
pub can_redelegate: Coin,
pub accumulated_rewards: Vec<Coin>,
}
impl_response_constructor!(
FullDelegation,
delegator: Addr,
validator: String,
amount: Coin,
can_redelegate: Coin,
accumulated_rewards: Vec<Coin>
);
impl FullDelegation {
pub fn create(
delegator: Addr,
validator: String,
amount: Coin,
can_redelegate: Coin,
accumulated_rewards: Vec<Coin>,
) -> Self {
Self {
delegator,
validator,
amount,
can_redelegate,
accumulated_rewards,
}
}
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[non_exhaustive]
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)]
#[non_exhaustive]
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)]
#[non_exhaustive]
pub struct Validator {
pub address: String,
pub commission: Decimal,
pub max_commission: Decimal,
pub max_change_rate: Decimal,
}
impl_response_constructor!(
Validator,
address: String,
commission: Decimal,
max_commission: Decimal,
max_change_rate: Decimal
);
impl Validator {
pub fn create(
address: String,
commission: Decimal,
max_commission: Decimal,
max_change_rate: Decimal,
) -> Self {
Self {
address,
commission,
max_commission,
max_change_rate,
}
}
}