From cea72d8a63a247c8bcba39ecd487731d045d75eb Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Mon, 25 Jul 2022 16:01:04 +0200 Subject: [PATCH] bitcoind: don't try to match bitcoind's error string when loading wallet The functional tests uncovered another error. And trying to pattern match any error is brittle. Just explicitly let anything through. --- src/bitcoin/d/mod.rs | 23 +++++------------------ src/lib.rs | 2 +- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/bitcoin/d/mod.rs b/src/bitcoin/d/mod.rs index ba2653d9..a1e3d6ad 100644 --- a/src/bitcoin/d/mod.rs +++ b/src/bitcoin/d/mod.rs @@ -418,27 +418,14 @@ impl BitcoinD { Ok(()) } - pub fn maybe_load_watchonly_wallet(&self) -> Result<(), BitcoindError> { - match self.make_fallible_node_request( + /// Try to load the watchonly wallet in bitcoind. It will continue on error (since it's + /// likely the wallet is just already loaded) and log it as info instead. + pub fn try_load_watchonly_wallet(&self) { + if let Err(e) = self.make_fallible_node_request( "loadwallet", ¶ms!(Json::String(self.watchonly_wallet_path.clone()),), ) { - Err(e) => { - if e.to_string().contains("is already loaded") { - Ok(()) - } else { - Err(e) - } - } - Ok(res) => { - if let Some(warning) = res.get("warning").map(Json::as_str).flatten() { - Err(BitcoindError::WalletLoading(warning.to_string())) - } else if res.get("name").is_none() { - Err(BitcoindError::WalletLoading(res.to_string())) - } else { - Ok(()) - } - } + log::info!("Got error '{}' while trying to load watchonly on bitcoind. It is possibly already loaded.", e); } } diff --git a/src/lib.rs b/src/lib.rs index a4c6618a..6a2fccb6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -171,7 +171,7 @@ impl DaemonHandle { bitcoind.create_watchonly_wallet(&config.main_descriptor)?; log::info!("Created a new watchonly wallet on bitcoind."); } - bitcoind.maybe_load_watchonly_wallet()?; + bitcoind.try_load_watchonly_wallet(); bitcoind.sanity_check(&config.main_descriptor, config.bitcoind_config.network)?; bitcoind.with_retry_limit(None); log::info!("Connection to bitcoind established and checked.");