Skip to content

Commit

Permalink
fix: bug when users install CLI (#1269)
Browse files Browse the repository at this point in the history
  • Loading branch information
dprats authored Feb 18, 2025
1 parent 77b9ff1 commit aca10be
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 487 deletions.
2 changes: 1 addition & 1 deletion clients/cli/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 clients/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nexus-network"
version = "0.4.6"
version = "0.5.0"
edition = "2021"
rust-version = "1.75"
build = "build.rs"
Expand Down
39 changes: 2 additions & 37 deletions clients/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ pub enum Environment {

impl Environment {
pub fn orchestrator_url(&self) -> String {
let url = match self {
match self {
Environment::Local => "http://localhost:8080".to_string(),
Environment::Dev => "https://dev.orchestrator.nexus.xyz".to_string(),
Environment::Staging => "https://staging.orchestrator.nexus.xyz".to_string(),
Environment::Beta => "https://beta.orchestrator.nexus.xyz".to_string(),
};
url
}
}

pub fn from_args(local: bool, dev: bool, staging: bool, beta: bool) -> Self {
Expand All @@ -33,37 +32,3 @@ impl Environment {
}
}
}

// // the firebase APP IDS by environment
// mod firebase {
// pub const DEV_APP_ID: &str = "1:954530464230:web:f0a14de14ef7bcdaa99627";
// pub const STAGING_APP_ID: &str = "1:222794630996:web:1758d64a85eba687eaaac1";
// pub const BETA_APP_ID: &str = "1:279395003658:web:04ee2c524474d683d75ef3";

// // Analytics keys for the different environments
// // These are keys that allow the measurement protocol to write to the analytics database
// // They are not sensitive. Worst case, if a malicious actor obtains the secret, they could potentially send false or misleading data to your GA4 property
// pub const DEV_API_SECRET: &str = "8ySxiKrtT8a76zClqqO8IQ";
// pub const STAGING_API_SECRET: &str = "OI7H53soRMSDWfJf1ittHQ";
// pub const BETA_API_SECRET: &str = "gxxzKAQLSl-uYI0eKbIi_Q";
// }

// // Release versions (existing code)
// pub fn analytics_id(env: &Environment) -> String {
// // Return the appropriate Firebase App ID based on the environment
// match env {
// Environment::Dev => firebase::DEV_APP_ID.to_string(),
// Environment::Staging => firebase::STAGING_APP_ID.to_string(),
// Environment::Beta => firebase::BETA_APP_ID.to_string(),
// _ => String::new(),
// }
// }

// pub fn analytics_api_key(env: &Environment) -> String {
// match env {
// Environment::Dev => firebase::DEV_API_SECRET.to_string(),
// Environment::Staging => firebase::STAGING_API_SECRET.to_string(),
// Environment::Beta => firebase::BETA_API_SECRET.to_string(),
// _ => String::new(),
// }
// }
9 changes: 2 additions & 7 deletions clients/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod config;
mod flops;
#[path = "proto/nexus.orchestrator.rs"]
mod nexus_orchestrator;
mod node_id_manager;
mod orchestrator_client;
mod setup;
mod utils;
Expand All @@ -24,13 +25,7 @@ use orchestrator_client::OrchestratorClient;

use clap::Parser;
use colored::Colorize;
// use serde_json;
use directories::ProjectDirs;
use rand::Rng;
use serde_json::json;
use sha3::{Digest, Keccak256};
use std::fs::File;
use std::io::Write;

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
Expand Down Expand Up @@ -179,7 +174,7 @@ async fn authenticated_proving(
println!("\tProof size: {} bytes", proof_bytes.len());
println!("4. Submitting proof...");
client
.submit_proof(&node_id, &proof_hash, proof_bytes)
.submit_proof(node_id, &proof_hash, proof_bytes)
.await?;
println!("{}", "5. Proof successfully submitted".green());

Expand Down
88 changes: 88 additions & 0 deletions clients/cli/src/node_id_manager.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
use colored::Colorize;
// use rand::RngCore;
// use random_word::Lang;
use std::{fs, path::Path, path::PathBuf};

pub fn get_home_directory() -> Result<PathBuf, &'static str> {
match home::home_dir() {
Some(path) if !path.as_os_str().is_empty() => Ok(path),
_ => {
println!("Could not determine home directory");
Err("No home directory found")
}
}
}

pub fn create_nexus_directory(nexus_dir: &Path) -> std::io::Result<()> {
println!("Attempting to create .nexus directory");
if let Err(e) = fs::create_dir(nexus_dir) {
eprintln!(
"{}: {}",
"Warning: Failed to create .nexus directory"
.to_string()
.yellow(),
e
);
return Err(e);
}

Ok(())
}

pub fn read_existing_node_id(node_id_path: &Path) -> Result<String, std::io::Error> {
let buf = fs::read(node_id_path)?;
let id = String::from_utf8(buf)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?
.trim()
.to_string();

if id.is_empty() {
return Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
"Node ID file is empty",
));
}

Ok(id)
}

fn save_node_id(path: &Path, id: &str) {
if let Err(e) = fs::write(path, id) {
println!("Failed to save node-id to file: {}", e);
} else {
println!("Successfully saved new node-id to file: {}", id);
}
}

pub fn handle_read_error(e: std::io::Error, path: &Path, default_id: &str) {
match e.kind() {
std::io::ErrorKind::NotFound => {
save_node_id(path, default_id);
}
std::io::ErrorKind::PermissionDenied => {
eprintln!(
"{}: {}",
"Error: Permission denied when accessing node-id file"
.to_string()
.yellow(),
e
);
}
std::io::ErrorKind::InvalidData => {
eprintln!(
"{}: {}",
"Error: node-id file is corrupted".to_string().yellow(),
e
);
}
_ => {
eprintln!(
"{}: {}",
"Error: Unexpected IO error when reading node-id file"
.to_string()
.yellow(),
e
);
}
}
}
Loading

0 comments on commit aca10be

Please sign in to comment.