Skip to content

Commit a9bc217

Browse files
committed
Update BOLT11 docs in ChannelManager
Update ChannelManager docs to use create_bolt11_invoice and correct references to modules in the lightning-invoice crate that no longer exist.
1 parent 266edbd commit a9bc217

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

lightning/src/ln/channelmanager.rs

+23-19
Original file line numberDiff line numberDiff line change
@@ -1732,56 +1732,58 @@ where
17321732
///
17331733
/// ## BOLT 11 Invoices
17341734
///
1735-
/// The [`lightning-invoice`] crate is useful for creating BOLT 11 invoices. Specifically, use the
1736-
/// functions in its `utils` module for constructing invoices that are compatible with
1737-
/// [`ChannelManager`]. These functions serve as a convenience for building invoices with the
1735+
/// The [`lightning-invoice`] crate is useful for creating BOLT 11 invoices. However, in order to
1736+
/// construct a [`Bolt11Invoice`] that is compatible with [`ChannelManager`], use
1737+
/// [`create_bolt11_invoice`]. This method serves as a convenience for building invoices with the
17381738
/// [`PaymentHash`] and [`PaymentSecret`] returned from [`create_inbound_payment`]. To provide your
1739-
/// own [`PaymentHash`], use [`create_inbound_payment_for_hash`] or the corresponding functions in
1740-
/// the [`lightning-invoice`] `utils` module.
1739+
/// own [`PaymentHash`], override the appropriate [`Bolt11InvoiceParameters`], which is equivalent
1740+
/// to using [`create_inbound_payment_for_hash`].
17411741
///
17421742
/// [`ChannelManager`] generates an [`Event::PaymentClaimable`] once the full payment has been
17431743
/// received. Call [`claim_funds`] to release the [`PaymentPreimage`], which in turn will result in
17441744
/// an [`Event::PaymentClaimed`].
17451745
///
17461746
/// ```
17471747
/// # use lightning::events::{Event, EventsProvider, PaymentPurpose};
1748-
/// # use lightning::ln::channelmanager::AChannelManager;
1748+
/// # use lightning::ln::channelmanager::{AChannelManager, Bolt11InvoiceParameters};
17491749
/// #
17501750
/// # fn example<T: AChannelManager>(channel_manager: T) {
17511751
/// # let channel_manager = channel_manager.get_cm();
1752-
/// // Or use utils::create_invoice_from_channelmanager
1753-
/// let known_payment_hash = match channel_manager.create_inbound_payment(
1754-
/// Some(10_000_000), 3600, None
1755-
/// ) {
1756-
/// Ok((payment_hash, _payment_secret)) => {
1757-
/// println!("Creating inbound payment {}", payment_hash);
1758-
/// payment_hash
1752+
/// let params = Bolt11InvoiceParameters {
1753+
/// amount_msats: Some(10_000_000),
1754+
/// invoice_expiry_delta_secs: Some(3600),
1755+
/// ..Default::default()
1756+
/// };
1757+
/// let invoice = match channel_manager.create_bolt11_invoice(params) {
1758+
/// Ok(invoice) => {
1759+
/// println!("Creating invoice with payment hash {}", invoice.payment_hash());
1760+
/// invoice
17591761
/// },
1760-
/// Err(()) => panic!("Error creating inbound payment"),
1762+
/// Err(e) => panic!("Error creating invoice: {}", e),
17611763
/// };
17621764
///
17631765
/// // On the event processing thread
17641766
/// channel_manager.process_pending_events(&|event| {
17651767
/// match event {
17661768
/// Event::PaymentClaimable { payment_hash, purpose, .. } => match purpose {
17671769
/// PaymentPurpose::Bolt11InvoicePayment { payment_preimage: Some(payment_preimage), .. } => {
1768-
/// assert_eq!(payment_hash, known_payment_hash);
1770+
/// assert_eq!(payment_hash.0, invoice.payment_hash().as_ref());
17691771
/// println!("Claiming payment {}", payment_hash);
17701772
/// channel_manager.claim_funds(payment_preimage);
17711773
/// },
17721774
/// PaymentPurpose::Bolt11InvoicePayment { payment_preimage: None, .. } => {
17731775
/// println!("Unknown payment hash: {}", payment_hash);
17741776
/// },
17751777
/// PaymentPurpose::SpontaneousPayment(payment_preimage) => {
1776-
/// assert_ne!(payment_hash, known_payment_hash);
1778+
/// assert_ne!(payment_hash.0, invoice.payment_hash().as_ref());
17771779
/// println!("Claiming spontaneous payment {}", payment_hash);
17781780
/// channel_manager.claim_funds(payment_preimage);
17791781
/// },
17801782
/// // ...
17811783
/// # _ => {},
17821784
/// },
17831785
/// Event::PaymentClaimed { payment_hash, amount_msat, .. } => {
1784-
/// assert_eq!(payment_hash, known_payment_hash);
1786+
/// assert_eq!(payment_hash.0, invoice.payment_hash().as_ref());
17851787
/// println!("Claimed {} msats", amount_msat);
17861788
/// },
17871789
/// // ...
@@ -1792,8 +1794,8 @@ where
17921794
/// # }
17931795
/// ```
17941796
///
1795-
/// For paying an invoice, [`lightning-invoice`] provides a `payment` module with convenience
1796-
/// functions for use with [`send_payment`].
1797+
/// For paying an invoice, see the [`bolt11_payment`] module with convenience functions for use with
1798+
/// [`send_payment`].
17971799
///
17981800
/// ```
17991801
/// # use lightning::events::{Event, EventsProvider};
@@ -2127,8 +2129,10 @@ where
21272129
/// [`list_recent_payments`]: Self::list_recent_payments
21282130
/// [`abandon_payment`]: Self::abandon_payment
21292131
/// [`lightning-invoice`]: https://docs.rs/lightning_invoice/latest/lightning_invoice
2132+
/// [`create_bolt11_invoice`]: Self::create_bolt11_invoice
21302133
/// [`create_inbound_payment`]: Self::create_inbound_payment
21312134
/// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
2135+
/// [`bolt11_payment`]: crate::ln::bolt11_payment
21322136
/// [`claim_funds`]: Self::claim_funds
21332137
/// [`send_payment`]: Self::send_payment
21342138
/// [`offers`]: crate::offers

0 commit comments

Comments
 (0)