Skip to content

Commit

Permalink
pnn-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Sep 6, 2024
1 parent 18739aa commit 0e96bea
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
27 changes: 24 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::imports::*;

const CONFIG_VERSION: u64 = 2;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
pub version: u64,
Expand All @@ -21,15 +23,15 @@ 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::<Vec<_>>();

let nginx = nginx::Config::default();

Ok(Config {
version: 1,
version: CONFIG_VERSION,
bootstrap: false,
disable_sudo_prompt: false,
public: true,
Expand All @@ -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<()> {
Expand Down
30 changes: 17 additions & 13 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ impl Origin {
self.branch.as_deref()
}

pub fn branch_mut(&mut self) -> &mut Option<String> {
&mut self.branch
}

pub fn api_url(&self) -> String {
let Origin {
owner,
Expand Down Expand Up @@ -174,32 +178,32 @@ 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 {
Preset::Custom
};

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("")
Expand Down
4 changes: 4 additions & 0 deletions src/kaspad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
Expand Down

0 comments on commit 0e96bea

Please sign in to comment.