@@ -162,7 +162,8 @@ fn _create_phantom_invoice<Signer: Sign, K: Deref>(
162
162
. current_timestamp ( )
163
163
. payment_hash ( Hash :: from_slice ( & payment_hash. 0 ) . unwrap ( ) )
164
164
. payment_secret ( payment_secret)
165
- . min_final_cltv_expiry ( MIN_FINAL_CLTV_EXPIRY . into ( ) ) ;
165
+ . min_final_cltv_expiry ( MIN_FINAL_CLTV_EXPIRY . into ( ) )
166
+ . expiry_time ( Duration :: from_secs ( invoice_expiry_delta_secs. into ( ) ) ) ;
166
167
if let Some ( amt) = amt_msat {
167
168
invoice = invoice. amount_milli_satoshis ( amt) ;
168
169
}
@@ -212,9 +213,12 @@ fn _create_phantom_invoice<Signer: Sign, K: Deref>(
212
213
/// method stores the invoice's payment secret and preimage in `ChannelManager`, so (a) the user
213
214
/// doesn't have to store preimage/payment secret information and (b) `ChannelManager` can verify
214
215
/// that the payment secret is valid when the invoice is paid.
216
+ ///
217
+ /// `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
218
+ /// in excess of the current time.
215
219
pub fn create_invoice_from_channelmanager < Signer : Sign , M : Deref , T : Deref , K : Deref , F : Deref , L : Deref > (
216
220
channelmanager : & ChannelManager < Signer , M , T , K , F , L > , keys_manager : K , network : Currency ,
217
- amt_msat : Option < u64 > , description : String
221
+ amt_msat : Option < u64 > , description : String , invoice_expiry_delta_secs : u32
218
222
) -> Result < Invoice , SignOrCreationError < ( ) > >
219
223
where
220
224
M :: Target : chain:: Watch < Signer > ,
@@ -227,7 +231,7 @@ where
227
231
let duration = SystemTime :: now ( ) . duration_since ( SystemTime :: UNIX_EPOCH )
228
232
. expect ( "for the foreseeable future this shouldn't happen" ) ;
229
233
create_invoice_from_channelmanager_and_duration_since_epoch (
230
- channelmanager, keys_manager, network, amt_msat, description, duration
234
+ channelmanager, keys_manager, network, amt_msat, description, duration, invoice_expiry_delta_secs
231
235
)
232
236
}
233
237
@@ -238,9 +242,12 @@ where
238
242
/// doesn't have to store preimage/payment secret information and (b) `ChannelManager` can verify
239
243
/// that the payment secret is valid when the invoice is paid.
240
244
/// Use this variant if you want to pass the `description_hash` to the invoice.
245
+ ///
246
+ /// `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
247
+ /// in excess of the current time.
241
248
pub fn create_invoice_from_channelmanager_with_description_hash < Signer : Sign , M : Deref , T : Deref , K : Deref , F : Deref , L : Deref > (
242
249
channelmanager : & ChannelManager < Signer , M , T , K , F , L > , keys_manager : K , network : Currency ,
243
- amt_msat : Option < u64 > , description_hash : Sha256 ,
250
+ amt_msat : Option < u64 > , description_hash : Sha256 , invoice_expiry_delta_secs : u32
244
251
) -> Result < Invoice , SignOrCreationError < ( ) > >
245
252
where
246
253
M :: Target : chain:: Watch < Signer > ,
@@ -256,7 +263,7 @@ where
256
263
. expect ( "for the foreseeable future this shouldn't happen" ) ;
257
264
258
265
create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch (
259
- channelmanager, keys_manager, network, amt_msat, description_hash, duration,
266
+ channelmanager, keys_manager, network, amt_msat, description_hash, duration, invoice_expiry_delta_secs
260
267
)
261
268
}
262
269
@@ -265,7 +272,7 @@ where
265
272
/// available and the current time is supplied by the caller.
266
273
pub fn create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch < Signer : Sign , M : Deref , T : Deref , K : Deref , F : Deref , L : Deref > (
267
274
channelmanager : & ChannelManager < Signer , M , T , K , F , L > , keys_manager : K , network : Currency ,
268
- amt_msat : Option < u64 > , description_hash : Sha256 , duration_since_epoch : Duration ,
275
+ amt_msat : Option < u64 > , description_hash : Sha256 , duration_since_epoch : Duration , invoice_expiry_delta_secs : u32
269
276
) -> Result < Invoice , SignOrCreationError < ( ) > >
270
277
where
271
278
M :: Target : chain:: Watch < Signer > ,
@@ -277,7 +284,7 @@ where
277
284
_create_invoice_from_channelmanager_and_duration_since_epoch (
278
285
channelmanager, keys_manager, network, amt_msat,
279
286
InvoiceDescription :: Hash ( & description_hash) ,
280
- duration_since_epoch,
287
+ duration_since_epoch, invoice_expiry_delta_secs
281
288
)
282
289
}
283
290
@@ -286,7 +293,7 @@ where
286
293
/// available and the current time is supplied by the caller.
287
294
pub fn create_invoice_from_channelmanager_and_duration_since_epoch < Signer : Sign , M : Deref , T : Deref , K : Deref , F : Deref , L : Deref > (
288
295
channelmanager : & ChannelManager < Signer , M , T , K , F , L > , keys_manager : K , network : Currency ,
289
- amt_msat : Option < u64 > , description : String , duration_since_epoch : Duration ,
296
+ amt_msat : Option < u64 > , description : String , duration_since_epoch : Duration , invoice_expiry_delta_secs : u32
290
297
) -> Result < Invoice , SignOrCreationError < ( ) > >
291
298
where
292
299
M :: Target : chain:: Watch < Signer > ,
@@ -300,13 +307,14 @@ where
300
307
InvoiceDescription :: Direct (
301
308
& Description :: new ( description) . map_err ( SignOrCreationError :: CreationError ) ?,
302
309
) ,
303
- duration_since_epoch,
310
+ duration_since_epoch, invoice_expiry_delta_secs
304
311
)
305
312
}
306
313
307
314
fn _create_invoice_from_channelmanager_and_duration_since_epoch < Signer : Sign , M : Deref , T : Deref , K : Deref , F : Deref , L : Deref > (
308
315
channelmanager : & ChannelManager < Signer , M , T , K , F , L > , keys_manager : K , network : Currency ,
309
316
amt_msat : Option < u64 > , description : InvoiceDescription , duration_since_epoch : Duration ,
317
+ invoice_expiry_delta_secs : u32
310
318
) -> Result < Invoice , SignOrCreationError < ( ) > >
311
319
where
312
320
M :: Target : chain:: Watch < Signer > ,
@@ -337,7 +345,8 @@ where
337
345
. payment_hash ( Hash :: from_slice ( & payment_hash. 0 ) . unwrap ( ) )
338
346
. payment_secret ( payment_secret)
339
347
. basic_mpp ( )
340
- . min_final_cltv_expiry ( MIN_FINAL_CLTV_EXPIRY . into ( ) ) ;
348
+ . min_final_cltv_expiry ( MIN_FINAL_CLTV_EXPIRY . into ( ) )
349
+ . expiry_time ( Duration :: from_secs ( invoice_expiry_delta_secs. into ( ) ) ) ;
341
350
if let Some ( amt) = amt_msat {
342
351
invoice = invoice. amount_milli_satoshis ( amt) ;
343
352
}
@@ -528,10 +537,11 @@ mod test {
528
537
create_unannounced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100000 , 10001 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
529
538
let invoice = create_invoice_from_channelmanager_and_duration_since_epoch (
530
539
& nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , Currency :: BitcoinTestnet , Some ( 10_000 ) , "test" . to_string ( ) ,
531
- Duration :: from_secs ( 1234567 ) ) . unwrap ( ) ;
540
+ Duration :: from_secs ( 1234567 ) , 3600 ) . unwrap ( ) ;
532
541
assert_eq ! ( invoice. amount_pico_btc( ) , Some ( 100_000 ) ) ;
533
542
assert_eq ! ( invoice. min_final_cltv_expiry( ) , MIN_FINAL_CLTV_EXPIRY as u64 ) ;
534
543
assert_eq ! ( invoice. description( ) , InvoiceDescription :: Direct ( & Description ( "test" . to_string( ) ) ) ) ;
544
+ assert_eq ! ( invoice. expiry_time( ) , Duration :: from_secs( 3600 ) ) ;
535
545
536
546
// Invoice SCIDs should always use inbound SCID aliases over the real channel ID, if one is
537
547
// available.
@@ -592,7 +602,7 @@ mod test {
592
602
let description_hash = crate :: Sha256 ( Hash :: hash ( "Testing description_hash" . as_bytes ( ) ) ) ;
593
603
let invoice = :: utils:: create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch (
594
604
& nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , Currency :: BitcoinTestnet , Some ( 10_000 ) ,
595
- description_hash, Duration :: from_secs ( 1234567 ) ,
605
+ description_hash, Duration :: from_secs ( 1234567 ) , 3600
596
606
) . unwrap ( ) ;
597
607
assert_eq ! ( invoice. amount_pico_btc( ) , Some ( 100_000 ) ) ;
598
608
assert_eq ! ( invoice. min_final_cltv_expiry( ) , MIN_FINAL_CLTV_EXPIRY as u64 ) ;
@@ -752,7 +762,7 @@ mod test {
752
762
) {
753
763
let invoice = create_invoice_from_channelmanager_and_duration_since_epoch (
754
764
& invoice_node. node , invoice_node. keys_manager , Currency :: BitcoinTestnet , invoice_amt, "test" . to_string ( ) ,
755
- Duration :: from_secs ( 1234567 ) ) . unwrap ( ) ;
765
+ Duration :: from_secs ( 1234567 ) , 3600 ) . unwrap ( ) ;
756
766
let hints = invoice. private_routes ( ) ;
757
767
758
768
for hint in hints {
@@ -811,6 +821,7 @@ mod test {
811
821
assert_eq ! ( invoice. min_final_cltv_expiry( ) , MIN_FINAL_CLTV_EXPIRY as u64 ) ;
812
822
assert_eq ! ( invoice. description( ) , InvoiceDescription :: Direct ( & Description ( "test" . to_string( ) ) ) ) ;
813
823
assert_eq ! ( invoice. route_hints( ) . len( ) , 2 ) ;
824
+ assert_eq ! ( invoice. expiry_time( ) , Duration :: from_secs( 3600 ) ) ;
814
825
assert ! ( !invoice. features( ) . unwrap( ) . supports_basic_mpp( ) ) ;
815
826
816
827
let payment_params = PaymentParameters :: from_node_id ( invoice. recover_payee_pub_key ( ) )
@@ -931,10 +942,23 @@ mod test {
931
942
] ;
932
943
933
944
let description_hash = crate :: Sha256 ( Hash :: hash ( "Description hash phantom invoice" . as_bytes ( ) ) ) ;
934
- let invoice = :: utils:: create_phantom_invoice_with_description_hash :: < EnforcingSigner , & test_utils:: TestKeysInterface > ( Some ( payment_amt) , None , 3600 , description_hash, route_hints, & nodes[ 1 ] . keys_manager , Currency :: BitcoinTestnet ) . unwrap ( ) ;
935
-
945
+ let non_default_invoice_expiry_secs = 4200 ;
946
+ let invoice = :: utils:: create_phantom_invoice_with_description_hash :: <
947
+ EnforcingSigner ,
948
+ & test_utils:: TestKeysInterface ,
949
+ > (
950
+ Some ( payment_amt) ,
951
+ None ,
952
+ non_default_invoice_expiry_secs,
953
+ description_hash,
954
+ route_hints,
955
+ & nodes[ 1 ] . keys_manager ,
956
+ Currency :: BitcoinTestnet ,
957
+ )
958
+ . unwrap ( ) ;
936
959
assert_eq ! ( invoice. amount_pico_btc( ) , Some ( 200_000 ) ) ;
937
960
assert_eq ! ( invoice. min_final_cltv_expiry( ) , MIN_FINAL_CLTV_EXPIRY as u64 ) ;
961
+ assert_eq ! ( invoice. expiry_time( ) , Duration :: from_secs( non_default_invoice_expiry_secs. into( ) ) ) ;
938
962
assert_eq ! ( invoice. description( ) , InvoiceDescription :: Hash ( & crate :: Sha256 ( Sha256 :: hash( "Description hash phantom invoice" . as_bytes( ) ) ) ) ) ;
939
963
}
940
964
0 commit comments