Skip to content

Commit 811f614

Browse files
committed
fix(cbf): typo and cbf dir config when sqlite feature disabled
1 parent b04fed2 commit 811f614

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

src/error.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use bdk_wallet::bitcoin::hex::HexToBytesError;
2+
use bdk_wallet::bitcoin::psbt::ExtractTxError;
23
use bdk_wallet::bitcoin::{base64, consensus};
34
use thiserror::Error;
45

@@ -51,7 +52,7 @@ pub enum BDKCliError {
5152
ParseOutPointError(#[from] bdk_wallet::bitcoin::blockdata::transaction::ParseOutPointError),
5253

5354
#[error("PsbtExtractTxError: {0}")]
54-
PsbtExtractTxError(#[from] bdk_wallet::bitcoin::psbt::ExtractTxError),
55+
PsbtExtractTxError(Box<ExtractTxError>),
5556

5657
#[error("PsbtError: {0}")]
5758
PsbtError(#[from] bdk_wallet::bitcoin::psbt::Error),
@@ -90,3 +91,9 @@ pub enum BDKCliError {
9091
#[error("BDK-Kyoto error: {0}")]
9192
BuilderError(#[from] bdk_kyoto::builder::BuilderError),
9293
}
94+
95+
impl From<ExtractTxError> for BDKCliError {
96+
fn from(value: ExtractTxError) -> Self {
97+
BDKCliError::PsbtExtractTxError(Box::new(value))
98+
}
99+
}

src/handlers.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use std::collections::BTreeMap;
4242
#[cfg(any(feature = "electrum", feature = "esplora"))]
4343
use std::collections::HashSet;
4444
use std::convert::TryFrom;
45-
#[cfg(feature = "repl")]
45+
#[cfg(any(feature = "repl", feature = "electrum", feature = "esplora"))]
4646
use std::io::Write;
4747
use std::str::FromStr;
4848

@@ -580,7 +580,7 @@ pub(crate) async fn handle_online_wallet_subcommand(
580580
while let Some(info) = info_subscriber.recv().await {
581581
match info {
582582
Info::TxGossiped(wtxid) => {
583-
tracing::info!("Succuessfully broadcast WTXID: {wtxid}");
583+
tracing::info!("Successfully broadcast WTXID: {wtxid}");
584584
break;
585585
}
586586
Info::ConnectionsMet => {
@@ -745,11 +745,11 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
745745
subcommand: WalletSubCommand::OnlineWalletSubCommand(online_subcommand),
746746
} => {
747747
let network = cli_opts.network;
748+
let home_dir = prepare_home_dir(cli_opts.datadir)?;
749+
let wallet_name = &wallet_opts.wallet;
750+
let database_path = prepare_wallet_db_dir(wallet_name, &home_dir)?;
748751
#[cfg(feature = "sqlite")]
749752
let result = {
750-
let home_dir = prepare_home_dir(cli_opts.datadir)?;
751-
let wallet_name = &wallet_opts.wallet;
752-
let database_path = prepare_wallet_db_dir(wallet_name, &home_dir)?;
753753
let mut persister = match &wallet_opts.database_type {
754754
#[cfg(feature = "sqlite")]
755755
DatabaseType::Sqlite => {
@@ -762,7 +762,7 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
762762

763763
let mut wallet = new_persisted_wallet(network, &mut persister, &wallet_opts)?;
764764
let blockchain_client =
765-
new_blockchain_client(&wallet_opts, &wallet, Some(database_path))?;
765+
new_blockchain_client(&wallet_opts, &wallet, database_path)?;
766766

767767
let result = handle_online_wallet_subcommand(
768768
&mut wallet,
@@ -775,6 +775,9 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
775775
};
776776
#[cfg(not(any(feature = "sqlite")))]
777777
let result = {
778+
let wallet = new_wallet(network, &wallet_opts)?;
779+
let blockchain_client =
780+
crate::utils::new_blockchain_client(&wallet_opts, &wallet, database_path)?;
778781
let mut wallet = new_wallet(network, &wallet_opts)?;
779782
handle_online_wallet_subcommand(&mut wallet, blockchain_client, online_subcommand)
780783
.await?
@@ -871,7 +874,7 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
871874
&mut wallet,
872875
&wallet_opts,
873876
line,
874-
Some(database_path.clone()),
877+
database_path.clone(),
875878
)
876879
.await;
877880
#[cfg(feature = "sqlite")]
@@ -904,7 +907,7 @@ async fn respond(
904907
wallet: &mut Wallet,
905908
wallet_opts: &WalletOpts,
906909
line: &str,
907-
_datadir: Option<std::path::PathBuf>,
910+
_datadir: std::path::PathBuf,
908911
) -> Result<bool, String> {
909912
use clap::Parser;
910913

src/utils.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use crate::error::BDKCliError as Error;
1313
use std::str::FromStr;
1414

15-
#[cfg(feature = "sqlite")]
1615
use std::path::{Path, PathBuf};
1716

1817
use crate::commands::WalletOpts;
@@ -76,11 +75,11 @@ pub(crate) fn parse_address(address_str: &str) -> Result<Address, Error> {
7675
Ok(unchecked_address.assume_checked())
7776
}
7877

79-
#[cfg(feature = "sqlite")]
8078
/// Prepare bdk-cli home directory
8179
///
8280
/// This function is called to check if [`crate::CliOpts`] datadir is set.
8381
/// If not the default home directory is created at `~/.bdk-bitcoin`.
82+
#[allow(dead_code)]
8483
pub(crate) fn prepare_home_dir(home_path: Option<PathBuf>) -> Result<PathBuf, Error> {
8584
let dir = home_path.unwrap_or_else(|| {
8685
let mut dir = PathBuf::new();
@@ -101,11 +100,11 @@ pub(crate) fn prepare_home_dir(home_path: Option<PathBuf>) -> Result<PathBuf, Er
101100
}
102101

103102
/// Prepare wallet database directory.
104-
#[cfg(feature = "sqlite")]
103+
#[allow(dead_code)]
105104
pub(crate) fn prepare_wallet_db_dir(
106105
wallet_name: &Option<String>,
107106
home_path: &Path,
108-
) -> Result<PathBuf, Error> {
107+
) -> Result<std::path::PathBuf, Error> {
109108
let mut dir = home_path.to_owned();
110109
if let Some(wallet_name) = wallet_name {
111110
dir.push(wallet_name);
@@ -153,8 +152,8 @@ pub(crate) enum BlockchainClient {
153152
/// Create a new blockchain from the wallet configuration options.
154153
pub(crate) fn new_blockchain_client(
155154
wallet_opts: &WalletOpts,
156-
wallet: &Wallet,
157-
datadir: Option<std::path::PathBuf>,
155+
_wallet: &Wallet,
156+
_datadir: PathBuf,
158157
) -> Result<BlockchainClient, Error> {
159158
#[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))]
160159
let url = wallet_opts.url.as_str();
@@ -200,14 +199,12 @@ pub(crate) fn new_blockchain_client(
200199
None => Sync,
201200
};
202201

203-
let mut builder = NodeBuilder::new(wallet.network());
202+
let builder = NodeBuilder::new(_wallet.network());
204203

205-
if let Some(datadir) = datadir {
206-
builder = builder.data_dir(&datadir);
207-
};
208204
let client = builder
209205
.required_peers(wallet_opts.compactfilter_opts.conn_count)
210-
.build_with_wallet(wallet, scan_type)?;
206+
.data_dir(&_datadir)
207+
.build_with_wallet(_wallet, scan_type)?;
211208

212209
BlockchainClient::KyotoClient { client }
213210
}

0 commit comments

Comments
 (0)