@@ -286,56 +286,11 @@ where
286286 )
287287}
288288
289- /// See [`create_invoice_from_channelmanager_with_description_hash`]
290- /// This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
291- /// available and the current time is supplied by the caller.
292- pub fn create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch < M : Deref , T : Deref , K : Deref , F : Deref , L : Deref > (
293- channelmanager : & ChannelManager < M , T , K , F , L > , keys_manager : K , logger : L ,
294- network : Currency , amt_msat : Option < u64 > , description_hash : Sha256 ,
295- duration_since_epoch : Duration , invoice_expiry_delta_secs : u32
296- ) -> Result < Invoice , SignOrCreationError < ( ) > >
297- where
298- M :: Target : chain:: Watch < <K :: Target as KeysInterface >:: Signer > ,
299- T :: Target : BroadcasterInterface ,
300- K :: Target : KeysInterface ,
301- F :: Target : FeeEstimator ,
302- L :: Target : Logger ,
303- {
304- _create_invoice_from_channelmanager_and_duration_since_epoch (
305- channelmanager, keys_manager, logger, network, amt_msat,
306- InvoiceDescription :: Hash ( & description_hash) ,
307- duration_since_epoch, invoice_expiry_delta_secs
308- )
309- }
310-
311- /// See [`create_invoice_from_channelmanager`]
312- /// This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
313- /// available and the current time is supplied by the caller.
314- pub fn create_invoice_from_channelmanager_and_duration_since_epoch < M : Deref , T : Deref , K : Deref , F : Deref , L : Deref > (
315- channelmanager : & ChannelManager < M , T , K , F , L > , keys_manager : K , logger : L ,
316- network : Currency , amt_msat : Option < u64 > , description : String , duration_since_epoch : Duration ,
317- invoice_expiry_delta_secs : u32
318- ) -> Result < Invoice , SignOrCreationError < ( ) > >
319- where
320- M :: Target : chain:: Watch < <K :: Target as KeysInterface >:: Signer > ,
321- T :: Target : BroadcasterInterface ,
322- K :: Target : KeysInterface ,
323- F :: Target : FeeEstimator ,
324- L :: Target : Logger ,
325- {
326- _create_invoice_from_channelmanager_and_duration_since_epoch (
327- channelmanager, keys_manager, logger, network, amt_msat,
328- InvoiceDescription :: Direct (
329- & Description :: new ( description) . map_err ( SignOrCreationError :: CreationError ) ?,
330- ) ,
331- duration_since_epoch, invoice_expiry_delta_secs
332- )
333- }
334-
289+ ///Function that allows for contructing invoices with custom payment hash
335290pub fn create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash < M : Deref , T : Deref , K : Deref , F : Deref , L : Deref > (
336291 channelmanager : & ChannelManager < M , T , K , F , L > , keys_manager : K , logger : L ,
337292 network : Currency , amt_msat : Option < u64 > , description : String , duration_since_epoch : Duration ,
338- invoice_expiry_delta_secs : u32 , payment_hash : PaymentHash , payment_secret : PaymentSecret
293+ invoice_expiry_delta_secs : u32 , payment_hash : PaymentHash
339294) -> Result < Invoice , SignOrCreationError < ( ) > >
340295 where
341296 M :: Target : chain:: Watch < <K :: Target as KeysInterface >:: Signer > ,
@@ -349,14 +304,14 @@ pub fn create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_
349304 InvoiceDescription :: Direct (
350305 & Description :: new ( description) . map_err ( SignOrCreationError :: CreationError ) ?,
351306 ) ,
352- duration_since_epoch, invoice_expiry_delta_secs, payment_hash, payment_secret
307+ duration_since_epoch, invoice_expiry_delta_secs, payment_hash
353308 )
354309}
355310
356311fn _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash < M : Deref , T : Deref , K : Deref , F : Deref , L : Deref > (
357312 channelmanager : & ChannelManager < M , T , K , F , L > , keys_manager : K , logger : L ,
358313 network : Currency , amt_msat : Option < u64 > , description : InvoiceDescription , duration_since_epoch : Duration ,
359- invoice_expiry_delta_secs : u32 , payment_hash : PaymentHash , payment_secret : PaymentSecret
314+ invoice_expiry_delta_secs : u32 , payment_hash : PaymentHash
360315) -> Result < Invoice , SignOrCreationError < ( ) > >
361316 where
362317 M :: Target : chain:: Watch < <K :: Target as KeysInterface >:: Signer > ,
@@ -367,7 +322,7 @@ fn _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_has
367322{
368323 let our_node_pubkey = channelmanager. get_our_node_id ( ) ;
369324 let channels = channelmanager. list_channels ( ) ;
370-
325+ let payment_secret = channelmanager . create_inbound_payment_for_hash ( payment_hash , amt_msat , invoice_expiry_delta_secs ) ;
371326 log_trace ! ( logger, "Creating invoice with payment hash {}" , log_bytes!( payment_hash. 0 ) ) ;
372327
373328 let invoice = match description {
@@ -381,7 +336,7 @@ fn _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_has
381336 . duration_since_epoch ( duration_since_epoch)
382337 . payee_pub_key ( our_node_pubkey)
383338 . payment_hash ( Hash :: from_slice ( & payment_hash. 0 ) . unwrap ( ) )
384- . payment_secret ( payment_secret)
339+ . payment_secret ( payment_secret. unwrap ( ) )
385340 . basic_mpp ( )
386341 . min_final_cltv_expiry ( MIN_FINAL_CLTV_EXPIRY . into ( ) )
387342 . expiry_time ( Duration :: from_secs ( invoice_expiry_delta_secs. into ( ) ) ) ;
@@ -408,6 +363,52 @@ fn _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_has
408363 }
409364}
410365
366+ /// See [`create_invoice_from_channelmanager_with_description_hash`]
367+ /// This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
368+ /// available and the current time is supplied by the caller.
369+ pub fn create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch < M : Deref , T : Deref , K : Deref , F : Deref , L : Deref > (
370+ channelmanager : & ChannelManager < M , T , K , F , L > , keys_manager : K , logger : L ,
371+ network : Currency , amt_msat : Option < u64 > , description_hash : Sha256 ,
372+ duration_since_epoch : Duration , invoice_expiry_delta_secs : u32
373+ ) -> Result < Invoice , SignOrCreationError < ( ) > >
374+ where
375+ M :: Target : chain:: Watch < <K :: Target as KeysInterface >:: Signer > ,
376+ T :: Target : BroadcasterInterface ,
377+ K :: Target : KeysInterface ,
378+ F :: Target : FeeEstimator ,
379+ L :: Target : Logger ,
380+ {
381+ _create_invoice_from_channelmanager_and_duration_since_epoch (
382+ channelmanager, keys_manager, logger, network, amt_msat,
383+ InvoiceDescription :: Hash ( & description_hash) ,
384+ duration_since_epoch, invoice_expiry_delta_secs
385+ )
386+ }
387+
388+ /// See [`create_invoice_from_channelmanager`]
389+ /// This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
390+ /// available and the current time is supplied by the caller.
391+ pub fn create_invoice_from_channelmanager_and_duration_since_epoch < M : Deref , T : Deref , K : Deref , F : Deref , L : Deref > (
392+ channelmanager : & ChannelManager < M , T , K , F , L > , keys_manager : K , logger : L ,
393+ network : Currency , amt_msat : Option < u64 > , description : String , duration_since_epoch : Duration ,
394+ invoice_expiry_delta_secs : u32
395+ ) -> Result < Invoice , SignOrCreationError < ( ) > >
396+ where
397+ M :: Target : chain:: Watch < <K :: Target as KeysInterface >:: Signer > ,
398+ T :: Target : BroadcasterInterface ,
399+ K :: Target : KeysInterface ,
400+ F :: Target : FeeEstimator ,
401+ L :: Target : Logger ,
402+ {
403+ _create_invoice_from_channelmanager_and_duration_since_epoch (
404+ channelmanager, keys_manager, logger, network, amt_msat,
405+ InvoiceDescription :: Direct (
406+ & Description :: new ( description) . map_err ( SignOrCreationError :: CreationError ) ?,
407+ ) ,
408+ duration_since_epoch, invoice_expiry_delta_secs
409+ )
410+ }
411+
411412fn _create_invoice_from_channelmanager_and_duration_since_epoch < M : Deref , T : Deref , K : Deref , F : Deref , L : Deref > (
412413 channelmanager : & ChannelManager < M , T , K , F , L > , keys_manager : K , logger : L ,
413414 network : Currency , amt_msat : Option < u64 > , description : InvoiceDescription ,
@@ -425,47 +426,8 @@ where
425426 let ( payment_hash, payment_secret) = channelmanager
426427 . create_inbound_payment ( amt_msat, invoice_expiry_delta_secs)
427428 . map_err ( |( ) | SignOrCreationError :: CreationError ( CreationError :: InvalidAmount ) ) ?;
428- let our_node_pubkey = channelmanager. get_our_node_id ( ) ;
429- let channels = channelmanager. list_channels ( ) ;
430-
431- log_trace ! ( logger, "Creating invoice with payment hash {}" , log_bytes!( payment_hash. 0 ) ) ;
432-
433- let invoice = match description {
434- InvoiceDescription :: Direct ( description) => {
435- InvoiceBuilder :: new ( network) . description ( description. 0 . clone ( ) )
436- }
437- InvoiceDescription :: Hash ( hash) => InvoiceBuilder :: new ( network) . description_hash ( hash. 0 ) ,
438- } ;
439-
440- let mut invoice = invoice
441- . duration_since_epoch ( duration_since_epoch)
442- . payee_pub_key ( our_node_pubkey)
443- . payment_hash ( Hash :: from_slice ( & payment_hash. 0 ) . unwrap ( ) )
444- . payment_secret ( payment_secret)
445- . basic_mpp ( )
446- . min_final_cltv_expiry ( MIN_FINAL_CLTV_EXPIRY . into ( ) )
447- . expiry_time ( Duration :: from_secs ( invoice_expiry_delta_secs. into ( ) ) ) ;
448- if let Some ( amt) = amt_msat {
449- invoice = invoice. amount_milli_satoshis ( amt) ;
450- }
451-
452- let route_hints = filter_channels ( channels, amt_msat, & logger) ;
453- for hint in route_hints {
454- invoice = invoice. private_route ( hint) ;
455- }
456-
457- let raw_invoice = match invoice. build_raw ( ) {
458- Ok ( inv) => inv,
459- Err ( e) => return Err ( SignOrCreationError :: CreationError ( e) )
460- } ;
461- let hrp_str = raw_invoice. hrp . to_string ( ) ;
462- let hrp_bytes = hrp_str. as_bytes ( ) ;
463- let data_without_signature = raw_invoice. data . to_base32 ( ) ;
464- let signed_raw_invoice = raw_invoice. sign ( |_| keys_manager. sign_invoice ( hrp_bytes, & data_without_signature, Recipient :: Node ) ) ;
465- match signed_raw_invoice {
466- Ok ( inv) => Ok ( Invoice :: from_signed ( inv) . unwrap ( ) ) ,
467- Err ( e) => Err ( SignOrCreationError :: SignError ( e) )
468- }
429+ _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash (
430+ channelmanager, keys_manager, logger, network, amt_msat, description, duration_since_epoch, invoice_expiry_delta_secs, payment_hash)
469431}
470432
471433/// Filters the `channels` for an invoice, and returns the corresponding `RouteHint`s to include
@@ -741,7 +703,6 @@ mod test {
741703 assert_eq ! ( invoice. description( ) , InvoiceDescription :: Hash ( & crate :: Sha256 ( Sha256 :: hash( "Testing description_hash" . as_bytes( ) ) ) ) ) ;
742704 }
743705
744-
745706 #[ test]
746707 fn test_create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash ( ) {
747708 let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
@@ -753,7 +714,7 @@ mod test {
753714 let invoice = crate :: utils:: create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash (
754715 & nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , nodes[ 1 ] . logger , Currency :: BitcoinTestnet ,
755716 Some ( 10_000 ) , "test" . to_string ( ) , Duration :: from_secs ( 1234567 ) , 3600 ,
756- payment_hash, payment_secret . unwrap ( )
717+ payment_hash
757718 ) . unwrap ( ) ;
758719 assert_eq ! ( invoice. amount_pico_btc( ) , Some ( 100_000 ) ) ;
759720 assert_eq ! ( invoice. min_final_cltv_expiry( ) , MIN_FINAL_CLTV_EXPIRY as u64 ) ;
@@ -787,10 +748,8 @@ mod test {
787748 let _chan_1_0_low_inbound_capacity = create_unannounced_chan_between_nodes_with_value ( & nodes, 1 , 0 , 100_000 , 0 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) ;
788749 let chan_1_0_high_inbound_capacity = create_unannounced_chan_between_nodes_with_value ( & nodes, 1 , 0 , 10_000_000 , 0 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) ;
789750 let _chan_1_0_medium_inbound_capacity = create_unannounced_chan_between_nodes_with_value ( & nodes, 1 , 0 , 1_000_000 , 0 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) ;
790-
791751 let mut scid_aliases = HashSet :: new ( ) ;
792752 scid_aliases. insert ( chan_1_0_high_inbound_capacity. 0 . short_channel_id_alias . unwrap ( ) ) ;
793-
794753 match_invoice_routes ( Some ( 5000 ) , & nodes[ 0 ] , scid_aliases) ;
795754 }
796755
0 commit comments