@@ -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 = Arc < crate :: ffi:: HumanReadableName > ;
47+
4348#[ derive( Debug , Clone ) ]
4449struct Extras {
4550 bolt11_invoice : Option < Bolt11Invoice > ,
@@ -166,12 +171,28 @@ 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) = LdkHumanReadableName :: from_encoded ( uri_str) {
177+ #[ cfg( feature = "hrn_tests" ) ]
178+ {
179+ let hrn_wrapped: HumanReadableName = maybe_wrap ( hrn) ;
180+ match crate :: dnssec_testing_utils:: get_testing_offer_override ( Some ( hrn_wrapped) ) {
181+ Some ( _) => bitcoin:: Network :: Bitcoin ,
182+ _ => self . config . network ,
183+ }
184+ }
185+ #[ cfg( not( feature = "hrn_tests" ) ) ]
186+ {
187+ let _ = hrn;
188+ self . config . network
189+ }
190+ } else {
191+ self . config . network
192+ } ;
193+
194+ let parse_fut =
195+ PaymentInstructions :: parse ( uri_str, target_network, resolver. as_ref ( ) , false ) ;
175196
176197 let instructions =
177198 tokio:: time:: timeout ( Duration :: from_secs ( HRN_RESOLUTION_TIMEOUT_SECS ) , parse_fut)
@@ -197,7 +218,7 @@ impl UnifiedPayment {
197218 Error :: InvalidAmount
198219 } ) ?;
199220
200- let fut = instr. set_amount ( amt, self . hrn_resolver . as_ref ( ) ) ;
221+ let fut = instr. set_amount ( amt, resolver . as_ref ( ) ) ;
201222
202223 tokio:: time:: timeout ( Duration :: from_secs ( HRN_RESOLUTION_TIMEOUT_SECS ) , fut)
203224 . await
@@ -237,18 +258,20 @@ impl UnifiedPayment {
237258 PaymentMethod :: LightningBolt12 ( offer) => {
238259 let offer = maybe_wrap ( offer. clone ( ) ) ;
239260
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- } ) ;
261+ let payment_result = {
262+ if let Ok ( hrn) = LdkHumanReadableName :: from_encoded ( uri_str) {
263+ let hrn = maybe_wrap ( hrn. clone ( ) ) ;
264+ self . bolt12_payment . send_using_amount_inner ( & offer, amount_msat. unwrap_or ( 0 ) , None , None , route_parameters, Some ( hrn) )
265+ } else if let Some ( amount_msat) = amount_msat {
266+ self . bolt12_payment . send_using_amount ( & offer, amount_msat, None , None , route_parameters)
267+ } else {
268+ self . bolt12_payment . send ( & offer, None , None , route_parameters)
269+ }
270+ . map_err ( |e| {
271+ log_error ! ( self . logger, "Failed to send BOLT12 offer: {:?}. This is part of a unified payment. Falling back to the BOLT11 invoice." , e) ;
272+ e
273+ } )
274+ } ;
252275
253276 if let Ok ( payment_id) = payment_result {
254277 return Ok ( UnifiedPaymentResult :: Bolt12 { payment_id } ) ;
0 commit comments