From b66ee14ec5ee84989c8183d6b698e350ed3d02d6 Mon Sep 17 00:00:00 2001 From: yeastplume Date: Sun, 11 Aug 2024 18:08:27 +0100 Subject: [PATCH 1/2] add command to output public address from config file --- src/bin/mwixnet.rs | 12 ++++++++++++ src/bin/mwixnet.yml | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/bin/mwixnet.rs b/src/bin/mwixnet.rs index 1f70f53..40fb3d8 100644 --- a/src/bin/mwixnet.rs +++ b/src/bin/mwixnet.rs @@ -116,6 +116,18 @@ fn real_main() -> Result<(), Box> { let password = prompt_password(); let mut server_config = config::load_config(&config_path, &password)?; + // Write a new config file if init-config command is supplied + if let ("address", Some(_)) = args.subcommand() { + if !config_path.exists() { + panic!( + "No public address configured (Config file not found). {}", + config_path.to_string_lossy() + ); + } + println!("{}", server_config.onion_address()); + return Ok(()) + } + // Override grin_node_url, if supplied if let Some(grin_node_url) = grin_node_url { server_config.grin_node_url = grin_node_url.parse()?; diff --git a/src/bin/mwixnet.yml b/src/bin/mwixnet.yml index 10326af..fdc238e 100644 --- a/src/bin/mwixnet.yml +++ b/src/bin/mwixnet.yml @@ -48,4 +48,6 @@ args: takes_value: true subcommands: - init-config: - about: Writes a new configuration file \ No newline at end of file + about: Writes a new configuration file + - address: + about: Displays the public key of the server \ No newline at end of file From d75abc1c6721f34b533c9cbcec99a08b29c7937e Mon Sep 17 00:00:00 2001 From: yeastplume Date: Sun, 11 Aug 2024 18:16:08 +0100 Subject: [PATCH 2/2] add option to output address to file --- src/bin/mwixnet.rs | 12 +++++++++++- src/bin/mwixnet.yml | 9 ++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/bin/mwixnet.rs b/src/bin/mwixnet.rs index 40fb3d8..04099ac 100644 --- a/src/bin/mwixnet.rs +++ b/src/bin/mwixnet.rs @@ -124,7 +124,17 @@ fn real_main() -> Result<(), Box> { config_path.to_string_lossy() ); } - println!("{}", server_config.onion_address()); + let sub_args = args.subcommand_matches("address").unwrap(); + if sub_args.is_present("output_file") + { + //output onion address to file + let output_file = sub_args.value_of("output_file").unwrap(); + let onion_address = server_config.onion_address(); + std::fs::write(output_file, format!("{}", onion_address))?; + println!("Onion address written to file: {}", output_file); + } else { + println!("{}", server_config.onion_address()); + } return Ok(()) } diff --git a/src/bin/mwixnet.yml b/src/bin/mwixnet.yml index fdc238e..cd29bba 100644 --- a/src/bin/mwixnet.yml +++ b/src/bin/mwixnet.yml @@ -50,4 +50,11 @@ subcommands: - init-config: about: Writes a new configuration file - address: - about: Displays the public key of the server \ No newline at end of file + about: Outputs the public key of the server + args: + - output_file: + help: Path to output the public key to + long: output_file + short: o + takes_value: true + required: false \ No newline at end of file