@@ -134,17 +134,16 @@ impl HTTPHrnResolver {
134
134
resolve_proof ( & dns_name, proof)
135
135
}
136
136
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 > {
139
138
let err = "Failed to fetch LN-Address initial well-known endpoint" ;
140
139
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) ?;
142
141
143
142
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" ) ;
145
144
}
146
145
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" ) ;
148
147
}
149
148
150
149
let err = "LNURL metadata was not in the correct format" ;
@@ -176,14 +175,20 @@ impl HrnResolver for HTTPHrnResolver {
176
175
Err ( e) if e == DNS_ERR => {
177
176
// If we got an error that might indicate the recipient doesn't support BIP
178
177
// 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
180
181
} ,
181
182
Err ( e) => Err ( e) ,
182
183
}
183
184
} )
184
185
}
185
186
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 > (
187
192
& ' a self , mut callback : String , amt : Amount , expected_description_hash : [ u8 ; 32 ] ,
188
193
) -> LNURLResolutionFuture < ' a > {
189
194
Box :: pin ( async move {
@@ -308,7 +313,8 @@ mod tests {
308
313
. unwrap ( ) ;
309
314
310
315
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( ) ) ;
312
318
313
319
assert_eq ! ( instr. pop_callback( ) , None ) ;
314
320
assert ! ( instr. bip_353_dnssec_proof( ) . is_none( ) ) ;
@@ -339,4 +345,42 @@ mod tests {
339
345
}
340
346
}
341
347
}
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
+ }
342
386
}
0 commit comments