2025-12-31 04:02:25 +03:00
|
|
|
use anyhow::{Context as _, Result};
|
2025-11-27 22:07:53 +03:00
|
|
|
use clap::{CommandFactory as _, Parser as _};
|
2025-12-31 04:02:25 +03:00
|
|
|
use wallet::{
|
|
|
|
|
WalletCore,
|
|
|
|
|
cli::{Args, execute_continuous_run, execute_subcommand, read_password_from_stdin},
|
|
|
|
|
config::WalletConfigOverrides,
|
|
|
|
|
helperfunctions::{fetch_config_path, fetch_persistent_storage_path},
|
|
|
|
|
};
|
2025-08-06 14:56:58 +03:00
|
|
|
|
2025-11-19 17:33:25 +03:00
|
|
|
// TODO #169: We have sample configs for sequencer, but not for wallet
|
2025-11-26 00:27:20 +03:00
|
|
|
// TODO #168: Why it requires config as a directory? Maybe better to deduce directory from config
|
2025-11-27 22:07:53 +03:00
|
|
|
// file path?
|
|
|
|
|
// TODO #172: Why it requires config as env var while sequencer_runner accepts as
|
|
|
|
|
// argument?
|
2025-12-31 04:02:25 +03:00
|
|
|
#[tokio::main]
|
|
|
|
|
async fn main() -> Result<()> {
|
|
|
|
|
let Args {
|
|
|
|
|
continuous_run,
|
|
|
|
|
auth,
|
|
|
|
|
command,
|
|
|
|
|
} = Args::parse();
|
2025-08-06 14:56:58 +03:00
|
|
|
|
2025-08-07 14:07:34 +03:00
|
|
|
env_logger::init();
|
|
|
|
|
|
2025-12-31 04:02:25 +03:00
|
|
|
let config_path = fetch_config_path().context("Could not fetch config path")?;
|
|
|
|
|
let storage_path =
|
|
|
|
|
fetch_persistent_storage_path().context("Could not fetch persistent storage path")?;
|
|
|
|
|
|
|
|
|
|
// Override basic auth if provided via CLI
|
|
|
|
|
let config_overrides = WalletConfigOverrides {
|
|
|
|
|
basic_auth: auth.map(|auth| auth.parse()).transpose()?.map(Some),
|
|
|
|
|
..Default::default()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if let Some(command) = command {
|
|
|
|
|
let mut wallet = if !storage_path.exists() {
|
|
|
|
|
// TODO: Maybe move to `WalletCore::from_env()` or similar?
|
|
|
|
|
|
|
|
|
|
println!("Persistent storage not found, need to execute setup");
|
|
|
|
|
|
|
|
|
|
let password = read_password_from_stdin()?;
|
|
|
|
|
let wallet = WalletCore::new_init_storage(
|
|
|
|
|
config_path,
|
|
|
|
|
storage_path,
|
|
|
|
|
Some(config_overrides),
|
|
|
|
|
password,
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
|
|
wallet.store_persistent_data().await?;
|
|
|
|
|
wallet
|
2025-10-15 15:17:30 +03:00
|
|
|
} else {
|
2025-12-31 04:02:25 +03:00
|
|
|
WalletCore::new_update_chain(config_path, storage_path, Some(config_overrides))?
|
|
|
|
|
};
|
|
|
|
|
let _output = execute_subcommand(&mut wallet, command).await?;
|
|
|
|
|
Ok(())
|
|
|
|
|
} else if continuous_run {
|
|
|
|
|
let mut wallet =
|
|
|
|
|
WalletCore::new_update_chain(config_path, storage_path, Some(config_overrides))?;
|
|
|
|
|
execute_continuous_run(&mut wallet).await
|
|
|
|
|
} else {
|
|
|
|
|
let help = Args::command().render_long_help();
|
|
|
|
|
println!("{help}");
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
2025-08-06 14:56:58 +03:00
|
|
|
}
|