Fixed formatting with rustfmt.
This commit is contained in:
parent
fba916a0d8
commit
cc208670b2
@ -1,11 +1,11 @@
|
|||||||
use bincode;
|
use bincode;
|
||||||
use bls::Keypair;
|
use bls::Keypair;
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
|
use slog::{debug, error, info};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{Error, ErrorKind};
|
use std::io::{Error, ErrorKind};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use slog::{debug, info, error};
|
|
||||||
use types::ChainSpec;
|
use types::ChainSpec;
|
||||||
|
|
||||||
/// Stores the core configuration for this validator instance.
|
/// Stores the core configuration for this validator instance.
|
||||||
@ -77,11 +77,9 @@ impl Config {
|
|||||||
|
|
||||||
/// Try to load keys from validator_dir, returning None if none are found or an error.
|
/// Try to load keys from validator_dir, returning None if none are found or an error.
|
||||||
pub fn fetch_keys(&self, log: &slog::Logger) -> Option<Vec<Keypair>> {
|
pub fn fetch_keys(&self, log: &slog::Logger) -> Option<Vec<Keypair>> {
|
||||||
|
|
||||||
let key_pairs: Vec<Keypair> = fs::read_dir(&self.data_dir)
|
let key_pairs: Vec<Keypair> = fs::read_dir(&self.data_dir)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.filter_map( |validator_dir| {
|
.filter_map(|validator_dir| {
|
||||||
|
|
||||||
let validator_dir = validator_dir.ok()?;
|
let validator_dir = validator_dir.ok()?;
|
||||||
|
|
||||||
if !(validator_dir.file_type().ok()?.is_dir()) {
|
if !(validator_dir.file_type().ok()?.is_dir()) {
|
||||||
@ -92,24 +90,40 @@ impl Config {
|
|||||||
let key_filename = validator_dir.path().join(DEFAULT_PRIVATE_KEY_FILENAME);
|
let key_filename = validator_dir.path().join(DEFAULT_PRIVATE_KEY_FILENAME);
|
||||||
|
|
||||||
if !(key_filename.is_file()) {
|
if !(key_filename.is_file()) {
|
||||||
info!(log, "Private key is not a file: {:?}", key_filename.to_str());
|
info!(
|
||||||
|
log,
|
||||||
|
"Private key is not a file: {:?}",
|
||||||
|
key_filename.to_str()
|
||||||
|
);
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!(log, "Deserializing private key from file: {:?}", key_filename.to_str());
|
debug!(
|
||||||
|
log,
|
||||||
|
"Deserializing private key from file: {:?}",
|
||||||
|
key_filename.to_str()
|
||||||
|
);
|
||||||
|
|
||||||
let mut key_file = File::open(key_filename.clone()).ok()?;
|
let mut key_file = File::open(key_filename.clone()).ok()?;
|
||||||
|
|
||||||
let key: Keypair = if let Ok(key_ok) = bincode::deserialize_from(&mut key_file) {
|
let key: Keypair = if let Ok(key_ok) = bincode::deserialize_from(&mut key_file) {
|
||||||
key_ok
|
key_ok
|
||||||
} else {
|
} else {
|
||||||
error!(log, "Unable to deserialize the private key file: {:?}", key_filename);
|
error!(
|
||||||
return None;
|
log,
|
||||||
};
|
"Unable to deserialize the private key file: {:?}", key_filename
|
||||||
|
);
|
||||||
|
return None;
|
||||||
|
};
|
||||||
|
|
||||||
let ki = key.identifier();
|
let ki = key.identifier();
|
||||||
if ki != validator_dir.file_name().into_string().ok()? {
|
if ki != validator_dir.file_name().into_string().ok()? {
|
||||||
error!(log, "The validator key ({:?}) did not match the directory filename {:?}.", ki, &validator_dir.path().to_string_lossy());
|
error!(
|
||||||
|
log,
|
||||||
|
"The validator key ({:?}) did not match the directory filename {:?}.",
|
||||||
|
ki,
|
||||||
|
&validator_dir.path().to_string_lossy()
|
||||||
|
);
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Some(key)
|
Some(key)
|
||||||
@ -122,7 +136,6 @@ impl Config {
|
|||||||
} else {
|
} else {
|
||||||
Some(key_pairs)
|
Some(key_pairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Saves a keypair to a file inside the appropriate validator directory. Returns the saved path filename.
|
/// Saves a keypair to a file inside the appropriate validator directory. Returns the saved path filename.
|
||||||
|
Loading…
Reference in New Issue
Block a user