Skip to content

Commit 9d8d3ff

Browse files
committed
fixup! Add support for sending to human-readable names that resolve to Bolt12 Offers
1 parent 3913fe5 commit 9d8d3ff

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
@@ -23,6 +23,7 @@ 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;
2627
use lightning::util::string::UntrustedString;
2728

2829
use rand::RngCore;
@@ -283,28 +284,35 @@ impl Bolt12Payment {
283284
let retry_strategy = Retry::Timeout(LDK_PAYMENT_RETRY_TIMEOUT);
284285
let max_total_routing_fee_msat = None;
285286

286-
let dns_resolvers = match &self.config.dns_resolvers {
287+
let dns_resolvers = match &self.config.dns_resolvers_node_ids {
287288
Some(dns_resolvers) => Ok(dns_resolvers.clone()),
288289
None => Err(Error::DnsResolversNotConfigured),
289290
}?;
290291

292+
let destinations: Vec<Destination> = dns_resolvers
293+
.into_iter()
294+
.map(|public_key| {
295+
Destination::Node(public_key)
296+
})
297+
.collect();
298+
291299
match self.channel_manager.pay_for_offer_from_human_readable_name(
292300
hrn.clone(),
293301
amount_msat,
294302
payment_id,
295303
retry_strategy,
296304
max_total_routing_fee_msat,
297-
dns_resolvers,
305+
destinations,
298306
) {
299307
Ok(()) => {
300308
log_info!(self.logger, "Initiated sending {} msats to {}", amount_msat, name);
301-
let kind = PaymentKind::Bolt12Offer {
302-
hash: None,
303-
preimage: None,
304-
secret: None,
309+
let kind = PaymentKind::Bolt12Offer {
310+
hash: None,
311+
preimage: None,
312+
secret: None,
305313
offer_id: None,
306-
payer_note: None,
307-
quantity: None
314+
payer_note: None,
315+
quantity: None,
308316
};
309317
let payment = PaymentDetails::new(
310318
payment_id,
@@ -319,13 +327,13 @@ impl Bolt12Payment {
319327
},
320328
Err(()) => {
321329
log_error!(self.logger, "Failed to send payment to {}", name);
322-
let kind = PaymentKind::Bolt12Offer {
323-
hash: None,
324-
preimage: None,
325-
secret: None,
330+
let kind = PaymentKind::Bolt12Offer {
331+
hash: None,
332+
preimage: None,
333+
secret: None,
326334
offer_id: None,
327-
payer_note: None,
328-
quantity: None
335+
payer_note: None,
336+
quantity: None,
329337
};
330338
let payment = PaymentDetails::new(
331339
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)