Skip to content

Commit

Permalink
Merge pull request #14 from karnotxyz/fix-debug-init-crash
Browse files Browse the repository at this point in the history
fix: make http call async
  • Loading branch information
apoorvsadana authored Jan 23, 2024
2 parents 87027e1 + b65afdb commit bac2cc1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/cli/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -44,7 +44,7 @@ pub fn init() {
log::info!("✅ New app chain initialised.");
}

fn generate_config() -> Result<AppChainConfig, InitError> {
async fn generate_config() -> Result<AppChainConfig, InitError> {
let app_chain = get_text_input("Enter you app chain name:", Some("madara"))?;

let app_chains_home = get_app_chains_home()?;
Expand All @@ -53,7 +53,7 @@ fn generate_config() -> Result<AppChainConfig, InitError> {

let mode = get_option("Select mode for your app chain:", RollupMode::iter().collect::<Vec<_>>())?;
let da_layer = get_option("Select DA layer for your app chain:", DALayer::iter().collect::<Vec<_>>())?;
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");
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/utils/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,14 +14,14 @@ struct Commit {
sha: String,
}

pub fn get_latest_commit_hash(org: &str, repo: &str) -> Result<String, GithubError> {
pub async fn get_latest_commit_hash(org: &str, repo: &str) -> Result<String, GithubError> {
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::<Vec<Commit>>() {
Ok(response) => match response.json::<Vec<Commit>>().await {
Ok(commits) => match commits.first() {
Some(latest_commit) => Ok(latest_commit.sha.clone()),
None => Err(GithubError::NoCommitsFound),
Expand Down

0 comments on commit bac2cc1

Please sign in to comment.