ldk_node/payment/
unified_qr.rs

1// This file is Copyright its original authors, visible in version control history.
2//
3// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
6// accordance with one or both of these licenses.
7
8//! Holds a payment handler allowing to create [BIP 21] URIs with an on-chain, [BOLT 11], and [BOLT 12] payment
9//! options.
10//!
11//! [BIP 21]: https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki
12//! [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
13//! [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
14use crate::error::Error;
15use crate::logger::{log_error, LdkLogger, Logger};
16use crate::payment::{bolt11::maybe_wrap_invoice, Bolt11Payment, Bolt12Payment, OnchainPayment};
17use crate::Config;
18
19use lightning::ln::channelmanager::PaymentId;
20use lightning::offers::offer::Offer;
21use lightning_invoice::{Bolt11Invoice, Bolt11InvoiceDescription, Description};
22
23use bip21::de::ParamKind;
24use bip21::{DeserializationError, DeserializeParams, Param, SerializeParams};
25use bitcoin::address::{NetworkChecked, NetworkUnchecked};
26use bitcoin::{Amount, Txid};
27
28use std::sync::Arc;
29use std::vec::IntoIter;
30
31type Uri<'a> = bip21::Uri<'a, NetworkChecked, Extras>;
32
33#[derive(Debug, Clone)]
34struct Extras {
35	bolt11_invoice: Option<Bolt11Invoice>,
36	bolt12_offer: Option<Offer>,
37}
38
39/// A payment handler allowing to create [BIP 21] URIs with an on-chain, [BOLT 11], and [BOLT 12] payment
40/// option.
41///
42/// Should be retrieved by calling [`Node::unified_qr_payment`]
43///
44/// [BIP 21]: https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki
45/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
46/// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
47/// [`Node::unified_qr_payment`]: crate::Node::unified_qr_payment
48pub struct UnifiedQrPayment {
49	onchain_payment: Arc<OnchainPayment>,
50	bolt11_invoice: Arc<Bolt11Payment>,
51	bolt12_payment: Arc<Bolt12Payment>,
52	config: Arc<Config>,
53	logger: Arc<Logger>,
54}
55
56impl UnifiedQrPayment {
57	pub(crate) fn new(
58		onchain_payment: Arc<OnchainPayment>, bolt11_invoice: Arc<Bolt11Payment>,
59		bolt12_payment: Arc<Bolt12Payment>, config: Arc<Config>, logger: Arc<Logger>,
60	) -> Self {
61		Self { onchain_payment, bolt11_invoice, bolt12_payment, config, logger }
62	}
63
64	/// Generates a URI with an on-chain address, [BOLT 11] invoice and [BOLT 12] offer.
65	///
66	/// The URI allows users to send the payment request allowing the wallet to decide
67	/// which payment method to use. This enables a fallback mechanism: older wallets
68	/// can always pay using the provided on-chain address, while newer wallets will
69	/// typically opt to use the provided BOLT11 invoice or BOLT12 offer.
70	///
71	/// The URI will always include an on-chain address. A BOLT11 invoice will be included
72	/// unless invoice generation fails, while a BOLT12 offer will only be included when
73	/// the node has suitable channels for routing.
74	///
75	/// # Parameters
76	/// - `amount_sats`: The amount to be received, specified in satoshis.
77	/// - `description`: A description or note associated with the payment.
78	///   This message is visible to the payer and can provide context or details about the payment.
79	/// - `expiry_sec`: The expiration time for the payment, specified in seconds.
80	///
81	/// Returns a payable URI that can be used to request and receive a payment of the amount
82	/// given. Failure to generate the on-chain address will result in an error return
83	/// (`Error::WalletOperationFailed`), while failures in invoice or offer generation will
84	/// result in those components being omitted from the URI.
85	///
86	/// The generated URI can then be given to a QR code library.
87	///
88	/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
89	/// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
90	pub fn receive(
91		&self, amount_sats: u64, description: &str, expiry_sec: u32,
92	) -> Result<String, Error> {
93		let onchain_address = self.onchain_payment.new_address()?;
94
95		let amount_msats = amount_sats * 1_000;
96
97		let bolt12_offer = match self.bolt12_payment.receive(amount_msats, description, None, None)
98		{
99			Ok(offer) => Some(offer),
100			Err(e) => {
101				log_error!(self.logger, "Failed to create offer: {}", e);
102				None
103			},
104		};
105
106		let invoice_description = Bolt11InvoiceDescription::Direct(
107			Description::new(description.to_string()).map_err(|_| Error::InvoiceCreationFailed)?,
108		);
109		let bolt11_invoice = match self.bolt11_invoice.receive_inner(
110			Some(amount_msats),
111			&invoice_description,
112			expiry_sec,
113			None,
114		) {
115			Ok(invoice) => Some(invoice),
116			Err(e) => {
117				log_error!(self.logger, "Failed to create invoice {}", e);
118				None
119			},
120		};
121
122		let extras = Extras { bolt11_invoice, bolt12_offer };
123
124		let mut uri = Uri::with_extras(onchain_address, extras);
125		uri.amount = Some(Amount::from_sat(amount_sats));
126		uri.message = Some(description.into());
127
128		Ok(format_uri(uri))
129	}
130
131	/// Sends a payment given a [BIP 21] URI.
132	///
133	/// This method parses the provided URI string and attempts to send the payment. If the URI
134	/// has an offer and or invoice, it will try to pay the offer first followed by the invoice.
135	/// If they both fail, the on-chain payment will be paid.
136	///
137	/// Returns a `QrPaymentResult` indicating the outcome of the payment. If an error
138	/// occurs, an `Error` is returned detailing the issue encountered.
139	///
140	/// [BIP 21]: https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki
141	pub fn send(&self, uri_str: &str) -> Result<QrPaymentResult, Error> {
142		let uri: bip21::Uri<NetworkUnchecked, Extras> =
143			uri_str.parse().map_err(|_| Error::InvalidUri)?;
144
145		let uri_network_checked =
146			uri.clone().require_network(self.config.network).map_err(|_| Error::InvalidNetwork)?;
147
148		if let Some(offer) = uri_network_checked.extras.bolt12_offer {
149			match self.bolt12_payment.send(&offer, None, None) {
150				Ok(payment_id) => return Ok(QrPaymentResult::Bolt12 { payment_id }),
151				Err(e) => log_error!(self.logger, "Failed to send BOLT12 offer: {:?}. This is part of a unified QR code payment. Falling back to the BOLT11 invoice.", e),
152			}
153		}
154
155		if let Some(invoice) = uri_network_checked.extras.bolt11_invoice {
156			let invoice = maybe_wrap_invoice(invoice);
157			match self.bolt11_invoice.send(&invoice, None) {
158				Ok(payment_id) => return Ok(QrPaymentResult::Bolt11 { payment_id }),
159				Err(e) => log_error!(self.logger, "Failed to send BOLT11 invoice: {:?}. This is part of a unified QR code payment. Falling back to the on-chain transaction.", e),
160			}
161		}
162
163		let amount = match uri_network_checked.amount {
164			Some(amount) => amount,
165			None => {
166				log_error!(self.logger, "No amount specified in the URI. Aborting the payment.");
167				return Err(Error::InvalidAmount);
168			},
169		};
170
171		let txid = self.onchain_payment.send_to_address(
172			&uri_network_checked.address,
173			amount.to_sat(),
174			None,
175		)?;
176
177		Ok(QrPaymentResult::Onchain { txid })
178	}
179}
180
181/// Represents the result of a payment made using a [BIP 21] QR code.
182///
183/// After a successful on-chain transaction, the transaction ID ([`Txid`]) is returned.
184/// For BOLT11 and BOLT12 payments, the corresponding [`PaymentId`] is returned.
185///
186/// [BIP 21]: https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki
187/// [`PaymentId`]: lightning::ln::channelmanager::PaymentId
188/// [`Txid`]: bitcoin::hash_types::Txid
189#[derive(Debug)]
190pub enum QrPaymentResult {
191	/// An on-chain payment.
192	Onchain {
193		/// The transaction ID (txid) of the on-chain payment.
194		txid: Txid,
195	},
196	/// A [BOLT 11] payment.
197	///
198	/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
199	Bolt11 {
200		/// The payment ID for the BOLT11 invoice.
201		payment_id: PaymentId,
202	},
203	/// A [BOLT 12] offer payment, i.e., a payment for an [`Offer`].
204	///
205	/// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
206	/// [`Offer`]: crate::lightning::offers::offer::Offer
207	Bolt12 {
208		/// The payment ID for the BOLT12 offer.
209		payment_id: PaymentId,
210	},
211}
212
213fn format_uri(uri: bip21::Uri<NetworkChecked, Extras>) -> String {
214	let mut uri = format!("{:#}", uri);
215
216	fn value_to_uppercase(uri: &mut String, key: &str) {
217		let mut start = 0;
218		while let Some(index) = uri[start..].find(key) {
219			let start_index = start + index;
220			let end_index = uri[start_index..].find('&').map_or(uri.len(), |i| start_index + i);
221			let lightning_value = &uri[start_index + key.len()..end_index];
222			let uppercase_lighting_value = lightning_value.to_uppercase();
223			uri.replace_range(start_index + key.len()..end_index, &uppercase_lighting_value);
224			start = end_index
225		}
226	}
227	value_to_uppercase(&mut uri, "lightning=");
228	value_to_uppercase(&mut uri, "lno=");
229	uri
230}
231
232impl<'a> SerializeParams for &'a Extras {
233	type Key = &'static str;
234	type Value = String;
235	type Iterator = IntoIter<(Self::Key, Self::Value)>;
236
237	fn serialize_params(self) -> Self::Iterator {
238		let mut params = Vec::new();
239
240		if let Some(bolt11_invoice) = &self.bolt11_invoice {
241			params.push(("lightning", bolt11_invoice.to_string()));
242		}
243		if let Some(bolt12_offer) = &self.bolt12_offer {
244			params.push(("lno", bolt12_offer.to_string()));
245		}
246
247		params.into_iter()
248	}
249}
250
251impl<'a> DeserializeParams<'a> for Extras {
252	type DeserializationState = DeserializationState;
253}
254
255#[derive(Default)]
256struct DeserializationState {
257	bolt11_invoice: Option<Bolt11Invoice>,
258	bolt12_offer: Option<Offer>,
259}
260
261impl<'a> bip21::de::DeserializationState<'a> for DeserializationState {
262	type Value = Extras;
263
264	fn is_param_known(&self, key: &str) -> bool {
265		key == "lightning" || key == "lno"
266	}
267
268	fn deserialize_temp(
269		&mut self, key: &str, value: Param<'_>,
270	) -> Result<ParamKind, <Self::Value as DeserializationError>::Error> {
271		match key {
272			"lightning" => {
273				let bolt11_value =
274					String::try_from(value).map_err(|_| Error::UriParameterParsingFailed)?;
275				let invoice = bolt11_value
276					.parse::<Bolt11Invoice>()
277					.map_err(|_| Error::UriParameterParsingFailed)?;
278				self.bolt11_invoice = Some(invoice);
279				Ok(bip21::de::ParamKind::Known)
280			},
281			"lno" => {
282				let bolt12_value =
283					String::try_from(value).map_err(|_| Error::UriParameterParsingFailed)?;
284				let offer =
285					bolt12_value.parse::<Offer>().map_err(|_| Error::UriParameterParsingFailed)?;
286				self.bolt12_offer = Some(offer);
287				Ok(bip21::de::ParamKind::Known)
288			},
289			_ => Ok(bip21::de::ParamKind::Unknown),
290		}
291	}
292
293	fn finalize(self) -> Result<Self::Value, <Self::Value as DeserializationError>::Error> {
294		Ok(Extras { bolt11_invoice: self.bolt11_invoice, bolt12_offer: self.bolt12_offer })
295	}
296}
297
298impl DeserializationError for Extras {
299	type Error = Error;
300}
301
302#[cfg(test)]
303mod tests {
304	use super::*;
305	use crate::payment::unified_qr::Extras;
306	use bitcoin::{Address, Network};
307	use std::str::FromStr;
308
309	#[test]
310	fn parse_uri() {
311		let uri_test1 = "BITCOIN:TB1QRSCD05XNY6QZ63TF9GJELGVK6D3UDJFEKK62VU?amount=1&message=Test%20message&lightning=LNTB1000M1PNXWM7MDQ523JHXAPQD4JHXUMPVAJSNP4QWP9QD2JFP8DUZ46JQG5LTKVDH04YG52G6UF2YAXP8H7YZPZM3DM5PP5KUP7YT429UP9Z4ACPA60R7WETSTL66549MG05P0JN0C4L2NCC40SSP5R0LH86DJCL0NK8HZHNZHX92VVUAAVNE48Z5RVKVY5DKTRQ0DMP7S9QYYSGQCQPCXQRRAQYR59FGN2VVC5R6DS0AZMETH493ZU56H0WSVMGYCW9LEPZ032PGQNZMQ6XKVEH90Z02C0NH3J5QGDAWCS2YC2ZNP22J0ZD0PPF78N4QQQEXTYS2";
312		let expected_bolt11_invoice_1 = "LNTB1000M1PNXWM7MDQ523JHXAPQD4JHXUMPVAJSNP4QWP9QD2JFP8DUZ46JQG5LTKVDH04YG52G6UF2YAXP8H7YZPZM3DM5PP5KUP7YT429UP9Z4ACPA60R7WETSTL66549MG05P0JN0C4L2NCC40SSP5R0LH86DJCL0NK8HZHNZHX92VVUAAVNE48Z5RVKVY5DKTRQ0DMP7S9QYYSGQCQPCXQRRAQYR59FGN2VVC5R6DS0AZMETH493ZU56H0WSVMGYCW9LEPZ032PGQNZMQ6XKVEH90Z02C0NH3J5QGDAWCS2YC2ZNP22J0ZD0PPF78N4QQQEXTYS2";
313		let parsed_uri = uri_test1
314			.parse::<bip21::Uri<NetworkUnchecked, Extras>>()
315			.expect("Failed Parsing")
316			.require_network(Network::Testnet)
317			.expect("Invalid Network");
318
319		assert_eq!(
320			parsed_uri.address,
321			bitcoin::Address::from_str("TB1QRSCD05XNY6QZ63TF9GJELGVK6D3UDJFEKK62VU")
322				.unwrap()
323				.require_network(Network::Testnet)
324				.unwrap()
325		);
326
327		assert_eq!(Amount::from_sat(100_000_000), Amount::from(parsed_uri.amount.unwrap()));
328
329		if let Some(invoice) = parsed_uri.extras.bolt11_invoice {
330			assert_eq!(invoice, Bolt11Invoice::from_str(expected_bolt11_invoice_1).unwrap());
331		} else {
332			panic!("No Lightning invoice found");
333		}
334
335		let uri_with_offer =  "BITCOIN:BCRT1QM0NW9S05QDPGC6F52FPKA9U6Q6VWTT5WVS30R2?amount=0.001&message=asdf&lightning=LNBCRT1M1PNGMY98DQ8V9EKGESNP4QDH5SL00QK4842UZMZVJVX2NLUZT4E6P2ZC2DLAGCU565TP42AUDYPP5XD0PRS5CRDLZVU8DNQQU08W9F4YP0XRXW06ZSHCLCHZU9X28HSSSSP5ES30JG9J4VK2CRW80YXTLRJU2M097TXMFTHR00VC5V0LGKVMURRQ9QYYSGQCQPCXQRRAQRZJQ0Q0K9CDYFSVZAJ5V3PDWYWDMHLEYCVD7TG0SVMY4AM4P6GQZJZ5XQQQQYQQX2QQQUQQQQLGQQQQQQQQFQWDQZX24PSHN68A9D4X4HD89F3XVC7DGGRDTFCA5WH4KZ546GSRTJVACA34QQ3DZ9W4JHLJD3XZRW44RA0RET6RDSRJCEZQC6AXANX6QPHZKHJK&lno=LNO1QGSQVGNWGCG35Z6EE2H3YCZRADDM72XRFUA9UVE2RLRM9DEU7XYFZRCYZPGTGRDWMGU44QPYUXLHLLMLWN4QSPQ97HSSQZSYV9EKGESSWCPK7JRAAUZ6574TSTVFJFSE20LSFWH8G9GTPFHL4RRJN23VX4TH35SRWKCNQ6S8R9ZW9HU5RXMPXVYCJVK2KY3NTEA8VXZTMWJF4NAJCCAQZQ7YZ7KDDZ600LAW2S2E7Q6XDYLPSMLMV4YAY0QXX5NC8QH05JRNUYQPQCAHK8Y5KQ8H9X624LS6A9GWFTGKYYPUZVUKKM93DWETTL8A7NE84L7SNHCSGR006EACQRQP8YWY6WPS0TS";
336		let expected_bolt11_invoice_2 = "LNBCRT1M1PNGMY98DQ8V9EKGESNP4QDH5SL00QK4842UZMZVJVX2NLUZT4E6P2ZC2DLAGCU565TP42AUDYPP5XD0PRS5CRDLZVU8DNQQU08W9F4YP0XRXW06ZSHCLCHZU9X28HSSSSP5ES30JG9J4VK2CRW80YXTLRJU2M097TXMFTHR00VC5V0LGKVMURRQ9QYYSGQCQPCXQRRAQRZJQ0Q0K9CDYFSVZAJ5V3PDWYWDMHLEYCVD7TG0SVMY4AM4P6GQZJZ5XQQQQYQQX2QQQUQQQQLGQQQQQQQQFQWDQZX24PSHN68A9D4X4HD89F3XVC7DGGRDTFCA5WH4KZ546GSRTJVACA34QQ3DZ9W4JHLJD3XZRW44RA0RET6RDSRJCEZQC6AXANX6QPHZKHJK";
337		let expected_bolt12_offer_2 = "LNO1QGSQVGNWGCG35Z6EE2H3YCZRADDM72XRFUA9UVE2RLRM9DEU7XYFZRCYZPGTGRDWMGU44QPYUXLHLLMLWN4QSPQ97HSSQZSYV9EKGESSWCPK7JRAAUZ6574TSTVFJFSE20LSFWH8G9GTPFHL4RRJN23VX4TH35SRWKCNQ6S8R9ZW9HU5RXMPXVYCJVK2KY3NTEA8VXZTMWJF4NAJCCAQZQ7YZ7KDDZ600LAW2S2E7Q6XDYLPSMLMV4YAY0QXX5NC8QH05JRNUYQPQCAHK8Y5KQ8H9X624LS6A9GWFTGKYYPUZVUKKM93DWETTL8A7NE84L7SNHCSGR006EACQRQP8YWY6WPS0TS";
338		let parsed_uri_with_offer = uri_with_offer
339			.parse::<bip21::Uri<NetworkUnchecked, Extras>>()
340			.expect("Failed Parsing")
341			.require_network(Network::Regtest)
342			.expect("Invalid Network");
343
344		assert_eq!(Amount::from_sat(100_000), Amount::from(parsed_uri_with_offer.amount.unwrap()));
345
346		assert_eq!(
347			parsed_uri_with_offer.address,
348			bitcoin::Address::from_str("BCRT1QM0NW9S05QDPGC6F52FPKA9U6Q6VWTT5WVS30R2")
349				.unwrap()
350				.require_network(Network::Regtest)
351				.unwrap()
352		);
353
354		if let Some(invoice) = parsed_uri_with_offer.extras.bolt11_invoice {
355			assert_eq!(invoice, Bolt11Invoice::from_str(expected_bolt11_invoice_2).unwrap());
356		} else {
357			panic!("No invoice found.")
358		}
359
360		if let Some(offer) = parsed_uri_with_offer.extras.bolt12_offer {
361			assert_eq!(offer, Offer::from_str(expected_bolt12_offer_2).unwrap());
362		} else {
363			panic!("No offer found.");
364		}
365
366		let zeus_test = "bitcoin:TB1QQ32G6LM2XKT0U2UGASH5DC4CFT3JTPEW65PZZ5?lightning=LNTB500U1PN89HH6PP5MA7K6DRM5SYVD05NTXMGSRNM728J7EHM8KV6VC96YNLKN7G7VDYQDQQCQZRCXQR8Q7SP5HU30L0EEXKYYPQSQYEZELZWUPT62HLJ0KV2662CALGPAML50QPXQ9QXPQYSGQDKTVFXEC8H2DG2GY3C95ETAJ0QKX50XAUCU304PPFV2SQVGFHZ6RMZWJV8MC3M0LXF3GW852C5VSK0DELK0JHLYUTYZDF7QKNAMT4PQQQN24WM&amount=0.0005";
367		let expected_bolt11_invoice_3 = "LNTB500U1PN89HH6PP5MA7K6DRM5SYVD05NTXMGSRNM728J7EHM8KV6VC96YNLKN7G7VDYQDQQCQZRCXQR8Q7SP5HU30L0EEXKYYPQSQYEZELZWUPT62HLJ0KV2662CALGPAML50QPXQ9QXPQYSGQDKTVFXEC8H2DG2GY3C95ETAJ0QKX50XAUCU304PPFV2SQVGFHZ6RMZWJV8MC3M0LXF3GW852C5VSK0DELK0JHLYUTYZDF7QKNAMT4PQQQN24WM";
368		let uri_test2 = zeus_test
369			.parse::<bip21::Uri<NetworkUnchecked, Extras>>()
370			.expect("Failed Parsing")
371			.require_network(Network::Testnet)
372			.expect("Invalid Network");
373
374		assert_eq!(
375			uri_test2.address,
376			bitcoin::Address::from_str("TB1QQ32G6LM2XKT0U2UGASH5DC4CFT3JTPEW65PZZ5")
377				.unwrap()
378				.require_network(Network::Testnet)
379				.unwrap()
380		);
381
382		if let Some(invoice) = uri_test2.extras.bolt11_invoice {
383			assert_eq!(invoice, Bolt11Invoice::from_str(expected_bolt11_invoice_3).unwrap());
384		} else {
385			panic!("No invoice found.");
386		}
387		assert_eq!(Amount::from(uri_test2.amount.unwrap()), Amount::from_sat(50000));
388
389		let muun_test = "bitcoin:bc1q6fmtam67h8wxfwtpumhazhtwyrh3uf039n058zke9xt5hr4ljzwsdcm2pj?amount=0.01&lightning=lnbc10m1pn8g2j4pp575tg4wt8jwgu2lvtk3aj6hy7mc6tnupw07wwkxcvyhtt3wlzw0zsdqqcqzzgxqyz5vqrzjqwnvuc0u4txn35cafc7w94gxvq5p3cu9dd95f7hlrh0fvs46wpvhdv6dzdeg0ww2eyqqqqryqqqqthqqpysp5fkd3k2rzvwdt2av068p58evf6eg50q0eftfhrpugaxkuyje4d25q9qrsgqqkfmnn67s5g6hadrcvf5h0l7p92rtlkwrfqdvc7uuf6lew0czxksvqhyux3zjrl3tlakwhtvezwl24zshnfumukwh0yntqsng9z6glcquvw7kc";
390		let expected_bolt11_invoice_4 = "lnbc10m1pn8g2j4pp575tg4wt8jwgu2lvtk3aj6hy7mc6tnupw07wwkxcvyhtt3wlzw0zsdqqcqzzgxqyz5vqrzjqwnvuc0u4txn35cafc7w94gxvq5p3cu9dd95f7hlrh0fvs46wpvhdv6dzdeg0ww2eyqqqqryqqqqthqqpysp5fkd3k2rzvwdt2av068p58evf6eg50q0eftfhrpugaxkuyje4d25q9qrsgqqkfmnn67s5g6hadrcvf5h0l7p92rtlkwrfqdvc7uuf6lew0czxksvqhyux3zjrl3tlakwhtvezwl24zshnfumukwh0yntqsng9z6glcquvw7kc";
391		let uri_test3 = muun_test
392			.parse::<bip21::Uri<NetworkUnchecked, Extras>>()
393			.expect("Failed Parsing")
394			.require_network(Network::Bitcoin)
395			.expect("Invalid Network");
396		assert_eq!(
397			uri_test3.address,
398			bitcoin::Address::from_str(
399				"bc1q6fmtam67h8wxfwtpumhazhtwyrh3uf039n058zke9xt5hr4ljzwsdcm2pj"
400			)
401			.unwrap()
402			.require_network(Network::Bitcoin)
403			.unwrap()
404		);
405
406		if let Some(invoice) = uri_test3.extras.bolt11_invoice {
407			assert_eq!(invoice, Bolt11Invoice::from_str(expected_bolt11_invoice_4).unwrap());
408		} else {
409			panic!("No invoice found");
410		}
411		assert_eq!(Amount::from(uri_test3.amount.unwrap()), Amount::from_sat(1_000_000));
412
413		let muun_test_no_amount = "bitcoin:bc1qwe94y974pjl9kg5afg8tmsc0nz4hct04u78hdhukxvnnphgu48hs9lx3k5?lightning=lnbc1pn8g249pp5f6ytj32ty90jhvw69enf30hwfgdhyymjewywcmfjevflg6s4z86qdqqcqzzgxqyz5vqrzjqwnvuc0u4txn35cafc7w94gxvq5p3cu9dd95f7hlrh0fvs46wpvhdfjjzh2j9f7ye5qqqqryqqqqthqqpysp5mm832athgcal3m7h35sc29j63lmgzvwc5smfjh2es65elc2ns7dq9qrsgqu2xcje2gsnjp0wn97aknyd3h58an7sjj6nhcrm40846jxphv47958c6th76whmec8ttr2wmg6sxwchvxmsc00kqrzqcga6lvsf9jtqgqy5yexa";
414		let expected_bolt11_invoice_5 = "lnbc1pn8g249pp5f6ytj32ty90jhvw69enf30hwfgdhyymjewywcmfjevflg6s4z86qdqqcqzzgxqyz5vqrzjqwnvuc0u4txn35cafc7w94gxvq5p3cu9dd95f7hlrh0fvs46wpvhdfjjzh2j9f7ye5qqqqryqqqqthqqpysp5mm832athgcal3m7h35sc29j63lmgzvwc5smfjh2es65elc2ns7dq9qrsgqu2xcje2gsnjp0wn97aknyd3h58an7sjj6nhcrm40846jxphv47958c6th76whmec8ttr2wmg6sxwchvxmsc00kqrzqcga6lvsf9jtqgqy5yexa";
415		let uri_test4 = muun_test_no_amount
416			.parse::<bip21::Uri<NetworkUnchecked, Extras>>()
417			.expect("Failed Parsing")
418			.require_network(Network::Bitcoin)
419			.expect("Invalid Network");
420		assert_eq!(
421			uri_test4.address,
422			Address::from_str("bc1qwe94y974pjl9kg5afg8tmsc0nz4hct04u78hdhukxvnnphgu48hs9lx3k5")
423				.unwrap()
424				.require_network(Network::Bitcoin)
425				.unwrap()
426		);
427		if let Some(invoice) = uri_test4.extras.bolt11_invoice {
428			assert_eq!(invoice, Bolt11Invoice::from_str(expected_bolt11_invoice_5).unwrap());
429		} else {
430			panic!("No invoice found");
431		}
432	}
433}