#[error("Miniscript compiler error: {0}")]
MiniscriptCompilerError(#[from] bdk_wallet::miniscript::policy::compiler::CompilerError),
+ #[cfg(any(feature = "sqlite", feature = "redb"))]
+ #[error("Wallet load error: {0}")]
+ LoadWallet(#[from] bdk_wallet::LoadError),
+
#[error(
"Transaction can weigh up to {weight:#} ({} vB) once signed, over the {:#} ({} vB) \
standard limit, so Bitcoin Core nodes will not relay it",
}
}
+#[cfg(any(feature = "sqlite", feature = "redb"))]
+impl From<bdk_wallet::LoadWithPersistError<BDKCliError>> for BDKCliError {
+ fn from(err: bdk_wallet::LoadWithPersistError<BDKCliError>) -> Self {
+ match err {
+ bdk_wallet::LoadWithPersistError::Persist(e) => e,
+ bdk_wallet::LoadWithPersistError::InvalidChangeSet(e) => e.into(),
+ }
+ }
+}
+
#[cfg(feature = "payjoin")]
impl<ApiErr, StorageErr, ErrorState>
From<payjoin::persist::PersistedError<ApiErr, StorageErr, ErrorState>> for BDKCliError
}
#[cfg(any(feature = "sqlite", feature = "redb"))]
-pub(crate) fn new_persisted_wallet<P: WalletPersister>(
+pub(crate) fn new_persisted_wallet<P>(
network: Network,
persister: &mut P,
wallet_opts: &WalletOpts,
) -> Result<PersistedWallet<P>, Error>
where
- P::Error: std::fmt::Display,
+ P: WalletPersister<Error = Error>,
{
let ext_descriptor = wallet_opts.ext_descriptor.clone();
let int_descriptor = wallet_opts.int_descriptor.clone();
let wallet_opt = wallet_load_params
.check_network(network)
- .load_wallet(persister)
- .map_err(|e| Error::Generic(e.to_string()))?;
+ .load_wallet(persister)?;
let wallet = match wallet_opt {
Some(wallet) => wallet,
Some("preserved-password")
);
}
+
+ #[test]
+ fn test_config_force_rejects_network_change() {
+ let temp_dir = TempDir::new().unwrap();
+ let regtest = BdkCli::new("regtest", Some(temp_dir.path().to_path_buf()));
+ let signet = BdkCli::new("signet", Some(temp_dir.path().to_path_buf()));
+ let wallet_name = "network_wallet";
+ let config_path = temp_dir.path().join("config.toml");
+
+ save_wallet(®test, wallet_name);
+ let before = fs::read_to_string(&config_path).unwrap();
+
+ let desc = signet
+ .cmd("descriptor", &["--type", "tr"])
+ .output()
+ .expect("Command to generate descriptors failed");
+ let desc_values: Value =
+ serde_json::from_slice(&desc.stdout).expect("Invalid JSON from output descriptor");
+ let pub_desc = &desc_values["public_descriptors"];
+
+ let mut command = signet.build_base_cmd();
+ command
+ .arg("wallet")
+ .args(["--wallet", wallet_name])
+ .arg("config")
+ .arg("--force")
+ .args(["--ext-descriptor", pub_desc["external"].as_str().unwrap()])
+ .args(["--int-descriptor", pub_desc["internal"].as_str().unwrap()])
+ .args(["--database-type", "sqlite"]);
+
+ #[cfg(feature = "rpc")]
+ command.args(["--client-type", "rpc", "--url", "http://localhost:18443"]);
+
+ command
+ .assert()
+ .failure()
+ .stderr(predicate::str::contains(
+ "Wallet 'network_wallet' is configured for network 'regtest', and --force cannot change it to 'signet'",
+ ));
+
+ let after = fs::read_to_string(&config_path).unwrap();
+ assert_eq!(
+ before, after,
+ "rejected --force must not change config.toml"
+ );
+ }
+
+ #[test]
+ fn test_config_force_same_network_updates_settings() {
+ let temp_dir = TempDir::new().unwrap();
+ let cli = BdkCli::new("regtest", Some(temp_dir.path().to_path_buf()));
+ let wallet_name = "network_wallet";
+ let config_path = temp_dir.path().join("config.toml");
+
+ save_wallet(&cli, wallet_name);
+ let before = fs::read_to_string(&config_path).unwrap();
+
+ let desc = cli
+ .cmd("descriptor", &["--type", "tr"])
+ .output()
+ .expect("Command to generate descriptors failed");
+ let desc_values: Value =
+ serde_json::from_slice(&desc.stdout).expect("Invalid JSON from output descriptor");
+ let pub_desc = &desc_values["public_descriptors"];
+
+ let mut command = cli.build_base_cmd();
+ command
+ .arg("wallet")
+ .args(["--wallet", wallet_name])
+ .arg("config")
+ .arg("--force")
+ .args(["--ext-descriptor", pub_desc["external"].as_str().unwrap()])
+ .args(["--int-descriptor", pub_desc["internal"].as_str().unwrap()])
+ .args(["--database-type", "sqlite"]);
+
+ #[cfg(feature = "rpc")]
+ command.args(["--client-type", "rpc", "--url", "http://localhost:18443"]);
+
+ command.assert().success();
+
+ let after = fs::read_to_string(&config_path).unwrap();
+ assert_ne!(before, after, "--force should save the new descriptors");
+ assert!(after.contains("network = \"regtest\""));
+ }
}
// SILENT PAYMENTS