@@ -134,17 +134,16 @@ impl HTTPHrnResolver {
134134 resolve_proof ( & dns_name, proof)
135135 }
136136
137- async fn resolve_lnurl ( & self , hrn : & HumanReadableName ) -> Result < HrnResolution , & ' static str > {
138- let init_url = format ! ( "https://{}/.well-known/lnurlp/{}" , hrn. domain( ) , hrn. user( ) ) ;
137+ async fn resolve_lnurl_impl ( & self , lnurl_url : & str ) -> Result < HrnResolution , & ' static str > {
139138 let err = "Failed to fetch LN-Address initial well-known endpoint" ;
140139 let init: LNURLInitResponse =
141- reqwest:: get ( init_url ) . await . map_err ( |_| err) ?. json ( ) . await . map_err ( |_| err) ?;
140+ reqwest:: get ( lnurl_url ) . await . map_err ( |_| err) ?. json ( ) . await . map_err ( |_| err) ?;
142141
143142 if init. tag != "payRequest" {
144- return Err ( "LNURL initial init_responseponse had an incorrect tag value" ) ;
143+ return Err ( "LNURL initial init_response had an incorrect tag value" ) ;
145144 }
146145 if init. min_sendable > init. max_sendable {
147- return Err ( "LNURL initial init_responseponse had no sendable amounts" ) ;
146+ return Err ( "LNURL initial init_response had no sendable amounts" ) ;
148147 }
149148
150149 let err = "LNURL metadata was not in the correct format" ;
@@ -176,14 +175,20 @@ impl HrnResolver for HTTPHrnResolver {
176175 Err ( e) if e == DNS_ERR => {
177176 // If we got an error that might indicate the recipient doesn't support BIP
178177 // 353, try LN-Address via LNURL
179- self . resolve_lnurl ( hrn) . await
178+ let init_url =
179+ format ! ( "https://{}/.well-known/lnurlp/{}" , hrn. domain( ) , hrn. user( ) ) ;
180+ self . resolve_lnurl ( & init_url) . await
180181 } ,
181182 Err ( e) => Err ( e) ,
182183 }
183184 } )
184185 }
185186
186- fn resolve_lnurl < ' a > (
187+ fn resolve_lnurl < ' a > ( & ' a self , url : & ' a str ) -> HrnResolutionFuture < ' a > {
188+ Box :: pin ( async move { self . resolve_lnurl_impl ( url) . await } )
189+ }
190+
191+ fn resolve_lnurl_to_invoice < ' a > (
187192 & ' a self , mut callback : String , amt : Amount , expected_description_hash : [ u8 ; 32 ] ,
188193 ) -> LNURLResolutionFuture < ' a > {
189194 Box :: pin ( async move {
@@ -308,7 +313,8 @@ mod tests {
308313 . unwrap ( ) ;
309314
310315 let resolved = if let PaymentInstructions :: ConfigurableAmount ( instr) = instructions {
311- // min_amt and max_amt may or may not be set by the LNURL server
316+ assert ! ( instr. min_amt( ) . is_some( ) ) ;
317+ assert ! ( instr. max_amt( ) . is_some( ) ) ;
312318
313319 assert_eq ! ( instr. pop_callback( ) , None ) ;
314320 assert ! ( instr. bip_353_dnssec_proof( ) . is_none( ) ) ;
@@ -339,4 +345,42 @@ mod tests {
339345 }
340346 }
341347 }
348+
349+ #[ tokio:: test]
350+ async fn test_http_lnurl_resolver ( ) {
351+ let instructions = PaymentInstructions :: parse (
352+ // lnurl encoding for [email protected] 353+ "lnurl1dp68gurn8ghj7cnfw33k76tw9ehxjmn2vyhjuam9d3kz66mwdamkutmvde6hymrs9akxuatjd36x2um5ahcq39" ,
354+ Network :: Bitcoin ,
355+ & HTTPHrnResolver ,
356+ true ,
357+ )
358+ . await
359+ . unwrap ( ) ;
360+
361+ let resolved = if let PaymentInstructions :: ConfigurableAmount ( instr) = instructions {
362+ assert ! ( instr. min_amt( ) . is_some( ) ) ;
363+ assert ! ( instr. max_amt( ) . is_some( ) ) ;
364+
365+ assert_eq ! ( instr. pop_callback( ) , None ) ;
366+ assert ! ( instr. bip_353_dnssec_proof( ) . is_none( ) ) ;
367+
368+ instr. set_amount ( Amount :: from_sats ( 100_000 ) . unwrap ( ) , & HTTPHrnResolver ) . await . unwrap ( )
369+ } else {
370+ panic ! ( ) ;
371+ } ;
372+
373+ assert_eq ! ( resolved. pop_callback( ) , None ) ;
374+ assert ! ( resolved. bip_353_dnssec_proof( ) . is_none( ) ) ;
375+
376+ for method in resolved. methods ( ) {
377+ match method {
378+ PaymentMethod :: LightningBolt11 ( invoice) => {
379+ assert_eq ! ( invoice. amount_milli_satoshis( ) , Some ( 100_000_000 ) ) ;
380+ } ,
381+ PaymentMethod :: LightningBolt12 ( _) => panic ! ( "Should only resolve to BOLT 11" ) ,
382+ PaymentMethod :: OnChain ( _) => panic ! ( "Should only resolve to BOLT 11" ) ,
383+ }
384+ }
385+ }
342386}
0 commit comments