From 43fd78b0b98c05cfaae2963f6b9d4db896c0645a Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Wed, 16 Oct 2024 17:04:38 +0200 Subject: [PATCH] Invoice utils: allow to set both description hash and payment hash --- lightning/src/ln/invoice_utils.rs | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lightning/src/ln/invoice_utils.rs b/lightning/src/ln/invoice_utils.rs index 4c7e347dab1..69c6955ad3b 100644 --- a/lightning/src/ln/invoice_utils.rs +++ b/lightning/src/ln/invoice_utils.rs @@ -490,6 +490,40 @@ where invoice_expiry_delta_secs, payment_hash, payment_secret, min_final_cltv_expiry_delta) } +/// See [`create_invoice_from_channelmanager_and_duration_since_epoch`] +/// This version allows for providing custom [`PaymentHash`] and description hash for the invoice. +/// +/// This may be useful if you're building an on-chain swap or involving another protocol where +/// the payment hash is also involved outside the scope of lightning and want to set the +/// description hash. +pub fn create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch_with_payment_hash( + channelmanager: &ChannelManager, node_signer: NS, logger: L, + network: Currency, amt_msat: Option, description_hash: Sha256, duration_since_epoch: Duration, + invoice_expiry_delta_secs: u32, payment_hash: PaymentHash, min_final_cltv_expiry_delta: Option, +) -> Result> +where + M::Target: chain::Watch<::EcdsaSigner>, + T::Target: BroadcasterInterface, + ES::Target: EntropySource, + NS::Target: NodeSigner, + SP::Target: SignerProvider, + F::Target: FeeEstimator, + R::Target: Router, + MR::Target: MessageRouter, + L::Target: Logger, +{ + let payment_secret = channelmanager + .create_inbound_payment_for_hash(payment_hash, amt_msat, invoice_expiry_delta_secs, + min_final_cltv_expiry_delta) + .map_err(|()| SignOrCreationError::CreationError(CreationError::InvalidAmount))?; + _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash( + channelmanager, node_signer, logger, network, amt_msat, + Bolt11InvoiceDescription::Hash(&description_hash), + duration_since_epoch, invoice_expiry_delta_secs, payment_hash, payment_secret, + min_final_cltv_expiry_delta, + ) +} + /// See [`create_invoice_from_channelmanager_and_duration_since_epoch`] /// This version allows for providing a custom [`PaymentHash`] for the invoice. /// This may be useful if you're building an on-chain swap or involving another protocol where