diem_types/
validator_info.rs1use crate::{
9 account_address::AccountAddress,
10 validator_config::{
11 ConsensusPublicKey, ConsensusVRFPublicKey, ValidatorConfig,
12 },
13};
14#[cfg(any(test, feature = "fuzzing"))]
15use proptest_derive::Arbitrary;
16use serde::{Deserialize, Serialize};
17use std::fmt;
18
19#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
26#[cfg_attr(any(test, feature = "fuzzing"), derive(Arbitrary))]
27pub struct ValidatorInfo {
28 account_address: AccountAddress,
32 consensus_voting_power: u64,
34 config: ValidatorConfig,
36 last_config_update_time: u64,
39}
40
41impl fmt::Display for ValidatorInfo {
42 fn fmt(&self, f: &mut fmt::Formatter) -> std::fmt::Result {
43 write!(
44 f,
45 "account_address: {}",
46 self.account_address.short_str_lossless()
47 )
48 }
49}
50
51impl ValidatorInfo {
52 pub fn new(
53 account_address: AccountAddress, consensus_voting_power: u64,
54 config: ValidatorConfig,
55 ) -> Self {
56 ValidatorInfo {
57 account_address,
58 consensus_voting_power,
59 config,
60 last_config_update_time: 0,
61 }
62 }
63
64 #[cfg(any(test, feature = "fuzzing"))]
65 pub fn new_with_test_network_keys(
66 account_address: AccountAddress,
67 consensus_public_key: ConsensusPublicKey,
68 vrf_public_key: Option<ConsensusVRFPublicKey>,
69 consensus_voting_power: u64,
70 ) -> Self {
71 let config = ValidatorConfig::new(
72 consensus_public_key,
73 vrf_public_key,
74 vec![],
75 vec![],
76 );
77
78 Self {
79 account_address,
80 consensus_voting_power,
81 config,
82 last_config_update_time: 0,
83 }
84 }
85
86 pub fn account_address(&self) -> &AccountAddress { &self.account_address }
89
90 pub fn consensus_public_key(&self) -> &ConsensusPublicKey {
92 &self.config.consensus_public_key
93 }
94
95 pub fn vrf_public_key(&self) -> &Option<ConsensusVRFPublicKey> {
96 &self.config.vrf_public_key
97 }
98
99 pub fn consensus_voting_power(&self) -> u64 { self.consensus_voting_power }
101
102 pub fn config(&self) -> &ValidatorConfig { &self.config }
104
105 pub fn into_config(self) -> ValidatorConfig { self.config }
107}