MCPcopy Create free account
hub / github.com/bitcoindevkit/bdk-cli / handle_config_subcommand

Function handle_config_subcommand

src/handlers.rs:748–862  ·  view source on GitHub ↗

Handle wallet config subcommand to create or update config.toml

(
    datadir: &Path,
    network: Network,
    wallet: String,
    wallet_opts: &WalletOpts,
    force: bool,
)

Source from the content-addressed store, hash-verified

746
747/// Handle wallet config subcommand to create or update config.toml
748pub fn handle_config_subcommand(
749 datadir: &Path,
750 network: Network,
751 wallet: String,
752 wallet_opts: &WalletOpts,
753 force: bool,
754) -> Result<String, Error> {
755 if network == Network::Bitcoin {
756 eprintln!(
757 "WARNING: You are configuring a wallet for Bitcoin MAINNET.
758 This software is experimental and not recommended for use with real funds.
759 Consider using a testnet for testing purposes. \n"
760 );
761 }
762
763 let ext_descriptor = wallet_opts.ext_descriptor.clone();
764 let int_descriptor = wallet_opts.int_descriptor.clone();
765
766 if ext_descriptor.contains("xprv") || ext_descriptor.contains("tprv") {
767 eprintln!(
768 "WARNING: Your external descriptor contains PRIVATE KEYS.
769 Private keys will be saved in PLAINTEXT in the config file.
770 This is a security risk. Consider using public descriptors instead.\n"
771 );
772 }
773
774 if let Some(ref internal_desc) = int_descriptor
775 && (internal_desc.contains("xprv") || internal_desc.contains("tprv"))
776 {
777 eprintln!(
778 "WARNING: Your internal descriptor contains PRIVATE KEYS.
779 Private keys will be saved in PLAINTEXT in the config file.
780 This is a security risk. Consider using public descriptors instead.\n"
781 );
782 }
783
784 let mut config = WalletConfig::load(datadir)?.unwrap_or(WalletConfig {
785 wallets: HashMap::new(),
786 });
787
788 if config.wallets.contains_key(&wallet) && !force {
789 return Err(Error::Generic(format!(
790 "Wallet '{wallet}' already exists in config.toml. Use --force to overwrite."
791 )));
792 }
793
794 #[cfg(any(
795 feature = "electrum",
796 feature = "esplora",
797 feature = "rpc",
798 feature = "cbf"
799 ))]
800 let client_type = wallet_opts.client_type.clone();
801 #[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))]
802 let url = &wallet_opts.url.clone();
803 #[cfg(any(feature = "sqlite", feature = "redb"))]
804 let database_type = match wallet_opts.database_type {
805 #[cfg(feature = "sqlite")]

Callers 2

handle_commandFunction · 0.85
respondFunction · 0.85

Calls 1

saveMethod · 0.80

Tested by

no test coverage detected