@@ -20,7 +20,7 @@ use lightning::offers::invoice::Bolt12Invoice;
2020use lightning:: offers:: offer:: { Amount , Offer , 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
@@ -30,6 +30,20 @@ use std::num::NonZeroU64;
3030use std:: sync:: { Arc , RwLock } ;
3131use std:: time:: { Duration , SystemTime , UNIX_EPOCH } ;
3232
33+ #[ cfg( not( feature = "uniffi" ) ) ]
34+ type HumanReadableName = LdkHumanReadableName ;
35+ #[ cfg( feature = "uniffi" ) ]
36+ type HumanReadableName = Arc < crate :: uniffi_types:: HumanReadableName > ;
37+
38+ #[ cfg( not( feature = "uniffi" ) ) ]
39+ pub fn maybe_convert_hrn ( hrn : HumanReadableName ) -> LdkHumanReadableName {
40+ hrn. clone ( )
41+ }
42+ #[ cfg( feature = "uniffi" ) ]
43+ pub fn maybe_convert_hrn ( hrn : HumanReadableName ) -> LdkHumanReadableName {
44+ hrn. inner . clone ( )
45+ }
46+
3347/// A payment handler allowing to create and pay [BOLT 12] offers and refunds.
3448///
3549/// Should be retrieved by calling [`Node::bolt12_payment`].
@@ -265,30 +279,30 @@ impl Bolt12Payment {
265279 /// This can be used to pay so-called "zero-amount" offers, i.e., an offer that leaves the
266280 /// amount paid to be determined by the user.
267281 ///
268- /// If `dns_resolvers_node_ids` in Config is set to `None` , this operation will fail.
282+ /// If `dns_resolvers_node_ids` in [` Config.hrn_config`] is empty , this operation will fail.
269283 pub fn send_to_human_readable_name (
270- & self , name : & str , amount_msat : u64 ,
284+ & self , hrn : HumanReadableName , amount_msat : u64 ,
271285 ) -> Result < PaymentId , Error > {
272286 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
273287 if rt_lock. is_none ( ) {
274288 return Err ( Error :: NotRunning ) ;
275289 }
276290
277- let hrn = HumanReadableName :: from_encoded ( & name) . map_err ( |_| Error :: HrnParsingFailed ) ?;
278-
279291 let mut random_bytes = [ 0u8 ; 32 ] ;
280292 rand:: thread_rng ( ) . fill_bytes ( & mut random_bytes) ;
281293 let payment_id = PaymentId ( random_bytes) ;
282294 let retry_strategy = Retry :: Timeout ( LDK_PAYMENT_RETRY_TIMEOUT ) ;
283295 let max_total_routing_fee_msat = None ;
284296
285- let dns_resolvers = match & self . config . dns_resolvers_node_ids {
286- Some ( dns_resolvers) => Ok ( dns_resolvers. clone ( ) ) ,
287- None => Err ( Error :: DnsResolversNotConfigured ) ,
288- } ?;
297+ let destinations: Vec < Destination > = self
298+ . config
299+ . hrn_config
300+ . dns_resolvers_node_ids
301+ . iter ( )
302+ . map ( |node_id| Destination :: Node ( * node_id) )
303+ . collect ( ) ;
289304
290- let destinations: Vec < Destination > =
291- dns_resolvers. into_iter ( ) . map ( |public_key| Destination :: Node ( public_key) ) . collect ( ) ;
305+ let hrn = maybe_convert_hrn ( hrn) ;
292306
293307 match self . channel_manager . pay_for_offer_from_human_readable_name (
294308 hrn. clone ( ) ,
@@ -299,7 +313,7 @@ impl Bolt12Payment {
299313 destinations,
300314 ) {
301315 Ok ( ( ) ) => {
302- log_info ! ( self . logger, "Initiated sending {} msats to {}" , amount_msat, name ) ;
316+ log_info ! ( self . logger, "Initiated sending {} msats to {:? }" , amount_msat, hrn ) ;
303317 let kind = PaymentKind :: Bolt12Offer {
304318 hash : None ,
305319 preimage : None ,
@@ -320,7 +334,7 @@ impl Bolt12Payment {
320334 Ok ( payment_id)
321335 } ,
322336 Err ( ( ) ) => {
323- log_error ! ( self . logger, "Failed to send payment to {}" , name ) ;
337+ log_error ! ( self . logger, "Failed to send payment to {:? }" , hrn ) ;
324338 let kind = PaymentKind :: Bolt12Offer {
325339 hash : None ,
326340 preimage : None ,
@@ -335,7 +349,7 @@ impl Bolt12Payment {
335349 Some ( amount_msat) ,
336350 None ,
337351 PaymentDirection :: Outbound ,
338- PaymentStatus :: Pending ,
352+ PaymentStatus :: Failed ,
339353 ) ;
340354 self . payment_store . insert ( payment) ?;
341355 Err ( Error :: PaymentSendingFailed )
0 commit comments