From: Valentine Wallace Date: Thu, 13 Jun 2024 21:12:03 +0000 (-0400) Subject: Support creating PaymentParameters from static invoices. X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=ad63a706f2d0849f16a1848d02807750dd958b03;p=rust-lightning Support creating PaymentParameters from static invoices. --- diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index a25609c89..5311cda63 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -20,6 +20,8 @@ use crate::ln::channelmanager::{PaymentId, MIN_FINAL_CLTV_EXPIRY_DELTA, Recipien use crate::ln::features::{BlindedHopFeatures, Bolt11InvoiceFeatures, Bolt12InvoiceFeatures, ChannelFeatures, NodeFeatures}; use crate::ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT}; use crate::ln::onion_utils; +#[cfg(async_payments)] +use crate::offers::static_invoice::StaticInvoice; use crate::offers::invoice::Bolt12Invoice; use crate::onion_message::messenger::{DefaultMessageRouter, Destination, MessageRouter, OnionMessagePath}; use crate::routing::gossip::{DirectedChannelInfo, EffectiveCapacity, ReadOnlyNetworkGraph, NetworkGraph, NodeId}; @@ -877,6 +879,16 @@ impl PaymentParameters { .with_expiry_time(invoice.created_at().as_secs().saturating_add(invoice.relative_expiry().as_secs())) } + /// Creates parameters for paying to a blinded payee from the provided invoice. Sets + /// [`Payee::Blinded::route_hints`], [`Payee::Blinded::features`], and + /// [`PaymentParameters::expiry_time`]. + #[cfg(async_payments)] + pub fn from_static_invoice(invoice: &StaticInvoice) -> Self { + Self::blinded(invoice.payment_paths().to_vec()) + .with_bolt12_features(invoice.invoice_features().clone()).unwrap() + .with_expiry_time(invoice.created_at().as_secs().saturating_add(invoice.relative_expiry().as_secs())) + } + /// Creates parameters for paying to a blinded payee from the provided blinded route hints. pub fn blinded(blinded_route_hints: Vec) -> Self { Self {