diff --git a/src/cli/init.rs b/src/cli/init.rs index 3260752..653741f 100644 --- a/src/cli/init.rs +++ b/src/cli/init.rs @@ -26,8 +26,8 @@ pub enum InitError { FailedToGenerateKeypair, } -pub fn init() { - let config = match generate_config() { +pub async fn init() { + let config = match generate_config().await { Ok(config) => config, Err(err) => { panic!("Failed to get input: {}", err); @@ -44,7 +44,7 @@ pub fn init() { log::info!("✅ New app chain initialised."); } -fn generate_config() -> Result { +async fn generate_config() -> Result { let app_chain = get_text_input("Enter you app chain name:", Some("madara"))?; let app_chains_home = get_app_chains_home()?; @@ -53,7 +53,7 @@ fn generate_config() -> Result { let mode = get_option("Select mode for your app chain:", RollupMode::iter().collect::>())?; let da_layer = get_option("Select DA layer for your app chain:", DALayer::iter().collect::>())?; - let madara_version = get_latest_commit_hash(MADARA_REPO_ORG, MADARA_REPO_NAME)?; + let madara_version = get_latest_commit_hash(MADARA_REPO_ORG, MADARA_REPO_NAME).await?; let config_version = ConfigVersion::Version1; log::info!("\n"); diff --git a/src/main.rs b/src/main.rs index 4d9af55..001f17e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,7 +33,7 @@ async fn main() { let cli = Cli::parse(); match &cli.command { - Some(Commands::Init) => cli::init::init(), + Some(Commands::Init) => cli::init::init().await, Some(Commands::List) => cli::list::list(), Some(Commands::Run) => cli::run::run().await, Some(Commands::Explorer) => cli::explorer::explorer().await, diff --git a/src/utils/github.rs b/src/utils/github.rs index b4bf704..cf32363 100644 --- a/src/utils/github.rs +++ b/src/utils/github.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use std::process::{Command, Stdio}; use git2::Repository; -use reqwest::blocking::Client; +use reqwest::Client; use serde::Deserialize; use crate::utils::errors::GithubError; @@ -14,14 +14,14 @@ struct Commit { sha: String, } -pub fn get_latest_commit_hash(org: &str, repo: &str) -> Result { +pub async fn get_latest_commit_hash(org: &str, repo: &str) -> Result { let github_api_url = format!("{}/repos/{}/{}/commits", GITHUB_API_BASE_URL, org, repo); let client = Client::new(); - let response = client.get(github_api_url).header("User-Agent", "reqwest").send(); + let response = client.get(github_api_url).header("User-Agent", "reqwest").send().await; return match response { - Ok(response) => match response.json::>() { + Ok(response) => match response.json::>().await { Ok(commits) => match commits.first() { Some(latest_commit) => Ok(latest_commit.sha.clone()), None => Err(GithubError::NoCommitsFound),