Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Oct 24, 2021
1 parent 309fa09 commit 401de31
Showing 1 changed file with 59 additions and 33 deletions.
92 changes: 59 additions & 33 deletions ol/onboard/src/commands/files_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -18,13 +18,13 @@ pub struct FilesCmd {
#[options(help = "github org of genesis repo")]
github_org: Option<String>,
#[options(help = "repo with with genesis transactions")]
repo: Option<String>,
repo: Option<String>,
#[options(help = "use a genesis file instead of building")]
prebuilt_genesis: Option<PathBuf>,
#[options(help = "only make fullnode config files")]
fullnode_only: bool,
#[options(help = "optional waypoint")]
waypoint: Option<Waypoint>,
waypoint: Option<Waypoint>,
}

impl Runnable for FilesCmd {
Expand All @@ -39,7 +39,7 @@ impl Runnable for FilesCmd {
&self.prebuilt_genesis,
&self.fullnode_only,
self.waypoint,
)
)
}
}

Expand All @@ -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()),
Expand All @@ -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<String>,
repo: &Option<String>
repo: &Option<String>,
) -> Result<PathBuf, Error> {
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())
}
// 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);
}
};


}

0 comments on commit 401de31

Please sign in to comment.