From d99fe3ff841cc11e91c2b9f4345806a04276569e Mon Sep 17 00:00:00 2001 From: danda Date: Wed, 22 May 2024 18:45:10 -0700 Subject: [PATCH] feat: add --listen-port and rename --port Changes: * adds --listen-port for specifying http port to listen on. * renames --port to --neptune-rpc-port which is clearer * updates README accordingly --- README.md | 5 ++--- src/main.rs | 7 +++++-- src/model/config.rs | 8 ++++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c68fa7f..d6f0757 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,8 @@ nohup neptune-explorer 2>&1 > /path/to/logs/neptune-explorer.log & Notes: * The block-explorer automatically uses the same network (mainnet, testnet, etc) as the neptune-core instance it is connected to, and the network is displayed in the web interface. -* if neptune-core RPC server is running on a non-standard port, you can provide it with the `--port` flag. +* If neptune-core RPC server is running on a non-standard port, you can provide it with the `--neptune-rpc-port` flag. +* neptune-explorer listens for http requests on port 3000 by default. This can be changed with the `--listen-port` flag. * Site name can be specified with the `--site-name` flag. @@ -39,8 +40,6 @@ Notes: Just navigate to http://localhost:3000/ -(note: the port is not yet configurable.) - ## SSL/TLS, Nginx, etc. diff --git a/src/main.rs b/src/main.rs index 4e1ad53..62639a3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,7 +69,7 @@ async fn main() -> Result<(), anyhow::Error> { // add state .with_state(shared_state); - let port = 3000; + let port = Config::parse().listen_port; let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{port}")) .await .with_context(|| format!("Failed to bind to port {port}"))?; @@ -85,7 +85,10 @@ async fn main() -> Result<(), anyhow::Error> { async fn rpc_client() -> Result { // Create connection to neptune-core RPC server let args: Config = Config::parse(); - let server_socket = SocketAddr::new(std::net::IpAddr::V4(Ipv4Addr::LOCALHOST), args.port); + let server_socket = SocketAddr::new( + std::net::IpAddr::V4(Ipv4Addr::LOCALHOST), + args.neptune_rpc_port, + ); let transport = tarpc::serde_transport::tcp::connect(server_socket, RpcJson::default) .await .with_context(|| { diff --git a/src/model/config.rs b/src/model/config.rs index 3964d97..d0b9280 100644 --- a/src/model/config.rs +++ b/src/model/config.rs @@ -6,7 +6,11 @@ pub struct Config { #[clap(long, default_value = "Neptune Explorer", value_name = "site-name")] pub site_name: String, - /// Sets the server address to connect to. + /// Sets the port to listen for http requests. + #[clap(long, default_value = "3000", value_name = "PORT")] + pub listen_port: u16, + + /// Sets the neptune-core rpc server address to connect to. #[clap(long, default_value = "9799", value_name = "PORT")] - pub port: u16, + pub neptune_rpc_port: u16, }