tendermint_config/
priv_validator_key.rsuse std::{fs, path::Path};
use serde::{Deserialize, Serialize};
use tendermint::{
account,
private_key::PrivateKey,
public_key::{PublicKey, TendermintKey},
};
use crate::{error::Error, prelude::*};
#[derive(Serialize, Deserialize)] pub struct PrivValidatorKey {
pub address: account::Id,
pub pub_key: PublicKey,
pub priv_key: PrivateKey,
}
impl PrivValidatorKey {
pub fn parse_json<T: AsRef<str>>(json_string: T) -> Result<Self, Error> {
let result =
serde_json::from_str::<Self>(json_string.as_ref()).map_err(Error::serde_json)?;
TendermintKey::new_consensus_key(result.priv_key.public_key())
.map_err(Error::tendermint)?;
Ok(result)
}
pub fn load_json_file<P>(path: &P) -> Result<Self, Error>
where
P: AsRef<Path>,
{
let json_string = fs::read_to_string(path)
.map_err(|e| Error::file_io(format!("{}", path.as_ref().display()), e))?;
Self::parse_json(json_string)
}
pub fn consensus_pubkey(&self) -> TendermintKey {
TendermintKey::new_consensus_key(self.priv_key.public_key()).unwrap()
}
}