@@ -20,7 +20,7 @@ use lightning::ln::channelmanager::{PaymentId, Retry};
2020use lightning:: offers:: offer:: { Amount , Offer as LdkOffer , Quantity } ;
2121use lightning:: offers:: parse:: Bolt12SemanticError ;
2222use lightning:: offers:: refund:: Refund ;
23- use lightning:: onion_message:: dns_resolution:: HumanReadableName ;
23+ use lightning:: onion_message:: dns_resolution:: HumanReadableName as LdkHumanReadableName ;
2424use lightning:: onion_message:: messenger:: Destination ;
2525use lightning:: util:: string:: UntrustedString ;
2626
@@ -44,6 +44,18 @@ type Offer = Arc<crate::ffi::Offer>;
4444type Refund = lightning:: offers:: refund:: Refund ;
4545#[ cfg( feature = "uniffi" ) ]
4646type Refund = Arc < crate :: ffi:: Refund > ;
47+ type HumanReadableName = LdkHumanReadableName ;
48+ #[ cfg( feature = "uniffi" ) ]
49+ type HumanReadableName = Arc < crate :: uniffi_types:: HumanReadableName > ;
50+
51+ #[ cfg( not( feature = "uniffi" ) ) ]
52+ pub fn maybe_convert_hrn ( hrn : HumanReadableName ) -> LdkHumanReadableName {
53+ hrn
54+ }
55+ #[ cfg( feature = "uniffi" ) ]
56+ pub fn maybe_convert_hrn ( hrn : HumanReadableName ) -> LdkHumanReadableName {
57+ hrn. inner . clone ( )
58+ }
4759
4860/// A payment handler allowing to create and pay [BOLT 12] offers and refunds.
4961///
@@ -282,30 +294,30 @@ impl Bolt12Payment {
282294 /// This can be used to pay so-called "zero-amount" offers, i.e., an offer that leaves the
283295 /// amount paid to be determined by the user.
284296 ///
285- /// If `dns_resolvers_node_ids` in Config is set to `None` , this operation will fail.
297+ /// If `dns_resolvers_node_ids` in [` Config.hrn_config`] is empty , this operation will fail.
286298 pub fn send_to_human_readable_name (
287- & self , name : & str , amount_msat : u64 ,
299+ & self , hrn : HumanReadableName , amount_msat : u64 ,
288300 ) -> Result < PaymentId , Error > {
289301 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
290302 if rt_lock. is_none ( ) {
291303 return Err ( Error :: NotRunning ) ;
292304 }
293305
294- let hrn = HumanReadableName :: from_encoded ( & name) . map_err ( |_| Error :: HrnParsingFailed ) ?;
295-
296306 let mut random_bytes = [ 0u8 ; 32 ] ;
297307 rand:: thread_rng ( ) . fill_bytes ( & mut random_bytes) ;
298308 let payment_id = PaymentId ( random_bytes) ;
299309 let retry_strategy = Retry :: Timeout ( LDK_PAYMENT_RETRY_TIMEOUT ) ;
300310 let max_total_routing_fee_msat = None ;
301311
302- let dns_resolvers = match & self . config . dns_resolvers_node_ids {
303- Some ( dns_resolvers) => Ok ( dns_resolvers. clone ( ) ) ,
304- None => Err ( Error :: DnsResolversNotConfigured ) ,
305- } ?;
312+ let destinations: Vec < Destination > = self
313+ . config
314+ . hrn_config
315+ . dns_resolvers_node_ids
316+ . iter ( )
317+ . map ( |node_id| Destination :: Node ( * node_id) )
318+ . collect ( ) ;
306319
307- let destinations: Vec < Destination > =
308- dns_resolvers. into_iter ( ) . map ( |public_key| Destination :: Node ( public_key) ) . collect ( ) ;
320+ let hrn = maybe_convert_hrn ( hrn) ;
309321
310322 match self . channel_manager . pay_for_offer_from_human_readable_name (
311323 hrn. clone ( ) ,
@@ -316,7 +328,7 @@ impl Bolt12Payment {
316328 destinations,
317329 ) {
318330 Ok ( ( ) ) => {
319- log_info ! ( self . logger, "Initiated sending {} msats to {}" , amount_msat, name ) ;
331+ log_info ! ( self . logger, "Initiated sending {} msats to {:? }" , amount_msat, hrn ) ;
320332 let kind = PaymentKind :: Bolt12Offer {
321333 hash : None ,
322334 preimage : None ,
@@ -337,7 +349,7 @@ impl Bolt12Payment {
337349 Ok ( payment_id)
338350 } ,
339351 Err ( ( ) ) => {
340- log_error ! ( self . logger, "Failed to send payment to {}" , name ) ;
352+ log_error ! ( self . logger, "Failed to send payment to {:? }" , hrn ) ;
341353 let kind = PaymentKind :: Bolt12Offer {
342354 hash : None ,
343355 preimage : None ,
@@ -352,7 +364,7 @@ impl Bolt12Payment {
352364 Some ( amount_msat) ,
353365 None ,
354366 PaymentDirection :: Outbound ,
355- PaymentStatus :: Pending ,
367+ PaymentStatus :: Failed ,
356368 ) ;
357369 self . payment_store . insert ( payment) ?;
358370 Err ( Error :: PaymentSendingFailed )
0 commit comments