Skip to content

Commit ad63a70

Browse files
Support creating PaymentParameters from static invoices.
1 parent cff6e34 commit ad63a70

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lightning/src/routing/router.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ use crate::ln::channelmanager::{PaymentId, MIN_FINAL_CLTV_EXPIRY_DELTA, Recipien
2020
use crate::ln::features::{BlindedHopFeatures, Bolt11InvoiceFeatures, Bolt12InvoiceFeatures, ChannelFeatures, NodeFeatures};
2121
use crate::ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT};
2222
use crate::ln::onion_utils;
23+
#[cfg(async_payments)]
24+
use crate::offers::static_invoice::StaticInvoice;
2325
use crate::offers::invoice::Bolt12Invoice;
2426
use crate::onion_message::messenger::{DefaultMessageRouter, Destination, MessageRouter, OnionMessagePath};
2527
use crate::routing::gossip::{DirectedChannelInfo, EffectiveCapacity, ReadOnlyNetworkGraph, NetworkGraph, NodeId};
@@ -877,6 +879,16 @@ impl PaymentParameters {
877879
.with_expiry_time(invoice.created_at().as_secs().saturating_add(invoice.relative_expiry().as_secs()))
878880
}
879881

882+
/// Creates parameters for paying to a blinded payee from the provided invoice. Sets
883+
/// [`Payee::Blinded::route_hints`], [`Payee::Blinded::features`], and
884+
/// [`PaymentParameters::expiry_time`].
885+
#[cfg(async_payments)]
886+
pub fn from_static_invoice(invoice: &StaticInvoice) -> Self {
887+
Self::blinded(invoice.payment_paths().to_vec())
888+
.with_bolt12_features(invoice.invoice_features().clone()).unwrap()
889+
.with_expiry_time(invoice.created_at().as_secs().saturating_add(invoice.relative_expiry().as_secs()))
890+
}
891+
880892
/// Creates parameters for paying to a blinded payee from the provided blinded route hints.
881893
pub fn blinded(blinded_route_hints: Vec<BlindedPaymentPath>) -> Self {
882894
Self {

0 commit comments

Comments
 (0)