use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::addresses::HumanAddr;
use crate::binary::Binary;
use crate::coins::Coin;
use crate::math::Decimal;
use crate::types::Empty;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryRequest<C: CustomQuery> {
Bank(BankQuery),
Custom(C),
Staking(StakingQuery),
Wasm(WasmQuery),
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum BankQuery {
Balance { address: HumanAddr, denom: String },
AllBalances { address: HumanAddr },
}
pub trait CustomQuery: Serialize {}
impl CustomQuery for Empty {}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum WasmQuery {
Smart {
contract_addr: HumanAddr,
msg: Binary,
},
Raw {
contract_addr: HumanAddr,
key: Binary,
},
}
impl<C: CustomQuery> From<BankQuery> for QueryRequest<C> {
fn from(msg: BankQuery) -> Self {
QueryRequest::Bank(msg)
}
}
impl<C: CustomQuery> From<C> for QueryRequest<C> {
fn from(msg: C) -> Self {
QueryRequest::Custom(msg)
}
}
#[cfg(feature = "staking")]
impl<C: CustomQuery> From<StakingQuery> for QueryRequest<C> {
fn from(msg: StakingQuery) -> Self {
QueryRequest::Staking(msg)
}
}
impl<C: CustomQuery> From<WasmQuery> for QueryRequest<C> {
fn from(msg: WasmQuery) -> Self {
QueryRequest::Wasm(msg)
}
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct BalanceResponse {
pub amount: Coin,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct AllBalanceResponse {
pub amount: Vec<Coin>,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum StakingQuery {
BondedDenom {},
AllDelegations { delegator: HumanAddr },
Delegation {
delegator: HumanAddr,
validator: HumanAddr,
},
Validators {},
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct BondedDenomResponse {
pub denom: String,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct AllDelegationsResponse {
pub delegations: Vec<Delegation>,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct Delegation {
pub delegator: HumanAddr,
pub validator: HumanAddr,
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, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct DelegationResponse {
pub delegation: Option<FullDelegation>,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct FullDelegation {
pub delegator: HumanAddr,
pub validator: HumanAddr,
pub amount: Coin,
pub can_redelegate: Coin,
pub accumulated_rewards: Vec<Coin>,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct ValidatorsResponse {
pub validators: Vec<Validator>,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct Validator {
pub address: HumanAddr,
pub commission: Decimal,
pub max_commission: Decimal,
pub max_change_rate: Decimal,
}