nym_api_requests/models/
node_families.rs1use super::CoinSchema;
5use cosmwasm_std::Coin;
6use nym_mixnet_contract_common::{NodeId, NodeRewarding};
7use serde::{Deserialize, Serialize};
8use std::time::Duration;
9use time::OffsetDateTime;
10use utoipa::ToSchema;
11
12#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
14pub struct PendingFamilyInvitation {
15 pub node_id: NodeId,
17
18 #[serde(with = "time::serde::rfc3339")]
20 #[schema(value_type = String)]
21 pub expires_at: OffsetDateTime,
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
26pub struct NodeStakeInformation {
27 #[schema(value_type = CoinSchema)]
29 pub stake: Coin,
30
31 #[schema(value_type = CoinSchema)]
33 pub bond: Coin,
34
35 #[schema(value_type = CoinSchema)]
37 pub delegations: Coin,
38
39 pub delegators: usize,
41}
42
43impl From<&NodeRewarding> for NodeStakeInformation {
44 fn from(rewarding: &NodeRewarding) -> Self {
45 let denom = &rewarding.cost_params.interval_operating_cost.denom;
46
47 let bond = rewarding.operator_pledge_with_reward(denom);
48 let delegations = rewarding.delegations_with_reward(denom);
49 let mut stake = bond.clone();
50 stake.amount += delegations.amount;
51
52 NodeStakeInformation {
53 stake,
54 bond,
55 delegations,
56 delegators: rewarding.unique_delegations as usize,
57 }
58 }
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
63pub struct NodeFamilyMember {
64 pub node_id: NodeId,
65
66 #[serde(with = "time::serde::rfc3339")]
68 #[schema(value_type = String)]
69 pub joined_at: OffsetDateTime,
70
71 pub stake_information: Option<NodeStakeInformation>,
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
79pub struct NodeFamily {
80 pub id: u32,
82
83 pub name: String,
85
86 pub description: String,
88
89 pub owner: String,
91
92 #[serde(with = "humantime_serde")]
94 #[schema(value_type = String)]
95 pub average_node_age: Duration,
96
97 #[schema(value_type = Option<CoinSchema>)]
99 pub total_stake: Option<Coin>,
100
101 #[serde(with = "time::serde::rfc3339")]
103 #[schema(value_type = String)]
104 pub created_at: OffsetDateTime,
105
106 pub members: Vec<NodeFamilyMember>,
108
109 pub pending_invitations: Vec<PendingFamilyInvitation>,
111}
112
113#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
116pub struct NodeFamilyResponse {
117 pub family: Option<NodeFamily>,
118}
119
120#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
124pub struct NodeFamilyForNodeResponse {
125 pub node_id: NodeId,
127
128 pub family: Option<NodeFamily>,
130}