Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)?;

Expand All @@ -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()?;
Expand All @@ -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)?;

Expand Down Expand Up @@ -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;

Expand All @@ -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())?;
Expand Down
8 changes: 7 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)?;

Expand Down
Loading