use anyhow::{Context, Result};
use bsv_wallet_toolbox::Chain;
use crate::cli::Cli;
pub async fn run(cli: &Cli) -> Result<()> {
let root_key_hex =
std::env::var("ROOT_KEY").context("ROOT_KEY not set. Run `bsv-wallet init` first.")?;
let chain = if cli.testnet {
Chain::Test
} else {
Chain::Main
};
let tenant = super::daemon_tenant::start(&cli.db, &root_key_hex, chain, cli.port).await?;
tokio::signal::ctrl_c().await?;
eprintln!("\nStopping monitor...");
tenant
.monitor
.stop()
.await
.map_err(|e| anyhow::anyhow!("{}", e))?;
eprintln!("Monitor stopped");
let _ = tenant.server.await;
Ok(())
}