diff --git a/gateway/src/commands/upgrade.rs b/gateway/src/commands/upgrade.rs index bd1ab0e72b..39d8f744a6 100644 --- a/gateway/src/commands/upgrade.rs +++ b/gateway/src/commands/upgrade.rs @@ -41,7 +41,7 @@ fn print_successful_upgrade(from: D1, to: D2) { ); } -fn pre_090_upgrade(from: &str, config: Config) -> Config { +fn pre_090_upgrade(from: &str, config: Config, matches: &ArgMatches) -> Config { // this is not extracted to separate function as you only have to manually pass version // if upgrading from pre090 version let from = match from.strip_prefix("v") { @@ -93,10 +93,15 @@ fn pre_090_upgrade(from: &str, config: Config) -> Config { DEFAULT_VALIDATOR_REST_ENDPOINT ); - let upgraded_config = config + let mut upgraded_config = config .with_custom_version(to_version.to_string().as_ref()) .with_custom_validator(DEFAULT_VALIDATOR_REST_ENDPOINT); + if let Some(incentives_address) = matches.value_of("incentives address") { + upgraded_config = upgraded_config.with_incentives_address(incentives_address); + println!("Setting incentives address to {}", incentives_address); + } + upgraded_config.save_to_file(None).unwrap_or_else(|err| { eprintln!("failed to overwrite config file! - {:?}", err); print_failed_upgrade(&from_version, &to_version); @@ -123,6 +128,11 @@ pub fn command_args<'a, 'b>() -> App<'a, 'b> { .help("REQUIRED FOR PRE-0.9.0 UPGRADES. Self provided version of the nym-gateway if none is available in the config. NOTE: if provided incorrectly, results may be catastrophic.") .takes_value(true) ) + .arg(Arg::with_name("incentives address") + .long("incentives-address") + .help("Optional, if participating in the incentives program, payment address") + .takes_value(true) + ) } pub fn execute(matches: &ArgMatches) { @@ -156,7 +166,7 @@ pub fn execute(matches: &ArgMatches) { }); // upgrades up to 0.9.0 - existing_config = pre_090_upgrade(self_reported_version, existing_config); + existing_config = pre_090_upgrade(self_reported_version, existing_config, &matches); } let config_version = Version::parse(existing_config.get_version()).unwrap_or_else(|err| { diff --git a/gateway/src/config/mod.rs b/gateway/src/config/mod.rs index 900ca0c34c..fc6c693951 100644 --- a/gateway/src/config/mod.rs +++ b/gateway/src/config/mod.rs @@ -523,7 +523,7 @@ pub struct Gateway { nym_root_directory: PathBuf, /// Optional, if participating in the incentives program, payment address. - #[serde(deserialize_with = "deserialize_option_string")] + #[serde(deserialize_with = "deserialize_option_string", default)] incentives_address: Option, } diff --git a/mixnode/src/commands/upgrade.rs b/mixnode/src/commands/upgrade.rs index 5666b3c0ee..3eec134a20 100644 --- a/mixnode/src/commands/upgrade.rs +++ b/mixnode/src/commands/upgrade.rs @@ -44,7 +44,7 @@ fn print_successful_upgrade(from: D1, to: D2) { ); } -fn pre_090_upgrade(from: &str, config: Config) -> Config { +fn pre_090_upgrade(from: &str, config: Config, matches: &ArgMatches) -> Config { // note: current is guaranteed to not have any `build` information suffix (nor pre-release // information), as this was asserted at the beginning of this command) // @@ -112,6 +112,11 @@ fn pre_090_upgrade(from: &str, config: Config) -> Config { .with_custom_metrics_server(DEFAULT_METRICS_SERVER) .with_custom_validator(DEFAULT_VALIDATOR_REST_ENDPOINT); + if let Some(incentives_address) = matches.value_of("incentives address") { + upgraded_config = upgraded_config.with_incentives_address(incentives_address); + println!("Setting incentives address to {}", incentives_address); + } + println!("Setting metrics server to {}", DEFAULT_METRICS_SERVER); println!( "Setting validator REST endpoint to to {}", @@ -147,18 +152,23 @@ fn pre_090_upgrade(from: &str, config: Config) -> Config { pub fn command_args<'a, 'b>() -> App<'a, 'b> { App::new("upgrade").about("Try to upgrade the mixnode") .arg( - Arg::with_name("id") - .long("id") - .help("Id of the nym-mixnode we want to upgrade") - .takes_value(true) - .required(true), + Arg::with_name("id") + .long("id") + .help("Id of the nym-mixnode we want to upgrade") + .takes_value(true) + .required(true), ) - // the rest of arguments depend on the upgrade path + // the rest of arguments depend on the upgrade path .arg(Arg::with_name("current version") .long("current-version") .help("REQUIRED FOR PRE-0.9.0 UPGRADES. Self provided version of the nym-mixnode if none is available in the config. NOTE: if provided incorrectly, results may be catastrophic.") .takes_value(true) ) + .arg(Arg::with_name("incentives address") + .long("incentives-address") + .help("Optional, if participating in the incentives program, payment address") + .takes_value(true) + ) } pub fn execute(matches: &ArgMatches) { @@ -192,7 +202,7 @@ pub fn execute(matches: &ArgMatches) { }); // upgrades up to 0.9.0 - existing_config = pre_090_upgrade(self_reported_version, existing_config); + existing_config = pre_090_upgrade(self_reported_version, existing_config, &matches); } let config_version = Version::parse(existing_config.get_version()).unwrap_or_else(|err| { diff --git a/mixnode/src/config/mod.rs b/mixnode/src/config/mod.rs index 06d78270a1..ea682a3afa 100644 --- a/mixnode/src/config/mod.rs +++ b/mixnode/src/config/mod.rs @@ -429,7 +429,7 @@ pub struct MixNode { nym_root_directory: PathBuf, /// Optional, if participating in the incentives program, payment address. - #[serde(deserialize_with = "deserialize_option_string")] + #[serde(deserialize_with = "deserialize_option_string", default)] incentives_address: Option, }