Skip to content

Commit a2c4884

Browse files
committed
f clean up huge match
1 parent 1cea8e1 commit a2c4884

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

lightning-block-sync/src/convert.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -270,24 +270,18 @@ impl TryInto<GetUtxosResponse> for JsonResponse {
270270
type Error = std::io::Error;
271271

272272
fn try_into(self) -> std::io::Result<GetUtxosResponse> {
273-
match self.0.as_object() {
274-
None => Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "expected an object")),
275-
Some(obj) => match obj.get("bitmap") {
276-
None => Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "missing bitmap field")),
277-
Some(bitmap) => match bitmap.as_str() {
278-
None => Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "bitmap should be an str")),
279-
Some(bitmap_str) => {
280-
let mut hit_bitmap_nonempty = false;
281-
for c in bitmap_str.chars() {
282-
if c < '0' || c > '9' {
283-
return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "invalid byte"));
284-
}
285-
if c > '0' { hit_bitmap_nonempty = true; }
286-
}
287-
Ok(GetUtxosResponse { hit_bitmap_nonempty })
288-
}
273+
let bitmap_str =
274+
self.0.as_object().ok_or(Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "expected an object")))?
275+
.get("bitmap").ok_or(Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "missing bitmap field")))?
276+
.as_str().ok_or(Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "bitmap should be an str")))?;
277+
let mut hit_bitmap_nonempty = false;
278+
for c in bitmap_str.chars() {
279+
if c < '0' || c > '9' {
280+
return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "invalid byte"));
289281
}
282+
if c > '0' { hit_bitmap_nonempty = true; }
290283
}
284+
Ok(GetUtxosResponse { hit_bitmap_nonempty })
291285
}
292286
}
293287
}

0 commit comments

Comments
 (0)