Skip to content

Commit 1f7de49

Browse files
committed
Fail Unified QR URI parsing if any known param fails
Previously, we decided to continue parsing any fields if we failed to parse a known (i.e., `lightning` or `lno`) parameter failed to parse. This however just hides the error and is a bit anti-idiomatic even though allowing to use *some* URI fields even in the face of incompatible formats for others. Here we therefore opt to fail parsing the URI if any field fails.
1 parent c16a6e1 commit 1f7de49

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/payment/unified_qr.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,22 +256,19 @@ impl<'a> bip21::de::DeserializationState<'a> for DeserializationState {
256256
"lightning" => {
257257
let bolt11_value =
258258
String::try_from(value).map_err(|_| Error::UriParameterParsingFailed)?;
259-
if let Ok(invoice) = bolt11_value.parse::<Bolt11Invoice>() {
260-
self.bolt11_invoice = Some(invoice);
261-
Ok(bip21::de::ParamKind::Known)
262-
} else {
263-
Ok(bip21::de::ParamKind::Unknown)
264-
}
259+
let invoice = bolt11_value
260+
.parse::<Bolt11Invoice>()
261+
.map_err(|_| Error::UriParameterParsingFailed)?;
262+
self.bolt11_invoice = Some(invoice);
263+
Ok(bip21::de::ParamKind::Known)
265264
},
266265
"lno" => {
267266
let bolt12_value =
268267
String::try_from(value).map_err(|_| Error::UriParameterParsingFailed)?;
269-
if let Ok(offer) = bolt12_value.parse::<Offer>() {
270-
self.bolt12_offer = Some(offer);
271-
Ok(bip21::de::ParamKind::Known)
272-
} else {
273-
Ok(bip21::de::ParamKind::Unknown)
274-
}
268+
let offer =
269+
bolt12_value.parse::<Offer>().map_err(|_| Error::UriParameterParsingFailed)?;
270+
self.bolt12_offer = Some(offer);
271+
Ok(bip21::de::ParamKind::Known)
275272
},
276273
_ => Ok(bip21::de::ParamKind::Unknown),
277274
}

0 commit comments

Comments
 (0)