Skip to content

Commit 09b650e

Browse files
committed
fixup! Add support for sending to human-readable names that resolve to Bolt12 Offers
1 parent 527e8ba commit 09b650e

File tree

3 files changed

+26
-32
lines changed

3 files changed

+26
-32
lines changed

bindings/ldk_node.udl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ interface PaymentKind {
408408
Onchain(Txid txid, ConfirmationStatus status);
409409
Bolt11(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret);
410410
Bolt11Jit(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret, u64? counterparty_skimmed_fee_msat, LSPFeeLimits lsp_fee_limits);
411-
Bolt12Offer(PaymentHash? hash, PaymentPreimage? preimage, PaymentSecret? secret, OfferId offer_id, UntrustedString? payer_note, u64? quantity);
411+
Bolt12Offer(PaymentHash? hash, PaymentPreimage? preimage, PaymentSecret? secret, OfferId? offer_id, UntrustedString? payer_note, u64? quantity);
412412
Bolt12Refund(PaymentHash? hash, PaymentPreimage? preimage, PaymentSecret? secret, UntrustedString? payer_note, u64? quantity);
413413
Spontaneous(PaymentHash hash, PaymentPreimage? preimage);
414414
};
@@ -859,7 +859,4 @@ typedef string NodeAlias;
859859
typedef string OrderId;
860860

861861
[Custom]
862-
typedef string DateTime;
863-
864-
[Custom]
865-
typedef string HumanReadableName;
862+
typedef string DateTime;

src/payment/bolt12.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ use crate::types::{ChannelManager, PaymentStore};
1919
use lightning::ln::channelmanager::{PaymentId, Retry};
2020
use lightning::offers::offer::{Amount, Offer as LdkOffer, Quantity};
2121
use lightning::offers::parse::Bolt12SemanticError;
22+
use lightning::offers::refund::Refund;
23+
use lightning::onion_message::dns_resolution::HumanReadableName;
24+
use lightning::onion_message::messenger::Destination;
2225
use lightning::util::string::UntrustedString;
2326

2427
use rand::RngCore;
@@ -296,28 +299,35 @@ impl Bolt12Payment {
296299
let retry_strategy = Retry::Timeout(LDK_PAYMENT_RETRY_TIMEOUT);
297300
let max_total_routing_fee_msat = None;
298301

299-
let dns_resolvers = match &self.config.dns_resolvers {
302+
let dns_resolvers = match &self.config.dns_resolvers_node_ids {
300303
Some(dns_resolvers) => Ok(dns_resolvers.clone()),
301304
None => Err(Error::DnsResolversNotConfigured),
302305
}?;
303306

307+
let destinations: Vec<Destination> = dns_resolvers
308+
.into_iter()
309+
.map(|public_key| {
310+
Destination::Node(public_key)
311+
})
312+
.collect();
313+
304314
match self.channel_manager.pay_for_offer_from_human_readable_name(
305315
hrn.clone(),
306316
amount_msat,
307317
payment_id,
308318
retry_strategy,
309319
max_total_routing_fee_msat,
310-
dns_resolvers,
320+
destinations,
311321
) {
312322
Ok(()) => {
313323
log_info!(self.logger, "Initiated sending {} msats to {}", amount_msat, name);
314-
let kind = PaymentKind::Bolt12Offer {
315-
hash: None,
316-
preimage: None,
317-
secret: None,
324+
let kind = PaymentKind::Bolt12Offer {
325+
hash: None,
326+
preimage: None,
327+
secret: None,
318328
offer_id: None,
319-
payer_note: None,
320-
quantity: None
329+
payer_note: None,
330+
quantity: None,
321331
};
322332
let payment = PaymentDetails::new(
323333
payment_id,
@@ -332,13 +342,13 @@ impl Bolt12Payment {
332342
},
333343
Err(()) => {
334344
log_error!(self.logger, "Failed to send payment to {}", name);
335-
let kind = PaymentKind::Bolt12Offer {
336-
hash: None,
337-
preimage: None,
338-
secret: None,
345+
let kind = PaymentKind::Bolt12Offer {
346+
hash: None,
347+
preimage: None,
348+
secret: None,
339349
offer_id: None,
340-
payer_note: None,
341-
quantity: None
350+
payer_note: None,
351+
quantity: None,
342352
};
343353
let payment = PaymentDetails::new(
344354
payment_id,

src/uniffi_types.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ pub use lightning_types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
3535

3636
pub use lightning_invoice::{Description, SignedRawBolt11Invoice};
3737

38-
pub use lightning::onion_message::dns_resolution::HumanReadableName;
3938
pub use lightning_liquidity::lsps1::msgs::ChannelInfo as ChannelOrderInfo;
4039
pub use lightning_liquidity::lsps1::msgs::{OrderId, OrderParameters, PaymentState};
4140

@@ -657,18 +656,6 @@ impl UniffiCustomTypeConverter for DateTime {
657656
}
658657
}
659658

660-
impl UniffiCustomTypeConverter for HumanReadableName {
661-
type Builtin = String;
662-
663-
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
664-
HumanReadableName::from_encoded(&val).map_err(|_| Error::HrnParsingFailed.into())
665-
}
666-
667-
fn from_custom(obj: Self) -> Self::Builtin {
668-
format!("{}@{}", obj.user(), obj.domain())
669-
}
670-
}
671-
672659
#[cfg(test)]
673660
mod tests {
674661
use super::*;

0 commit comments

Comments
 (0)