Skip to content

Commit 246f12c

Browse files
Support creating PaymentParameters from static invoices.
1 parent ae51409 commit 246f12c

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::{BlindedPayInfo, Bolt12Invoice};
2426
use crate::onion_message::messenger::{DefaultMessageRouter, Destination, MessageRouter, OnionMessagePath};
2527
use crate::routing::gossip::{DirectedChannelInfo, EffectiveCapacity, ReadOnlyNetworkGraph, NetworkGraph, NodeId, RoutingFees};
@@ -873,6 +875,16 @@ impl PaymentParameters {
873875
.with_expiry_time(invoice.created_at().as_secs().saturating_add(invoice.relative_expiry().as_secs()))
874876
}
875877

878+
#[cfg(async_payments)]
879+
/// Creates parameters for paying to a blinded payee from the provided invoice. Sets
880+
/// [`Payee::Blinded::route_hints`], [`Payee::Blinded::features`], and
881+
/// [`PaymentParameters::expiry_time`].
882+
pub fn from_static_invoice(invoice: &StaticInvoice) -> Self {
883+
Self::blinded(invoice.payment_paths().to_vec())
884+
.with_bolt12_features(invoice.invoice_features().clone()).unwrap()
885+
.with_expiry_time(invoice.created_at().as_secs().saturating_add(invoice.relative_expiry().as_secs()))
886+
}
887+
876888
/// Creates parameters for paying to a blinded payee from the provided blinded route hints.
877889
pub fn blinded(blinded_route_hints: Vec<(BlindedPayInfo, BlindedPath)>) -> Self {
878890
Self {

0 commit comments

Comments
 (0)