Skip to content

Commit

Permalink
improve error on empty string invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
JssDWt committed Nov 3, 2023
1 parent 5adbfac commit 7615a05
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libs/sdk-core/src/invoice.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::anyhow;
use bitcoin::secp256k1::{self, PublicKey};
use hex::ToHex;
use lightning::routing::gossip::RoutingFees;
Expand Down Expand Up @@ -189,6 +190,11 @@ pub fn add_lsp_routing_hints(

/// Parse a BOLT11 payment request and return a structure contains the parsed fields.
pub fn parse_invoice(bolt11: &str) -> InvoiceResult<LNInvoice> {
if bolt11.trim().is_empty() {
return Err(InvoiceError::Validation(anyhow!(
"bolt11 is an empty string"
)));
}
let re = Regex::new(r"(?i)^lightning:")?;
let bolt11 = re.replace_all(bolt11, "");
let signed = bolt11.parse::<SignedRawInvoice>()?;
Expand Down

0 comments on commit 7615a05

Please sign in to comment.