@@ -6,6 +6,7 @@ use lightning_invoice::{Description, Bolt11InvoiceDescription, Sha256};
6
6
use crate :: prelude:: * ;
7
7
8
8
use bitcoin:: hashes:: Hash ;
9
+ use bitcoin:: network:: Network ;
9
10
use crate :: chain;
10
11
use crate :: chain:: chaininterface:: { BroadcasterInterface , FeeEstimator } ;
11
12
use crate :: sign:: { Recipient , NodeSigner , SignerProvider , EntropySource } ;
@@ -331,7 +332,7 @@ fn rotate_through_iterators<T, I: Iterator<Item = T>>(mut vecs: Vec<I>) -> impl
331
332
/// [`MIN_FINAL_CLTV_EXPIRY_DETLA`]: crate::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
332
333
pub fn create_invoice_from_channelmanager < M : Deref , T : Deref , ES : Deref , NS : Deref , SP : Deref , F : Deref , R : Deref , MR : Deref , L : Deref > (
333
334
channelmanager : & ChannelManager < M , T , ES , NS , SP , F , R , MR , L > , node_signer : NS , logger : L ,
334
- network : Currency , amt_msat : Option < u64 > , description : String , invoice_expiry_delta_secs : u32 ,
335
+ amt_msat : Option < u64 > , description : String , invoice_expiry_delta_secs : u32 ,
335
336
min_final_cltv_expiry_delta : Option < u16 > ,
336
337
) -> Result < Bolt11Invoice , SignOrCreationError < ( ) > >
337
338
where
@@ -351,7 +352,7 @@ where
351
352
. expect ( "for the foreseeable future this shouldn't happen" ) ;
352
353
353
354
_create_invoice_from_channelmanager_and_duration_since_epoch (
354
- channelmanager, node_signer, logger, network , amt_msat,
355
+ channelmanager, node_signer, logger, amt_msat,
355
356
Bolt11InvoiceDescription :: Direct (
356
357
Description :: new ( description) . map_err ( SignOrCreationError :: CreationError ) ?,
357
358
) ,
@@ -378,7 +379,7 @@ where
378
379
/// [`MIN_FINAL_CLTV_EXPIRY_DETLA`]: crate::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
379
380
pub fn create_invoice_from_channelmanager_with_description_hash < M : Deref , T : Deref , ES : Deref , NS : Deref , SP : Deref , F : Deref , R : Deref , MR : Deref , L : Deref > (
380
381
channelmanager : & ChannelManager < M , T , ES , NS , SP , F , R , MR , L > , node_signer : NS , logger : L ,
381
- network : Currency , amt_msat : Option < u64 > , description_hash : Sha256 ,
382
+ amt_msat : Option < u64 > , description_hash : Sha256 ,
382
383
invoice_expiry_delta_secs : u32 , min_final_cltv_expiry_delta : Option < u16 > ,
383
384
) -> Result < Bolt11Invoice , SignOrCreationError < ( ) > >
384
385
where
@@ -398,15 +399,15 @@ where
398
399
. expect ( "for the foreseeable future this shouldn't happen" ) ;
399
400
400
401
_create_invoice_from_channelmanager_and_duration_since_epoch (
401
- channelmanager, node_signer, logger, network , amt_msat,
402
+ channelmanager, node_signer, logger, amt_msat,
402
403
Bolt11InvoiceDescription :: Hash ( description_hash) ,
403
404
duration_since_epoch, invoice_expiry_delta_secs, min_final_cltv_expiry_delta,
404
405
)
405
406
}
406
407
407
408
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 > (
408
409
channelmanager : & ChannelManager < M , T , ES , NS , SP , F , R , MR , L > , node_signer : NS , logger : L ,
409
- network : Currency , amt_msat : Option < u64 > , description : Bolt11InvoiceDescription ,
410
+ amt_msat : Option < u64 > , description : Bolt11InvoiceDescription ,
410
411
duration_since_epoch : Duration , invoice_expiry_delta_secs : u32 , min_final_cltv_expiry_delta : Option < u16 > ,
411
412
) -> Result < Bolt11Invoice , SignOrCreationError < ( ) > >
412
413
where
@@ -430,7 +431,7 @@ where
430
431
. create_inbound_payment ( amt_msat, invoice_expiry_delta_secs, min_final_cltv_expiry_delta)
431
432
. map_err ( |( ) | SignOrCreationError :: CreationError ( CreationError :: InvalidAmount ) ) ?;
432
433
_create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash (
433
- channelmanager, node_signer, logger, network , amt_msat, description, duration_since_epoch,
434
+ channelmanager, node_signer, logger, amt_msat, description, duration_since_epoch,
434
435
invoice_expiry_delta_secs, payment_hash, payment_secret, min_final_cltv_expiry_delta)
435
436
}
436
437
@@ -444,7 +445,7 @@ where
444
445
/// description hash.
445
446
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 > (
446
447
channelmanager : & ChannelManager < M , T , ES , NS , SP , F , R , MR , L > , node_signer : NS , logger : L ,
447
- network : Currency , amt_msat : Option < u64 > , description_hash : Sha256 ,
448
+ amt_msat : Option < u64 > , description_hash : Sha256 ,
448
449
invoice_expiry_delta_secs : u32 , payment_hash : PaymentHash , min_final_cltv_expiry_delta : Option < u16 > ,
449
450
) -> Result < Bolt11Invoice , SignOrCreationError < ( ) > >
450
451
where
@@ -468,7 +469,7 @@ where
468
469
min_final_cltv_expiry_delta)
469
470
. map_err ( |( ) | SignOrCreationError :: CreationError ( CreationError :: InvalidAmount ) ) ?;
470
471
_create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash (
471
- channelmanager, node_signer, logger, network , amt_msat,
472
+ channelmanager, node_signer, logger, amt_msat,
472
473
Bolt11InvoiceDescription :: Hash ( description_hash) ,
473
474
duration_since_epoch, invoice_expiry_delta_secs, payment_hash, payment_secret,
474
475
min_final_cltv_expiry_delta,
@@ -483,7 +484,7 @@ where
483
484
/// the payment hash is also involved outside the scope of lightning.
484
485
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 > (
485
486
channelmanager : & ChannelManager < M , T , ES , NS , SP , F , R , MR , L > , node_signer : NS , logger : L ,
486
- network : Currency , amt_msat : Option < u64 > , description : String , invoice_expiry_delta_secs : u32 ,
487
+ amt_msat : Option < u64 > , description : String , invoice_expiry_delta_secs : u32 ,
487
488
payment_hash : PaymentHash , min_final_cltv_expiry_delta : Option < u16 > ,
488
489
) -> Result < Bolt11Invoice , SignOrCreationError < ( ) > >
489
490
where
@@ -507,7 +508,7 @@ where
507
508
min_final_cltv_expiry_delta)
508
509
. map_err ( |( ) | SignOrCreationError :: CreationError ( CreationError :: InvalidAmount ) ) ?;
509
510
_create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash (
510
- channelmanager, node_signer, logger, network , amt_msat,
511
+ channelmanager, node_signer, logger, amt_msat,
511
512
Bolt11InvoiceDescription :: Direct (
512
513
Description :: new ( description) . map_err ( SignOrCreationError :: CreationError ) ?,
513
514
) ,
@@ -518,7 +519,7 @@ where
518
519
519
520
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 > (
520
521
channelmanager : & ChannelManager < M , T , ES , NS , SP , F , R , MR , L > , node_signer : NS , logger : L ,
521
- network : Currency , amt_msat : Option < u64 > , description : Bolt11InvoiceDescription ,
522
+ amt_msat : Option < u64 > , description : Bolt11InvoiceDescription ,
522
523
duration_since_epoch : Duration , invoice_expiry_delta_secs : u32 , payment_hash : PaymentHash ,
523
524
payment_secret : PaymentSecret , min_final_cltv_expiry_delta : Option < u16 > ,
524
525
) -> Result < Bolt11Invoice , SignOrCreationError < ( ) > >
@@ -536,6 +537,10 @@ where
536
537
let our_node_pubkey = channelmanager. get_our_node_id ( ) ;
537
538
let channels = channelmanager. list_channels ( ) ;
538
539
540
+ let network = Network :: from_chain_hash ( channelmanager. chain_hash )
541
+ . map ( Into :: into)
542
+ . unwrap_or ( Currency :: Bitcoin ) ;
543
+
539
544
if min_final_cltv_expiry_delta. is_some ( ) && min_final_cltv_expiry_delta. unwrap ( ) . saturating_add ( 3 ) < MIN_FINAL_CLTV_EXPIRY_DELTA {
540
545
return Err ( SignOrCreationError :: CreationError ( CreationError :: MinFinalCltvExpiryDeltaTooShort ) ) ;
541
546
}
@@ -873,7 +878,7 @@ mod test {
873
878
create_unannounced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100000 , 10001 ) ;
874
879
let non_default_invoice_expiry_secs = 4200 ;
875
880
let invoice = create_invoice_from_channelmanager (
876
- nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , nodes[ 1 ] . logger , Currency :: BitcoinTestnet ,
881
+ nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , nodes[ 1 ] . logger ,
877
882
Some ( 10_000 ) , "test" . to_string ( ) , non_default_invoice_expiry_secs, None ,
878
883
) . unwrap ( ) ;
879
884
assert_eq ! ( invoice. amount_milli_satoshis( ) , Some ( 10_000 ) ) ;
@@ -924,7 +929,7 @@ mod test {
924
929
let custom_min_final_cltv_expiry_delta = Some ( 50 ) ;
925
930
926
931
let invoice = create_invoice_from_channelmanager (
927
- nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , nodes[ 1 ] . logger , Currency :: BitcoinTestnet ,
932
+ nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , nodes[ 1 ] . logger ,
928
933
Some ( 10_000 ) , "" . into ( ) , 3600 ,
929
934
if with_custom_delta { custom_min_final_cltv_expiry_delta } else { None } ,
930
935
) . unwrap ( ) ;
@@ -947,7 +952,7 @@ mod test {
947
952
let custom_min_final_cltv_expiry_delta = Some ( 21 ) ;
948
953
949
954
let invoice = create_invoice_from_channelmanager (
950
- nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , nodes[ 1 ] . logger , Currency :: BitcoinTestnet ,
955
+ nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , nodes[ 1 ] . logger ,
951
956
Some ( 10_000 ) , "" . into ( ) , 3600 , custom_min_final_cltv_expiry_delta,
952
957
) . unwrap ( ) ;
953
958
assert_eq ! ( invoice. min_final_cltv_expiry_delta( ) , MIN_FINAL_CLTV_EXPIRY_DELTA as u64 ) ;
@@ -961,7 +966,7 @@ mod test {
961
966
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
962
967
let description_hash = Sha256 ( Hash :: hash ( "Testing description_hash" . as_bytes ( ) ) ) ;
963
968
let invoice = create_invoice_from_channelmanager_with_description_hash (
964
- nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , nodes[ 1 ] . logger , Currency :: BitcoinTestnet ,
969
+ nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , nodes[ 1 ] . logger ,
965
970
Some ( 10_000 ) , description_hash, 3600 , None ,
966
971
) . unwrap ( ) ;
967
972
assert_eq ! ( invoice. amount_milli_satoshis( ) , Some ( 10_000 ) ) ;
@@ -977,7 +982,7 @@ mod test {
977
982
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
978
983
let payment_hash = PaymentHash ( [ 0 ; 32 ] ) ;
979
984
let invoice = create_invoice_from_channelmanager_with_payment_hash (
980
- nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , nodes[ 1 ] . logger , Currency :: BitcoinTestnet ,
985
+ nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , nodes[ 1 ] . logger ,
981
986
Some ( 10_000 ) , "test" . to_string ( ) , 3600 , payment_hash, None ,
982
987
) . unwrap ( ) ;
983
988
assert_eq ! ( invoice. amount_milli_satoshis( ) , Some ( 10_000 ) ) ;
@@ -1269,7 +1274,7 @@ mod test {
1269
1274
) {
1270
1275
let invoice = create_invoice_from_channelmanager (
1271
1276
invoice_node. node , invoice_node. keys_manager , invoice_node. logger ,
1272
- Currency :: BitcoinTestnet , invoice_amt, "test" . to_string ( ) , 3600 , None ,
1277
+ invoice_amt, "test" . to_string ( ) , 3600 , None ,
1273
1278
) . unwrap ( ) ;
1274
1279
let hints = invoice. private_routes ( ) ;
1275
1280
@@ -1906,7 +1911,7 @@ mod test {
1906
1911
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
1907
1912
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1908
1913
let result = create_invoice_from_channelmanager (
1909
- nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , nodes[ 1 ] . logger , Currency :: BitcoinTestnet ,
1914
+ nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , nodes[ 1 ] . logger ,
1910
1915
Some ( 10_000 ) , "Some description" . into ( ) , 3600 , Some ( MIN_FINAL_CLTV_EXPIRY_DELTA - 4 ) ,
1911
1916
) ;
1912
1917
match result {
0 commit comments