use clap::Parser;
use colored::Colorize;
mod chain;
mod cli;
mod collect_rewards_lib;
mod config;
mod error;
mod log;
mod subsquid;
mod wallet;
mod wormhole_lib;
use cli::Commands;
use error::QuantusError;
#[derive(Parser)]
#[command(name = "quantus")]
#[command(author = "Quantus Network")]
#[command(version = env!("CARGO_PKG_VERSION"))]
#[command(about = "Command line interface for the Quantus Network", long_about = None)]
#[command(arg_required_else_help = true)]
struct Cli {
#[command(subcommand)]
command: Commands,
#[arg(short, long, global = true)]
verbose: bool,
#[arg(long, global = true, default_value = "ws://127.0.0.1:9944")]
node_url: String,
#[arg(long, global = true, default_value = "false")]
finalized_tx: bool,
#[arg(long, global = true, default_value = "false")]
wait_for_transaction: bool,
}
#[tokio::main]
async fn main() -> Result<(), QuantusError> {
sp_core::crypto::set_default_ss58_version(sp_core::crypto::Ss58AddressFormat::custom(189));
let cli = Cli::parse();
log::set_verbose(cli.verbose);
log_print!("{}", "🔮 Quantus CLI".bright_cyan().bold());
log_verbose!("{}", "Connecting to the quantum future...".dimmed());
log_verbose!("");
if cli.finalized_tx {
log_print!("⚠️ Warning: Waiting for finalized block may take a while in PoW chain.");
}
let execution_mode = cli::common::ExecutionMode {
finalized: cli.finalized_tx,
wait_for_transaction: cli.wait_for_transaction,
};
let start_time = std::time::Instant::now();
let result =
cli::execute_command(cli.command, &cli.node_url, cli.verbose, execution_mode).await;
let elapsed = start_time.elapsed();
match result {
Ok(_) => {
log_verbose!("");
log_verbose!("Command executed successfully!");
log_print!("⏱️ Completed in {:.2}s", elapsed.as_secs_f64());
Ok(())
},
Err(e) => {
log_error!("{}", e);
log_print!("⏱️ Failed after {:.2}s", elapsed.as_secs_f64());
std::process::exit(1);
},
}
}