@@ -26,7 +26,7 @@ use bitcoin_payment_instructions::amount::Amount as BPIAmount;
2626use bitcoin_payment_instructions:: { PaymentInstructions , PaymentMethod } ;
2727use lightning:: ln:: channelmanager:: PaymentId ;
2828use lightning:: offers:: offer:: Offer ;
29- use lightning:: onion_message:: dns_resolution:: HumanReadableName ;
29+ use lightning:: onion_message:: dns_resolution:: HumanReadableName as LdkHumanReadableName ;
3030use lightning:: routing:: router:: RouteParametersConfig ;
3131use lightning_invoice:: { Bolt11Invoice , Bolt11InvoiceDescription , Description } ;
3232
@@ -40,6 +40,11 @@ use crate::Config;
4040
4141type Uri < ' a > = bip21:: Uri < ' a , NetworkChecked , Extras > ;
4242
43+ #[ cfg( not( feature = "uniffi" ) ) ]
44+ type HumanReadableName = LdkHumanReadableName ;
45+ #[ cfg( feature = "uniffi" ) ]
46+ type HumanReadableName = crate :: ffi:: HumanReadableName ;
47+
4348#[ derive( Debug , Clone ) ]
4449struct Extras {
4550 bolt11_invoice : Option < Bolt11Invoice > ,
@@ -166,12 +171,33 @@ impl UnifiedPayment {
166171 Error :: HrnResolverNotConfigured
167172 } ) ?;
168173
169- let parse_fut = PaymentInstructions :: parse (
170- uri_str,
171- self . config . network ,
172- self . hrn_resolver . as_ref ( ) ,
173- false ,
174- ) ;
174+ let target_network;
175+
176+ target_network = if let Ok ( hrn) = HumanReadableName :: from_encoded ( uri_str) {
177+ #[ cfg( feature = "hrn_tests" ) ]
178+ {
179+ #[ cfg( feature = "uniffi" ) ]
180+ let hrn_wrapped: Arc < HumanReadableName > = maybe_wrap ( hrn) ;
181+ #[ cfg( not( feature = "uniffi" ) ) ]
182+ let hrn_wrapped: HumanReadableName = maybe_wrap ( hrn) ;
183+ match crate :: dnssec_testing_utils:: get_testing_offer_override ( Some (
184+ hrn_wrapped. into ( ) ,
185+ ) ) {
186+ Some ( _) => bitcoin:: Network :: Bitcoin ,
187+ _ => self . config . network ,
188+ }
189+ }
190+ #[ cfg( not( feature = "hrn_tests" ) ) ]
191+ {
192+ let _ = hrn;
193+ self . config . network
194+ }
195+ } else {
196+ self . config . network
197+ } ;
198+
199+ let parse_fut =
200+ PaymentInstructions :: parse ( uri_str, target_network, resolver. as_ref ( ) , false ) ;
175201
176202 let instructions =
177203 tokio:: time:: timeout ( Duration :: from_secs ( HRN_RESOLUTION_TIMEOUT_SECS ) , parse_fut)
@@ -197,7 +223,7 @@ impl UnifiedPayment {
197223 Error :: InvalidAmount
198224 } ) ?;
199225
200- let fut = instr. set_amount ( amt, self . hrn_resolver . as_ref ( ) ) ;
226+ let fut = instr. set_amount ( amt, resolver . as_ref ( ) ) ;
201227
202228 tokio:: time:: timeout ( Duration :: from_secs ( HRN_RESOLUTION_TIMEOUT_SECS ) , fut)
203229 . await
@@ -237,18 +263,20 @@ impl UnifiedPayment {
237263 PaymentMethod :: LightningBolt12 ( offer) => {
238264 let offer = maybe_wrap ( offer. clone ( ) ) ;
239265
240- let payment_result = if let Ok ( hrn) = HumanReadableName :: from_encoded ( uri_str) {
241- let hrn = maybe_wrap ( hrn. clone ( ) ) ;
242- self . bolt12_payment . send_using_amount_inner ( & offer, amount_msat. unwrap_or ( 0 ) , None , None , route_parameters, Some ( hrn) )
243- } else if let Some ( amount_msat) = amount_msat {
244- self . bolt12_payment . send_using_amount ( & offer, amount_msat, None , None , route_parameters)
245- } else {
246- self . bolt12_payment . send ( & offer, None , None , route_parameters)
247- }
248- . map_err ( |e| {
249- log_error ! ( self . logger, "Failed to send BOLT12 offer: {:?}. This is part of a unified payment. Falling back to the BOLT11 invoice." , e) ;
250- e
251- } ) ;
266+ let payment_result = {
267+ if let Ok ( hrn) = HumanReadableName :: from_encoded ( uri_str) {
268+ let hrn = maybe_wrap ( hrn. clone ( ) ) ;
269+ self . bolt12_payment . send_using_amount_inner ( & offer, amount_msat. unwrap_or ( 0 ) , None , None , route_parameters, Some ( hrn) )
270+ } else if let Some ( amount_msat) = amount_msat {
271+ self . bolt12_payment . send_using_amount ( & offer, amount_msat, None , None , route_parameters)
272+ } else {
273+ self . bolt12_payment . send ( & offer, None , None , route_parameters)
274+ }
275+ . map_err ( |e| {
276+ log_error ! ( self . logger, "Failed to send BOLT12 offer: {:?}. This is part of a unified payment. Falling back to the BOLT11 invoice." , e) ;
277+ e
278+ } )
279+ } ;
252280
253281 if let Ok ( payment_id) = payment_result {
254282 return Ok ( UnifiedPaymentResult :: Bolt12 { payment_id } ) ;
0 commit comments