@@ -346,11 +346,16 @@ where
346
346
L :: Target : Logger ,
347
347
{
348
348
use std:: time:: SystemTime ;
349
- let duration = SystemTime :: now ( ) . duration_since ( SystemTime :: UNIX_EPOCH )
349
+ let duration_since_epoch = SystemTime :: now ( )
350
+ . duration_since ( SystemTime :: UNIX_EPOCH )
350
351
. expect ( "for the foreseeable future this shouldn't happen" ) ;
351
- create_invoice_from_channelmanager_and_duration_since_epoch (
352
+
353
+ _create_invoice_from_channelmanager_and_duration_since_epoch (
352
354
channelmanager, node_signer, logger, network, amt_msat,
353
- description, duration, invoice_expiry_delta_secs, min_final_cltv_expiry_delta,
355
+ Bolt11InvoiceDescription :: Direct (
356
+ Description :: new ( description) . map_err ( SignOrCreationError :: CreationError ) ?,
357
+ ) ,
358
+ duration_since_epoch, invoice_expiry_delta_secs, min_final_cltv_expiry_delta,
354
359
)
355
360
}
356
361
@@ -388,77 +393,17 @@ where
388
393
L :: Target : Logger ,
389
394
{
390
395
use std:: time:: SystemTime ;
391
-
392
- let duration = SystemTime :: now ( )
396
+ let duration_since_epoch = SystemTime :: now ( )
393
397
. duration_since ( SystemTime :: UNIX_EPOCH )
394
398
. expect ( "for the foreseeable future this shouldn't happen" ) ;
395
399
396
- create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch (
397
- channelmanager, node_signer, logger, network, amt_msat,
398
- description_hash, duration, invoice_expiry_delta_secs, min_final_cltv_expiry_delta,
399
- )
400
- }
401
-
402
- /// Utility to construct an invoice. Generally, unless you want to do something like a custom
403
- /// `cltv_expiry`, this is what you should be using to create an invoice.
404
- #[ cfg_attr( feature = "std" , doc = "" ) ]
405
- #[ cfg_attr( feature = "std" , doc = "See [`create_invoice_from_channelmanager_with_description_hash`] for more information." ) ]
406
- #[ cfg_attr( feature = "std" , doc = "" ) ]
407
- #[ cfg_attr( feature = "std" , doc = "This can be used in a `no_std` environment, where [`std::time::SystemTime`] is not available and the current time is supplied by the caller." ) ]
408
- pub fn create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch < M : Deref , T : Deref , ES : Deref , NS : Deref , SP : Deref , F : Deref , R : Deref , MR : Deref , L : Deref > (
409
- channelmanager : & ChannelManager < M , T , ES , NS , SP , F , R , MR , L > , node_signer : NS , logger : L ,
410
- network : Currency , amt_msat : Option < u64 > , description_hash : Sha256 ,
411
- duration_since_epoch : Duration , invoice_expiry_delta_secs : u32 , min_final_cltv_expiry_delta : Option < u16 > ,
412
- ) -> Result < Bolt11Invoice , SignOrCreationError < ( ) > >
413
- where
414
- M :: Target : chain:: Watch < <SP :: Target as SignerProvider >:: EcdsaSigner > ,
415
- T :: Target : BroadcasterInterface ,
416
- ES :: Target : EntropySource ,
417
- NS :: Target : NodeSigner ,
418
- SP :: Target : SignerProvider ,
419
- F :: Target : FeeEstimator ,
420
- R :: Target : Router ,
421
- MR :: Target : MessageRouter ,
422
- L :: Target : Logger ,
423
- {
424
400
_create_invoice_from_channelmanager_and_duration_since_epoch (
425
401
channelmanager, node_signer, logger, network, amt_msat,
426
402
Bolt11InvoiceDescription :: Hash ( description_hash) ,
427
403
duration_since_epoch, invoice_expiry_delta_secs, min_final_cltv_expiry_delta,
428
404
)
429
405
}
430
406
431
- /// Utility to construct an invoice. Generally, unless you want to do something like a custom
432
- /// `cltv_expiry`, this is what you should be using to create an invoice.
433
- #[ cfg_attr( feature = "std" , doc = "" ) ]
434
- #[ cfg_attr( feature = "std" , doc = "See [`create_invoice_from_channelmanager`] for more information." ) ]
435
- #[ cfg_attr( feature = "std" , doc = "" ) ]
436
- #[ cfg_attr( feature = "std" , doc = "This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not available and the current time is supplied by the caller." ) ]
437
- pub fn create_invoice_from_channelmanager_and_duration_since_epoch < M : Deref , T : Deref , ES : Deref , NS : Deref , SP : Deref , F : Deref , R : Deref , MR : Deref , L : Deref > (
438
- channelmanager : & ChannelManager < M , T , ES , NS , SP , F , R , MR , L > , node_signer : NS , logger : L ,
439
- network : Currency , amt_msat : Option < u64 > , description : String , duration_since_epoch : Duration ,
440
- invoice_expiry_delta_secs : u32 , min_final_cltv_expiry_delta : Option < u16 > ,
441
- ) -> Result < Bolt11Invoice , SignOrCreationError < ( ) > >
442
- where
443
- M :: Target : chain:: Watch < <SP :: Target as SignerProvider >:: EcdsaSigner > ,
444
- T :: Target : BroadcasterInterface ,
445
- ES :: Target : EntropySource ,
446
- NS :: Target : NodeSigner ,
447
- SP :: Target : SignerProvider ,
448
- F :: Target : FeeEstimator ,
449
- R :: Target : Router ,
450
- MR :: Target : MessageRouter ,
451
- L :: Target : Logger ,
452
- {
453
- _create_invoice_from_channelmanager_and_duration_since_epoch (
454
- channelmanager, node_signer, logger, network, amt_msat,
455
- Bolt11InvoiceDescription :: Direct (
456
- Description :: new ( description) . map_err ( SignOrCreationError :: CreationError ) ?,
457
- ) ,
458
- duration_since_epoch, invoice_expiry_delta_secs, min_final_cltv_expiry_delta,
459
- )
460
- }
461
-
462
407
fn _create_invoice_from_channelmanager_and_duration_since_epoch < M : Deref , T : Deref , ES : Deref , NS : Deref , SP : Deref , F : Deref , R : Deref , MR : Deref , L : Deref > (
463
408
channelmanager : & ChannelManager < M , T , ES , NS , SP , F , R , MR , L > , node_signer : NS , logger : L ,
464
409
network : Currency , amt_msat : Option < u64 > , description : Bolt11InvoiceDescription ,
@@ -489,15 +434,17 @@ where
489
434
invoice_expiry_delta_secs, payment_hash, payment_secret, min_final_cltv_expiry_delta)
490
435
}
491
436
492
- /// See [`create_invoice_from_channelmanager_and_duration_since_epoch`]
437
+ #[ cfg( feature = "std" ) ]
438
+ /// See [`create_invoice_from_channelmanager`].
439
+ ///
493
440
/// This version allows for providing custom [`PaymentHash`] and description hash for the invoice.
494
441
///
495
442
/// This may be useful if you're building an on-chain swap or involving another protocol where
496
443
/// the payment hash is also involved outside the scope of lightning and want to set the
497
444
/// description hash.
498
- pub fn create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch_with_payment_hash < M : Deref , T : Deref , ES : Deref , NS : Deref , SP : Deref , F : Deref , R : Deref , MR : Deref , L : Deref > (
445
+ pub fn create_invoice_from_channelmanager_with_description_hash_and_payment_hash < M : Deref , T : Deref , ES : Deref , NS : Deref , SP : Deref , F : Deref , R : Deref , MR : Deref , L : Deref > (
499
446
channelmanager : & ChannelManager < M , T , ES , NS , SP , F , R , MR , L > , node_signer : NS , logger : L ,
500
- network : Currency , amt_msat : Option < u64 > , description_hash : Sha256 , duration_since_epoch : Duration ,
447
+ network : Currency , amt_msat : Option < u64 > , description_hash : Sha256 ,
501
448
invoice_expiry_delta_secs : u32 , payment_hash : PaymentHash , min_final_cltv_expiry_delta : Option < u16 > ,
502
449
) -> Result < Bolt11Invoice , SignOrCreationError < ( ) > >
503
450
where
@@ -511,6 +458,11 @@ where
511
458
MR :: Target : MessageRouter ,
512
459
L :: Target : Logger ,
513
460
{
461
+ use std:: time:: SystemTime ;
462
+ let duration_since_epoch = SystemTime :: now ( )
463
+ . duration_since ( SystemTime :: UNIX_EPOCH )
464
+ . expect ( "for the foreseeable future this shouldn't happen" ) ;
465
+
514
466
let payment_secret = channelmanager
515
467
. create_inbound_payment_for_hash ( payment_hash, amt_msat, invoice_expiry_delta_secs,
516
468
min_final_cltv_expiry_delta)
@@ -523,14 +475,16 @@ where
523
475
)
524
476
}
525
477
526
- /// See [`create_invoice_from_channelmanager_and_duration_since_epoch`]
478
+ #[ cfg( feature = "std" ) ]
479
+ /// See [`create_invoice_from_channelmanager`].
480
+ ///
527
481
/// This version allows for providing a custom [`PaymentHash`] for the invoice.
528
482
/// This may be useful if you're building an on-chain swap or involving another protocol where
529
483
/// the payment hash is also involved outside the scope of lightning.
530
- pub fn create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash < M : Deref , T : Deref , ES : Deref , NS : Deref , SP : Deref , F : Deref , R : Deref , MR : Deref , L : Deref > (
484
+ pub fn create_invoice_from_channelmanager_with_payment_hash < M : Deref , T : Deref , ES : Deref , NS : Deref , SP : Deref , F : Deref , R : Deref , MR : Deref , L : Deref > (
531
485
channelmanager : & ChannelManager < M , T , ES , NS , SP , F , R , MR , L > , node_signer : NS , logger : L ,
532
- network : Currency , amt_msat : Option < u64 > , description : String , duration_since_epoch : Duration ,
533
- invoice_expiry_delta_secs : u32 , payment_hash : PaymentHash , min_final_cltv_expiry_delta : Option < u16 > ,
486
+ network : Currency , amt_msat : Option < u64 > , description : String , invoice_expiry_delta_secs : u32 ,
487
+ payment_hash : PaymentHash , min_final_cltv_expiry_delta : Option < u16 > ,
534
488
) -> Result < Bolt11Invoice , SignOrCreationError < ( ) > >
535
489
where
536
490
M :: Target : chain:: Watch < <SP :: Target as SignerProvider >:: EcdsaSigner > ,
@@ -543,6 +497,11 @@ where
543
497
MR :: Target : MessageRouter ,
544
498
L :: Target : Logger ,
545
499
{
500
+ use std:: time:: SystemTime ;
501
+ let duration_since_epoch = SystemTime :: now ( )
502
+ . duration_since ( SystemTime :: UNIX_EPOCH )
503
+ . expect ( "for the foreseeable future this shouldn't happen" ) ;
504
+
546
505
let payment_secret = channelmanager
547
506
. create_inbound_payment_for_hash ( payment_hash, amt_msat, invoice_expiry_delta_secs,
548
507
min_final_cltv_expiry_delta)
@@ -913,10 +872,10 @@ mod test {
913
872
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
914
873
create_unannounced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100000 , 10001 ) ;
915
874
let non_default_invoice_expiry_secs = 4200 ;
916
- let invoice = create_invoice_from_channelmanager_and_duration_since_epoch (
875
+ let invoice = create_invoice_from_channelmanager (
917
876
nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , nodes[ 1 ] . logger , Currency :: BitcoinTestnet ,
918
- Some ( 10_000 ) , "test" . to_string ( ) , Duration :: from_secs ( 1234567 ) ,
919
- non_default_invoice_expiry_secs , None ) . unwrap ( ) ;
877
+ Some ( 10_000 ) , "test" . to_string ( ) , non_default_invoice_expiry_secs , None ,
878
+ ) . unwrap ( ) ;
920
879
assert_eq ! ( invoice. amount_milli_satoshis( ) , Some ( 10_000 ) ) ;
921
880
// If no `min_final_cltv_expiry_delta` is specified, then it should be `MIN_FINAL_CLTV_EXPIRY_DELTA`.
922
881
assert_eq ! ( invoice. min_final_cltv_expiry_delta( ) , MIN_FINAL_CLTV_EXPIRY_DELTA as u64 ) ;
@@ -964,9 +923,9 @@ mod test {
964
923
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
965
924
let custom_min_final_cltv_expiry_delta = Some ( 50 ) ;
966
925
967
- let invoice = create_invoice_from_channelmanager_and_duration_since_epoch (
926
+ let invoice = create_invoice_from_channelmanager (
968
927
nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , nodes[ 1 ] . logger , Currency :: BitcoinTestnet ,
969
- Some ( 10_000 ) , "" . into ( ) , Duration :: from_secs ( 1234567 ) , 3600 ,
928
+ Some ( 10_000 ) , "" . into ( ) , 3600 ,
970
929
if with_custom_delta { custom_min_final_cltv_expiry_delta } else { None } ,
971
930
) . unwrap ( ) ;
972
931
assert_eq ! ( invoice. min_final_cltv_expiry_delta( ) , if with_custom_delta {
@@ -987,10 +946,9 @@ mod test {
987
946
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
988
947
let custom_min_final_cltv_expiry_delta = Some ( 21 ) ;
989
948
990
- let invoice = create_invoice_from_channelmanager_and_duration_since_epoch (
949
+ let invoice = create_invoice_from_channelmanager (
991
950
nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , nodes[ 1 ] . logger , Currency :: BitcoinTestnet ,
992
- Some ( 10_000 ) , "" . into ( ) , Duration :: from_secs ( 1234567 ) , 3600 ,
993
- custom_min_final_cltv_expiry_delta,
951
+ Some ( 10_000 ) , "" . into ( ) , 3600 , custom_min_final_cltv_expiry_delta,
994
952
) . unwrap ( ) ;
995
953
assert_eq ! ( invoice. min_final_cltv_expiry_delta( ) , MIN_FINAL_CLTV_EXPIRY_DELTA as u64 ) ;
996
954
}
@@ -1002,9 +960,9 @@ mod test {
1002
960
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
1003
961
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1004
962
let description_hash = Sha256 ( Hash :: hash ( "Testing description_hash" . as_bytes ( ) ) ) ;
1005
- let invoice = create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch (
963
+ let invoice = create_invoice_from_channelmanager_with_description_hash (
1006
964
nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , nodes[ 1 ] . logger , Currency :: BitcoinTestnet ,
1007
- Some ( 10_000 ) , description_hash, Duration :: from_secs ( 1234567 ) , 3600 , None ,
965
+ Some ( 10_000 ) , description_hash, 3600 , None ,
1008
966
) . unwrap ( ) ;
1009
967
assert_eq ! ( invoice. amount_milli_satoshis( ) , Some ( 10_000 ) ) ;
1010
968
assert_eq ! ( invoice. min_final_cltv_expiry_delta( ) , MIN_FINAL_CLTV_EXPIRY_DELTA as u64 ) ;
@@ -1018,10 +976,9 @@ mod test {
1018
976
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
1019
977
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1020
978
let payment_hash = PaymentHash ( [ 0 ; 32 ] ) ;
1021
- let invoice = create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash (
979
+ let invoice = create_invoice_from_channelmanager_with_payment_hash (
1022
980
nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , nodes[ 1 ] . logger , Currency :: BitcoinTestnet ,
1023
- Some ( 10_000 ) , "test" . to_string ( ) , Duration :: from_secs ( 1234567 ) , 3600 ,
1024
- payment_hash, None ,
981
+ Some ( 10_000 ) , "test" . to_string ( ) , 3600 , payment_hash, None ,
1025
982
) . unwrap ( ) ;
1026
983
assert_eq ! ( invoice. amount_milli_satoshis( ) , Some ( 10_000 ) ) ;
1027
984
assert_eq ! ( invoice. min_final_cltv_expiry_delta( ) , MIN_FINAL_CLTV_EXPIRY_DELTA as u64 ) ;
@@ -1310,10 +1267,10 @@ mod test {
1310
1267
invoice_node : & Node < ' a , ' b , ' c > ,
1311
1268
mut chan_ids_to_match : HashSet < u64 >
1312
1269
) {
1313
- let invoice = create_invoice_from_channelmanager_and_duration_since_epoch (
1270
+ let invoice = create_invoice_from_channelmanager (
1314
1271
invoice_node. node , invoice_node. keys_manager , invoice_node. logger ,
1315
- Currency :: BitcoinTestnet , invoice_amt, "test" . to_string ( ) , Duration :: from_secs ( 1234567 ) ,
1316
- 3600 , None ) . unwrap ( ) ;
1272
+ Currency :: BitcoinTestnet , invoice_amt, "test" . to_string ( ) , 3600 , None ,
1273
+ ) . unwrap ( ) ;
1317
1274
let hints = invoice. private_routes ( ) ;
1318
1275
1319
1276
for hint in hints {
@@ -1948,9 +1905,9 @@ mod test {
1948
1905
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
1949
1906
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
1950
1907
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1951
- let result = create_invoice_from_channelmanager_and_duration_since_epoch (
1908
+ let result = create_invoice_from_channelmanager (
1952
1909
nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , nodes[ 1 ] . logger , Currency :: BitcoinTestnet ,
1953
- Some ( 10_000 ) , "Some description" . into ( ) , Duration :: from_secs ( 1234567 ) , 3600 , Some ( MIN_FINAL_CLTV_EXPIRY_DELTA - 4 ) ,
1910
+ Some ( 10_000 ) , "Some description" . into ( ) , 3600 , Some ( MIN_FINAL_CLTV_EXPIRY_DELTA - 4 ) ,
1954
1911
) ;
1955
1912
match result {
1956
1913
Err ( SignOrCreationError :: CreationError ( CreationError :: MinFinalCltvExpiryDeltaTooShort ) ) => { } ,
0 commit comments