Skip to content

Commit 805d075

Browse files
committed
feat(wallet-conf): rebase and merge conflicts
1 parent 2ec0017 commit 805d075

File tree

2 files changed

+41
-19
lines changed

2 files changed

+41
-19
lines changed

src/handlers.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,6 @@ use std::str::FromStr;
6363
#[cfg(any(feature = "redb", feature = "compiler"))]
6464
use std::sync::Arc;
6565

66-
#[cfg(feature = "electrum")]
67-
use crate::utils::BlockchainClient::Electrum;
68-
#[cfg(feature = "cbf")]
69-
use bdk_kyoto::LightClient;
70-
use bdk_wallet::bitcoin::base64::prelude::*;
71-
#[cfg(feature = "cbf")]
72-
use tokio::select;
7366
#[cfg(any(
7467
feature = "electrum",
7568
feature = "esplora",
@@ -864,8 +857,8 @@ pub fn handle_config_subcommand(
864857
) -> Result<String, Error> {
865858
if network == Network::Bitcoin {
866859
eprintln!(
867-
"WARNING: You are configuring a wallet for Bitcoin MAINNET.\n\
868-
This software is experimental and not recommended for use with real funds.\n\
860+
"WARNING: You are configuring a wallet for Bitcoin MAINNET.
861+
This software is experimental and not recommended for use with real funds.
869862
Consider using a testnet for testing purposes. \n"
870863
);
871864
}
@@ -875,18 +868,18 @@ pub fn handle_config_subcommand(
875868

876869
if ext_descriptor.contains("xprv") || ext_descriptor.contains("tprv") {
877870
eprintln!(
878-
"WARNING: Your external descriptor contains PRIVATE KEYS.\n\
879-
Private keys will be saved in PLAINTEXT in the config file.\n\
880-
This is a security risk. Consider using public descriptors instead."
871+
"WARNING: Your external descriptor contains PRIVATE KEYS.
872+
Private keys will be saved in PLAINTEXT in the config file.
873+
This is a security risk. Consider using public descriptors instead.\n"
881874
);
882875
}
883876

884877
if let Some(ref internal_desc) = int_descriptor {
885878
if internal_desc.contains("xprv") || internal_desc.contains("tprv") {
886879
eprintln!(
887-
"WARNING: Your internal descriptor contains PRIVATE KEYS.\n\
888-
Private keys will be saved in PLAINTEXT in the config file.\n\
889-
This is a security risk. Consider using public descriptors instead."
880+
"WARNING: Your internal descriptor contains PRIVATE KEYS.
881+
Private keys will be saved in PLAINTEXT in the config file.
882+
This is a security risk. Consider using public descriptors instead.\n"
890883
);
891884
}
892885
}
@@ -1353,8 +1346,9 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
13531346
}
13541347
};
13551348

1356-
let mut wallet = new_persisted_wallet(network, &mut persister, wallet_opts)?;
1357-
let blockchain_client = new_blockchain_client(wallet_opts, &wallet, database_path)?;
1349+
let mut wallet = new_persisted_wallet(network, &mut persister, &wallet_opts)?;
1350+
let blockchain_client =
1351+
new_blockchain_client(&wallet_opts, &wallet, database_path)?;
13581352

13591353
let result = handle_online_wallet_subcommand(
13601354
&mut wallet,
@@ -1419,10 +1413,10 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
14191413
};
14201414
#[cfg(not(any(feature = "sqlite", feature = "redb")))]
14211415
let result = {
1422-
let mut wallet = new_wallet(network, wallet_opts)?;
1416+
let mut wallet = new_wallet(network, &wallet_opts)?;
14231417
handle_offline_wallet_subcommand(
14241418
&mut wallet,
1425-
wallet_opts,
1419+
&wallet_opts,
14261420
&cli_opts,
14271421
offline_subcommand.clone(),
14281422
)?

src/utils.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,3 +620,31 @@ pub fn format_descriptor_output(result: &Value, pretty: bool) -> Result<String,
620620

621621
Ok(format!("{table}"))
622622
}
623+
624+
pub fn load_wallet_config(
625+
home_dir: &Path,
626+
wallet_name: &str,
627+
) -> Result<(WalletOpts, Network), Error> {
628+
let config = WalletConfig::load(home_dir)?.ok_or(Error::Generic(format!(
629+
"No config found for wallet {wallet_name}",
630+
)))?;
631+
632+
let wallet_opts = config.get_wallet_opts(wallet_name)?;
633+
let wallet_config = config
634+
.wallets
635+
.get(wallet_name)
636+
.ok_or(Error::Generic(format!(
637+
"Wallet '{wallet_name}' not found in config"
638+
)))?;
639+
640+
let network = match wallet_config.network.as_str() {
641+
"bitcoin" => Ok(Network::Bitcoin),
642+
"testnet" => Ok(Network::Testnet),
643+
"regtest" => Ok(Network::Regtest),
644+
"signet" => Ok(Network::Signet),
645+
"testnet4" => Ok(Network::Testnet4),
646+
_ => Err(Error::Generic("Invalid network in config".to_string())),
647+
}?;
648+
649+
Ok((wallet_opts, network))
650+
}

0 commit comments

Comments
 (0)