Skip to content

Commit

Permalink
Merge pull request #20 from karnotxyz/explorer_patch
Browse files Browse the repository at this point in the history
Explorer patch
  • Loading branch information
apoorvsadana authored Jan 26, 2024
2 parents d1b5b97 + 5c622dd commit bfa0259
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/cli/explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@ use bollard::models::{HostConfig, PortBinding};
use rand::distributions::Alphanumeric;
use rand::Rng;

use clap::Args;
use std::collections::HashMap;

use crate::utils::docker::{container_exists, kill_container, run_docker_image};

pub async fn explorer() {
#[derive(Args)]
pub struct ExplorerOpts {
#[clap(long, default_value = "localhost")]
pub host: String,
}

pub async fn explorer(opts: &ExplorerOpts) {
let random_string: String = (0..64).map(|_| rand::thread_rng().sample(Alphanumeric).to_string()).collect();
let secret_key_base = format!("SECRET_KEY_BASE={}", random_string);

let host_env = format!("PHX_HOST={}", opts.host);
let env = vec![
"RPC_API_HOST=http://host.docker.internal:9944",
"DB_TYPE=sqlite",
"DISABLE_MAINNET_SYNC=false",
"DISABLE_TESTNET_SYNC=true",
"TESTNET_RPC_API_HOST=http://host.docker.internal:9944",
"DATABASE_PATH=/use/exp.db",
"PHX_HOST=localhost",
host_env.as_str(),
&secret_key_base,
];

Expand All @@ -37,7 +45,7 @@ pub async fn explorer() {
}

run_docker_image(
"ghcr.io/lambdaclass/stark_compass_explorer:v0.2.34.2",
"ghcr.io/lambdaclass/stark_compass_explorer:v0.2.34.3-1",
CONTAINER_NAME,
Some(env),
Some(host_config),
Expand Down
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use clap::{Parser, Subcommand};
use log::LevelFilter;
use madara_cli::cli;
use madara_cli::cli::explorer::ExplorerOpts;

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
Expand All @@ -18,7 +19,7 @@ enum Commands {
/// Runs the App Chain using Madara
Run,
/// Runs the L2 explorer
Explorer,
Explorer(ExplorerOpts),
}

#[tokio::main]
Expand All @@ -36,7 +37,7 @@ async fn main() {
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,
Some(Commands::Explorer(opts)) => cli::explorer::explorer(opts).await,
None => log::info!("Use --help to see the complete list of available commands"),
}
}

0 comments on commit bfa0259

Please sign in to comment.