use bdk_wallet::bitcoin::hex::HexToBytesError;
+use bdk_wallet::bitcoin::psbt::ExtractTxError;
use bdk_wallet::bitcoin::{base64, consensus};
use thiserror::Error;
ParseOutPointError(#[from] bdk_wallet::bitcoin::blockdata::transaction::ParseOutPointError),
#[error("PsbtExtractTxError: {0}")]
- PsbtExtractTxError(#[from] bdk_wallet::bitcoin::psbt::ExtractTxError),
+ PsbtExtractTxError(Box<ExtractTxError>),
#[error("PsbtError: {0}")]
PsbtError(#[from] bdk_wallet::bitcoin::psbt::Error),
#[error("BDK-Kyoto error: {0}")]
BuilderError(#[from] bdk_kyoto::builder::BuilderError),
}
+
+impl From<ExtractTxError> for BDKCliError {
+ fn from(value: ExtractTxError) -> Self {
+ BDKCliError::PsbtExtractTxError(Box::new(value))
+ }
+}
#[cfg(any(feature = "electrum", feature = "esplora"))]
use std::collections::HashSet;
use std::convert::TryFrom;
-#[cfg(feature = "repl")]
+#[cfg(any(feature = "repl", feature = "electrum", feature = "esplora"))]
use std::io::Write;
use std::str::FromStr;
while let Some(info) = info_subscriber.recv().await {
match info {
Info::TxGossiped(wtxid) => {
- tracing::info!("Succuessfully broadcast WTXID: {wtxid}");
+ tracing::info!("Successfully broadcast WTXID: {wtxid}");
break;
}
Info::ConnectionsMet => {
subcommand: WalletSubCommand::OnlineWalletSubCommand(online_subcommand),
} => {
let network = cli_opts.network;
+ let home_dir = prepare_home_dir(cli_opts.datadir)?;
+ let wallet_name = &wallet_opts.wallet;
+ let database_path = prepare_wallet_db_dir(wallet_name, &home_dir)?;
#[cfg(feature = "sqlite")]
let result = {
- let home_dir = prepare_home_dir(cli_opts.datadir)?;
- let wallet_name = &wallet_opts.wallet;
- let database_path = prepare_wallet_db_dir(wallet_name, &home_dir)?;
let mut persister = match &wallet_opts.database_type {
#[cfg(feature = "sqlite")]
DatabaseType::Sqlite => {
let mut wallet = new_persisted_wallet(network, &mut persister, &wallet_opts)?;
let blockchain_client =
- new_blockchain_client(&wallet_opts, &wallet, Some(database_path))?;
+ new_blockchain_client(&wallet_opts, &wallet, database_path)?;
let result = handle_online_wallet_subcommand(
&mut wallet,
};
#[cfg(not(any(feature = "sqlite")))]
let result = {
+ let wallet = new_wallet(network, &wallet_opts)?;
+ let blockchain_client =
+ crate::utils::new_blockchain_client(&wallet_opts, &wallet, database_path)?;
let mut wallet = new_wallet(network, &wallet_opts)?;
handle_online_wallet_subcommand(&mut wallet, blockchain_client, online_subcommand)
.await?
&mut wallet,
&wallet_opts,
line,
- Some(database_path.clone()),
+ database_path.clone(),
)
.await;
#[cfg(feature = "sqlite")]
wallet: &mut Wallet,
wallet_opts: &WalletOpts,
line: &str,
- _datadir: Option<std::path::PathBuf>,
+ _datadir: std::path::PathBuf,
) -> Result<bool, String> {
use clap::Parser;
use crate::error::BDKCliError as Error;
use std::str::FromStr;
-#[cfg(feature = "sqlite")]
use std::path::{Path, PathBuf};
use crate::commands::WalletOpts;
Ok(unchecked_address.assume_checked())
}
-#[cfg(feature = "sqlite")]
/// Prepare bdk-cli home directory
///
/// This function is called to check if [`crate::CliOpts`] datadir is set.
/// If not the default home directory is created at `~/.bdk-bitcoin`.
+#[allow(dead_code)]
pub(crate) fn prepare_home_dir(home_path: Option<PathBuf>) -> Result<PathBuf, Error> {
let dir = home_path.unwrap_or_else(|| {
let mut dir = PathBuf::new();
}
/// Prepare wallet database directory.
-#[cfg(feature = "sqlite")]
+#[allow(dead_code)]
pub(crate) fn prepare_wallet_db_dir(
wallet_name: &Option<String>,
home_path: &Path,
-) -> Result<PathBuf, Error> {
+) -> Result<std::path::PathBuf, Error> {
let mut dir = home_path.to_owned();
if let Some(wallet_name) = wallet_name {
dir.push(wallet_name);
/// Create a new blockchain from the wallet configuration options.
pub(crate) fn new_blockchain_client(
wallet_opts: &WalletOpts,
- wallet: &Wallet,
- datadir: Option<std::path::PathBuf>,
+ _wallet: &Wallet,
+ _datadir: PathBuf,
) -> Result<BlockchainClient, Error> {
#[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))]
let url = wallet_opts.url.as_str();
None => Sync,
};
- let mut builder = NodeBuilder::new(wallet.network());
+ let 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)?;
+ .data_dir(&_datadir)
+ .build_with_wallet(_wallet, scan_type)?;
BlockchainClient::KyotoClient { client }
}