Skip to content

Commit a71ce33

Browse files
committed
fixup! Add support for sending to human-readable names that resolve to Bolt12 Offers
1 parent 605d45d commit a71ce33

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,7 @@ impl Node {
873873
Arc::clone(&self.channel_manager),
874874
Arc::clone(&self.payment_store),
875875
Arc::clone(&self.logger),
876+
Arc::clone(&self.config),
876877
)
877878
}
878879

@@ -886,6 +887,7 @@ impl Node {
886887
Arc::clone(&self.channel_manager),
887888
Arc::clone(&self.payment_store),
888889
Arc::clone(&self.logger),
890+
Arc::clone(&self.config),
889891
))
890892
}
891893

src/payment/bolt12.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//!
1010
//! [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
1111
12-
use crate::config::LDK_PAYMENT_RETRY_TIMEOUT;
12+
use crate::config::{Config, LDK_PAYMENT_RETRY_TIMEOUT};
1313
use crate::error::Error;
1414
use crate::logger::{log_error, log_info, LdkLogger, Logger};
1515
use crate::payment::store::{
@@ -23,7 +23,6 @@ use lightning::offers::offer::{Amount, Offer, Quantity};
2323
use lightning::offers::parse::Bolt12SemanticError;
2424
use lightning::offers::refund::Refund;
2525
use lightning::onion_message::dns_resolution::HumanReadableName;
26-
use lightning::onion_message::messenger::Destination;
2726
use lightning::util::string::UntrustedString;
2827

2928
use rand::RngCore;
@@ -43,15 +42,16 @@ pub struct Bolt12Payment {
4342
channel_manager: Arc<ChannelManager>,
4443
payment_store: Arc<PaymentStore<Arc<Logger>>>,
4544
logger: Arc<Logger>,
45+
config: Arc<Config>,
4646
}
4747

4848
impl Bolt12Payment {
4949
pub(crate) fn new(
5050
runtime: Arc<RwLock<Option<Arc<tokio::runtime::Runtime>>>>,
5151
channel_manager: Arc<ChannelManager>, payment_store: Arc<PaymentStore<Arc<Logger>>>,
52-
logger: Arc<Logger>,
52+
logger: Arc<Logger>, config: Arc<Config>,
5353
) -> Self {
54-
Self { runtime, channel_manager, payment_store, logger }
54+
Self { runtime, channel_manager, payment_store, logger, config }
5555
}
5656

5757
/// Send a payment given an offer.
@@ -266,11 +266,9 @@ impl Bolt12Payment {
266266
/// This can be used to pay so-called "zero-amount" offers, i.e., an offer that leaves the
267267
/// amount paid to be determined by the user.
268268
///
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.
272270
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,
274272
) -> Result<PaymentId, Error> {
275273
let rt_lock = self.runtime.read().unwrap();
276274
if rt_lock.is_none() {
@@ -285,6 +283,11 @@ impl Bolt12Payment {
285283
let retry_strategy = Retry::Timeout(LDK_PAYMENT_RETRY_TIMEOUT);
286284
let max_total_routing_fee_msat = None;
287285

286+
let dns_resolvers = match &self.config.dns_resolvers {
287+
Some(dns_resolvers) => Ok(dns_resolvers.clone()),
288+
None => Err(Error::DnsResolversNotConfigured),
289+
}?;
290+
288291
match self.channel_manager.pay_for_offer_from_human_readable_name(
289292
hrn.clone(),
290293
amount_msat,

0 commit comments

Comments
 (0)