9
9
//!
10
10
//! [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
11
11
12
- use crate :: config:: LDK_PAYMENT_RETRY_TIMEOUT ;
12
+ use crate :: config:: { Config , LDK_PAYMENT_RETRY_TIMEOUT } ;
13
13
use crate :: error:: Error ;
14
14
use crate :: logger:: { log_error, log_info, LdkLogger , Logger } ;
15
15
use crate :: payment:: store:: { PaymentDetails , PaymentDirection , PaymentKind , PaymentStatus } ;
@@ -21,7 +21,6 @@ use lightning::offers::offer::{Amount, Offer, Quantity};
21
21
use lightning:: offers:: parse:: Bolt12SemanticError ;
22
22
use lightning:: offers:: refund:: Refund ;
23
23
use lightning:: onion_message:: dns_resolution:: HumanReadableName ;
24
- use lightning:: onion_message:: messenger:: Destination ;
25
24
use lightning:: util:: string:: UntrustedString ;
26
25
27
26
use rand:: RngCore ;
@@ -41,15 +40,16 @@ pub struct Bolt12Payment {
41
40
channel_manager : Arc < ChannelManager > ,
42
41
payment_store : Arc < PaymentStore > ,
43
42
logger : Arc < Logger > ,
43
+ config : Arc < Config > ,
44
44
}
45
45
46
46
impl Bolt12Payment {
47
47
pub ( crate ) fn new (
48
48
runtime : Arc < RwLock < Option < Arc < tokio:: runtime:: Runtime > > > > ,
49
49
channel_manager : Arc < ChannelManager > , payment_store : Arc < PaymentStore > ,
50
- logger : Arc < Logger > ,
50
+ logger : Arc < Logger > , config : Arc < Config > ,
51
51
) -> Self {
52
- Self { runtime, channel_manager, payment_store, logger }
52
+ Self { runtime, channel_manager, payment_store, logger, config }
53
53
}
54
54
55
55
/// Send a payment given an offer.
@@ -264,11 +264,9 @@ impl Bolt12Payment {
264
264
/// This can be used to pay so-called "zero-amount" offers, i.e., an offer that leaves the
265
265
/// amount paid to be determined by the user.
266
266
///
267
- /// `dns_resolvers` should be a list of node Destinations that are configured for dns resolution (as outlined in bLIP 32).
268
- /// These nodes can be found by running a search through the `NetworkGraph` to find nodes that announce the
269
- /// `dns_resolver` feature flag.
267
+ /// If `dns_resolvers` in Config is set to `None`, this operation will fail.
270
268
pub fn send_to_human_readable_name (
271
- & self , name : & str , amount_msat : u64 , dns_resolvers : Vec < Destination > ,
269
+ & self , name : & str , amount_msat : u64 ,
272
270
) -> Result < PaymentId , Error > {
273
271
let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
274
272
if rt_lock. is_none ( ) {
@@ -283,6 +281,11 @@ impl Bolt12Payment {
283
281
let retry_strategy = Retry :: Timeout ( LDK_PAYMENT_RETRY_TIMEOUT ) ;
284
282
let max_total_routing_fee_msat = None ;
285
283
284
+ let dns_resolvers = match & self . config . dns_resolvers {
285
+ Some ( dns_resolvers) => Ok ( dns_resolvers. clone ( ) ) ,
286
+ None => Err ( Error :: DnsResolversNotConfigured ) ,
287
+ } ?;
288
+
286
289
match self . channel_manager . pay_for_offer_from_human_readable_name (
287
290
hrn. clone ( ) ,
288
291
amount_msat,
0 commit comments