Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for wallet to load #4095

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,34 @@ impl Wallet {
});
}

settings
.bitcoin_rpc_client(Some(name.clone()))?
.call::<serde_json::Value>("importdescriptors", &[serde_json::to_value(descriptors)?])?;
loop {
match settings
.bitcoin_rpc_client(Some(name.clone()))?
.call::<serde_json::Value>(
"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(())
}
Expand Down
24 changes: 23 additions & 1 deletion src/wallet/wallet_constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 && 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 load wallet {}: {err}", self.name);
}
}
}
}

if client.get_wallet_info()?.private_keys_enabled {
Expand Down
Loading