From 0e96bea9ffeb23d4614c70bc88727db86b0fc921 Mon Sep 17 00:00:00 2001 From: Anton Yemelyanov Date: Fri, 6 Sep 2024 14:20:29 +0300 Subject: [PATCH] pnn-v1 --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/config.rs | 27 ++++++++++++++++++++++++--- src/git.rs | 30 +++++++++++++++++------------- src/kaspad.rs | 4 ++++ 5 files changed, 47 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f216af4..7158ab5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1465,7 +1465,7 @@ dependencies = [ [[package]] name = "khost" -version = "0.1.0" +version = "0.2.0" dependencies = [ "addr", "bytes", diff --git a/Cargo.toml b/Cargo.toml index d02def1..046af0c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "khost" -version = "0.1.0" +version = "0.2.0" edition = "2021" authors = ["Kaspa developers"] license = "MIT OR Apache-2.0" diff --git a/src/config.rs b/src/config.rs index d9befab..5ecb5ab 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,5 +1,7 @@ use crate::imports::*; +const CONFIG_VERSION: u64 = 2; + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Config { pub version: u64, @@ -21,7 +23,7 @@ impl Config { .with_stats() .with_local_interface(8989); - let origin = Origin::try_new("https://github.com/aspectron/rusty-kaspa", Some("omega"))?; + let origin = Origin::try_new("https://github.com/aspectron/rusty-kaspa", Some("pnn-v1"))?; let kaspad = Network::into_iter() .map(|network| kaspad::Config::new(origin.clone(), network)) .collect::>(); @@ -29,7 +31,7 @@ impl Config { let nginx = nginx::Config::default(); Ok(Config { - version: 1, + version: CONFIG_VERSION, bootstrap: false, disable_sudo_prompt: false, public: true, @@ -48,7 +50,26 @@ impl Config { if !config_path.exists() { return Err(Error::custom("Config file not found")); } - Ok(serde_json::from_str(&fs::read_to_string(config_path)?)?) + let mut config: Config = serde_json::from_str(&fs::read_to_string(config_path)?)?; + + let mut update = false; + // Migrate old config + if config.version < 1 { + config.kaspad.iter_mut().for_each(|config| { + if let Some(branch) = config.origin_mut().branch_mut() { + if branch == "omega" { + *branch = "pnn-v1".to_string(); + update = true; + } + } + }); + } + + if update { + config.save()?; + } + + Ok(config) } pub fn save(&self) -> Result<()> { diff --git a/src/git.rs b/src/git.rs index 1049580..1f909d5 100644 --- a/src/git.rs +++ b/src/git.rs @@ -67,6 +67,10 @@ impl Origin { self.branch.as_deref() } + pub fn branch_mut(&mut self) -> &mut Option { + &mut self.branch + } + pub fn api_url(&self) -> String { let Origin { owner, @@ -174,19 +178,19 @@ where #[derive(Debug, Clone, Copy, Eq, PartialEq)] enum Preset { - Omega, - Delta, + PNNv1, + // Delta, Custom, } let preset = if name == "rusty-kaspa" { cliclack::select(format!("Select git origin for '{name}':")) - .item(Preset::Omega, "Omega (aspectron/omega - wRPC v2)", "") - .item( - Preset::Delta, - "Delta", - "(aspectron/delta - wRPC v2 + GD perf)", - ) + .item(Preset::PNNv1, "pnn-v1 (aspectron/pnn-v1)", "") + // .item( + // Preset::Delta, + // "Delta", + // "(aspectron/delta - wRPC v2 + GD perf)", + // ) .item(Preset::Custom, "Custom", "") .interact()? } else { @@ -194,12 +198,12 @@ where }; let origin = match preset { - Preset::Omega => { - Origin::try_new("https://github.com/aspectron/rusty-kaspa", Some("omega"))? - } - Preset::Delta => { - Origin::try_new("https://github.com/aspectron/rusty-kaspa", Some("delta"))? + Preset::PNNv1 => { + Origin::try_new("https://github.com/aspectron/rusty-kaspa", Some("pnn-v1"))? } + // Preset::Delta => { + // Origin::try_new("https://github.com/aspectron/rusty-kaspa", Some("delta"))? + // } Preset::Custom => { let mut input = cliclack::input("Enter GitHub repository owner/organization:") .placeholder("") diff --git a/src/kaspad.rs b/src/kaspad.rs index 9cde431..ad52007 100644 --- a/src/kaspad.rs +++ b/src/kaspad.rs @@ -125,6 +125,10 @@ impl Config { pub fn set_origin(&mut self, origin: Origin) { self.origin = origin; } + + pub fn origin_mut(&mut self) -> &mut Origin { + &mut self.origin + } } impl From<&Config> for Vec {