@@ -26,7 +26,6 @@ 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 ;
3029use lightning:: routing:: router:: RouteParametersConfig ;
3130use lightning_invoice:: { Bolt11Invoice , Bolt11InvoiceDescription , Description } ;
3231
@@ -40,6 +39,11 @@ use crate::Config;
4039
4140type Uri < ' a > = bip21:: Uri < ' a , NetworkChecked , Extras > ;
4241
42+ #[ cfg( not( feature = "uniffi" ) ) ]
43+ type HumanReadableName = lightning:: onion_message:: dns_resolution:: HumanReadableName ;
44+ #[ cfg( feature = "uniffi" ) ]
45+ type HumanReadableName = crate :: ffi:: HumanReadableName ;
46+
4347#[ derive( Debug , Clone ) ]
4448struct Extras {
4549 bolt11_invoice : Option < Bolt11Invoice > ,
@@ -166,8 +170,33 @@ impl UnifiedPayment {
166170 Error :: HrnResolverNotConfigured
167171 } ) ?;
168172
173+ let target_network;
174+
175+ target_network = if let Ok ( hrn) = HumanReadableName :: from_encoded ( uri_str) {
176+ #[ cfg( feature = "hrn_tests" ) ]
177+ {
178+ #[ cfg( feature = "uniffi" ) ]
179+ let hrn_wrapped: Arc < HumanReadableName > = maybe_wrap ( hrn) ;
180+ #[ cfg( not( feature = "uniffi" ) ) ]
181+ let hrn_wrapped: HumanReadableName = maybe_wrap ( hrn) ;
182+ match crate :: dnssec_testing_utils:: get_testing_offer_override ( Some (
183+ hrn_wrapped. into ( ) ,
184+ ) ) {
185+ Some ( _) => bitcoin:: Network :: Bitcoin ,
186+ _ => self . config . network ,
187+ }
188+ }
189+ #[ cfg( not( feature = "hrn_tests" ) ) ]
190+ {
191+ let _ = hrn;
192+ self . config . network
193+ }
194+ } else {
195+ self . config . network
196+ } ;
197+
169198 let parse_fut =
170- PaymentInstructions :: parse ( uri_str, self . config . network , resolver. as_ref ( ) , false ) ;
199+ PaymentInstructions :: parse ( uri_str, target_network , resolver. as_ref ( ) , false ) ;
171200
172201 let instructions =
173202 tokio:: time:: timeout ( Duration :: from_secs ( HRN_RESOLUTION_TIMEOUT_SECS ) , parse_fut)
@@ -233,18 +262,20 @@ impl UnifiedPayment {
233262 PaymentMethod :: LightningBolt12 ( offer) => {
234263 let offer = maybe_wrap ( offer. clone ( ) ) ;
235264
236- let payment_result = if let Ok ( hrn) = HumanReadableName :: from_encoded ( uri_str) {
237- let hrn = maybe_wrap ( hrn. clone ( ) ) ;
238- self . bolt12_payment . send_using_amount_inner ( & offer, amount_msat. unwrap_or ( 0 ) , None , None , route_parameters, Some ( hrn) )
239- } else if let Some ( amount_msat) = amount_msat {
240- self . bolt12_payment . send_using_amount ( & offer, amount_msat, None , None , route_parameters)
241- } else {
242- self . bolt12_payment . send ( & offer, None , None , route_parameters)
243- }
244- . map_err ( |e| {
245- log_error ! ( self . logger, "Failed to send BOLT12 offer: {:?}. This is part of a unified payment. Falling back to the BOLT11 invoice." , e) ;
246- e
247- } ) ;
265+ let payment_result = {
266+ if let Ok ( hrn) = HumanReadableName :: from_encoded ( uri_str) {
267+ let hrn = maybe_wrap ( hrn. clone ( ) ) ;
268+ self . bolt12_payment . send_using_amount_inner ( & offer, amount_msat. unwrap_or ( 0 ) , None , None , route_parameters, Some ( hrn) )
269+ } else if let Some ( amount_msat) = amount_msat {
270+ self . bolt12_payment . send_using_amount ( & offer, amount_msat, None , None , route_parameters)
271+ } else {
272+ self . bolt12_payment . send ( & offer, None , None , route_parameters)
273+ }
274+ . map_err ( |e| {
275+ log_error ! ( self . logger, "Failed to send BOLT12 offer: {:?}. This is part of a unified payment. Falling back to the BOLT11 invoice." , e) ;
276+ e
277+ } )
278+ } ;
248279
249280 if let Ok ( payment_id) = payment_result {
250281 return Ok ( UnifiedPaymentResult :: Bolt12 { payment_id } ) ;
0 commit comments