From e0fdb61f94525e963dbe68deb085060559575753 Mon Sep 17 00:00:00 2001 From: Andrei Date: Wed, 18 Dec 2024 00:00:00 +0000 Subject: [PATCH] Decode BOLT-12 refund --- cli/src/main.rs | 3 +++ invoice-detective/src/decoder.rs | 7 ++++++- sample/invoices.csv | 3 ++- sample/refunds.csv | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 sample/refunds.csv diff --git a/cli/src/main.rs b/cli/src/main.rs index 991b7a3..2ecf870 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -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}"); diff --git a/invoice-detective/src/decoder.rs b/invoice-detective/src/decoder.rs index 417c49b..f3ede6a 100644 --- a/invoice-detective/src/decoder.rs +++ b/invoice-detective/src/decoder.rs @@ -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; @@ -15,6 +16,7 @@ use std::time::Duration; pub enum DecodedData { Invoice(Bolt11Invoice), Offer(Offer), + Refund(Refund), LightningAddress(LightningAddress), LnUrl(LnUrl), } @@ -42,13 +44,16 @@ pub fn decode(input: &str) -> Result { 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::()?; DecodedData::Invoice(invoice) } else { // TODO: Support BIP-21. - // TODO: Support Invoice request (BOLT12 withdraw usecase). bail!("Input is not recognized"); }; Ok(decoded_data) diff --git a/sample/invoices.csv b/sample/invoices.csv index debaaa3..19d9b83 100644 --- a/sample/invoices.csv +++ b/sample/invoices.csv @@ -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 diff --git a/sample/refunds.csv b/sample/refunds.csv new file mode 100644 index 0000000..85b7d1e --- /dev/null +++ b/sample/refunds.csv @@ -0,0 +1 @@ +lnr1qqsqzqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqg2qpfqyqlgtqssxkl9a9rcyzt8f2twvrclqdlkzaj5plgqr7sav355wux9dfmsn3pv