@@ -25,7 +25,7 @@ use bitcoin_payment_instructions::amount::Amount as BPIAmount;
2525use bitcoin_payment_instructions:: { PaymentInstructions , PaymentMethod } ;
2626use lightning:: ln:: channelmanager:: PaymentId ;
2727use lightning:: offers:: offer:: Offer ;
28- use lightning:: onion_message:: dns_resolution:: HumanReadableName ;
28+ use lightning:: onion_message:: dns_resolution:: HumanReadableName as LdkHumanReadableName ;
2929use lightning:: routing:: router:: RouteParametersConfig ;
3030use lightning_invoice:: { Bolt11Invoice , Bolt11InvoiceDescription , Description } ;
3131
@@ -38,6 +38,11 @@ use crate::Config;
3838
3939type Uri < ' a > = bip21:: Uri < ' a , NetworkChecked , Extras > ;
4040
41+ #[ cfg( not( feature = "uniffi" ) ) ]
42+ type HumanReadableName = LdkHumanReadableName ;
43+ #[ cfg( feature = "uniffi" ) ]
44+ type HumanReadableName = Arc < crate :: ffi:: HumanReadableName > ;
45+
4146#[ derive( Debug , Clone ) ]
4247struct Extras {
4348 bolt11_invoice : Option < Bolt11Invoice > ,
@@ -164,8 +169,28 @@ impl UnifiedPayment {
164169 Error :: HrnResolverNotConfigured
165170 } ) ?;
166171
172+ let target_network;
173+
174+ target_network = if let Ok ( hrn) = LdkHumanReadableName :: from_encoded ( uri_str) {
175+ #[ cfg( feature = "hrn_tests" ) ]
176+ {
177+ let hrn_wrapped: HumanReadableName = maybe_wrap ( hrn) ;
178+ match crate :: dnssec_testing_utils:: get_testing_offer_override ( Some ( hrn_wrapped) ) {
179+ Some ( _) => bitcoin:: Network :: Bitcoin ,
180+ _ => self . config . network ,
181+ }
182+ }
183+ #[ cfg( not( feature = "hrn_tests" ) ) ]
184+ {
185+ let _ = hrn;
186+ self . config . network
187+ }
188+ } else {
189+ self . config . network
190+ } ;
191+
167192 let instructions =
168- PaymentInstructions :: parse ( uri_str, self . config . network , resolver. as_ref ( ) , false )
193+ PaymentInstructions :: parse ( uri_str, target_network , resolver. as_ref ( ) , false )
169194 . await
170195 . map_err ( |e| {
171196 log_error ! ( self . logger, "Failed to parse payment instructions: {:?}" , e) ;
@@ -212,18 +237,20 @@ impl UnifiedPayment {
212237 PaymentMethod :: LightningBolt12 ( offer) => {
213238 let offer = maybe_wrap ( offer. clone ( ) ) ;
214239
215- let payment_result = if let Ok ( hrn) = HumanReadableName :: from_encoded ( uri_str) {
216- let hrn = maybe_wrap ( hrn. clone ( ) ) ;
217- self . bolt12_payment . send_using_amount_inner ( & offer, amount_msat. unwrap_or ( 0 ) , None , None , route_parameters, Some ( hrn) )
218- } else if let Some ( amount_msat) = amount_msat {
219- self . bolt12_payment . send_using_amount ( & offer, amount_msat, None , None , route_parameters)
220- } else {
221- self . bolt12_payment . send ( & offer, None , None , route_parameters)
222- }
223- . map_err ( |e| {
224- log_error ! ( self . logger, "Failed to send BOLT12 offer: {:?}. This is part of a unified payment. Falling back to the BOLT11 invoice." , e) ;
225- e
226- } ) ;
240+ let payment_result = {
241+ if let Ok ( hrn) = LdkHumanReadableName :: from_encoded ( uri_str) {
242+ let hrn = maybe_wrap ( hrn. clone ( ) ) ;
243+ self . bolt12_payment . send_using_amount_inner ( & offer, amount_msat. unwrap_or ( 0 ) , None , None , route_parameters, Some ( hrn) )
244+ } else if let Some ( amount_msat) = amount_msat {
245+ self . bolt12_payment . send_using_amount ( & offer, amount_msat, None , None , route_parameters)
246+ } else {
247+ self . bolt12_payment . send ( & offer, None , None , route_parameters)
248+ }
249+ . map_err ( |e| {
250+ log_error ! ( self . logger, "Failed to send BOLT12 offer: {:?}. This is part of a unified payment. Falling back to the BOLT11 invoice." , e) ;
251+ e
252+ } )
253+ } ;
227254
228255 if let Ok ( payment_id) = payment_result {
229256 return Ok ( UnifiedPaymentResult :: Bolt12 { payment_id } ) ;
0 commit comments