Skip to content

Commit 1a2341a

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

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::{PaymentDetails, PaymentDirection, PaymentKind, PaymentStatus};
@@ -21,7 +21,6 @@ use lightning::offers::offer::{Amount, Offer, Quantity};
2121
use lightning::offers::parse::Bolt12SemanticError;
2222
use lightning::offers::refund::Refund;
2323
use lightning::onion_message::dns_resolution::HumanReadableName;
24-
use lightning::onion_message::messenger::Destination;
2524
use lightning::util::string::UntrustedString;
2625

2726
use rand::RngCore;
@@ -41,15 +40,16 @@ pub struct Bolt12Payment {
4140
channel_manager: Arc<ChannelManager>,
4241
payment_store: Arc<PaymentStore>,
4342
logger: Arc<Logger>,
43+
config: Arc<Config>,
4444
}
4545

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

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

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

0 commit comments

Comments
 (0)