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