]> Untitled Git - bdk-cli/commitdiff
chore(cbf): mv kyoto data to existing datadir
authorVihiga Tyonum <withtvpeter@gmail.com>
Sat, 10 May 2025 03:19:01 +0000 (04:19 +0100)
committerVihiga Tyonum <withtvpeter@gmail.com>
Sat, 10 May 2025 03:19:01 +0000 (04:19 +0100)
move light_client_data to existing data dir for
the wallet

src/handlers.rs
src/utils.rs

index 1b7bf25c5dee18b4d797f326350de6f51417ddad..1ef05268df9e3b7be9d3174a013c32b56081aaa4 100644 (file)
@@ -697,7 +697,8 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
                 };
 
                 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<String, Error> {
             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<String, Error> {
             };
             #[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<String, Error> {
                     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<std::path::PathBuf>,
 ) -> Result<bool, String> {
     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())?;
index feb08b481d1d70404f0069c089fd58e8a2c09eb0..3e31710b264ae1532e6829bdd5074f7f8bd83f39 100644 (file)
@@ -154,6 +154,7 @@ pub(crate) enum BlockchainClient {
 pub(crate) fn new_blockchain_client(
     wallet_opts: &WalletOpts,
     wallet: &Wallet,
+    datadir: Option<std::path::PathBuf>,
 ) -> Result<BlockchainClient, Error> {
     #[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)?;