Merge branch 'develop' of github.com:nymtech/nym into develop
This commit is contained in:
Generated
+5
-5
@@ -345,7 +345,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "client-core"
|
||||
version = "0.9.2"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"config",
|
||||
"crypto",
|
||||
@@ -1420,7 +1420,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nym-client"
|
||||
version = "0.9.2"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"client-core",
|
||||
@@ -1471,7 +1471,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nym-gateway"
|
||||
version = "0.9.2"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"config",
|
||||
@@ -1501,7 +1501,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nym-mixnode"
|
||||
version = "0.9.2"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"bs58 0.4.0",
|
||||
"clap",
|
||||
@@ -1574,7 +1574,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nym-socks5-client"
|
||||
version = "0.9.2"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"client-core",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "client-core"
|
||||
version = "0.9.2"
|
||||
version = "0.10.0"
|
||||
authors = ["Dave Hrycyszyn <futurechimp@users.noreply.github.com>"]
|
||||
edition = "2018"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "nym-client"
|
||||
version = "0.9.2"
|
||||
version = "0.10.0"
|
||||
authors = ["Dave Hrycyszyn <futurechimp@users.noreply.github.com>", "Jędrzej Stuczyński <andrew@nymtech.net>"]
|
||||
edition = "2018"
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
use crate::client::config::{Config, MISSING_VALUE};
|
||||
use clap::{App, Arg, ArgMatches};
|
||||
use client_core::config::DEFAULT_VALIDATOR_REST_ENDPOINT;
|
||||
use client_core::config::{DEFAULT_MIXNET_CONTRACT_ADDRESS, DEFAULT_VALIDATOR_REST_ENDPOINT};
|
||||
use config::NymConfig;
|
||||
use std::fmt::Display;
|
||||
use std::process;
|
||||
@@ -41,6 +41,62 @@ fn print_successful_upgrade<D1: Display, D2: Display>(from: D1, to: D2) {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn command_args<'a, 'b>() -> App<'a, 'b> {
|
||||
App::new("upgrade").about("Try to upgrade the client")
|
||||
.arg(
|
||||
Arg::with_name("id")
|
||||
.long("id")
|
||||
.help("Id of the nym-client we want to upgrade")
|
||||
.takes_value(true)
|
||||
.required(true),
|
||||
)
|
||||
// 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. Specifies current version of the configuration file to help to determine a valid upgrade path. Valid formats include '0.8.1', 'v0.8.1' or 'V0.8.1'")
|
||||
.takes_value(true)
|
||||
)
|
||||
}
|
||||
|
||||
fn unsupported_upgrade(config_version: Version, package_version: Version) -> ! {
|
||||
eprintln!("Cannot perform upgrade from {} to {}. Please let the developers know about this issue if you expected it to work!", config_version, package_version);
|
||||
process::exit(1)
|
||||
}
|
||||
|
||||
fn parse_config_version(config: &Config) -> Version {
|
||||
let version = Version::parse(config.get_base().get_version()).unwrap_or_else(|err| {
|
||||
eprintln!("failed to parse client version! - {:?}", err);
|
||||
process::exit(1)
|
||||
});
|
||||
|
||||
if version.is_prerelease() || !version.build.is_empty() {
|
||||
eprintln!(
|
||||
"Trying to upgrade from a non-released version {}. This is not supported!",
|
||||
version
|
||||
);
|
||||
process::exit(1)
|
||||
}
|
||||
|
||||
version
|
||||
}
|
||||
|
||||
fn parse_package_version() -> Version {
|
||||
let version = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
|
||||
|
||||
// technically this is not a correct way of checking it as a released version might contain valid build identifiers
|
||||
// however, we are not using them ourselves at the moment and hence it should be fine.
|
||||
// if we change our mind, we could easily tweak this code
|
||||
if version.is_prerelease() || !version.build.is_empty() {
|
||||
eprintln!(
|
||||
"Trying to upgrade to a non-released version {}. This is not supported!",
|
||||
version
|
||||
);
|
||||
process::exit(1)
|
||||
}
|
||||
|
||||
version
|
||||
}
|
||||
|
||||
fn pre_090_upgrade(from: &str, mut config: Config) -> Config {
|
||||
// this is not extracted to separate function as you only have to manually pass version
|
||||
// if upgrading from pre090 version
|
||||
@@ -112,89 +168,86 @@ fn pre_090_upgrade(from: &str, mut config: Config) -> Config {
|
||||
config
|
||||
}
|
||||
|
||||
fn patch_09x_upgrade(mut config: Config, _matches: &ArgMatches) -> Config {
|
||||
// this call must succeed as it was already called before
|
||||
let from_version = Version::parse(config.get_base().get_version()).unwrap();
|
||||
let to_version = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
|
||||
/*
|
||||
changes:
|
||||
- introduction of mixnet contract address field
|
||||
- change to default validator rest endpoint
|
||||
*/
|
||||
fn minor_010_upgrade(
|
||||
mut config: Config,
|
||||
_matches: &ArgMatches,
|
||||
config_version: &Version,
|
||||
package_version: &Version,
|
||||
) -> Config {
|
||||
let to_version = if package_version.major == 0 && package_version.minor == 10 {
|
||||
package_version.clone()
|
||||
} else {
|
||||
Version::new(0, 10, 0)
|
||||
};
|
||||
|
||||
print_start_upgrade(&from_version, &to_version);
|
||||
print_start_upgrade(&config_version, &to_version);
|
||||
|
||||
// 0.9.1 upgrade:
|
||||
config
|
||||
.get_base_mut()
|
||||
.set_custom_version(to_version.to_string().as_ref());
|
||||
|
||||
if config.get_base().get_validator_mixnet_contract_address() != MISSING_VALUE {
|
||||
eprintln!("existing config seems to have specified mixnet contract address which was only introduced in 0.10.0! Can't perform upgrade.");
|
||||
print_failed_upgrade(&config_version, &to_version);
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
println!(
|
||||
"Setting mixnet contract address to {}",
|
||||
DEFAULT_MIXNET_CONTRACT_ADDRESS
|
||||
);
|
||||
|
||||
config
|
||||
.get_base_mut()
|
||||
.set_mixnet_contract(DEFAULT_MIXNET_CONTRACT_ADDRESS);
|
||||
|
||||
// The default validator endpoint changed
|
||||
println!(
|
||||
"Setting validator REST endpoint to to {}",
|
||||
DEFAULT_VALIDATOR_REST_ENDPOINT
|
||||
);
|
||||
|
||||
config
|
||||
.get_base_mut()
|
||||
.set_custom_validator(DEFAULT_VALIDATOR_REST_ENDPOINT);
|
||||
|
||||
config.save_to_file(None).unwrap_or_else(|err| {
|
||||
eprintln!("failed to overwrite config file! - {:?}", err);
|
||||
print_failed_upgrade(&from_version, &to_version);
|
||||
print_failed_upgrade(&config_version, &to_version);
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
print_successful_upgrade(from_version, to_version);
|
||||
print_successful_upgrade(config_version, to_version);
|
||||
|
||||
config
|
||||
}
|
||||
|
||||
pub fn command_args<'a, 'b>() -> App<'a, 'b> {
|
||||
App::new("upgrade").about("Try to upgrade the client")
|
||||
.arg(
|
||||
Arg::with_name("id")
|
||||
.long("id")
|
||||
.help("Id of the nym-client we want to upgrade")
|
||||
.takes_value(true)
|
||||
.required(true),
|
||||
)
|
||||
// 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. Specifies current version of the configuration file to help to determine a valid upgrade path. Valid formats include '0.8.1', 'v0.8.1' or 'V0.8.1'")
|
||||
.takes_value(true)
|
||||
)
|
||||
}
|
||||
|
||||
fn unsupported_upgrade(current_version: Version, config_version: Version) -> ! {
|
||||
eprintln!("Cannot perform upgrade from {} to {}. Please let the developers know about this issue if you expected it to work!", config_version, current_version);
|
||||
process::exit(1)
|
||||
}
|
||||
|
||||
fn do_upgrade(mut config: Config, matches: &ArgMatches) {
|
||||
let current = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
|
||||
|
||||
fn do_upgrade(mut config: Config, matches: &ArgMatches, package_version: Version) {
|
||||
loop {
|
||||
let config_version =
|
||||
Version::parse(config.get_base().get_version()).unwrap_or_else(|err| {
|
||||
eprintln!("failed to parse client version! - {:?}", err);
|
||||
process::exit(1)
|
||||
});
|
||||
let config_version = parse_config_version(&config);
|
||||
|
||||
if config_version == current {
|
||||
if config_version == package_version {
|
||||
println!("You're using the most recent version!");
|
||||
return;
|
||||
}
|
||||
|
||||
config = match config_version.major {
|
||||
0 => match config_version.minor {
|
||||
9 => patch_09x_upgrade(config, &matches),
|
||||
_ => unsupported_upgrade(current, config_version),
|
||||
9 => minor_010_upgrade(config, &matches, &config_version, &package_version),
|
||||
_ => unsupported_upgrade(config_version, package_version),
|
||||
},
|
||||
_ => unsupported_upgrade(current, config_version),
|
||||
_ => unsupported_upgrade(config_version, package_version),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn execute(matches: &ArgMatches) {
|
||||
let current = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
|
||||
|
||||
// technically this is not a correct way of checking it as a released version might contain valid build identifiers
|
||||
// however, we are not using them ourselves at the moment and hence it should be fine.
|
||||
// if we change our mind, we could easily tweak this code
|
||||
if current.is_prerelease() || !current.build.is_empty() {
|
||||
eprintln!(
|
||||
"Trying to upgrade to a non-released version {}. This is not supported!",
|
||||
current
|
||||
);
|
||||
process::exit(1)
|
||||
}
|
||||
let package_version = parse_package_version();
|
||||
|
||||
let id = matches.value_of("id").unwrap();
|
||||
|
||||
@@ -216,24 +269,6 @@ pub fn execute(matches: &ArgMatches) {
|
||||
existing_config = pre_090_upgrade(self_reported_version, existing_config);
|
||||
}
|
||||
|
||||
let config_version =
|
||||
Version::parse(existing_config.get_base().get_version()).unwrap_or_else(|err| {
|
||||
eprintln!("failed to parse client version! - {:?}", err);
|
||||
process::exit(1)
|
||||
});
|
||||
|
||||
if config_version.is_prerelease() || !config_version.build.is_empty() {
|
||||
eprintln!(
|
||||
"Trying to upgrade from non-released version {}. This is not supported!",
|
||||
config_version
|
||||
);
|
||||
process::exit(1)
|
||||
}
|
||||
|
||||
// here be upgrade path to 0.9.X and beyond based on version number from config
|
||||
if config_version == current {
|
||||
println!("You're using the most recent version!");
|
||||
} else {
|
||||
do_upgrade(existing_config, matches)
|
||||
}
|
||||
do_upgrade(existing_config, matches, package_version)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "nym-socks5-client"
|
||||
version = "0.9.2"
|
||||
version = "0.10.0"
|
||||
authors = ["Dave Hrycyszyn <futurechimp@users.noreply.github.com>"]
|
||||
edition = "2018"
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
use crate::client::config::{Config, MISSING_VALUE};
|
||||
use clap::{App, Arg, ArgMatches};
|
||||
use client_core::config::DEFAULT_VALIDATOR_REST_ENDPOINT;
|
||||
use client_core::config::{DEFAULT_MIXNET_CONTRACT_ADDRESS, DEFAULT_VALIDATOR_REST_ENDPOINT};
|
||||
use config::NymConfig;
|
||||
use std::fmt::Display;
|
||||
use std::process;
|
||||
@@ -41,6 +41,62 @@ fn print_successful_upgrade<D1: Display, D2: Display>(from: D1, to: D2) {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn command_args<'a, 'b>() -> App<'a, 'b> {
|
||||
App::new("upgrade").about("Try to upgrade the client")
|
||||
.arg(
|
||||
Arg::with_name("id")
|
||||
.long("id")
|
||||
.help("Id of the nym-socks5-client we want to upgrade")
|
||||
.takes_value(true)
|
||||
.required(true),
|
||||
)
|
||||
// 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. Specifies current version of the configuration file to help to determine a valid upgrade path. Valid formats include '0.8.1', 'v0.8.1' or 'V0.8.1'")
|
||||
.takes_value(true)
|
||||
)
|
||||
}
|
||||
|
||||
fn unsupported_upgrade(config_version: Version, package_version: Version) -> ! {
|
||||
eprintln!("Cannot perform upgrade from {} to {}. Please let the developers know about this issue if you expected it to work!", config_version, package_version);
|
||||
process::exit(1)
|
||||
}
|
||||
|
||||
fn parse_config_version(config: &Config) -> Version {
|
||||
let version = Version::parse(config.get_base().get_version()).unwrap_or_else(|err| {
|
||||
eprintln!("failed to parse client version! - {:?}", err);
|
||||
process::exit(1)
|
||||
});
|
||||
|
||||
if version.is_prerelease() || !version.build.is_empty() {
|
||||
eprintln!(
|
||||
"Trying to upgrade from a non-released version {}. This is not supported!",
|
||||
version
|
||||
);
|
||||
process::exit(1)
|
||||
}
|
||||
|
||||
version
|
||||
}
|
||||
|
||||
fn parse_package_version() -> Version {
|
||||
let version = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
|
||||
|
||||
// technically this is not a correct way of checking it as a released version might contain valid build identifiers
|
||||
// however, we are not using them ourselves at the moment and hence it should be fine.
|
||||
// if we change our mind, we could easily tweak this code
|
||||
if version.is_prerelease() || !version.build.is_empty() {
|
||||
eprintln!(
|
||||
"Trying to upgrade to a non-released version {}. This is not supported!",
|
||||
version
|
||||
);
|
||||
process::exit(1)
|
||||
}
|
||||
|
||||
version
|
||||
}
|
||||
|
||||
fn pre_090_upgrade(from: &str, mut config: Config) -> Config {
|
||||
// this is not extracted to separate function as you only have to manually pass version
|
||||
// if upgrading from pre090 version
|
||||
@@ -112,89 +168,86 @@ fn pre_090_upgrade(from: &str, mut config: Config) -> Config {
|
||||
config
|
||||
}
|
||||
|
||||
fn patch_09x_upgrade(mut config: Config, _matches: &ArgMatches) -> Config {
|
||||
// this call must succeed as it was already called before
|
||||
let from_version = Version::parse(config.get_base().get_version()).unwrap();
|
||||
let to_version = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
|
||||
/*
|
||||
changes:
|
||||
- introduction of mixnet contract address field
|
||||
- change to default validator rest endpoint
|
||||
*/
|
||||
fn minor_010_upgrade(
|
||||
mut config: Config,
|
||||
_matches: &ArgMatches,
|
||||
config_version: &Version,
|
||||
package_version: &Version,
|
||||
) -> Config {
|
||||
let to_version = if package_version.major == 0 && package_version.minor == 10 {
|
||||
package_version.clone()
|
||||
} else {
|
||||
Version::new(0, 10, 0)
|
||||
};
|
||||
|
||||
print_start_upgrade(&from_version, &to_version);
|
||||
print_start_upgrade(&config_version, &to_version);
|
||||
|
||||
// 0.9.1 upgrade:
|
||||
config
|
||||
.get_base_mut()
|
||||
.set_custom_version(to_version.to_string().as_ref());
|
||||
|
||||
if config.get_base().get_validator_mixnet_contract_address() != MISSING_VALUE {
|
||||
eprintln!("existing config seems to have specified mixnet contract address which was only introduced in 0.10.0! Can't perform upgrade.");
|
||||
print_failed_upgrade(&config_version, &to_version);
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
println!(
|
||||
"Setting mixnet contract address to {}",
|
||||
DEFAULT_MIXNET_CONTRACT_ADDRESS
|
||||
);
|
||||
|
||||
config
|
||||
.get_base_mut()
|
||||
.set_mixnet_contract(DEFAULT_MIXNET_CONTRACT_ADDRESS);
|
||||
|
||||
// The default validator endpoint changed
|
||||
println!(
|
||||
"Setting validator REST endpoint to to {}",
|
||||
DEFAULT_VALIDATOR_REST_ENDPOINT
|
||||
);
|
||||
|
||||
config
|
||||
.get_base_mut()
|
||||
.set_custom_validator(DEFAULT_VALIDATOR_REST_ENDPOINT);
|
||||
|
||||
config.save_to_file(None).unwrap_or_else(|err| {
|
||||
eprintln!("failed to overwrite config file! - {:?}", err);
|
||||
print_failed_upgrade(&from_version, &to_version);
|
||||
print_failed_upgrade(&config_version, &to_version);
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
print_successful_upgrade(from_version, to_version);
|
||||
print_successful_upgrade(config_version, to_version);
|
||||
|
||||
config
|
||||
}
|
||||
|
||||
pub fn command_args<'a, 'b>() -> App<'a, 'b> {
|
||||
App::new("upgrade").about("Try to upgrade the client")
|
||||
.arg(
|
||||
Arg::with_name("id")
|
||||
.long("id")
|
||||
.help("Id of the nym-socks5-client we want to upgrade")
|
||||
.takes_value(true)
|
||||
.required(true),
|
||||
)
|
||||
// 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. Specifies current version of the configuration file to help to determine a valid upgrade path. Valid formats include '0.8.1', 'v0.8.1' or 'V0.8.1'")
|
||||
.takes_value(true)
|
||||
)
|
||||
}
|
||||
|
||||
fn unsupported_upgrade(current_version: Version, config_version: Version) -> ! {
|
||||
eprintln!("Cannot perform upgrade from {} to {}. Please let the developers know about this issue if you expected it to work!", config_version, current_version);
|
||||
process::exit(1)
|
||||
}
|
||||
|
||||
fn do_upgrade(mut config: Config, matches: &ArgMatches) {
|
||||
let current = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
|
||||
|
||||
fn do_upgrade(mut config: Config, matches: &ArgMatches, package_version: Version) {
|
||||
loop {
|
||||
let config_version =
|
||||
Version::parse(config.get_base().get_version()).unwrap_or_else(|err| {
|
||||
eprintln!("failed to parse client version! - {:?}", err);
|
||||
process::exit(1)
|
||||
});
|
||||
let config_version = parse_config_version(&config);
|
||||
|
||||
if config_version == current {
|
||||
if config_version == package_version {
|
||||
println!("You're using the most recent version!");
|
||||
return;
|
||||
}
|
||||
|
||||
config = match config_version.major {
|
||||
0 => match config_version.minor {
|
||||
9 => patch_09x_upgrade(config, &matches),
|
||||
_ => unsupported_upgrade(current, config_version),
|
||||
9 => minor_010_upgrade(config, &matches, &config_version, &package_version),
|
||||
_ => unsupported_upgrade(config_version, package_version),
|
||||
},
|
||||
_ => unsupported_upgrade(current, config_version),
|
||||
_ => unsupported_upgrade(config_version, package_version),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn execute(matches: &ArgMatches) {
|
||||
let current = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
|
||||
|
||||
// technically this is not a correct way of checking it as a released version might contain valid build identifiers
|
||||
// however, we are not using them ourselves at the moment and hence it should be fine.
|
||||
// if we change our mind, we could easily tweak this code
|
||||
if current.is_prerelease() || !current.build.is_empty() {
|
||||
eprintln!(
|
||||
"Trying to upgrade to a non-released version {}. This is not supported!",
|
||||
current
|
||||
);
|
||||
process::exit(1)
|
||||
}
|
||||
let package_version = parse_package_version();
|
||||
|
||||
let id = matches.value_of("id").unwrap();
|
||||
|
||||
@@ -216,24 +269,6 @@ pub fn execute(matches: &ArgMatches) {
|
||||
existing_config = pre_090_upgrade(self_reported_version, existing_config);
|
||||
}
|
||||
|
||||
let config_version =
|
||||
Version::parse(existing_config.get_base().get_version()).unwrap_or_else(|err| {
|
||||
eprintln!("failed to parse client version! - {:?}", err);
|
||||
process::exit(1)
|
||||
});
|
||||
|
||||
if config_version.is_prerelease() || !config_version.build.is_empty() {
|
||||
eprintln!(
|
||||
"Trying to upgrade from non-released version {}. This is not supported!",
|
||||
config_version
|
||||
);
|
||||
process::exit(1)
|
||||
}
|
||||
|
||||
// here be upgrade path to 0.9.X and beyond based on version number from config
|
||||
if config_version == current {
|
||||
println!("You're using the most recent version!");
|
||||
} else {
|
||||
do_upgrade(existing_config, matches)
|
||||
}
|
||||
do_upgrade(existing_config, matches, package_version)
|
||||
}
|
||||
|
||||
@@ -36,4 +36,5 @@ If you're a Nym platform developer who's made changes to the client and wants to
|
||||
|
||||
1. Bump the version number (use SemVer)
|
||||
1. `npm run build`
|
||||
1. `npm login` (if you haven't already)
|
||||
1. `npm login` (if you haven't already)
|
||||
1. `npm publish`
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nymproject/nym-validator-client",
|
||||
"version": "0.10.0-rc2",
|
||||
"version": "0.10.0-rc4",
|
||||
"description": "A TypeScript client for interacting with smart contracts in Nym validators",
|
||||
"repository": "https://github.com/nymtech/nym",
|
||||
"main": "./dist/index.js",
|
||||
|
||||
@@ -21,6 +21,15 @@ export function printableBalance(balance?: readonly Coin[]): string {
|
||||
return balance.map(printableCoin).join(", ");
|
||||
}
|
||||
|
||||
// converts display amount, such as "12.0346" to its native token representation,
|
||||
// with 6 fractional digits. So in that case it would result in "12034600"
|
||||
// Basically does the same job as `displayAmountToNative` but without the requirement
|
||||
// of having the coinMap
|
||||
export function printableBalanceToNative(amountToDisplay: string): string {
|
||||
const decimalAmount = Decimal.fromUserInput(amountToDisplay, 6);
|
||||
return decimalAmount.atomics;
|
||||
}
|
||||
|
||||
export interface MappedCoin {
|
||||
readonly denom: string;
|
||||
readonly fractionalDigits: number;
|
||||
|
||||
@@ -8,9 +8,9 @@ import { BroadcastTxResponse } from "@cosmjs/stargate"
|
||||
import { ExecuteResult, InstantiateOptions, InstantiateResult, UploadMeta, UploadResult } from "@cosmjs/cosmwasm";
|
||||
import { CoinMap, displayAmountToNative, MappedCoin, nativeCoinToDisplay, printableBalance, printableCoin } from "./currency";
|
||||
import GatewaysCache from "./caches/gateways";
|
||||
import QueryClient, {IQueryClient} from "./query-client";
|
||||
import QueryClient, { IQueryClient } from "./query-client";
|
||||
|
||||
export { coins };
|
||||
export { coins, coin };
|
||||
export { Coin };
|
||||
export { displayAmountToNative, nativeCoinToDisplay, printableCoin, printableBalance, MappedCoin, CoinMap }
|
||||
|
||||
@@ -43,6 +43,14 @@ export default class ValidatorClient {
|
||||
return new ValidatorClient(url, queryClient, contractAddress, stakeDenom)
|
||||
}
|
||||
|
||||
public get address(): string {
|
||||
if (this.client instanceof NetClient) {
|
||||
return this.client.clientAddress
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: re-enable this once we move back to client-side wallets running on people's machines
|
||||
* instead of the web wallet.
|
||||
@@ -115,7 +123,7 @@ export default class ValidatorClient {
|
||||
async bond(mixNode: MixNode): Promise<ExecuteResult> {
|
||||
if (this.client instanceof NetClient) {
|
||||
const bond = [{ amount: "1000000000", denom: this.stakeDenom }];
|
||||
const result = await this.client.executeContract(this.client.clientAddress, this.contractAddress, {register_mixnode: {mix_node: mixNode}}, "adding mixnode", bond);
|
||||
const result = await this.client.executeContract(this.client.clientAddress, this.contractAddress, { register_mixnode: { mix_node: mixNode } }, "adding mixnode", bond);
|
||||
console.log(`account ${this.client.clientAddress} added mixnode with ${mixNode.host}`);
|
||||
return result;
|
||||
} else {
|
||||
@@ -129,7 +137,7 @@ export default class ValidatorClient {
|
||||
*/
|
||||
async unbond(): Promise<ExecuteResult> {
|
||||
if (this.client instanceof NetClient) {
|
||||
const result = await this.client.executeContract(this.client.clientAddress, this.contractAddress, {un_register_mixnode: {}})
|
||||
const result = await this.client.executeContract(this.client.clientAddress, this.contractAddress, { un_register_mixnode: {} })
|
||||
console.log(`account ${this.client.clientAddress} unbonded mixnode`);
|
||||
return result;
|
||||
} else {
|
||||
@@ -196,7 +204,7 @@ export default class ValidatorClient {
|
||||
async bondGateway(gateway: Gateway): Promise<ExecuteResult> {
|
||||
if (this.client instanceof NetClient) {
|
||||
const bond = this.minimumGatewayBond()
|
||||
const result = await this.client.executeContract(this.client.clientAddress, this.contractAddress, {bond_gateway: {gateway: gateway}}, "adding gateway", [bond]);
|
||||
const result = await this.client.executeContract(this.client.clientAddress, this.contractAddress, { bond_gateway: { gateway: gateway } }, "adding gateway", [bond]);
|
||||
console.log(`account ${this.client.clientAddress} added gateway with ${gateway.mix_host}`);
|
||||
return result;
|
||||
} else {
|
||||
@@ -209,7 +217,7 @@ export default class ValidatorClient {
|
||||
*/
|
||||
async unbondGateway(): Promise<ExecuteResult> {
|
||||
if (this.client instanceof NetClient) {
|
||||
const result = await this.client.executeContract(this.client.clientAddress, this.contractAddress, {unbond_gateway: {}})
|
||||
const result = await this.client.executeContract(this.client.clientAddress, this.contractAddress, { unbond_gateway: {} })
|
||||
console.log(`account ${this.client.clientAddress} unbonded gateway`);
|
||||
return result;
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
|
||||
[package]
|
||||
name = "nym-gateway"
|
||||
version = "0.9.2"
|
||||
version = "0.10.0"
|
||||
authors = ["Dave Hrycyszyn <futurechimp@users.noreply.github.com>", "Jędrzej Stuczyński <andrew@nymtech.net>"]
|
||||
edition = "2018"
|
||||
|
||||
|
||||
@@ -94,6 +94,56 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> {
|
||||
)
|
||||
}
|
||||
|
||||
fn show_bonding_info(config: &Config) {
|
||||
fn load_sphinx_keys(pathfinder: &GatewayPathfinder) -> encryption::KeyPair {
|
||||
let sphinx_keypair: encryption::KeyPair =
|
||||
pemstore::load_keypair(&pemstore::KeyPairPath::new(
|
||||
pathfinder.private_encryption_key().to_owned(),
|
||||
pathfinder.public_encryption_key().to_owned(),
|
||||
))
|
||||
.expect("Failed to read stored sphinx key files");
|
||||
println!(
|
||||
"Public sphinx key: {}\n",
|
||||
sphinx_keypair.public_key().to_base58_string()
|
||||
);
|
||||
sphinx_keypair
|
||||
}
|
||||
|
||||
fn load_identity_keys(pathfinder: &GatewayPathfinder) -> identity::KeyPair {
|
||||
let identity_keypair: identity::KeyPair =
|
||||
pemstore::load_keypair(&pemstore::KeyPairPath::new(
|
||||
pathfinder.private_identity_key().to_owned(),
|
||||
pathfinder.public_identity_key().to_owned(),
|
||||
))
|
||||
.expect("Failed to read stored identity key files");
|
||||
println!(
|
||||
"Public identity key: {}\n",
|
||||
identity_keypair.public_key().to_base58_string()
|
||||
);
|
||||
identity_keypair
|
||||
}
|
||||
|
||||
let pathfinder = GatewayPathfinder::new_from_config(&config);
|
||||
let identity_keypair = load_identity_keys(&pathfinder);
|
||||
let sphinx_keypair = load_sphinx_keys(&pathfinder);
|
||||
|
||||
println!(
|
||||
"\nTo bond your gateway you will [most likely] need to provide the following:
|
||||
Identity key: {}
|
||||
Sphinx key: {}
|
||||
Mix Host: {}
|
||||
Clients Host: {}
|
||||
Location: [physical location of your node's server]
|
||||
Version: {}
|
||||
",
|
||||
identity_keypair.public_key().to_base58_string(),
|
||||
sphinx_keypair.public_key().to_base58_string(),
|
||||
config.get_mix_announce_address(),
|
||||
config.get_clients_announce_address(),
|
||||
config.get_version(),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn execute(matches: &ArgMatches) {
|
||||
let id = matches.value_of("id").unwrap();
|
||||
println!("Initialising gateway {}...", id);
|
||||
@@ -144,4 +194,5 @@ pub fn execute(matches: &ArgMatches) {
|
||||
println!("Saved configuration file to {:?}", config_save_location);
|
||||
|
||||
println!("Gateway configuration completed.\n\n\n");
|
||||
show_bonding_info(&config);
|
||||
}
|
||||
|
||||
+101
-75
@@ -1,8 +1,8 @@
|
||||
// Copyright 2020 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::config::DEFAULT_VALIDATOR_REST_ENDPOINT;
|
||||
use crate::config::{Config, MISSING_VALUE};
|
||||
use crate::config::{DEFAULT_MIXNET_CONTRACT_ADDRESS, DEFAULT_VALIDATOR_REST_ENDPOINT};
|
||||
use clap::{App, Arg, ArgMatches};
|
||||
use config::NymConfig;
|
||||
use std::fmt::Display;
|
||||
@@ -30,7 +30,63 @@ fn print_successful_upgrade<D1: Display, D2: Display>(from: D1, to: D2) {
|
||||
);
|
||||
}
|
||||
|
||||
fn pre_090_upgrade(from: &str, config: Config, _matches: &ArgMatches) -> Config {
|
||||
pub fn command_args<'a, 'b>() -> App<'a, 'b> {
|
||||
App::new("upgrade").about("Try to upgrade the gateway")
|
||||
.arg(
|
||||
Arg::with_name("id")
|
||||
.long("id")
|
||||
.help("Id of the nym-gateway we want to upgrade")
|
||||
.takes_value(true)
|
||||
.required(true),
|
||||
)
|
||||
// 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. Specifies current version of the configuration file to help to determine a valid upgrade path. Valid formats include '0.8.1', 'v0.8.1' or 'V0.8.1'")
|
||||
.takes_value(true)
|
||||
)
|
||||
}
|
||||
|
||||
fn unsupported_upgrade(current_version: Version, config_version: Version) -> ! {
|
||||
eprintln!("Cannot perform upgrade from {} to {}. Please let the developers know about this issue if you expected it to work!", config_version, current_version);
|
||||
process::exit(1)
|
||||
}
|
||||
|
||||
fn parse_config_version(config: &Config) -> Version {
|
||||
let version = Version::parse(config.get_version()).unwrap_or_else(|err| {
|
||||
eprintln!("failed to parse client version! - {:?}", err);
|
||||
process::exit(1)
|
||||
});
|
||||
|
||||
if version.is_prerelease() || !version.build.is_empty() {
|
||||
eprintln!(
|
||||
"Trying to upgrade from a non-released version {}. This is not supported!",
|
||||
version
|
||||
);
|
||||
process::exit(1)
|
||||
}
|
||||
|
||||
version
|
||||
}
|
||||
|
||||
fn parse_package_version() -> Version {
|
||||
let version = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
|
||||
|
||||
// technically this is not a correct way of checking it as a released version might contain valid build identifiers
|
||||
// however, we are not using them ourselves at the moment and hence it should be fine.
|
||||
// if we change our mind, we could easily tweak this code
|
||||
if version.is_prerelease() || !version.build.is_empty() {
|
||||
eprintln!(
|
||||
"Trying to upgrade to a non-released version {}. This is not supported!",
|
||||
version
|
||||
);
|
||||
process::exit(1)
|
||||
}
|
||||
|
||||
version
|
||||
}
|
||||
|
||||
fn pre_090_upgrade(from: &str, config: Config) -> 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") {
|
||||
@@ -97,86 +153,73 @@ fn pre_090_upgrade(from: &str, config: Config, _matches: &ArgMatches) -> Config
|
||||
upgraded_config
|
||||
}
|
||||
|
||||
fn patch_09x_upgrade(config: Config, _matches: &ArgMatches) -> Config {
|
||||
// this call must succeed as it was already called before
|
||||
let from_version = Version::parse(config.get_version()).unwrap();
|
||||
let to_version = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
|
||||
fn minor_010_upgrade(
|
||||
config: Config,
|
||||
_matches: &ArgMatches,
|
||||
config_version: &Version,
|
||||
package_version: &Version,
|
||||
) -> Config {
|
||||
let to_version = if package_version.major == 0 && package_version.minor == 10 {
|
||||
package_version.clone()
|
||||
} else {
|
||||
Version::new(0, 10, 0)
|
||||
};
|
||||
|
||||
print_start_upgrade(&from_version, &to_version);
|
||||
print_start_upgrade(&config_version, &to_version);
|
||||
|
||||
// 0.9.1 upgrade:
|
||||
let upgraded_config = config.with_custom_version(to_version.to_string().as_ref());
|
||||
if config.get_validator_mixnet_contract_address() != MISSING_VALUE {
|
||||
eprintln!("existing config seems to have specified mixnet contract address which was only introduced in 0.10.0! Can't perform upgrade.");
|
||||
print_failed_upgrade(&config_version, &to_version);
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
println!(
|
||||
"Setting validator REST endpoint to {}",
|
||||
DEFAULT_VALIDATOR_REST_ENDPOINT
|
||||
);
|
||||
|
||||
println!(
|
||||
"Setting mixnet contract address to {}",
|
||||
DEFAULT_MIXNET_CONTRACT_ADDRESS
|
||||
);
|
||||
|
||||
let upgraded_config = config
|
||||
.with_custom_version(to_version.to_string().as_ref())
|
||||
.with_custom_validator(DEFAULT_VALIDATOR_REST_ENDPOINT)
|
||||
.with_custom_mixnet_contract(DEFAULT_MIXNET_CONTRACT_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);
|
||||
print_failed_upgrade(&config_version, &to_version);
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
print_successful_upgrade(from_version, to_version);
|
||||
print_successful_upgrade(config_version, to_version);
|
||||
|
||||
upgraded_config
|
||||
}
|
||||
|
||||
pub fn command_args<'a, 'b>() -> App<'a, 'b> {
|
||||
App::new("upgrade").about("Try to upgrade the gateway")
|
||||
.arg(
|
||||
Arg::with_name("id")
|
||||
.long("id")
|
||||
.help("Id of the nym-gateway we want to upgrade")
|
||||
.takes_value(true)
|
||||
.required(true),
|
||||
)
|
||||
// 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. Specifies current version of the configuration file to help to determine a valid upgrade path. Valid formats include '0.8.1', 'v0.8.1' or 'V0.8.1'")
|
||||
.takes_value(true)
|
||||
)
|
||||
}
|
||||
|
||||
fn unsupported_upgrade(current_version: Version, config_version: Version) -> ! {
|
||||
eprintln!("Cannot perform upgrade from {} to {}. Please let the developers know about this issue if you expected it to work!", config_version, current_version);
|
||||
process::exit(1)
|
||||
}
|
||||
|
||||
fn do_upgrade(mut config: Config, matches: &ArgMatches) {
|
||||
let current = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
|
||||
|
||||
fn do_upgrade(mut config: Config, matches: &ArgMatches, package_version: Version) {
|
||||
loop {
|
||||
let config_version = Version::parse(config.get_version()).unwrap_or_else(|err| {
|
||||
eprintln!("failed to parse node version! - {:?}", err);
|
||||
process::exit(1)
|
||||
});
|
||||
let config_version = parse_config_version(&config);
|
||||
|
||||
if config_version == current {
|
||||
if config_version == package_version {
|
||||
println!("You're using the most recent version!");
|
||||
return;
|
||||
}
|
||||
|
||||
config = match config_version.major {
|
||||
0 => match config_version.minor {
|
||||
9 => patch_09x_upgrade(config, &matches),
|
||||
_ => unsupported_upgrade(current, config_version),
|
||||
9 => minor_010_upgrade(config, &matches, &config_version, &package_version),
|
||||
_ => unsupported_upgrade(config_version, package_version),
|
||||
},
|
||||
_ => unsupported_upgrade(current, config_version),
|
||||
_ => unsupported_upgrade(config_version, package_version),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn execute(matches: &ArgMatches) {
|
||||
let current = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
|
||||
|
||||
// technically this is not a correct way of checking it as a released version might contain valid build identifiers
|
||||
// however, we are not using them ourselves at the moment and hence it should be fine.
|
||||
// if we change our mind, we could easily tweak this code
|
||||
if current.is_prerelease() || !current.build.is_empty() {
|
||||
eprintln!(
|
||||
"Trying to upgrade to a non-released version {}. This is not supported!",
|
||||
current
|
||||
);
|
||||
process::exit(1)
|
||||
}
|
||||
let package_version = parse_package_version();
|
||||
|
||||
let id = matches.value_of("id").unwrap();
|
||||
|
||||
@@ -195,26 +238,9 @@ pub fn execute(matches: &ArgMatches) {
|
||||
});
|
||||
|
||||
// upgrades up to 0.9.0
|
||||
existing_config = pre_090_upgrade(self_reported_version, existing_config, &matches);
|
||||
}
|
||||
|
||||
let config_version = Version::parse(existing_config.get_version()).unwrap_or_else(|err| {
|
||||
eprintln!("failed to parse node version! - {:?}", err);
|
||||
process::exit(1)
|
||||
});
|
||||
|
||||
if config_version.is_prerelease() || !config_version.build.is_empty() {
|
||||
eprintln!(
|
||||
"Trying to upgrade from non-released version {}. This is not supported!",
|
||||
config_version
|
||||
);
|
||||
process::exit(1)
|
||||
existing_config = pre_090_upgrade(self_reported_version, existing_config);
|
||||
}
|
||||
|
||||
// here be upgrade path to 0.9.X and beyond based on version number from config
|
||||
if config_version == current {
|
||||
println!("You're using the most recent version!");
|
||||
} else {
|
||||
do_upgrade(existing_config, matches)
|
||||
}
|
||||
do_upgrade(existing_config, matches, package_version)
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
|
||||
[package]
|
||||
name = "nym-mixnode"
|
||||
version = "0.9.2"
|
||||
version = "0.10.0"
|
||||
authors = ["Dave Hrycyszyn <futurechimp@users.noreply.github.com>", "Jędrzej Stuczyński <andrew@nymtech.net>"]
|
||||
edition = "2018"
|
||||
|
||||
|
||||
@@ -128,6 +128,48 @@ async fn choose_layer(
|
||||
*layer_with_fewest
|
||||
}
|
||||
|
||||
fn show_bonding_info(config: &Config) {
|
||||
fn load_identity_keys(pathfinder: &MixNodePathfinder) -> identity::KeyPair {
|
||||
let identity_keypair: identity::KeyPair =
|
||||
pemstore::load_keypair(&pemstore::KeyPairPath::new(
|
||||
pathfinder.private_identity_key().to_owned(),
|
||||
pathfinder.public_identity_key().to_owned(),
|
||||
))
|
||||
.expect("Failed to read stored identity key files");
|
||||
identity_keypair
|
||||
}
|
||||
|
||||
fn load_sphinx_keys(pathfinder: &MixNodePathfinder) -> encryption::KeyPair {
|
||||
let sphinx_keypair: encryption::KeyPair =
|
||||
pemstore::load_keypair(&pemstore::KeyPairPath::new(
|
||||
pathfinder.private_encryption_key().to_owned(),
|
||||
pathfinder.public_encryption_key().to_owned(),
|
||||
))
|
||||
.expect("Failed to read stored sphinx key files");
|
||||
sphinx_keypair
|
||||
}
|
||||
|
||||
let pathfinder = MixNodePathfinder::new_from_config(&config);
|
||||
let identity_keypair = load_identity_keys(&pathfinder);
|
||||
let sphinx_keypair = load_sphinx_keys(&pathfinder);
|
||||
|
||||
println!(
|
||||
"\nTo bond your mixnode you will need to provide the following:
|
||||
Identity key: {}
|
||||
Sphinx key: {}
|
||||
Host: {}
|
||||
Layer: {}
|
||||
Location: [physical location of your node's server]
|
||||
Version: {}
|
||||
",
|
||||
identity_keypair.public_key().to_base58_string(),
|
||||
sphinx_keypair.public_key().to_base58_string(),
|
||||
config.get_announce_address(),
|
||||
config.get_layer(),
|
||||
config.get_version(),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn execute(matches: &ArgMatches) {
|
||||
// TODO: this should probably be made implicit by slapping `#[tokio::main]` on our main method
|
||||
// and then removing runtime from mixnode itself in `run`
|
||||
@@ -185,5 +227,7 @@ pub fn execute(matches: &ArgMatches) {
|
||||
.expect("Failed to save the config file");
|
||||
println!("Saved configuration file to {:?}", config_save_location);
|
||||
println!("Mixnode configuration completed.\n\n\n");
|
||||
|
||||
show_bonding_info(&config)
|
||||
})
|
||||
}
|
||||
|
||||
+102
-75
@@ -2,7 +2,8 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::config::{
|
||||
missing_string_value, Config, DEFAULT_METRICS_SERVER, DEFAULT_VALIDATOR_REST_ENDPOINT,
|
||||
missing_string_value, Config, DEFAULT_METRICS_SERVER, DEFAULT_MIXNET_CONTRACT_ADDRESS,
|
||||
DEFAULT_VALIDATOR_REST_ENDPOINT, MISSING_VALUE,
|
||||
};
|
||||
use clap::{App, Arg, ArgMatches};
|
||||
use config::NymConfig;
|
||||
@@ -33,7 +34,63 @@ fn print_successful_upgrade<D1: Display, D2: Display>(from: D1, to: D2) {
|
||||
);
|
||||
}
|
||||
|
||||
fn pre_090_upgrade(from: &str, config: Config, _matches: &ArgMatches) -> 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),
|
||||
)
|
||||
// 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. Specifies current version of the configuration file to help to determine a valid upgrade path. Valid formats include '0.8.1', 'v0.8.1' or 'V0.8.1'")
|
||||
.takes_value(true)
|
||||
)
|
||||
}
|
||||
|
||||
fn unsupported_upgrade(config_version: Version, package_version: Version) -> ! {
|
||||
eprintln!("Cannot perform upgrade from {} to {}. Please let the developers know about this issue if you expected it to work!", config_version, package_version);
|
||||
process::exit(1)
|
||||
}
|
||||
|
||||
fn parse_config_version(config: &Config) -> Version {
|
||||
let version = Version::parse(config.get_version()).unwrap_or_else(|err| {
|
||||
eprintln!("failed to parse client version! - {:?}", err);
|
||||
process::exit(1)
|
||||
});
|
||||
|
||||
if version.is_prerelease() || !version.build.is_empty() {
|
||||
eprintln!(
|
||||
"Trying to upgrade from a non-released version {}. This is not supported!",
|
||||
version
|
||||
);
|
||||
process::exit(1)
|
||||
}
|
||||
|
||||
version
|
||||
}
|
||||
|
||||
fn parse_package_version() -> Version {
|
||||
let version = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
|
||||
|
||||
// technically this is not a correct way of checking it as a released version might contain valid build identifiers
|
||||
// however, we are not using them ourselves at the moment and hence it should be fine.
|
||||
// if we change our mind, we could easily tweak this code
|
||||
if version.is_prerelease() || !version.build.is_empty() {
|
||||
eprintln!(
|
||||
"Trying to upgrade to a non-released version {}. This is not supported!",
|
||||
version
|
||||
);
|
||||
process::exit(1)
|
||||
}
|
||||
|
||||
version
|
||||
}
|
||||
|
||||
fn pre_090_upgrade(from: &str, config: Config) -> 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)
|
||||
//
|
||||
@@ -135,86 +192,73 @@ fn pre_090_upgrade(from: &str, config: Config, _matches: &ArgMatches) -> Config
|
||||
upgraded_config
|
||||
}
|
||||
|
||||
fn patch_09x_upgrade(config: Config, _matches: &ArgMatches) -> Config {
|
||||
// this call must succeed as it was already called before
|
||||
let from_version = Version::parse(config.get_version()).unwrap();
|
||||
let to_version = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
|
||||
fn minor_010_upgrade(
|
||||
config: Config,
|
||||
_matches: &ArgMatches,
|
||||
config_version: &Version,
|
||||
package_version: &Version,
|
||||
) -> Config {
|
||||
let to_version = if package_version.major == 0 && package_version.minor == 10 {
|
||||
package_version.clone()
|
||||
} else {
|
||||
Version::new(0, 10, 0)
|
||||
};
|
||||
|
||||
print_start_upgrade(&from_version, &to_version);
|
||||
print_start_upgrade(&config_version, &to_version);
|
||||
|
||||
// 0.9.1 upgrade:
|
||||
let upgraded_config = config.with_custom_version(to_version.to_string().as_ref());
|
||||
if config.get_validator_mixnet_contract_address() != MISSING_VALUE {
|
||||
eprintln!("existing config seems to have specified mixnet contract address which was only introduced in 0.10.0! Can't perform upgrade.");
|
||||
print_failed_upgrade(&config_version, &to_version);
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
println!(
|
||||
"Setting validator REST endpoint to {}",
|
||||
DEFAULT_VALIDATOR_REST_ENDPOINT
|
||||
);
|
||||
|
||||
println!(
|
||||
"Setting mixnet contract address to {}",
|
||||
DEFAULT_MIXNET_CONTRACT_ADDRESS
|
||||
);
|
||||
|
||||
let upgraded_config = config
|
||||
.with_custom_version(to_version.to_string().as_ref())
|
||||
.with_custom_validator(DEFAULT_VALIDATOR_REST_ENDPOINT)
|
||||
.with_custom_mixnet_contract(DEFAULT_MIXNET_CONTRACT_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);
|
||||
print_failed_upgrade(&config_version, &to_version);
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
print_successful_upgrade(from_version, to_version);
|
||||
print_successful_upgrade(config_version, to_version);
|
||||
|
||||
upgraded_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),
|
||||
)
|
||||
// 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. Specifies current version of the configuration file to help to determine a valid upgrade path. Valid formats include '0.8.1', 'v0.8.1' or 'V0.8.1'")
|
||||
.takes_value(true)
|
||||
)
|
||||
}
|
||||
|
||||
fn unsupported_upgrade(current_version: Version, config_version: Version) -> ! {
|
||||
eprintln!("Cannot perform upgrade from {} to {}. Please let the developers know about this issue if you expected it to work!", config_version, current_version);
|
||||
process::exit(1)
|
||||
}
|
||||
|
||||
fn do_upgrade(mut config: Config, matches: &ArgMatches) {
|
||||
let current = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
|
||||
|
||||
fn do_upgrade(mut config: Config, matches: &ArgMatches, package_version: Version) {
|
||||
loop {
|
||||
let config_version = Version::parse(config.get_version()).unwrap_or_else(|err| {
|
||||
eprintln!("failed to parse node version! - {:?}", err);
|
||||
process::exit(1)
|
||||
});
|
||||
let config_version = parse_config_version(&config);
|
||||
|
||||
if config_version == current {
|
||||
if config_version == package_version {
|
||||
println!("You're using the most recent version!");
|
||||
return;
|
||||
}
|
||||
|
||||
config = match config_version.major {
|
||||
0 => match config_version.minor {
|
||||
9 => patch_09x_upgrade(config, &matches),
|
||||
_ => unsupported_upgrade(current, config_version),
|
||||
9 => minor_010_upgrade(config, &matches, &config_version, &package_version),
|
||||
_ => unsupported_upgrade(config_version, package_version),
|
||||
},
|
||||
_ => unsupported_upgrade(current, config_version),
|
||||
_ => unsupported_upgrade(config_version, package_version),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn execute(matches: &ArgMatches) {
|
||||
let current = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
|
||||
|
||||
// technically this is not a correct way of checking it as a released version might contain valid build identifiers
|
||||
// however, we are not using them ourselves at the moment and hence it should be fine.
|
||||
// if we change our mind, we could easily tweak this code
|
||||
if current.is_prerelease() || !current.build.is_empty() {
|
||||
eprintln!(
|
||||
"Trying to upgrade to a non-released version {}. This is not supported!",
|
||||
current
|
||||
);
|
||||
process::exit(1)
|
||||
}
|
||||
let package_version = parse_package_version();
|
||||
|
||||
let id = matches.value_of("id").unwrap();
|
||||
|
||||
@@ -233,26 +277,9 @@ pub fn execute(matches: &ArgMatches) {
|
||||
});
|
||||
|
||||
// upgrades up to 0.9.0
|
||||
existing_config = pre_090_upgrade(self_reported_version, existing_config, &matches);
|
||||
}
|
||||
|
||||
let config_version = Version::parse(existing_config.get_version()).unwrap_or_else(|err| {
|
||||
eprintln!("failed to parse node version! - {:?}", err);
|
||||
process::exit(1)
|
||||
});
|
||||
|
||||
if config_version.is_prerelease() || !config_version.build.is_empty() {
|
||||
eprintln!(
|
||||
"Trying to upgrade from non-released version {}. This is not supported!",
|
||||
config_version
|
||||
);
|
||||
process::exit(1)
|
||||
existing_config = pre_090_upgrade(self_reported_version, existing_config);
|
||||
}
|
||||
|
||||
// here be upgrade path to 0.9.X and beyond based on version number from config
|
||||
if config_version == current {
|
||||
println!("You're using the most recent version!");
|
||||
} else {
|
||||
do_upgrade(existing_config, matches)
|
||||
}
|
||||
do_upgrade(existing_config, matches, package_version)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user