Repository: paritytech/parity-bitcoin (language: rust)

Issue:
Listening address is hardcoded to 127.0.0.1
https://github.com/paritytech/parity-bitcoin/blob/6db8c5e235c10988f7f52185c57db8629859360c/pbtc/commands/start.rs#L99

Any reason why pbtc is binding to 127.0.0.1 instead of 0.0.0.0? I'd like to allow incoming connections from the Internet.

Moreover, this doesn't respect `--only-net ipv6`.


Discussion / hints:
hah, true! feel free to open a pr and fix it! 👍 
Ok I'm a Rust noob but I'll give it a try :)
@debris @infertux 
What if we add a CLI option, like `--host`, with fallback to `0.0.0.0`. That would give a freedom to provide a custom IP address.

But here is the question:
. . . from `--help` :
```
--only-net <NET> Only connect to nodes in network version <NET> (ipv4 or ipv6).
```
So, if `--only-net` is `ipv6` - should `local_address` be as well? In this case, we need to validate `local_address` and have two fallbacks for `ipv4` and `ipv6`? 
@i1skn sounds like a plan :)

Fix patch:
diff --git a/pbtc/cli.yml b/pbtc/cli.yml
index c3bd031c2..82e6f35e4 100644
--- a/pbtc/cli.yml
+++ b/pbtc/cli.yml
@@ -21,6 +21,12 @@ args:
         value_name: IP
         help: Connect only to the specified node.
         takes_value: true
+    - host:
+        short: h
+        long: host
+        value_name: HOST
+        help: Listen for connections on HOST.
+        takes_value: true
     - seednode:
         short: s
         long: seednode
diff --git a/pbtc/commands/start.rs b/pbtc/commands/start.rs
index 25bfd1f7a..d0a065344 100644
--- a/pbtc/commands/start.rs
+++ b/pbtc/commands/start.rs
@@ -96,7 +96,7 @@ pub fn start(cfg: config::Config) -> Result<(), String> {
 			protocol_version: PROTOCOL_VERSION,
 			protocol_minimum: PROTOCOL_MINIMUM,
 			magic: cfg.consensus.magic(),
-			local_address: SocketAddr::new("127.0.0.1".parse().unwrap(), cfg.port),
+			local_address: SocketAddr::new(cfg.host, cfg.port),
 			services: cfg.services,
 			user_agent: cfg.user_agent,
 			start_height: 0,
diff --git a/pbtc/config.rs b/pbtc/config.rs
index 5c17ff604..99462dcbe 100644
--- a/pbtc/config.rs
+++ b/pbtc/config.rs
@@ -19,6 +19,7 @@ pub struct Config {
 	pub services: Services,
 	pub port: u16,
 	pub connect: Option<net::SocketAddr>,
+	pub host: net::IpAddr,
 	pub seednodes: Vec<String>,
 	pub quiet: bool,
 	pub inbound_connections: u32,
@@ -111,6 +112,14 @@ pub fn parse(matches: &clap::ArgMatches) -> Result<Config, String> {
 		None => InternetProtocol::default(),
 	};
 
+	let host =  match matches.value_of("host") {
+		Some(s) => s.parse::<net::IpAddr>().map_err(|_| "Invalid host".to_owned())?,
+		None => match only_net {
+			InternetProtocol::IpV6 => "::".parse().unwrap(),
+			_ => "0.0.0.0".parse().unwrap(),
+		}
+	};
+
 	let rpc_config = parse_rpc_config(network, matches)?;
 
 	let block_notify_command = match matches.value_of("blocknotify") {
@@ -147,6 +156,7 @@ pub fn parse(matches: &clap::ArgMatches) -> Result<Config, String> {
 		services: services,
 		port: port,
 		connect: connect,
+		host: host,
 		seednodes: seednodes,
 		inbound_connections: in_connections,
 		outbound_connections: out_connections,


Test patch: