From 702363ea01bbcaaae9b7864312f87e112a1a1649 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Thu, 21 Nov 2024 14:19:37 -0800 Subject: [PATCH 1/4] Wait for wallet to load --- src/wallet/wallet_constructor.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet_constructor.rs b/src/wallet/wallet_constructor.rs index d9d60fce5a..032ecf68f1 100644 --- a/src/wallet/wallet_constructor.rs +++ b/src/wallet/wallet_constructor.rs @@ -52,7 +52,29 @@ impl WalletConstructor { Wallet::check_version(self.settings.bitcoin_rpc_client(Some(self.name.clone()))?)?; if !client.list_wallets()?.contains(&self.name) { - client.load_wallet(&self.name)?; + loop { + match client.load_wallet(&self.name) { + Ok(_) => { + break; + } + Err(bitcoincore_rpc::Error::JsonRpc(bitcoincore_rpc::jsonrpc::Error::Rpc(err))) + if err.code == -4 => + { + // wallet loading + thread::sleep(Duration::from_secs(3)); + continue; + } + Err(bitcoincore_rpc::Error::JsonRpc(bitcoincore_rpc::jsonrpc::Error::Rpc(err))) + if err.code == -35 => + { + // wallet already loaded + break; + } + Err(err) => { + bail!("Failed to load wallet {}: {err}", self.name); + } + } + } } if client.get_wallet_info()?.private_keys_enabled { From a8a4b8eea950780c04be58614dd8bc6b1575b7a8 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Thu, 21 Nov 2024 14:32:09 -0800 Subject: [PATCH 2/4] Same for wallet create --- src/wallet.rs | 31 ++++++++++++++++++++++++++++--- src/wallet/wallet_constructor.rs | 2 +- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/wallet.rs b/src/wallet.rs index 2387d45838..243f786e18 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -555,9 +555,34 @@ impl Wallet { }); } - settings - .bitcoin_rpc_client(Some(name.clone()))? - .call::("importdescriptors", &[serde_json::to_value(descriptors)?])?; + loop { + match settings + .bitcoin_rpc_client(Some(name.clone()))? + .call::( + "importdescriptors", + &[serde_json::to_value(descriptors.clone())?], + ) { + Ok(_) => { + break; + } + Err(bitcoincore_rpc::Error::JsonRpc(bitcoincore_rpc::jsonrpc::Error::Rpc(err))) + if err.code == -4 && err.message == "Wallet already loading." => + { + // wallet loading + thread::sleep(Duration::from_secs(3)); + continue; + } + Err(bitcoincore_rpc::Error::JsonRpc(bitcoincore_rpc::jsonrpc::Error::Rpc(err))) + if err.code == -35 => + { + // wallet already loaded + break; + } + Err(err) => { + bail!("Failed to import descriptors for wallet {}: {err}", name); + } + } + } Ok(()) } diff --git a/src/wallet/wallet_constructor.rs b/src/wallet/wallet_constructor.rs index 032ecf68f1..cdc559cda8 100644 --- a/src/wallet/wallet_constructor.rs +++ b/src/wallet/wallet_constructor.rs @@ -58,7 +58,7 @@ impl WalletConstructor { break; } Err(bitcoincore_rpc::Error::JsonRpc(bitcoincore_rpc::jsonrpc::Error::Rpc(err))) - if err.code == -4 => + if err.code == -4 && err.message == "Wallet already loading." => { // wallet loading thread::sleep(Duration::from_secs(3)); From e04ead916d0a58600f1d91834b0d399ae90133c8 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Tue, 10 Dec 2024 16:51:36 -0500 Subject: [PATCH 3/4] Amend --- src/wallet.rs | 49 +++++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/src/wallet.rs b/src/wallet.rs index 00fe1622a1..2b4cf7685b 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -555,36 +555,29 @@ impl Wallet { }); } - loop { - match settings - .bitcoin_rpc_client(Some(name.clone()))? - .call::( - "importdescriptors", - &[serde_json::to_value(descriptors.clone())?], - ) { - Ok(_) => { - break; - } - Err(bitcoincore_rpc::Error::JsonRpc(bitcoincore_rpc::jsonrpc::Error::Rpc(err))) - if err.code == -4 && err.message == "Wallet already loading." => - { - // wallet loading - thread::sleep(Duration::from_secs(3)); - continue; - } - Err(bitcoincore_rpc::Error::JsonRpc(bitcoincore_rpc::jsonrpc::Error::Rpc(err))) - if err.code == -35 => - { - // wallet already loaded - break; - } - Err(err) => { - bail!("Failed to import descriptors for wallet {}: {err}", name); - } + match settings + .bitcoin_rpc_client(Some(name.clone()))? + .call::( + "importdescriptors", + &[serde_json::to_value(descriptors.clone())?], + ) { + Ok(_) => Ok(()), + Err(bitcoincore_rpc::Error::JsonRpc(bitcoincore_rpc::jsonrpc::Error::Rpc(err))) + if err.code == -4 && err.message == "Wallet already loading." => + { + // wallet loading + Ok(()) + } + Err(bitcoincore_rpc::Error::JsonRpc(bitcoincore_rpc::jsonrpc::Error::Rpc(err))) + if err.code == -35 => + { + // wallet already loaded + Ok(()) + } + Err(err) => { + bail!("Failed to import descriptors for wallet {}: {err}", name) } } - - Ok(()) } pub(crate) fn check_version(client: Client) -> Result { From 2fbe1983a1828702408b20068cfd35680028b8ad Mon Sep 17 00:00:00 2001 From: raphjaph Date: Wed, 11 Dec 2024 18:57:36 -0500 Subject: [PATCH 4/4] Amend --- src/wallet/wallet_constructor.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/wallet_constructor.rs b/src/wallet/wallet_constructor.rs index cdc559cda8..0319fcb9d9 100644 --- a/src/wallet/wallet_constructor.rs +++ b/src/wallet/wallet_constructor.rs @@ -61,6 +61,7 @@ impl WalletConstructor { if err.code == -4 && err.message == "Wallet already loading." => { // wallet loading + eprint!("."); thread::sleep(Duration::from_secs(3)); continue; }