@@ -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,16 @@ 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`]
493
439
/// This version allows for providing custom [`PaymentHash`] and description hash for the invoice.
494
440
///
495
441
/// This may be useful if you're building an on-chain swap or involving another protocol where
496
442
/// the payment hash is also involved outside the scope of lightning and want to set the
497
443
/// 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 > (
444
+ 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
445
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 ,
446
+ network : Currency , amt_msat : Option < u64 > , description_hash : Sha256 ,
501
447
invoice_expiry_delta_secs : u32 , payment_hash : PaymentHash , min_final_cltv_expiry_delta : Option < u16 > ,
502
448
) -> Result < Bolt11Invoice , SignOrCreationError < ( ) > >
503
449
where
@@ -511,6 +457,11 @@ where
511
457
MR :: Target : MessageRouter ,
512
458
L :: Target : Logger ,
513
459
{
460
+ use std:: time:: SystemTime ;
461
+ let duration_since_epoch = SystemTime :: now ( )
462
+ . duration_since ( SystemTime :: UNIX_EPOCH )
463
+ . expect ( "for the foreseeable future this shouldn't happen" ) ;
464
+
514
465
let payment_secret = channelmanager
515
466
. create_inbound_payment_for_hash ( payment_hash, amt_msat, invoice_expiry_delta_secs,
516
467
min_final_cltv_expiry_delta)
@@ -523,14 +474,15 @@ where
523
474
)
524
475
}
525
476
526
- /// See [`create_invoice_from_channelmanager_and_duration_since_epoch`]
477
+ #[ cfg( feature = "std" ) ]
478
+ /// See [`create_invoice_from_channelmanager`]
527
479
/// This version allows for providing a custom [`PaymentHash`] for the invoice.
528
480
/// This may be useful if you're building an on-chain swap or involving another protocol where
529
481
/// 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 > (
482
+ 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
483
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 > ,
484
+ network : Currency , amt_msat : Option < u64 > , description : String , invoice_expiry_delta_secs : u32 ,
485
+ payment_hash : PaymentHash , min_final_cltv_expiry_delta : Option < u16 > ,
534
486
) -> Result < Bolt11Invoice , SignOrCreationError < ( ) > >
535
487
where
536
488
M :: Target : chain:: Watch < <SP :: Target as SignerProvider >:: EcdsaSigner > ,
@@ -543,6 +495,11 @@ where
543
495
MR :: Target : MessageRouter ,
544
496
L :: Target : Logger ,
545
497
{
498
+ use std:: time:: SystemTime ;
499
+ let duration_since_epoch = SystemTime :: now ( )
500
+ . duration_since ( SystemTime :: UNIX_EPOCH )
501
+ . expect ( "for the foreseeable future this shouldn't happen" ) ;
502
+
546
503
let payment_secret = channelmanager
547
504
. create_inbound_payment_for_hash ( payment_hash, amt_msat, invoice_expiry_delta_secs,
548
505
min_final_cltv_expiry_delta)
@@ -913,10 +870,10 @@ mod test {
913
870
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
914
871
create_unannounced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100000 , 10001 ) ;
915
872
let non_default_invoice_expiry_secs = 4200 ;
916
- let invoice = create_invoice_from_channelmanager_and_duration_since_epoch (
873
+ let invoice = create_invoice_from_channelmanager (
917
874
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 ( ) ;
875
+ Some ( 10_000 ) , "test" . to_string ( ) , non_default_invoice_expiry_secs , None ,
876
+ ) . unwrap ( ) ;
920
877
assert_eq ! ( invoice. amount_milli_satoshis( ) , Some ( 10_000 ) ) ;
921
878
// If no `min_final_cltv_expiry_delta` is specified, then it should be `MIN_FINAL_CLTV_EXPIRY_DELTA`.
922
879
assert_eq ! ( invoice. min_final_cltv_expiry_delta( ) , MIN_FINAL_CLTV_EXPIRY_DELTA as u64 ) ;
@@ -964,9 +921,9 @@ mod test {
964
921
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
965
922
let custom_min_final_cltv_expiry_delta = Some ( 50 ) ;
966
923
967
- let invoice = create_invoice_from_channelmanager_and_duration_since_epoch (
924
+ let invoice = create_invoice_from_channelmanager (
968
925
nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , nodes[ 1 ] . logger , Currency :: BitcoinTestnet ,
969
- Some ( 10_000 ) , "" . into ( ) , Duration :: from_secs ( 1234567 ) , 3600 ,
926
+ Some ( 10_000 ) , "" . into ( ) , 3600 ,
970
927
if with_custom_delta { custom_min_final_cltv_expiry_delta } else { None } ,
971
928
) . unwrap ( ) ;
972
929
assert_eq ! ( invoice. min_final_cltv_expiry_delta( ) , if with_custom_delta {
@@ -987,10 +944,9 @@ mod test {
987
944
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
988
945
let custom_min_final_cltv_expiry_delta = Some ( 21 ) ;
989
946
990
- let invoice = create_invoice_from_channelmanager_and_duration_since_epoch (
947
+ let invoice = create_invoice_from_channelmanager (
991
948
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,
949
+ Some ( 10_000 ) , "" . into ( ) , 3600 , custom_min_final_cltv_expiry_delta,
994
950
) . unwrap ( ) ;
995
951
assert_eq ! ( invoice. min_final_cltv_expiry_delta( ) , MIN_FINAL_CLTV_EXPIRY_DELTA as u64 ) ;
996
952
}
@@ -1002,9 +958,9 @@ mod test {
1002
958
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
1003
959
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1004
960
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 (
961
+ let invoice = create_invoice_from_channelmanager_with_description_hash (
1006
962
nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , nodes[ 1 ] . logger , Currency :: BitcoinTestnet ,
1007
- Some ( 10_000 ) , description_hash, Duration :: from_secs ( 1234567 ) , 3600 , None ,
963
+ Some ( 10_000 ) , description_hash, 3600 , None ,
1008
964
) . unwrap ( ) ;
1009
965
assert_eq ! ( invoice. amount_milli_satoshis( ) , Some ( 10_000 ) ) ;
1010
966
assert_eq ! ( invoice. min_final_cltv_expiry_delta( ) , MIN_FINAL_CLTV_EXPIRY_DELTA as u64 ) ;
@@ -1018,10 +974,9 @@ mod test {
1018
974
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
1019
975
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1020
976
let payment_hash = PaymentHash ( [ 0 ; 32 ] ) ;
1021
- let invoice = create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash (
977
+ let invoice = create_invoice_from_channelmanager_with_payment_hash (
1022
978
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 ,
979
+ Some ( 10_000 ) , "test" . to_string ( ) , 3600 , payment_hash, None ,
1025
980
) . unwrap ( ) ;
1026
981
assert_eq ! ( invoice. amount_milli_satoshis( ) , Some ( 10_000 ) ) ;
1027
982
assert_eq ! ( invoice. min_final_cltv_expiry_delta( ) , MIN_FINAL_CLTV_EXPIRY_DELTA as u64 ) ;
@@ -1310,10 +1265,10 @@ mod test {
1310
1265
invoice_node : & Node < ' a , ' b , ' c > ,
1311
1266
mut chan_ids_to_match : HashSet < u64 >
1312
1267
) {
1313
- let invoice = create_invoice_from_channelmanager_and_duration_since_epoch (
1268
+ let invoice = create_invoice_from_channelmanager (
1314
1269
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 ( ) ;
1270
+ Currency :: BitcoinTestnet , invoice_amt, "test" . to_string ( ) , 3600 , None ,
1271
+ ) . unwrap ( ) ;
1317
1272
let hints = invoice. private_routes ( ) ;
1318
1273
1319
1274
for hint in hints {
@@ -1948,9 +1903,9 @@ mod test {
1948
1903
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
1949
1904
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
1950
1905
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1951
- let result = create_invoice_from_channelmanager_and_duration_since_epoch (
1906
+ let result = create_invoice_from_channelmanager (
1952
1907
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 ) ,
1908
+ Some ( 10_000 ) , "Some description" . into ( ) , 3600 , Some ( MIN_FINAL_CLTV_EXPIRY_DELTA - 4 ) ,
1954
1909
) ;
1955
1910
match result {
1956
1911
Err ( SignOrCreationError :: CreationError ( CreationError :: MinFinalCltvExpiryDeltaTooShort ) ) => { } ,
0 commit comments