mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-11 04:31:51 +00:00
Refactor ClientConfig, add serde to it
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
use clap::ArgMatches;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
/// RPC Configuration
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Config {
|
||||
/// Enable the RPC server.
|
||||
pub enabled: bool,
|
||||
@@ -20,3 +22,23 @@ impl Default for Config {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn apply_cli_args(&mut self, args: &ArgMatches) -> Result<(), &'static str> {
|
||||
if args.is_present("rpc") {
|
||||
self.enabled = true;
|
||||
}
|
||||
|
||||
if let Some(rpc_address) = args.value_of("rpc-address") {
|
||||
self.listen_address = rpc_address
|
||||
.parse::<Ipv4Addr>()
|
||||
.map_err(|_| "rpc-address is not IPv4 address")?;
|
||||
}
|
||||
|
||||
if let Some(rpc_port) = args.value_of("rpc-port") {
|
||||
self.port = rpc_port.parse::<u16>().map_err(|_| "rpc-port is not u16")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user