Merge #498: bitcoind: do not assert presence of 'warning' field in unloadwallet response
0f07361d9b6a9d118360607479ef9f7e5d9278e1 bitcoind: adapt the warning detection with interface breakage in v25 (Antoine Poinsot)
3a82c3a81d2c6f6a726395a8a2fbab462466f3e6 bitcoind: do not assert presence of 'warning' field in unloadwallet response (Antoine Poinsot)
Pull request description:
We should really be less picky in the bitcoind interface... Too many unnecessary assertions.
ACKs for top commit:
darosior:
self-ACK 0f07361d9b6a9d118360607479ef9f7e5d9278e1
Tree-SHA512: 0e85f18caf777da40e8d91b6e834ba629d2c4d4b230b7d3d96f075864cb79670bfa3a48150b96c5bf7ff54a80e424b08117a3de2eb422ffbc9c887d121633796
This commit is contained in:
commit
9490159e7c
@ -446,18 +446,38 @@ impl BitcoinD {
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn unload_wallet(&self, wallet_path: String) -> Option<String> {
|
||||
self.make_node_request("unloadwallet", ¶ms!(Json::String(wallet_path),))
|
||||
.get("warning")
|
||||
.expect("No 'warning' in 'unloadwallet' response?")
|
||||
.as_str()
|
||||
.and_then(|w| {
|
||||
if w.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(w.to_string())
|
||||
// Get a warning from the result of a wallet command. It was modified in v25 so it's a bit
|
||||
// messy...
|
||||
fn warning_from_res(&self, res: &Json) -> Option<String> {
|
||||
// In v24, it's a "warning" field.
|
||||
if let Some(warning) = res.get("warning").and_then(Json::as_str) {
|
||||
if !warning.is_empty() {
|
||||
return Some(warning.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
// In v25 it becomes a "warnings" field...
|
||||
if let Some(warnings) = res.get("warnings").and_then(Json::as_array) {
|
||||
// FIXME: don't drop the other warnings if there are more than one.
|
||||
let first_actual_warning = warnings.iter().find_map(|w| {
|
||||
if let Some(w) = w.as_str() {
|
||||
if !w.is_empty() {
|
||||
return Some(w);
|
||||
}
|
||||
}
|
||||
})
|
||||
None
|
||||
});
|
||||
if let Some(warning) = first_actual_warning {
|
||||
return Some(warning.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn unload_wallet(&self, wallet_path: String) -> Option<String> {
|
||||
let res = self.make_node_request("unloadwallet", ¶ms!(Json::String(wallet_path),));
|
||||
self.warning_from_res(&res)
|
||||
}
|
||||
|
||||
fn create_wallet(&self, wallet_path: String) -> Result<(), String> {
|
||||
@ -472,10 +492,8 @@ impl BitcoinD {
|
||||
)
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
if let Some(warning) = res.get("warning").and_then(Json::as_str) {
|
||||
if !warning.is_empty() {
|
||||
return Err(warning.to_string());
|
||||
}
|
||||
if let Some(warning) = self.warning_from_res(&res) {
|
||||
return Err(warning);
|
||||
}
|
||||
if res.get("name").is_none() {
|
||||
return Err("Unknown error when create watchonly wallet".to_string());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user