Skip to content

Commit

Permalink
Update web3-http-port to web3-http-address
Browse files Browse the repository at this point in the history
  • Loading branch information
njgheorghita committed Nov 1, 2021
1 parent adbba25 commit 5e5ec21
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ OPTIONS:
--pool-size <pool_size> max size of threadpool [default: 2]
--unsafe-private-key <private_key> Hex encoded 32 byte private key (considered unsafe to pass in pk as cli
arg, as it's stored in terminal history - keyfile support coming soon)
--web3-http-port <web3_http_port> port to accept json-rpc http connections [default: 8545]
--web3-http-address <web3-http-address> address to accept json-rpc http connections [default: 127.0.0.1:8545]
--web3-ipc-path <web3_ipc_path> path to json-rpc endpoint over IPC [default: /tmp/trin-jsonrpc.ipc]
--web3-transport <web3_transport> select transport protocol to serve json-rpc endpoint [default: ipc]
[possible values: http, ipc]
Expand Down
48 changes: 24 additions & 24 deletions trin-core/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::net::SocketAddr;
use structopt::StructOpt;

pub const DEFAULT_WEB3_IPC_PATH: &str = "/tmp/trin-jsonrpc.ipc";
pub const DEFAULT_WEB3_HTTP_PORT: &str = "8545";
pub const DEFAULT_WEB3_HTTP_ADDRESS: &str = "127.0.0.1:8545";
const DEFAULT_DISCOVERY_PORT: &str = "9000";
pub const HISTORY_NETWORK: &str = "history";
pub const STATE_NETWORK: &str = "state";
Expand All @@ -29,11 +29,11 @@ pub struct TrinConfig {
pub web3_transport: String,

#[structopt(
default_value(DEFAULT_WEB3_HTTP_PORT),
long = "web3-http-port",
help = "port to accept json-rpc http connections"
default_value(DEFAULT_WEB3_HTTP_ADDRESS),
long = "web3-http-address",
help = "address to accept json-rpc http connections"
)]
pub web3_http_port: u16,
pub web3_http_address: String,

