1212use crate :: Bolt11Invoice ;
1313use bitcoin:: hashes:: Hash ;
1414
15- use lightning:: ln:: types:: PaymentHash ;
1615use lightning:: ln:: channelmanager:: RecipientOnionFields ;
16+ use lightning:: ln:: types:: PaymentHash ;
1717use lightning:: routing:: router:: { PaymentParameters , RouteParameters } ;
1818
1919/// Builds the necessary parameters to pay or pre-flight probe the given zero-amount
@@ -28,8 +28,9 @@ use lightning::routing::router::{PaymentParameters, RouteParameters};
2828///
2929/// [`ChannelManager::send_payment`]: lightning::ln::channelmanager::ChannelManager::send_payment
3030/// [`ChannelManager::send_preflight_probes`]: lightning::ln::channelmanager::ChannelManager::send_preflight_probes
31- pub fn payment_parameters_from_zero_amount_invoice ( invoice : & Bolt11Invoice , amount_msat : u64 )
32- -> Result < ( PaymentHash , RecipientOnionFields , RouteParameters ) , ( ) > {
31+ pub fn payment_parameters_from_zero_amount_invoice (
32+ invoice : & Bolt11Invoice , amount_msat : u64 ,
33+ ) -> Result < ( PaymentHash , RecipientOnionFields , RouteParameters ) , ( ) > {
3334 if invoice. amount_milli_satoshis ( ) . is_some ( ) {
3435 Err ( ( ) )
3536 } else {
@@ -48,27 +49,30 @@ pub fn payment_parameters_from_zero_amount_invoice(invoice: &Bolt11Invoice, amou
4849///
4950/// [`ChannelManager::send_payment`]: lightning::ln::channelmanager::ChannelManager::send_payment
5051/// [`ChannelManager::send_preflight_probes`]: lightning::ln::channelmanager::ChannelManager::send_preflight_probes
51- pub fn payment_parameters_from_invoice ( invoice : & Bolt11Invoice )
52- -> Result < ( PaymentHash , RecipientOnionFields , RouteParameters ) , ( ) > {
52+ pub fn payment_parameters_from_invoice (
53+ invoice : & Bolt11Invoice ,
54+ ) -> Result < ( PaymentHash , RecipientOnionFields , RouteParameters ) , ( ) > {
5355 if let Some ( amount_msat) = invoice. amount_milli_satoshis ( ) {
5456 Ok ( params_from_invoice ( invoice, amount_msat) )
5557 } else {
5658 Err ( ( ) )
5759 }
5860}
5961
60- fn params_from_invoice ( invoice : & Bolt11Invoice , amount_msat : u64 )
61- -> ( PaymentHash , RecipientOnionFields , RouteParameters ) {
62+ fn params_from_invoice (
63+ invoice : & Bolt11Invoice , amount_msat : u64 ,
64+ ) -> ( PaymentHash , RecipientOnionFields , RouteParameters ) {
6265 let payment_hash = PaymentHash ( ( * invoice. payment_hash ( ) ) . to_byte_array ( ) ) ;
6366
6467 let mut recipient_onion = RecipientOnionFields :: secret_only ( * invoice. payment_secret ( ) ) ;
6568 recipient_onion. payment_metadata = invoice. payment_metadata ( ) . map ( |v| v. clone ( ) ) ;
6669
6770 let mut payment_params = PaymentParameters :: from_node_id (
68- invoice. recover_payee_pub_key ( ) ,
69- invoice. min_final_cltv_expiry_delta ( ) as u32
70- )
71- . with_route_hints ( invoice. route_hints ( ) ) . unwrap ( ) ;
71+ invoice. recover_payee_pub_key ( ) ,
72+ invoice. min_final_cltv_expiry_delta ( ) as u32 ,
73+ )
74+ . with_route_hints ( invoice. route_hints ( ) )
75+ . unwrap ( ) ;
7276 if let Some ( expiry) = invoice. expires_at ( ) {
7377 payment_params = payment_params. with_expiry_time ( expiry. as_secs ( ) ) ;
7478 }
@@ -83,19 +87,18 @@ fn params_from_invoice(invoice: &Bolt11Invoice, amount_msat: u64)
8387#[ cfg( test) ]
8488mod tests {
8589 use super :: * ;
86- use crate :: { InvoiceBuilder , Currency } ;
90+ use crate :: { Currency , InvoiceBuilder } ;
8791 use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
92+ use core:: time:: Duration ;
8893 use lightning:: ln:: types:: PaymentSecret ;
8994 use lightning:: routing:: router:: Payee ;
90- use secp256k1:: { SecretKey , PublicKey , Secp256k1 } ;
91- use core:: time:: Duration ;
95+ use secp256k1:: { PublicKey , Secp256k1 , SecretKey } ;
9296 #[ cfg( feature = "std" ) ]
9397 use std:: time:: SystemTime ;
9498
9599 fn duration_since_epoch ( ) -> Duration {
96100 #[ cfg( feature = "std" ) ]
97- let duration_since_epoch =
98- SystemTime :: now ( ) . duration_since ( SystemTime :: UNIX_EPOCH ) . unwrap ( ) ;
101+ let duration_since_epoch = SystemTime :: now ( ) . duration_since ( SystemTime :: UNIX_EPOCH ) . unwrap ( ) ;
99102 #[ cfg( not( feature = "std" ) ) ]
100103 let duration_since_epoch = Duration :: from_secs ( 1234567 ) ;
101104 duration_since_epoch
@@ -115,9 +118,7 @@ mod tests {
115118 . duration_since_epoch ( duration_since_epoch ( ) )
116119 . min_final_cltv_expiry_delta ( 144 )
117120 . amount_milli_satoshis ( 128 )
118- . build_signed ( |hash| {
119- secp_ctx. sign_ecdsa_recoverable ( hash, & private_key)
120- } )
121+ . build_signed ( |hash| secp_ctx. sign_ecdsa_recoverable ( hash, & private_key) )
121122 . unwrap ( ) ;
122123
123124 assert ! ( payment_parameters_from_zero_amount_invoice( & invoice, 42 ) . is_err( ) ) ;
@@ -147,14 +148,13 @@ mod tests {
147148 . payment_secret ( PaymentSecret ( [ 0 ; 32 ] ) )
148149 . duration_since_epoch ( duration_since_epoch ( ) )
149150 . min_final_cltv_expiry_delta ( 144 )
150- . build_signed ( |hash| {
151- secp_ctx. sign_ecdsa_recoverable ( hash, & private_key)
152- } )
153- . unwrap ( ) ;
151+ . build_signed ( |hash| secp_ctx. sign_ecdsa_recoverable ( hash, & private_key) )
152+ . unwrap ( ) ;
154153
155154 assert ! ( payment_parameters_from_invoice( & invoice) . is_err( ) ) ;
156155
157- let ( hash, onion, params) = payment_parameters_from_zero_amount_invoice ( & invoice, 42 ) . unwrap ( ) ;
156+ let ( hash, onion, params) =
157+ payment_parameters_from_zero_amount_invoice ( & invoice, 42 ) . unwrap ( ) ;
158158 assert_eq ! ( & hash. 0 [ ..] , & payment_hash[ ..] ) ;
159159 assert_eq ! ( onion. payment_secret, Some ( PaymentSecret ( [ 0 ; 32 ] ) ) ) ;
160160 assert_eq ! ( params. final_value_msat, 42 ) ;
@@ -170,9 +170,9 @@ mod tests {
170170 #[ cfg( feature = "std" ) ]
171171 fn payment_metadata_end_to_end ( ) {
172172 use lightning:: events:: Event ;
173- use lightning:: ln:: channelmanager:: { Retry , PaymentId } ;
174- use lightning:: ln:: msgs:: ChannelMessageHandler ;
173+ use lightning:: ln:: channelmanager:: { PaymentId , Retry } ;
175174 use lightning:: ln:: functional_test_utils:: * ;
175+ use lightning:: ln:: msgs:: ChannelMessageHandler ;
176176 // Test that a payment metadata read from an invoice passed to `pay_invoice` makes it all
177177 // the way out through the `PaymentClaimable` event.
178178 let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
@@ -195,8 +195,10 @@ mod tests {
195195 . amount_milli_satoshis ( 50_000 )
196196 . payment_metadata ( payment_metadata. clone ( ) )
197197 . build_signed ( |hash| {
198- Secp256k1 :: new ( ) . sign_ecdsa_recoverable ( hash,
199- & nodes[ 1 ] . keys_manager . backing . get_node_secret_key ( ) )
198+ Secp256k1 :: new ( ) . sign_ecdsa_recoverable (
199+ hash,
200+ & nodes[ 1 ] . keys_manager . backing . get_node_secret_key ( ) ,
201+ )
200202 } )
201203 . unwrap ( ) ;
202204
@@ -216,7 +218,7 @@ mod tests {
216218 Event :: PaymentClaimable { onion_fields, .. } => {
217219 assert_eq ! ( Some ( payment_metadata) , onion_fields. unwrap( ) . payment_metadata) ;
218220 } ,
219- _ => panic ! ( "Unexpected event" )
221+ _ => panic ! ( "Unexpected event" ) ,
220222 }
221223 }
222224}
0 commit comments