Skip to content

Commit 2a5d1bc

Browse files
committed
Accept RPC responses with a null result
This is actually a valid response in some cases, at least for the `gettxout` command, where `null` is returned if no corresponding UTXO was found, but the command otherwise succeeded.
1 parent 0e8da58 commit 2a5d1bc

File tree

1 file changed

+7
-6
lines changed
  • lightning-block-sync/src

1 file changed

+7
-6
lines changed

lightning-block-sync/src/rpc.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,13 @@ impl RpcClient {
105105
return Err(std::io::Error::new(std::io::ErrorKind::Other, rpc_error));
106106
}
107107

108-
let result = &mut response["result"];
109-
if result.is_null() {
110-
return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "expected JSON result"));
111-
}
108+
let result = match response.get_mut("result") {
109+
Some(result) => result.take(),
110+
None =>
111+
return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "expected JSON result")),
112+
};
112113

113-
JsonResponse(result.take()).try_into()
114+
JsonResponse(result).try_into()
114115
}
115116
}
116117

@@ -205,7 +206,7 @@ mod tests {
205206

206207
#[tokio::test]
207208
async fn call_method_returning_missing_result() {
208-
let response = serde_json::json!({ "result": null });
209+
let response = serde_json::json!({ });
209210
let server = HttpServer::responding_with_ok(MessageBody::Content(response));
210211
let client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
211212

0 commit comments

Comments
 (0)