1010//! Convenient utilities for paying Lightning invoices.
1111
1212use crate :: Bolt11Invoice ;
13- use crate :: prelude:: * ;
1413
1514use bitcoin_hashes:: Hash ;
1615
1716use lightning:: ln:: PaymentHash ;
1817use lightning:: ln:: channelmanager:: RecipientOnionFields ;
1918use lightning:: routing:: router:: { PaymentParameters , RouteParameters } ;
2019
21- use core:: time:: Duration ;
22-
2320/// Builds the necessary parameters to pay or pre-flight probe the given zero-amount
2421/// [`Bolt11Invoice`] using [`ChannelManager::send_payment`] or
2522/// [`ChannelManager::send_preflight_probes`].
@@ -61,10 +58,6 @@ pub fn payment_parameters_from_invoice(invoice: &Bolt11Invoice)
6158 }
6259}
6360
64- fn expiry_time_from_unix_epoch ( invoice : & Bolt11Invoice ) -> Duration {
65- invoice. signed_invoice . raw_invoice . data . timestamp . 0 + invoice. expiry_time ( )
66- }
67-
6861fn params_from_invoice ( invoice : & Bolt11Invoice , amount_msat : u64 )
6962-> ( PaymentHash , RecipientOnionFields , RouteParameters ) {
7063 let payment_hash = PaymentHash ( ( * invoice. payment_hash ( ) ) . into_inner ( ) ) ;
@@ -76,8 +69,10 @@ fn params_from_invoice(invoice: &Bolt11Invoice, amount_msat: u64)
7669 invoice. recover_payee_pub_key ( ) ,
7770 invoice. min_final_cltv_expiry_delta ( ) as u32
7871 )
79- . with_expiry_time ( expiry_time_from_unix_epoch ( invoice) . as_secs ( ) )
8072 . with_route_hints ( invoice. route_hints ( ) ) . unwrap ( ) ;
73+ if let Some ( expiry) = invoice. expires_at ( ) {
74+ payment_params = payment_params. with_expiry_time ( expiry. as_secs ( ) ) ;
75+ }
8176 if let Some ( features) = invoice. features ( ) {
8277 payment_params = payment_params. with_bolt11_features ( features. clone ( ) ) . unwrap ( ) ;
8378 }
0 commit comments