bitcoind: be less stupid when loading the watchonly wallet
Only load it if isn't there already.
This commit is contained in:
parent
de629cc075
commit
9211d849c1
@ -553,16 +553,15 @@ impl BitcoinD {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 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) {
|
||||
// TODO: check if it's not loaded instead of blindly trying to load it.
|
||||
if let Err(e) = self.make_fallible_node_request(
|
||||
"loadwallet",
|
||||
¶ms!(Json::String(self.watchonly_wallet_path.clone()),),
|
||||
) {
|
||||
log::info!("Got error '{}' while trying to load watchonly on bitcoind. It is possibly already loaded.", e);
|
||||
/// Load the watchonly wallet on bitcoind, if it isn't already.
|
||||
pub fn maybe_load_watchonly_wallet(&self) -> Result<(), BitcoindError> {
|
||||
if !self.list_wallets().contains(&self.watchonly_wallet_path) {
|
||||
self.make_fallible_node_request(
|
||||
"loadwallet",
|
||||
¶ms!(Json::String(self.watchonly_wallet_path.clone()),),
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Perform various sanity checks on the bitcoind instance.
|
||||
|
||||
13
src/lib.rs
13
src/lib.rs
@ -203,7 +203,7 @@ fn setup_bitcoind(
|
||||
bitcoind.create_watchonly_wallet(&config.main_descriptor)?;
|
||||
log::info!("Created a new watchonly wallet on bitcoind.");
|
||||
}
|
||||
bitcoind.try_load_watchonly_wallet();
|
||||
bitcoind.maybe_load_watchonly_wallet()?;
|
||||
bitcoind.sanity_check(&config.main_descriptor, config.bitcoin_config.network)?;
|
||||
log::info!("Connection to bitcoind established and checked.");
|
||||
|
||||
@ -488,12 +488,19 @@ mod tests {
|
||||
|
||||
// Send them a dummy result to loadwallet.
|
||||
fn complete_wallet_loading(server: &net::TcpListener) {
|
||||
let net_resp =
|
||||
let listwallets_resp =
|
||||
"HTTP/1.1 200\n\r\n{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":[]}\n".as_bytes();
|
||||
let (mut stream, _) = server.accept().unwrap();
|
||||
read_til_json_end(&mut stream);
|
||||
stream.write_all(listwallets_resp).unwrap();
|
||||
stream.flush().unwrap();
|
||||
|
||||
let loadwallet_resp =
|
||||
"HTTP/1.1 200\n\r\n{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"name\":\"dummy\"}}\n"
|
||||
.as_bytes();
|
||||
let (mut stream, _) = server.accept().unwrap();
|
||||
read_til_json_end(&mut stream);
|
||||
stream.write_all(net_resp).unwrap();
|
||||
stream.write_all(loadwallet_resp).unwrap();
|
||||
stream.flush().unwrap();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user