mod commands;
use atupa_core::config::AtupaConfig;
use clap::{Parser, Subcommand};
use colored::*;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand, Debug)]
enum Commands {
Profile {
#[arg(short, long, default_value = "")]
tx: String,
#[arg(short, long, default_value = "http://localhost:8545")]
rpc: String,
#[arg(long, default_value_t = false)]
demo: bool,
#[arg(short, long)]
out: Option<String>,
#[arg(long, env = "ETHERSCAN_API_KEY")]
etherscan_key: Option<String>,
},
Diff {
#[arg(short, long)]
base: String,
#[arg(short, long)]
target: String,
},
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
env_logger::init();
let cli = Cli::parse();
let config = AtupaConfig::load();
eprintln!(
"{}",
"Atupa: High-Fidelity Ethereum Tracing Suite".bold().cyan()
);
match cli.command {
Commands::Profile {
tx,
rpc,
demo,
out,
etherscan_key,
} => {
let effective_rpc = if rpc != "http://localhost:8545" {
rpc
} else {
config.rpc_url
};
let effective_key = etherscan_key.or(config.etherscan_key);
if !demo && tx.is_empty() {
eprintln!(
"\n{} You must provide a transaction hash (--tx) or run with --demo.",
"Error:".bold().red()
);
std::process::exit(1);
}
let display_tx = if demo { "demo" } else { &tx };
eprintln!(
"Profiling transaction: {} on {}",
display_tx.green(),
effective_rpc.yellow()
);
commands::profile::execute_profile(&tx, &effective_rpc, demo, out, effective_key)
.await?;
}
Commands::Diff { base, target } => {
eprintln!("Comparing traces: {} and {}", base.green(), target.yellow());
}
}
Ok(())
}