Skip to content

Commit a95a621

Browse files
committed
feat(wallet-conf): rebase and merge conflicts
1 parent 18e26c8 commit a95a621

2 files changed

Lines changed: 41 additions & 19 deletions

File tree

src/handlers.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,6 @@ use std::str::FromStr;
6969
))]
7070
use std::sync::Arc;
7171

72-
#[cfg(feature = "electrum")]
73-
use crate::utils::BlockchainClient::Electrum;
74-
#[cfg(feature = "cbf")]
75-
use bdk_kyoto::LightClient;
76-
use bdk_wallet::bitcoin::base64::prelude::*;
77-
#[cfg(feature = "cbf")]
78-
use tokio::select;
7972
#[cfg(any(
8073
feature = "electrum",
8174
feature = "esplora",
@@ -760,8 +753,8 @@ pub fn handle_config_subcommand(
760753
) -> Result<String, Error> {
761754
if network == Network::Bitcoin {
762755
eprintln!(
763-
"WARNING: You are configuring a wallet for Bitcoin MAINNET.\n\
764-
This software is experimental and not recommended for use with real funds.\n\
756+
"WARNING: You are configuring a wallet for Bitcoin MAINNET.
757+
This software is experimental and not recommended for use with real funds.
765758
Consider using a testnet for testing purposes. \n"
766759
);
767760
}
@@ -771,18 +764,18 @@ pub fn handle_config_subcommand(
771764

772765
if ext_descriptor.contains("xprv") || ext_descriptor.contains("tprv") {
773766
eprintln!(
774-
"WARNING: Your external descriptor contains PRIVATE KEYS.\n\
775-
Private keys will be saved in PLAINTEXT in the config file.\n\
776-
This is a security risk. Consider using public descriptors instead."
767+
"WARNING: Your external descriptor contains PRIVATE KEYS.
768+
Private keys will be saved in PLAINTEXT in the config file.
769+
This is a security risk. Consider using public descriptors instead.\n"
777770
);
778771
}
779772

780773
if let Some(ref internal_desc) = int_descriptor {
781774
if internal_desc.contains("xprv") || internal_desc.contains("tprv") {
782775
eprintln!(
783-
"WARNING: Your internal descriptor contains PRIVATE KEYS.\n\
784-
Private keys will be saved in PLAINTEXT in the config file.\n\
785-
This is a security risk. Consider using public descriptors instead."
776+
"WARNING: Your internal descriptor contains PRIVATE KEYS.
777+
Private keys will be saved in PLAINTEXT in the config file.
778+
This is a security risk. Consider using public descriptors instead.\n"
786779
);
787780
}
788781
}
@@ -1249,8 +1242,9 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
12491242
}
12501243
};
12511244

1252-
let mut wallet = new_persisted_wallet(network, &mut persister, wallet_opts)?;
1253-
let blockchain_client = new_blockchain_client(wallet_opts, &wallet, database_path)?;
1245+
let mut wallet = new_persisted_wallet(network, &mut persister, &wallet_opts)?;
1246+
let blockchain_client =
1247+
new_blockchain_client(&wallet_opts, &wallet, database_path)?;
12541248

12551249
let result = handle_online_wallet_subcommand(
12561250
&mut wallet,
@@ -1314,10 +1308,10 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
13141308
};
13151309
#[cfg(not(any(feature = "sqlite", feature = "redb")))]
13161310
let result = {
1317-
let mut wallet = new_wallet(network, wallet_opts)?;
1311+
let mut wallet = new_wallet(network, &wallet_opts)?;
13181312
handle_offline_wallet_subcommand(
13191313
&mut wallet,
1320-
wallet_opts,
1314+
&wallet_opts,
13211315
&cli_opts,
13221316
offline_subcommand.clone(),
13231317
)?

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)