Skip to content

Commit f4928ab

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

File tree

3 files changed

+24
-32
lines changed

3 files changed

+24
-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
};
@@ -803,7 +803,4 @@ typedef string NodeAlias;
803803
typedef string OrderId;
804804

805805
[Custom]
806-
typedef string DateTime;
807-
808-
[Custom]
809-
typedef string HumanReadableName;
806+
typedef string DateTime;

src/payment/bolt12.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ 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;
2425
use lightning::util::string::UntrustedString;
2526

2627
use rand::RngCore;
@@ -281,28 +282,35 @@ impl Bolt12Payment {
281282
let retry_strategy = Retry::Timeout(LDK_PAYMENT_RETRY_TIMEOUT);
282283
let max_total_routing_fee_msat = None;
283284

284-
let dns_resolvers = match &self.config.dns_resolvers {
285+
let dns_resolvers = match &self.config.dns_resolvers_node_ids {
285286
Some(dns_resolvers) => Ok(dns_resolvers.clone()),
286287
None => Err(Error::DnsResolversNotConfigured),
287288
}?;
288289

290+
let destinations: Vec<Destination> = dns_resolvers
291+
.into_iter()
292+
.map(|public_key| {
293+
Destination::Node(public_key)
294+
})
295+
.collect();
296+
289297
match self.channel_manager.pay_for_offer_from_human_readable_name(
290298
hrn.clone(),
291299
amount_msat,
292300
payment_id,
293301
retry_strategy,
294302
max_total_routing_fee_msat,
295-
dns_resolvers,
303+
destinations,
296304
) {
297305
Ok(()) => {
298306
log_info!(self.logger, "Initiated sending {} msats to {}", amount_msat, name);
299-
let kind = PaymentKind::Bolt12Offer {
300-
hash: None,
301-
preimage: None,
302-
secret: None,
307+
let kind = PaymentKind::Bolt12Offer {
308+
hash: None,
309+
preimage: None,
310+
secret: None,
303311
offer_id: None,
304-
payer_note: None,
305-
quantity: None
312+
payer_note: None,
313+
quantity: None,
306314
};
307315
let payment = PaymentDetails::new(
308316
payment_id,
@@ -317,13 +325,13 @@ impl Bolt12Payment {
317325
},
318326
Err(()) => {
319327
log_error!(self.logger, "Failed to send payment to {}", name);
320-
let kind = PaymentKind::Bolt12Offer {
321-
hash: None,
322-
preimage: None,
323-
secret: None,
328+
let kind = PaymentKind::Bolt12Offer {
329+
hash: None,
330+
preimage: None,
331+
secret: None,
324332
offer_id: None,
325-
payer_note: None,
326-
quantity: None
333+
payer_note: None,
334+
quantity: None,
327335
};
328336
let payment = PaymentDetails::new(
329337
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)