From 8883f64bd6e34d062dd8b3cd71ca325c6f6e4650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Fri, 27 Oct 2023 12:43:38 +0100 Subject: [PATCH] added mixnode clap argument to set nyxd urls --- mixnode/src/commands/init.rs | 5 +++++ mixnode/src/commands/mod.rs | 17 ++++++++++++----- mixnode/src/commands/run.rs | 5 +++++ mixnode/src/config/mod.rs | 6 ++++++ 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/mixnode/src/commands/init.rs b/mixnode/src/commands/init.rs index ac2b8a5b45..da9a91d611 100644 --- a/mixnode/src/commands/init.rs +++ b/mixnode/src/commands/init.rs @@ -40,6 +40,10 @@ pub(crate) struct Init { #[arg(long, alias = "validators", value_delimiter = ',')] nym_apis: Option>, + /// Comma separated list of endpoints of the nyxd validators + #[arg(long, value_delimiter = ',')] + nyxd_urls: Option>, + /// Specifies whether this node should accepts and send out packets that would only go to nodes /// on the next mix layer #[arg(long)] @@ -59,6 +63,7 @@ impl From for OverrideConfig { http_api_port: init_config.http_api_port, enforce_forward_travel: Some(init_config.enforce_forward_travel), nym_apis: init_config.nym_apis, + nyxd_urls: init_config.nyxd_urls, } } } diff --git a/mixnode/src/commands/mod.rs b/mixnode/src/commands/mod.rs index 17bbeb7739..c917faf432 100644 --- a/mixnode/src/commands/mod.rs +++ b/mixnode/src/commands/mod.rs @@ -10,7 +10,7 @@ use colored::Colorize; use log::{error, info, warn}; use nym_bin_common::completions::{fig_generate, ArgShell}; use nym_bin_common::version_checker; -use nym_config::defaults::var_names::{BECH32_PREFIX, NYM_API}; +use nym_config::defaults::var_names; use nym_config::OptionalSet; use nym_crypto::bech32_address_validation; use std::net::IpAddr; @@ -60,6 +60,7 @@ struct OverrideConfig { http_api_port: Option, enforce_forward_travel: Option, nym_apis: Option>, + nyxd_urls: Option>, } pub(crate) async fn execute(args: Cli) -> anyhow::Result<()> { @@ -91,19 +92,25 @@ fn override_config(config: Config, args: OverrideConfig) -> Config { .with_optional_custom_env( Config::with_custom_nym_apis, args.nym_apis, - NYM_API, + var_names::NYM_API, + nym_config::parse_urls, + ) + .with_optional_custom_env( + Config::with_custom_nyxd, + args.nyxd_urls, + var_names::NYXD, nym_config::parse_urls, ) } /// Ensures that a given bech32 address is valid, or exits pub(crate) fn validate_bech32_address_or_exit(address: &str) { - let prefix = std::env::var(BECH32_PREFIX).expect("bech32 prefix not set"); + let prefix = std::env::var(var_names::BECH32_PREFIX).expect("bech32 prefix not set"); if let Err(bech32_address_validation::Bech32Error::DecodeFailed(err)) = bech32_address_validation::try_bech32_decode(address) { let error_message = format!("Error: wallet address decoding failed: {err}").red(); - error!("{}", error_message); + error!("{error_message}"); error!("Exiting..."); process::exit(1); } @@ -112,7 +119,7 @@ pub(crate) fn validate_bech32_address_or_exit(address: &str) { bech32_address_validation::validate_bech32_prefix(&prefix, address) { let error_message = format!("Error: wallet address type is wrong, {err}").red(); - error!("{}", error_message); + error!("{error_message}"); error!("Exiting..."); process::exit(1); } diff --git a/mixnode/src/commands/run.rs b/mixnode/src/commands/run.rs index e3d583e044..5d081886e2 100644 --- a/mixnode/src/commands/run.rs +++ b/mixnode/src/commands/run.rs @@ -42,6 +42,10 @@ pub(crate) struct Run { #[arg(long, alias = "validators", value_delimiter = ',')] nym_apis: Option>, + /// Comma separated list of endpoints of the nyxd validators + #[arg(long, value_delimiter = ',')] + nyxd_urls: Option>, + /// Specifies whether this node should accepts and send out packets that would only go to nodes /// on the next mix layer #[arg(long)] @@ -61,6 +65,7 @@ impl From for OverrideConfig { http_api_port: run_config.http_api_port, enforce_forward_travel: run_config.enforce_forward_travel, nym_apis: run_config.nym_apis, + nyxd_urls: run_config.nyxd_urls, } } } diff --git a/mixnode/src/config/mod.rs b/mixnode/src/config/mod.rs index ee892e9fb9..42ffff21fe 100644 --- a/mixnode/src/config/mod.rs +++ b/mixnode/src/config/mod.rs @@ -181,6 +181,12 @@ impl Config { self } + #[must_use] + pub fn with_custom_nyxd(mut self, nyxd_urls: Vec) -> Self { + self.mixnode.nyxd_urls = nyxd_urls; + self + } + #[must_use] pub fn with_listening_address(mut self, listening_address: IpAddr) -> Self { self.mixnode.listening_address = listening_address;