]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Support creating PaymentParameters from static invoices.
authorValentine Wallace <vwallace@protonmail.com>
Thu, 13 Jun 2024 21:12:03 +0000 (17:12 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Fri, 13 Sep 2024 14:40:05 +0000 (10:40 -0400)
lightning/src/routing/router.rs

index a25609c89bbe8f85414989f6abeef2044a58fb89..5311cda630fe4123ba3bf9914d200ac254237430 100644 (file)
@@ -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<BlindedPaymentPath>) -> Self {
                Self {