Skip to content

Commit

Permalink
Decode BOLT-12 refund
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-21 committed Dec 18, 2024
1 parent 69037e5 commit e0fdb61
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ async fn main() -> Result<()> {
let findings = invoice_detective.investigate_bolt12(offer)?;
print_findings(findings)
}
DecodedData::Refund(refund) => {
println!("{refund:?}")
}
DecodedData::LnUrl(lnurl) => {
let invoice = resolve_lnurl(lnurl).await?;
println!("Investigating invoice: {invoice}");
Expand Down
7 changes: 6 additions & 1 deletion invoice-detective/src/decoder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::{anyhow, bail, Result};
use lightning::offers::offer::Offer;
use lightning::offers::refund::Refund;
use lightning_invoice::Bolt11Invoice;
use lnurl::lightning_address::LightningAddress;
use lnurl::lnurl::LnUrl;
Expand All @@ -15,6 +16,7 @@ use std::time::Duration;
pub enum DecodedData {
Invoice(Bolt11Invoice),
Offer(Offer),
Refund(Refund),
LightningAddress(LightningAddress),
LnUrl(LnUrl),
}
Expand Down Expand Up @@ -42,13 +44,16 @@ pub fn decode(input: &str) -> Result<DecodedData> {
println!("Decoding as BOLT12 offer");
let offer = Offer::from_str(input).map_err(|e| anyhow!("{e:?}"))?;
DecodedData::Offer(offer)
} else if filtered_input.starts_with("lnr") {
println!("Decoding as BOLT12 refund (naked invoice request)");
let refund = Refund::from_str(input).map_err(|e| anyhow!("{e:?}"))?;
DecodedData::Refund(refund)
} else if input.starts_with("ln") {
println!("Decoding as BOLT11 invoice");
let invoice = input.parse::<Bolt11Invoice>()?;
DecodedData::Invoice(invoice)
} else {
// TODO: Support BIP-21.
// TODO: Support Invoice request (BOLT12 withdraw usecase).
bail!("Input is not recognized");
};
Ok(decoded_data)
Expand Down
3 changes: 2 additions & 1 deletion sample/invoices.csv
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Custodial Consumer Wallet Alby lnbc1431800n1pjcgm4epp5hxr22je783fzcr37d4xp0gn50
tippin.me
Business Wallet lipa for Business LNBC1140N1PJ64FV9PP5C73PHSUA89FAMFEU34NRZCS5QS8WPV303HYGSJJ89LFSN3RD04FQDQL2PSHJGPS9CCRGGZRFPRZQTFQD35HQCGCQZZSXQYZ5VQSP5M6GR4X8389DV3MHLQ9RSNHFZQ4ZVTLH8WTLYQRWPE80PQ9505AQQ9QYYSSQ80HAM8AHTSVTZ8LX5WDYSS4RGNRRQSPZ6Q40USVRTT5EFKT8KGVPZTT0X0KLNPMDP6W2CVELS3T44JZUCPHLN0TU43L7C2GR82KJX2CQNW90TQ
OpenNode
IBEX
IBEX
tryspeed.com,lnbc1pn4uqvzpp52kcwlwpyyvv8kgcd5jeswa75efvga3awf0m0vqzu09nkpcedzgeqdph2pshjmt9de6zqar0yppkjunrd3jjqnmwv5s9xmmxw3mkzun9ypxycsccqzzsxqzjhsp5z3qu3lm3pzmdgvg85kdf55afw4zja4d4uu47q292csa0ahycc6ps9p4gqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpqysgqjazpfcme89uvlxteh90h9cawn7520r56t6da3mfq5nk5hwwkg6xj54ut67gzjn573ugn9d5s0t4p7kurd4jhmmy7tx78wz48v7dj05qq2pyha3

Exchange Binance
Bitfinex
Expand Down
1 change: 1 addition & 0 deletions sample/refunds.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lnr1qqsqzqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqg2qpfqyqlgtqssxkl9a9rcyzt8f2twvrclqdlkzaj5plgqr7sav355wux9dfmsn3pv

0 comments on commit e0fdb61

Please sign in to comment.