From: Vihiga Tyonum Date: Sat, 10 May 2025 03:19:01 +0000 (+0100) Subject: chore(cbf): mv kyoto data to existing datadir X-Git-Tag: v1.0.0~5^2 X-Git-Url: http://internal-gitweb-vhost/?a=commitdiff_plain;h=afc2f9d97f5729f7cbd6abcba5576ce8ed06e4e8;p=bdk-cli chore(cbf): mv kyoto data to existing datadir move light_client_data to existing data dir for the wallet --- diff --git a/src/handlers.rs b/src/handlers.rs index 1b7bf25..1ef0526 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -697,7 +697,8 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result { }; let mut wallet = new_persisted_wallet(network, &mut persister, &wallet_opts)?; - let blockchain_client = new_blockchain_client(&wallet_opts, &wallet)?; + let blockchain_client = + new_blockchain_client(&wallet_opts, &wallet, Some(database_path))?; let result = handle_online_wallet_subcommand( &mut wallet, @@ -773,7 +774,7 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result { let (mut wallet, mut persister) = { let wallet_name = &wallet_opts.wallet; - let home_dir = prepare_home_dir(cli_opts.datadir)?; + let home_dir = prepare_home_dir(cli_opts.datadir.clone())?; let database_path = prepare_wallet_db_dir(wallet_name, &home_dir)?; @@ -791,6 +792,8 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result { }; #[cfg(not(any(feature = "sqlite")))] let mut wallet = new_wallet(network, &wallet_opts)?; + let home_dir = prepare_home_dir(cli_opts.datadir.clone())?; + let database_path = prepare_wallet_db_dir(&wallet_opts.wallet, &home_dir)?; loop { let line = readline()?; @@ -799,7 +802,14 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result { continue; } - let result = respond(network, &mut wallet, &wallet_opts, line).await; + let result = respond( + network, + &mut wallet, + &wallet_opts, + line, + Some(database_path.clone()), + ) + .await; #[cfg(feature = "sqlite")] wallet.persist(&mut persister)?; @@ -830,6 +840,7 @@ async fn respond( wallet: &mut Wallet, wallet_opts: &WalletOpts, line: &str, + _datadir: Option, ) -> Result { use clap::Parser; @@ -846,7 +857,7 @@ async fn respond( subcommand: WalletSubCommand::OnlineWalletSubCommand(online_subcommand), } => { let blockchain = - new_blockchain_client(wallet_opts, &wallet).map_err(|e| e.to_string())?; + new_blockchain_client(wallet_opts, &wallet, _datadir).map_err(|e| e.to_string())?; let value = handle_online_wallet_subcommand(wallet, blockchain, online_subcommand) .await .map_err(|e| e.to_string())?; diff --git a/src/utils.rs b/src/utils.rs index feb08b4..3e31710 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -154,6 +154,7 @@ pub(crate) enum BlockchainClient { pub(crate) fn new_blockchain_client( wallet_opts: &WalletOpts, wallet: &Wallet, + datadir: Option, ) -> Result { #[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))] let url = wallet_opts.url.as_str(); @@ -199,7 +200,12 @@ pub(crate) fn new_blockchain_client( None => Sync, }; - let client = NodeBuilder::new(wallet.network()) + let mut builder = NodeBuilder::new(wallet.network()); + + if let Some(datadir) = datadir { + builder = builder.data_dir(&datadir); + }; + let client = builder .required_peers(wallet_opts.compactfilter_opts.conn_count) .build_with_wallet(wallet, scan_type)?;