#[cfg(any(test, feature = "fuzzing"))]
use crate::network_address::NetworkAddress;
use crate::{account_address::AccountAddress, validator_config::ValidatorConfig};
use aptos_crypto::bls12381;
#[cfg(any(test, feature = "fuzzing"))]
use proptest_derive::Arbitrary;
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[cfg_attr(any(test, feature = "fuzzing"), derive(Arbitrary))]
pub struct ValidatorInfo {
pub account_address: AccountAddress,
consensus_voting_power: u64,
config: ValidatorConfig,
}
impl fmt::Display for ValidatorInfo {
fn fmt(&self, f: &mut fmt::Formatter) -> std::fmt::Result {
write!(
f,
"account_address: {}",
self.account_address.short_str_lossless()
)
}
}
impl ValidatorInfo {
pub fn new(
account_address: AccountAddress,
consensus_voting_power: u64,
config: ValidatorConfig,
) -> Self {
ValidatorInfo {
account_address,
consensus_voting_power,
config,
}
}
#[cfg(any(test, feature = "fuzzing"))]
pub fn new_with_test_network_keys(
account_address: AccountAddress,
consensus_public_key: bls12381::PublicKey,
consensus_voting_power: u64,
validator_index: u64,
) -> Self {
let addr = NetworkAddress::mock();
let config = ValidatorConfig::new(
consensus_public_key,
bcs::to_bytes(&vec![addr.clone()]).unwrap(),
bcs::to_bytes(&vec![addr]).unwrap(),
validator_index,
);
Self {
account_address,
consensus_voting_power,
config,
}
}
pub fn account_address(&self) -> &AccountAddress {
&self.account_address
}
pub fn consensus_public_key(&self) -> &bls12381::PublicKey {
&self.config.consensus_public_key
}
pub fn consensus_voting_power(&self) -> u64 {
self.consensus_voting_power
}
pub fn config(&self) -> &ValidatorConfig {
&self.config
}
pub fn into_config(self) -> ValidatorConfig {
self.config
}
}