@@ -309,6 +309,29 @@ impl<MR: Deref> OffersMessageFlow<MR>
309
309
where
310
310
MR :: Target : MessageRouter ,
311
311
{
312
+ /// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
313
+ /// to pay us.
314
+ ///
315
+ /// See [`ChannelManager::create_inbound_payment`] for more details.
316
+ ///
317
+ /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
318
+ pub fn create_inbound_payment < ES : Deref > (
319
+ & self , entropy_source : ES , min_value_msat : Option < u64 > , invoice_expiry_delta_secs : u32 ,
320
+ min_final_cltv_expiry_delta : Option < u16 > ,
321
+ ) -> Result < ( PaymentHash , PaymentSecret ) , ( ) >
322
+ where
323
+ ES :: Target : EntropySource ,
324
+ {
325
+ inbound_payment:: create (
326
+ & self . inbound_payment_key ,
327
+ min_value_msat,
328
+ invoice_expiry_delta_secs,
329
+ & entropy_source,
330
+ self . highest_seen_timestamp . load ( Ordering :: Acquire ) as u64 ,
331
+ min_final_cltv_expiry_delta,
332
+ )
333
+ }
334
+
312
335
/// Verifies an [`InvoiceRequest`] using the provided [`OffersContext`] or the invoice request's own metadata.
313
336
///
314
337
/// - If an [`OffersContext::InvoiceRequest`] with a `nonce` is provided, verification is performed using recipient context data.
@@ -725,8 +748,8 @@ where
725
748
///
726
749
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
727
750
pub fn create_invoice_builder_from_refund < ' a , ES : Deref , R : Deref > (
728
- & ' a self , router : & R , entropy_source : ES , refund : & ' a Refund , payment_hash : PaymentHash ,
729
- payment_secret : PaymentSecret , usable_channels : Vec < ChannelDetails > ,
751
+ & ' a self , router : & R , entropy_source : ES , refund : & ' a Refund ,
752
+ usable_channels : Vec < ChannelDetails > ,
730
753
) -> Result < InvoiceBuilder < ' a , DerivedSigningPubkey > , Bolt12SemanticError >
731
754
where
732
755
ES :: Target : EntropySource ,
@@ -742,6 +765,10 @@ where
742
765
let amount_msats = refund. amount_msats ( ) ;
743
766
let relative_expiry = DEFAULT_RELATIVE_EXPIRY . as_secs ( ) as u32 ;
744
767
768
+ let ( payment_hash, payment_secret) = self
769
+ . create_inbound_payment ( entropy, Some ( amount_msats) , relative_expiry, None )
770
+ . map_err ( |_| Bolt12SemanticError :: InvalidAmount ) ?;
771
+
745
772
let payment_context = PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ;
746
773
let payment_paths = self
747
774
. create_blinded_payment_paths (
@@ -787,19 +814,27 @@ where
787
814
/// - We fail to generate a valid signed [`Bolt12Invoice`] for the [`InvoiceRequest`].
788
815
pub fn create_response_for_invoice_request < ES : Deref , NS : Deref , R : Deref > (
789
816
& self , signer : & NS , router : & R , entropy_source : ES ,
790
- invoice_request : VerifiedInvoiceRequest , amount_msats : u64 , payment_hash : PaymentHash ,
791
- payment_secret : PaymentSecret , usable_channels : Vec < ChannelDetails > ,
817
+ invoice_request : VerifiedInvoiceRequest , amount_msats : u64 ,
818
+ usable_channels : Vec < ChannelDetails > ,
792
819
) -> ( OffersMessage , Option < MessageContext > )
793
820
where
794
821
ES :: Target : EntropySource ,
795
822
NS :: Target : NodeSigner ,
796
823
R :: Target : Router ,
797
824
{
798
- let expanded_key = & self . inbound_payment_key ;
799
825
let entropy = & * entropy_source;
826
+ let expanded_key = & self . inbound_payment_key ;
800
827
let secp_ctx = & self . secp_ctx ;
801
828
802
829
let relative_expiry = DEFAULT_RELATIVE_EXPIRY . as_secs ( ) as u32 ;
830
+ let ( payment_hash, payment_secret) =
831
+ match self . create_inbound_payment ( entropy, Some ( amount_msats) , relative_expiry, None ) {
832
+ Ok ( ( payment_hash, payment_secret) ) => ( payment_hash, payment_secret) ,
833
+ Err ( ( ) ) => {
834
+ let error = Bolt12SemanticError :: InvalidAmount ;
835
+ return ( OffersMessage :: InvoiceError ( error. into ( ) ) , None ) ;
836
+ } ,
837
+ } ;
803
838
804
839
let context = PaymentContext :: Bolt12Offer ( Bolt12OfferContext {
805
840
offer_id : invoice_request. offer_id ,
0 commit comments