Skip to content

Commit afc2f9d

Browse files
committed
chore(cbf): mv kyoto data to existing datadir
move light_client_data to existing data dir for the wallet
1 parent 6ac12a1 commit afc2f9d

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/handlers.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,8 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
697697
};
698698

699699
let mut wallet = new_persisted_wallet(network, &mut persister, &wallet_opts)?;
700-
let blockchain_client = new_blockchain_client(&wallet_opts, &wallet)?;
700+
let blockchain_client =
701+
new_blockchain_client(&wallet_opts, &wallet, Some(database_path))?;
701702

702703
let result = handle_online_wallet_subcommand(
703704
&mut wallet,
@@ -773,7 +774,7 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
773774
let (mut wallet, mut persister) = {
774775
let wallet_name = &wallet_opts.wallet;
775776

776-
let home_dir = prepare_home_dir(cli_opts.datadir)?;
777+
let home_dir = prepare_home_dir(cli_opts.datadir.clone())?;
777778

778779
let database_path = prepare_wallet_db_dir(wallet_name, &home_dir)?;
779780

@@ -791,6 +792,8 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
791792
};
792793
#[cfg(not(any(feature = "sqlite")))]
793794
let mut wallet = new_wallet(network, &wallet_opts)?;
795+
let home_dir = prepare_home_dir(cli_opts.datadir.clone())?;
796+
let database_path = prepare_wallet_db_dir(&wallet_opts.wallet, &home_dir)?;
794797

795798
loop {
796799
let line = readline()?;
@@ -799,7 +802,14 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
799802
continue;
800803
}
801804

802-
let result = respond(network, &mut wallet, &wallet_opts, line).await;
805+
let result = respond(
806+
network,
807+
&mut wallet,
808+
&wallet_opts,
809+
line,
810+
Some(database_path.clone()),
811+
)
812+
.await;
803813
#[cfg(feature = "sqlite")]
804814
wallet.persist(&mut persister)?;
805815

@@ -830,6 +840,7 @@ async fn respond(
830840
wallet: &mut Wallet,
831841
wallet_opts: &WalletOpts,
832842
line: &str,
843+
_datadir: Option<std::path::PathBuf>,
833844
) -> Result<bool, String> {
834845
use clap::Parser;
835846

@@ -846,7 +857,7 @@ async fn respond(
846857
subcommand: WalletSubCommand::OnlineWalletSubCommand(online_subcommand),
847858
} => {
848859
let blockchain =
849-
new_blockchain_client(wallet_opts, &wallet).map_err(|e| e.to_string())?;
860+
new_blockchain_client(wallet_opts, &wallet, _datadir).map_err(|e| e.to_string())?;
850861
let value = handle_online_wallet_subcommand(wallet, blockchain, online_subcommand)
851862
.await
852863
.map_err(|e| e.to_string())?;

src/utils.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ pub(crate) enum BlockchainClient {
154154
pub(crate) fn new_blockchain_client(
155155
wallet_opts: &WalletOpts,
156156
wallet: &Wallet,
157+
datadir: Option<std::path::PathBuf>,
157158
) -> Result<BlockchainClient, Error> {
158159
#[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))]
159160
let url = wallet_opts.url.as_str();
@@ -199,7 +200,12 @@ pub(crate) fn new_blockchain_client(
199200
None => Sync,
200201
};
201202

202-
let client = NodeBuilder::new(wallet.network())
203+
let mut builder = NodeBuilder::new(wallet.network());
204+
205+
if let Some(datadir) = datadir {
206+
builder = builder.data_dir(&datadir);
207+
};
208+
let client = builder
203209
.required_peers(wallet_opts.compactfilter_opts.conn_count)
204210
.build_with_wallet(wallet, scan_type)?;
205211

0 commit comments

Comments
 (0)