From 8164cb930714129cde4d3f671f6f0b82621285c0 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sat, 29 Apr 2023 22:31:24 +0000 Subject: [PATCH] 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. --- lightning-block-sync/src/rpc.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lightning-block-sync/src/rpc.rs b/lightning-block-sync/src/rpc.rs index 4c4706cb1..c778279ae 100644 --- a/lightning-block-sync/src/rpc.rs +++ b/lightning-block-sync/src/rpc.rs @@ -105,12 +105,13 @@ impl RpcClient { return Err(std::io::Error::new(std::io::ErrorKind::Other, rpc_error)); } - let result = &mut response["result"]; - if result.is_null() { - return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "expected JSON result")); - } + let result = match response.get_mut("result") { + Some(result) => result.take(), + None => + return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "expected JSON result")), + }; - JsonResponse(result.take()).try_into() + JsonResponse(result).try_into() } } @@ -205,7 +206,7 @@ mod tests { #[tokio::test] async fn call_method_returning_missing_result() { - let response = serde_json::json!({ "result": null }); + let response = serde_json::json!({ }); let server = HttpServer::responding_with_ok(MessageBody::Content(response)); let client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap(); -- 2.39.5