@@ -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,12 +170,33 @@ impl UnifiedPayment {
166170 Error :: HrnResolverNotConfigured
167171 } ) ?;
168172
169- let parse_fut = PaymentInstructions :: parse (
170- uri_str,
171- self . config . network ,
172- self . hrn_resolver . as_ref ( ) ,
173- false ,
174- ) ;
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+
198+ let parse_fut =
199+ PaymentInstructions :: parse ( uri_str, target_network, resolver. as_ref ( ) , false ) ;
175200
176201 let instructions =
177202 tokio:: time:: timeout ( Duration :: from_secs ( HRN_RESOLUTION_TIMEOUT_SECS ) , parse_fut)
@@ -197,7 +222,7 @@ impl UnifiedPayment {
197222 Error :: InvalidAmount
198223 } ) ?;
199224
200- let fut = instr. set_amount ( amt, self . hrn_resolver . as_ref ( ) ) ;
225+ let fut = instr. set_amount ( amt, resolver . as_ref ( ) ) ;
201226
202227 tokio:: time:: timeout ( Duration :: from_secs ( HRN_RESOLUTION_TIMEOUT_SECS ) , fut)
203228 . await
@@ -237,18 +262,20 @@ impl UnifiedPayment {
237262 PaymentMethod :: LightningBolt12 ( offer) => {
238263 let offer = maybe_wrap ( offer. clone ( ) ) ;
239264
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- } ) ;
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+ } ;
252279
253280 if let Ok ( payment_id) = payment_result {
254281 return Ok ( UnifiedPaymentResult :: Bolt12 { payment_id } ) ;
0 commit comments