1use crate::currency::{DecCoin, RegisteredCoins};
5use crate::error::TypesError;
6use crate::mixnode::NodeRewarding;
7use nym_mixnet_contract_common::{NodeId, NymNode, PendingNodeChanges};
8use nym_mixnet_contract_common::{
9 NymNodeBond as MixnetContractNymNodeBond, NymNodeDetails as MixnetContractNymNodeDetails,
10};
11use schemars::JsonSchema;
12use serde::{Deserialize, Serialize};
13
14#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
16#[cfg_attr(
17 feature = "generate-ts",
18 ts(
19 export,
20 export_to = "ts-packages/types/src/types/rust/NymNodeDetails.ts"
21 )
22)]
23#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, JsonSchema)]
24pub struct NymNodeDetails {
25 pub bond_information: NymNodeBond,
27
28 pub rewarding_details: NodeRewarding,
30
31 pub pending_changes: PendingNodeChanges,
33}
34
35impl NymNodeDetails {
36 pub fn from_mixnet_contract_nym_node_details(
37 details: MixnetContractNymNodeDetails,
38 reg: &RegisteredCoins,
39 ) -> Result<NymNodeDetails, TypesError> {
40 Ok(NymNodeDetails {
41 bond_information: NymNodeBond::from_mixnet_contract_mixnode_bond(
42 details.bond_information,
43 reg,
44 )?,
45 rewarding_details: NodeRewarding::from_mixnet_contract_node_rewarding(
46 details.rewarding_details,
47 reg,
48 )?,
49 pending_changes: details.pending_changes,
50 })
51 }
52}
53
54#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
55#[cfg_attr(
56 feature = "generate-ts",
57 ts(export, export_to = "ts-packages/types/src/types/rust/NymNodeBond.ts")
58)]
59#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, JsonSchema)]
60pub struct NymNodeBond {
61 pub node_id: NodeId,
63
64 pub owner: String,
66
67 pub original_pledge: DecCoin,
69
70 pub bonding_height: u64,
72
73 pub is_unbonding: bool,
76
77 #[serde(flatten)]
78 pub node: NymNode,
80}
81
82impl NymNodeBond {
83 pub fn from_mixnet_contract_mixnode_bond(
84 bond: MixnetContractNymNodeBond,
85 reg: &RegisteredCoins,
86 ) -> Result<NymNodeBond, TypesError> {
87 Ok(NymNodeBond {
88 node_id: bond.node_id,
89 owner: bond.owner.into_string(),
90 original_pledge: reg
91 .attempt_convert_to_display_dec_coin(bond.original_pledge.into())?,
92 node: bond.node,
93 bonding_height: bond.bonding_height,
94 is_unbonding: bond.is_unbonding,
95 })
96 }
97}