Skip to content

Commit

Permalink
update: version & add: fast-flags (#29)
Browse files Browse the repository at this point in the history
* update: version

* add: fast flags

* add: flag in run command to supply additional madara flags

* chg: take madara args as positional arg instead of a flag

* fix:lint

* update: starkcompass image
  • Loading branch information
anshalshukla authored Feb 27, 2024
1 parent 554021a commit 11765b1
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "madara-cli"
version = "0.1.0"
version = "0.2.0"
edition = "2021"

[[bin]]
Expand Down
4 changes: 2 additions & 2 deletions src/app/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use strum::EnumIter;
use strum_macros::Display;
use strum_macros::{Display, EnumString};
use toml::ser::Error;

use crate::da::da_layers::DALayer;
Expand All @@ -24,7 +24,7 @@ impl AppChainConfig {
}
}

#[derive(Debug, Serialize, Deserialize, EnumIter, Display)]
#[derive(Debug, Serialize, Deserialize, EnumIter, Display, Clone, EnumString, clap::ValueEnum)]
pub enum RollupMode {
Sovereign,
// Validity,
Expand Down
8 changes: 1 addition & 7 deletions src/cli/explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ pub async fn explorer(opts: &ExplorerOpts) {
let _ = kill_container(CONTAINER_NAME).await;
}

run_docker_image(
"ghcr.io/lambdaclass/stark_compass_explorer:v0.2.34.3-1",
CONTAINER_NAME,
Some(env),
Some(host_config),
)
.await;
run_docker_image("ghcr.io/karnotxyz/starkcompass:latest", CONTAINER_NAME, Some(env), Some(host_config)).await;
log::info!("🧭 Explorer is running on http://localhost:4000");
}
29 changes: 23 additions & 6 deletions src/cli/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ pub enum InitError {
FailedToSerializeToToml(#[from] toml::ser::Error),
#[error("Failed to generate keypair")]
FailedToGenerateKeypair,
#[error("Failed to convert string to enum")]
FailedToGetEnum(#[from] strum::ParseError),
}

pub async fn init() {
let config = match generate_config().await {
pub async fn init(chain_name: &Option<String>, chain_mode: &Option<RollupMode>, da: &Option<DALayer>) {
let config = match generate_config(chain_name, chain_mode, da).await {
Ok(config) => config,
Err(err) => {
panic!("Failed to get input: {}", err);
Expand All @@ -44,15 +46,30 @@ pub async fn init() {
log::info!("✅ New app chain initialised.");
}

async fn generate_config() -> Result<AppChainConfig, InitError> {
let app_chain = get_text_input("Enter you app chain name:", Some("madara"))?;
async fn generate_config(
chain_name: &Option<String>,
chain_mode: &Option<RollupMode>,
da: &Option<DALayer>,
) -> Result<AppChainConfig, InitError> {
let app_chain: String = match chain_name {
Some(chain_name) => chain_name.clone(),
None => get_text_input("Enter you app chain name:", Some("madara"))?,
};

let app_chains_home = get_app_chains_home()?;
let binding = app_chains_home.join(format!("{}/data", app_chain));
let default_base_path = binding.to_str().unwrap_or("madara-data");

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 mode: RollupMode = match chain_mode {
Some(chain_mode) => chain_mode.clone(),
None => get_option("Select mode for your app chain:", RollupMode::iter().collect::<Vec<_>>())?,
};

let da_layer: DALayer = match da {
Some(da) => da.clone(),
None => 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, MADARA_BRANCH_NAME).await?;
let config_version = ConfigVersion::Version2;

Expand Down
20 changes: 12 additions & 8 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub enum RunError {
Other(#[from] eyre::Error),
}

pub async fn run() {
match start_app_chain().await {
pub async fn run(chain_name: &Option<String>, madara_flags: &[String]) {
match start_app_chain(chain_name, madara_flags).await {
Ok(_) => {
log::info!("Madara setup successful");
}
Expand All @@ -35,12 +35,16 @@ pub async fn run() {
}
}

async fn start_app_chain() -> Result<(), RunError> {
let app_chains_list = get_apps_list()?;
let app = get_option("Select the app chain:", app_chains_list)?;
let app_chain: &str = &app;
async fn start_app_chain(chain_name: &Option<String>, madara_flags: &[String]) -> Result<(), RunError> {
let app_chain: String = match chain_name {
Some(chain_name) => chain_name.to_string(),
None => {
let app_chains_list = get_apps_list()?;
get_option("Select the app chain:", app_chains_list)?
}
};

let (config, _) = match regenerate_app_config(app_chain) {
let (config, _) = match regenerate_app_config(&app_chain) {
Ok((config, valid)) => (config, valid),
Err(err) => {
log::error!("Failed to fetch the required app chain: {}", err);
Expand All @@ -54,7 +58,7 @@ async fn start_app_chain() -> Result<(), RunError> {
da_factory.confirm_minimum_balance(&config)?;
da_factory.setup(&config).await?;

madara::setup_and_run_madara(config)?;
madara::setup_and_run_madara(config, madara_flags)?;

Ok(())
}
4 changes: 2 additions & 2 deletions src/da/da_layers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::io;
use std::path::PathBuf;

use serde::{Deserialize, Serialize};
use strum_macros::{Display, EnumIter};
use strum_macros::{Display, EnumIter, EnumString};
use thiserror::Error;

use crate::app::config::AppChainConfig;
Expand All @@ -15,7 +15,7 @@ use crate::utils::constants::APP_DA_CONFIG_NAME;
use crate::utils::paths::get_app_home;
use eyre::Result as EyreResult;

#[derive(Debug, Serialize, Deserialize, EnumIter, Display, Clone)]
#[derive(Debug, Serialize, Deserialize, EnumIter, Display, Clone, EnumString, clap::ValueEnum)]
pub enum DALayer {
Avail,
Ethereum,
Expand Down
26 changes: 22 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use clap::{Parser, Subcommand};
use log::LevelFilter;
use madara_cli::app::config::RollupMode;
use madara_cli::cli;
use madara_cli::cli::explorer::ExplorerOpts;
use madara_cli::da::da_layers::DALayer;

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
Expand All @@ -13,11 +15,27 @@ struct Cli {
#[derive(Subcommand)]
enum Commands {
/// Init a new App Chain config
Init,
Init {
/// App chain name
#[clap(short, long = "chain-name")]
name: Option<String>,
/// Choose a supported Rollup Mode
#[clap(short, long = "chain-mode", value_enum, ignore_case = true)]
mode: Option<RollupMode>,
/// Choose a supported DA Layer
#[clap(short, long = "da-layer", value_enum, ignore_case = true)]
da: Option<DALayer>,
},
/// Lists all the existing App Chain configs
List,
/// Runs the App Chain using Madara
Run,
Run {
/// App chain name
#[clap(short, long = "chain-name")]
name: Option<String>,
/// Additional arguments for Madara
madara_flags: Vec<String>,
},
/// Runs the L2 explorer
Explorer(ExplorerOpts),
}
Expand All @@ -34,9 +52,9 @@ async fn main() {
let cli = Cli::parse();

match &cli.command {
Some(Commands::Init) => cli::init::init().await,
Some(Commands::Init { name, mode, da }) => cli::init::init(name, mode, da).await,
Some(Commands::List) => cli::list::list(),
Some(Commands::Run) => cli::run::run().await,
Some(Commands::Run { name, madara_flags }) => cli::run::run(name, madara_flags).await,
Some(Commands::Explorer(opts)) => cli::explorer::explorer(opts).await,
None => log::info!("Use --help to see the complete list of available commands"),
}
Expand Down
4 changes: 3 additions & 1 deletion src/utils/madara.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn clone_madara_and_build_repo(config: &AppChainConfig) -> Result<(), Madara
Ok(())
}

pub fn setup_and_run_madara(config: AppChainConfig) -> Result<(), MadaraError> {
pub fn setup_and_run_madara(config: AppChainConfig, madara_flags: &[String]) -> Result<(), MadaraError> {
let madara_path = get_madara_home()?.join("madara");

let app_home = get_app_home(config.app_chain.as_str())?;
Expand All @@ -60,6 +60,8 @@ pub fn setup_and_run_madara(config: AppChainConfig) -> Result<(), MadaraError> {
&base_path,
];

args.extend(madara_flags.iter().map(|arg| arg.as_str()));

match config.da_layer {
DALayer::Ethereum => {
let ethereum_conf = vec!["--da-layer=ethereum", &da_conf];
Expand Down

1 comment on commit 11765b1

@FEKUUUU
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cant understand anything

Please sign in to comment.