helium_api/models/
validator.rs

1use super::Hnt;
2use chrono::{DateTime, Utc};
3use serde::{Deserialize, Serialize};
4
5#[derive(Clone, Serialize, Deserialize, Debug)]
6/// Represents a validator on the blockchain.
7pub struct Validator {
8    /// The validator address is the base58 check-encoded public key of
9    /// the validator.
10    pub address: String,
11    /// The validator pwner is the base58 check-encoded public key of
12    /// the owner of the validator.
13    pub owner: String,
14    /// The staked amount for the validator
15    pub stake: Hnt,
16    /// The last heartbeat transaction of the validator
17    pub last_heartbeat: u64,
18    /// The last heartbeat version of the validator heartbeat
19    pub version_heartbeat: u64,
20    /// The current status of the validator (staked, cooldown, unstaked)
21    pub stake_status: String,
22    /// The total penalty of the validator
23    pub penalty: f64,
24    /// A list of penalties this validator has received
25    pub penalties: Vec<Penalty>,
26    /// The block this validator was added to chain
27    pub block_added: u64,
28    /// The current block this validator is synced to
29    pub block: u64,
30}
31
32/// Stats for validators
33#[derive(Clone, Serialize, Deserialize, Debug)]
34pub struct ValidatorStats {
35    /// The number of active validators. An active validator is one that emits
36    /// heartbeat transactions on a regular basis. `None` indicates the active
37    /// number is unknown at this time.
38    pub active: Option<u64>,
39    pub staked: StakeStats,
40    pub unstaked: StakeStats,
41    pub cooldown: StakeStats,
42}
43
44/// Reward for validator
45#[derive(Clone, Debug, Deserialize, Serialize)]
46pub struct Reward {
47    /// The owner address is the base58 check-encoded public key of
48    /// the owner's wallet address.
49    pub account: String,
50    /// The reward amount.
51    #[serde(deserialize_with = "Hnt::deserialize")]
52    pub amount: Hnt,
53    /// The block the reward was earned in.
54    pub block: i64,
55    /// The validator address is the base58 check-encoded public key of
56    /// the validator.
57    pub gateway: String,
58    /// The transaction hash of the reward.
59    pub hash: String,
60    /// The timestamp of the rewards.
61    pub timestamp: DateTime<Utc>,
62}
63
64/// Stats for a specific validator stake status
65#[derive(Clone, Serialize, Deserialize, Debug)]
66pub struct StakeStats {
67    /// The amount of HNT committed in the staked status
68    pub amount: f64,
69    /// The number of validators in the staked status
70    pub count: u64,
71}
72
73#[derive(Clone, Serialize, Deserialize, Debug)]
74#[serde(rename_all = "snake_case")]
75/// The Penalty types reported for a validator.
76pub enum PenaltyType {
77    Performance,
78    Tenure,
79    Dkg,
80}
81
82#[derive(Clone, Serialize, Deserialize, Debug)]
83/// Represents a penalty for a validator.
84pub struct Penalty {
85    /// The type of penalty
86    #[serde(rename = "type")]
87    pub kind: PenaltyType,
88    /// The block the penalty occured in.
89    pub height: u64,
90    /// The amount of penalty.
91    pub amount: f64,
92}