Update config and cli for rpc
This commit is contained in:
parent
d2f12b7c18
commit
037c3b8307
@ -4,8 +4,8 @@ use fork_choice::ForkChoiceAlgorithm;
|
||||
use network::NetworkConfig;
|
||||
use slog::error;
|
||||
use std::fs;
|
||||
use std::net::IpAddr;
|
||||
use std::net::SocketAddr;
|
||||
use std::net::{IpAddr, Ipv4Addr};
|
||||
use std::path::PathBuf;
|
||||
use types::multiaddr::Protocol;
|
||||
use types::multiaddr::ToMultiaddr;
|
||||
@ -58,7 +58,7 @@ impl ClientConfig {
|
||||
pub fn parse_args(args: ArgMatches, log: &slog::Logger) -> Result<Self, &'static str> {
|
||||
let mut config = ClientConfig::default();
|
||||
|
||||
// Network related args
|
||||
/* Network related arguments */
|
||||
|
||||
// Custom p2p listen port
|
||||
if let Some(port_str) = args.value_of("port") {
|
||||
@ -88,13 +88,33 @@ impl ClientConfig {
|
||||
}
|
||||
}
|
||||
|
||||
// filesystem args
|
||||
/* Filesystem related arguments */
|
||||
|
||||
// Custom datadir
|
||||
if let Some(dir) = args.value_of("datadir") {
|
||||
config.data_dir = PathBuf::from(dir.to_string());
|
||||
};
|
||||
|
||||
/* RPC related arguments */
|
||||
|
||||
if let Some(rpc_address) = args.value_of("rpc-address") {
|
||||
if let Ok(listen_address) = rpc_address.parse::<Ipv4Addr>() {
|
||||
config.rpc_conf.listen_address = listen_address;
|
||||
} else {
|
||||
error!(log, "Invalid RPC listen address"; "Address" => rpc_address);
|
||||
return Err("Invalid RPC listen address");
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(rpc_port) = args.value_of("rpc-port") {
|
||||
if let Ok(port) = rpc_port.parse::<u16>() {
|
||||
config.rpc_conf.port = port;
|
||||
} else {
|
||||
error!(log, "Invalid RPC port"; "port" => rpc_port);
|
||||
return Err("Invalid RPC port");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
}
|
||||
|
22
beacon_node/rpc/src/config.rs
Normal file
22
beacon_node/rpc/src/config.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
/// RPC Configuration
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Config {
|
||||
/// Enable the RPC server.
|
||||
pub enabled: bool,
|
||||
/// The IPv4 address the RPC will listen on.
|
||||
pub listen_address: Ipv4Addr,
|
||||
/// The port the RPC will listen on.
|
||||
pub port: u16,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Config {
|
||||
enabled: false, // rpc disabled by default
|
||||
listen_address: Ipv4Addr::new(127, 0, 0, 1),
|
||||
port: 5051,
|
||||
}
|
||||
}
|
||||
}
|
@ -37,6 +37,27 @@ fn main() {
|
||||
.help("Network listen port for p2p connections.")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("rpc")
|
||||
.long("Enable RPC")
|
||||
.value_name("RPC")
|
||||
.help("Enable the RPC server.")
|
||||
.takes_value(false),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("rpc-address")
|
||||
.long("rpc address")
|
||||
.value_name("RPCADDRESS")
|
||||
.help("Listen address for RPC endpoint.")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("rpc-port")
|
||||
.long("rpc port")
|
||||
.value_name("RPCPORT")
|
||||
.help("Listen port for RPC endpoint.")
|
||||
.takes_value(true),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
// invalid arguments, panic
|
||||
|
Loading…
Reference in New Issue
Block a user