-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
claddy
committed
Sep 30, 2024
1 parent
f1c232c
commit 4ee02fe
Showing
3 changed files
with
25 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use lightning_invoice::Bolt11Invoice; | ||
use lnurl::{ | ||
lnurl::LnUrl, | ||
Builder, | ||
LnUrlResponse | ||
}; | ||
use std::error::Error; | ||
use std::str::FromStr; | ||
async fn fetch_invoice(lnurl_string: &str, amount_msats: u64) -> Result<String, dyn Error> { | ||
let lnurl = LnUrl::from_str(lnurl_string)?; | ||
let async_client = Builder::default().build_async()?; | ||
let res = async_client.make_request(&lnurl_string).await?; | ||
if let LnUrlResponse::LnUrlPayResponse(pay) = res { | ||
let pay_result = async_client.get_invoice(&pay, amount_msats, None, None).await?; | ||
let invoice = Bolt11Invoice::from_str(&pay_result.invoice())?; | ||
if invoice.amount_milli_satoshis() != Some(amount_msats) { | ||
return Err("Invoice amount doesn't match requested amount".into()); | ||
} | ||
Ok(pay_result.invoice().to_string()) | ||
} else { panic!("Wrong response type"); } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters