Skip to content

Commit

Permalink
Fail Unified QR URI parsing if any known param fails
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tnull committed Jan 3, 2025
1 parent 009257c commit cac705d
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/payment/unified_qr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,22 +256,19 @@ impl<'a> bip21::de::DeserializationState<'a> for DeserializationState {
"lightning" => {
let bolt11_value =
String::try_from(value).map_err(|_| Error::UriParameterParsingFailed)?;
if let Ok(invoice) = bolt11_value.parse::<Bolt11Invoice>() {
self.bolt11_invoice = Some(invoice);
Ok(bip21::de::ParamKind::Known)
} else {
Ok(bip21::de::ParamKind::Unknown)
}
let invoice = bolt11_value
.parse::<Bolt11Invoice>()
.map_err(|_| Error::UriParameterParsingFailed)?;
self.bolt11_invoice = Some(invoice);
Ok(bip21::de::ParamKind::Known)
},
"lno" => {
let bolt12_value =
String::try_from(value).map_err(|_| Error::UriParameterParsingFailed)?;
if let Ok(offer) = bolt12_value.parse::<Offer>() {
self.bolt12_offer = Some(offer);
Ok(bip21::de::ParamKind::Known)
} else {
Ok(bip21::de::ParamKind::Unknown)
}
let offer =
bolt12_value.parse::<Offer>().map_err(|_| Error::UriParameterParsingFailed)?;
self.bolt12_offer = Some(offer);
Ok(bip21::de::ParamKind::Known)
},
_ => Ok(bip21::de::ParamKind::Unknown),
}
Expand Down

0 comments on commit cac705d

Please sign in to comment.