use super::CoinSchema;
use cosmwasm_std::Coin;
use nym_mixnet_contract_common::{NodeId, NodeRewarding};
use serde::{Deserialize, Serialize};
use std::time::Duration;
use time::OffsetDateTime;
use utoipa::ToSchema;
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct PendingFamilyInvitation {
pub node_id: NodeId,
#[serde(with = "time::serde::rfc3339")]
#[schema(value_type = String)]
pub expires_at: OffsetDateTime,
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct NodeStakeInformation {
#[schema(value_type = CoinSchema)]
pub stake: Coin,
#[schema(value_type = CoinSchema)]
pub bond: Coin,
#[schema(value_type = CoinSchema)]
pub delegations: Coin,
pub delegators: usize,
}
impl From<&NodeRewarding> for NodeStakeInformation {
fn from(rewarding: &NodeRewarding) -> Self {
let denom = &rewarding.cost_params.interval_operating_cost.denom;
let bond = rewarding.operator_pledge_with_reward(denom);
let delegations = rewarding.delegations_with_reward(denom);
let mut stake = bond.clone();
stake.amount += delegations.amount;
NodeStakeInformation {
stake,
bond,
delegations,
delegators: rewarding.unique_delegations as usize,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct NodeFamilyMember {
pub node_id: NodeId,
#[serde(with = "time::serde::rfc3339")]
#[schema(value_type = String)]
pub joined_at: OffsetDateTime,
pub stake_information: Option<NodeStakeInformation>,
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct NodeFamily {
pub id: u32,
pub name: String,
pub description: String,
pub owner: String,
#[serde(with = "humantime_serde")]
#[schema(value_type = String)]
pub average_node_age: Duration,
#[schema(value_type = Option<CoinSchema>)]
pub total_stake: Option<Coin>,
#[serde(with = "time::serde::rfc3339")]
#[schema(value_type = String)]
pub created_at: OffsetDateTime,
pub members: Vec<NodeFamilyMember>,
pub pending_invitations: Vec<PendingFamilyInvitation>,
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct NodeFamilyResponse {
pub family: Option<NodeFamily>,
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct NodeFamilyForNodeResponse {
pub node_id: NodeId,
pub family: Option<NodeFamily>,
}