#[structopt(
default_value(DEFAULT_WEB3_IPC_PATH),
Expand Down Expand Up @@ -113,9 +113,9 @@ impl TrinConfig {
DEFAULT_WEB3_IPC_PATH => {}
_ => panic!("Must not supply an ipc path when using http protocol for json-rpc"),
},
"ipc" => match &config.web3_http_port.to_string()[..] {
DEFAULT_WEB3_HTTP_PORT => {}
_ => panic!("Must not supply an http port when using ipc protocol for json-rpc"),
"ipc" => match &config.web3_http_address.to_string()[..] {
DEFAULT_WEB3_HTTP_ADDRESS => {}
_ => panic!("Must not supply an http address when using ipc protocol for json-rpc"),
},
val => panic!("Unsupported json-rpc protocol: {}", val),
}
Expand All @@ -127,7 +127,7 @@ impl TrinConfig {
info!("Launching with config:");
match self.web3_transport.as_str() {
"http" => {
info!("- JSON-RPC HTTP port: {}", self.web3_http_port)
info!("- JSON-RPC HTTP address: {}", self.web3_http_address)
}
"ipc" => {
info!("- JSON-RPC IPC path: {}", self.web3_ipc_path)
Expand Down Expand Up @@ -170,7 +170,7 @@ mod test {
fn test_default_args() {
assert!(env_is_set());
let expected_config = TrinConfig {
web3_http_port: DEFAULT_WEB3_HTTP_PORT.parse::<u16>().unwrap(),
web3_http_address: DEFAULT_WEB3_HTTP_ADDRESS.to_string(),
web3_ipc_path: DEFAULT_WEB3_IPC_PATH.to_string(),
pool_size: 2,
web3_transport: "ipc".to_string(),
Expand All @@ -186,7 +186,7 @@ mod test {
};
let actual_config = TrinConfig::new_from(["trin"].iter()).unwrap();
assert_eq!(actual_config.web3_transport, expected_config.web3_transport);
assert_eq!(actual_config.web3_http_port, expected_config.web3_http_port);
assert_eq!(actual_config.web3_http_address, expected_config.web3_http_address);
assert_eq!(actual_config.pool_size, expected_config.pool_size);
assert_eq!(actual_config.external_addr, expected_config.external_addr);
}
Expand All @@ -197,7 +197,7 @@ mod test {
let expected_config = TrinConfig {
external_addr: None,
private_key: None,
web3_http_port: 8080,
web3_http_address: "0.0.0.0:8080".to_string(),
web3_ipc_path: DEFAULT_WEB3_IPC_PATH.to_string(),
pool_size: 3,
web3_transport: "http".to_string(),
Expand All @@ -214,16 +214,16 @@ mod test {
"trin",
"--web3-transport",
"http",
"--web3-http-port",
"8080",
"--web3-http-address",
"0.0.0.0:8080",
"--pool-size",
"3",
]
.iter(),
)
.unwrap();
assert_eq!(actual_config.web3_transport, expected_config.web3_transport);
assert_eq!(actual_config.web3_http_port, expected_config.web3_http_port);
assert_eq!(actual_config.web3_http_address, expected_config.web3_http_address);
assert_eq!(actual_config.pool_size, expected_config.pool_size);
}

Expand All @@ -235,7 +235,7 @@ mod test {
let expected_config = TrinConfig {
external_addr: None,
private_key: None,
web3_http_port: DEFAULT_WEB3_HTTP_PORT.parse::<u16>().unwrap(),
web3_http_address: DEFAULT_WEB3_HTTP_ADDRESS.to_string(),
web3_ipc_path: DEFAULT_WEB3_IPC_PATH.to_string(),
pool_size: 2,
web3_transport: "ipc".to_string(),
Expand All @@ -248,7 +248,7 @@ mod test {
.collect(),
};
assert_eq!(actual_config.web3_transport, expected_config.web3_transport);
assert_eq!(actual_config.web3_http_port, expected_config.web3_http_port);
assert_eq!(actual_config.web3_http_address, expected_config.web3_http_address);
assert_eq!(actual_config.pool_size, expected_config.pool_size);
}

Expand All @@ -269,7 +269,7 @@ mod test {
let expected_config = TrinConfig {
private_key: None,
external_addr: None,
web3_http_port: DEFAULT_WEB3_HTTP_PORT.parse::<u16>().unwrap(),
web3_http_address: DEFAULT_WEB3_HTTP_ADDRESS.to_string(),
web3_ipc_path: "/path/test.ipc".to_string(),
pool_size: 2,
web3_transport: "ipc".to_string(),
Expand All @@ -282,7 +282,7 @@ mod test {
.collect(),
};
assert_eq!(actual_config.web3_transport, expected_config.web3_transport);
assert_eq!(actual_config.web3_http_port, expected_config.web3_http_port);
assert_eq!(actual_config.web3_http_address, expected_config.web3_http_address);
assert_eq!(actual_config.pool_size, expected_config.pool_size);
assert_eq!(actual_config.web3_ipc_path, expected_config.web3_ipc_path);
}
Expand All @@ -306,14 +306,14 @@ mod test {

#[test]
#[should_panic(expected = "Must not supply an http port when using ipc")]
fn test_ipc_protocol_rejects_custom_web3_http_port() {
fn test_ipc_protocol_rejects_custom_web3_http_address() {
assert!(env_is_set());
TrinConfig::new_from(
[
"trin",
"--web3-transport",
"ipc",
"--web3-http-port",
"--web3-http-address",
"7879",
]
.iter(),
Expand All @@ -327,7 +327,7 @@ mod test {
let expected_config = TrinConfig {
external_addr: None,
private_key: None,
web3_http_port: DEFAULT_WEB3_HTTP_PORT.parse::<u16>().unwrap(),
web3_http_address: DEFAULT_WEB3_HTTP_ADDRESS.to_string(),
web3_ipc_path: DEFAULT_WEB3_IPC_PATH.to_string(),
pool_size: 2,
web3_transport: "ipc".to_string(),
Expand All @@ -350,7 +350,7 @@ mod test {
let expected_config = TrinConfig {
external_addr: None,
private_key: None,
web3_http_port: DEFAULT_WEB3_HTTP_PORT.parse::<u16>().unwrap(),
web3_http_address: DEFAULT_WEB3_HTTP_ADDRESS.to_string(),
web3_ipc_path: DEFAULT_WEB3_IPC_PATH.to_string(),
pool_size: 2,
web3_transport: "ipc".to_string(),
Expand Down Expand Up @@ -395,7 +395,7 @@ mod test {
let expected_config = TrinConfig {
external_addr: None,
private_key: Some(HexData(vec![1; 32])),
web3_http_port: DEFAULT_WEB3_HTTP_PORT.parse::<u16>().unwrap(),
web3_http_address: DEFAULT_WEB3_HTTP_ADDRESS.to_string(),
web3_ipc_path: DEFAULT_WEB3_IPC_PATH.to_string(),
pool_size: 2,
web3_transport: "ipc".to_string(),
Expand Down
3 changes: 1 addition & 2 deletions trin-core/src/jsonrpc/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ fn launch_http_client(
})
.expect("Error setting Ctrl-C handler.");

let uri = format!("0.0.0.0:{}", trin_config.web3_http_port);
let listener = TcpListener::bind(uri).unwrap();
let listener = TcpListener::bind(trin_config.web3_http_address).unwrap();
for stream in listener.incoming() {
match stream {
Ok(stream) => {
Expand Down

0 comments on commit 5e5ec21

Please # to comment.