diff --git a/ol/onboard/src/commands/files_cmd.rs b/ol/onboard/src/commands/files_cmd.rs index 14961cbb42..090ee3e29f 100644 --- a/ol/onboard/src/commands/files_cmd.rs +++ b/ol/onboard/src/commands/files_cmd.rs @@ -2,13 +2,13 @@ #![allow(clippy::never_loop)] -use std::{fs::File, io::Write, path::{PathBuf}}; -use crate::{application::app_config}; +use crate::application::app_config; use abscissa_core::{Command, Options, Runnable}; -use anyhow::Error; +use anyhow::{bail, Error}; use diem_genesis_tool::ol_node_files; use diem_types::waypoint::Waypoint; use ol_types::config::AppCfg; +use std::{fs::File, io::Write, path::PathBuf}; /// `files` subcommand #[derive(Command, Debug, Default, Options)] @@ -18,13 +18,13 @@ pub struct FilesCmd { #[options(help = "github org of genesis repo")] github_org: Option, #[options(help = "repo with with genesis transactions")] - repo: Option, + repo: Option, #[options(help = "use a genesis file instead of building")] prebuilt_genesis: Option, #[options(help = "only make fullnode config files")] fullnode_only: bool, #[options(help = "optional waypoint")] - waypoint: Option, + waypoint: Option, } impl Runnable for FilesCmd { @@ -39,7 +39,7 @@ impl Runnable for FilesCmd { &self.prebuilt_genesis, &self.fullnode_only, self.waypoint, - ) + ) } } @@ -56,9 +56,9 @@ pub fn genesis_files( let home_dir = miner_config.workspace.node_home.to_owned(); // 0L convention is for the namespace of the operator to be appended by '-oper' let namespace = miner_config.profile.auth_key.clone().to_string() + "-oper"; - + ol_node_files::write_node_config_files( - home_dir.clone(), + home_dir.clone(), chain_id.unwrap_or(1), &github_org.clone().unwrap_or("OLSF".to_string()), &repo.clone().unwrap_or("experimetal-genesis".to_string()), @@ -67,44 +67,70 @@ pub fn genesis_files( fullnode_only, way_opt, &None, - ).unwrap(); + ) + .unwrap(); - println!("validator configurations initialized, file saved to: {:?}", + println!( + "validator configurations initialized, file saved to: {:?}", &home_dir.join("validator.node.yaml") ); - } /// fetch files from github pub fn fetch_genesis_files_from_repo( home_dir: PathBuf, github_org: &Option, - repo: &Option + repo: &Option, ) -> Result { let github_org = github_org.clone().unwrap_or("OLSF".to_string()); let repo = repo.clone().unwrap_or("genesis-registration".to_string()); - let base_url = format!( - "https://raw.githubusercontent.com/{github_org}/{repo}/main/genesis/", - github_org=github_org, - repo=repo + "https://raw.githubusercontent.com/{github_org}/{repo}/main/genesis/", + github_org = github_org, + repo = repo ); - let w_res = reqwest::blocking::get(&format!("{}genesis_waypoint.txt", base_url)); - let w_path = &home_dir.join("genesis_waypoint"); - let mut w_file = File::create(&w_path)?; - let w_content = w_res.unwrap().text()?; - w_file.write_all(w_content.as_bytes())?; - println!("genesis waypoint fetched, file saved to: {:?}", w_path); - - let g_res = reqwest::blocking::get(&format!("{}genesis.blob", base_url)); - // default path for genesis.blob - let g_path = &home_dir.join("genesis.blob"); - let mut g_file = File::create(&g_path).expect("couldn't create file"); - let g_content = g_res.unwrap().bytes().unwrap().to_vec(); //.text().unwrap(); - g_file.write_all(g_content.as_slice())?; - - println!("genesis transactions fetched, file saved to: {:?}", g_path); - Ok(g_path.to_owned()) -} \ No newline at end of file + // let w_res = reqwest::blocking::get(&format!("{}genesis_waypoint.txt", base_url)); + // let w_path = &home_dir.join("genesis_waypoint"); + // let mut w_file = File::create(&w_path)?; + // let w_content = w_res.unwrap().text()?; + // w_file.write_all(w_content.as_bytes())?; + // println!("genesis waypoint fetched, file saved to: {:?}", w_path); + + let g_res = reqwest::blocking::get(&format!("{}genesis_waypoint.txt", base_url))?; + match g_res.status().is_success() { + true => { + let g_content = g_res.bytes().unwrap().to_vec(); + // default path for genesis.blob + let g_path = &home_dir.join("genesis_waypoint.txt"); + let mut g_file = File::create(&g_path).expect("couldn't create file"); + g_file.write_all(g_content.as_slice())?; + + println!("genesis_waypoint.txt fetched, file saved to: {:?}", g_path); + } + _ => { + bail!("Cannot fetch genesis_waypoint.txt from Github repo: {}", base_url); + } + }; + + let g_res = reqwest::blocking::get(&format!("{}genesis.blob", base_url))?; + match g_res.status().is_success() { + true => { + let g_content = g_res.bytes().unwrap().to_vec(); + + // default path for genesis.blob + let g_path = &home_dir.join("genesis.blob"); + let mut g_file = File::create(&g_path).expect("couldn't create file"); + g_file.write_all(g_content.as_slice())?; + + println!("genesis.blob fetched, file saved to: {:?}", g_path); + return Ok(g_path.to_owned()); + } + _ => { + bail!("Cannot fetch genesis.blob from Github repo: {}", base_url); + } + }; + + +}