@@ -1732,56 +1732,58 @@ where
1732
1732
///
1733
1733
/// ## BOLT 11 Invoices
1734
1734
///
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
1738
1738
/// [`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`] .
1741
1741
///
1742
1742
/// [`ChannelManager`] generates an [`Event::PaymentClaimable`] once the full payment has been
1743
1743
/// received. Call [`claim_funds`] to release the [`PaymentPreimage`], which in turn will result in
1744
1744
/// an [`Event::PaymentClaimed`].
1745
1745
///
1746
1746
/// ```
1747
1747
/// # use lightning::events::{Event, EventsProvider, PaymentPurpose};
1748
- /// # use lightning::ln::channelmanager::AChannelManager;
1748
+ /// # use lightning::ln::channelmanager::{ AChannelManager, Bolt11InvoiceParameters} ;
1749
1749
/// #
1750
1750
/// # fn example<T: AChannelManager>(channel_manager: T) {
1751
1751
/// # 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
1759
1761
/// },
1760
- /// Err(()) => panic!("Error creating inbound payment" ),
1762
+ /// Err(e) => panic!("Error creating invoice: {}", e ),
1761
1763
/// };
1762
1764
///
1763
1765
/// // On the event processing thread
1764
1766
/// channel_manager.process_pending_events(&|event| {
1765
1767
/// match event {
1766
1768
/// Event::PaymentClaimable { payment_hash, purpose, .. } => match purpose {
1767
1769
/// 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() );
1769
1771
/// println!("Claiming payment {}", payment_hash);
1770
1772
/// channel_manager.claim_funds(payment_preimage);
1771
1773
/// },
1772
1774
/// PaymentPurpose::Bolt11InvoicePayment { payment_preimage: None, .. } => {
1773
1775
/// println!("Unknown payment hash: {}", payment_hash);
1774
1776
/// },
1775
1777
/// PaymentPurpose::SpontaneousPayment(payment_preimage) => {
1776
- /// assert_ne!(payment_hash, known_payment_hash );
1778
+ /// assert_ne!(payment_hash.0, invoice.payment_hash().as_ref() );
1777
1779
/// println!("Claiming spontaneous payment {}", payment_hash);
1778
1780
/// channel_manager.claim_funds(payment_preimage);
1779
1781
/// },
1780
1782
/// // ...
1781
1783
/// # _ => {},
1782
1784
/// },
1783
1785
/// 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() );
1785
1787
/// println!("Claimed {} msats", amount_msat);
1786
1788
/// },
1787
1789
/// // ...
@@ -1792,8 +1794,8 @@ where
1792
1794
/// # }
1793
1795
/// ```
1794
1796
///
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`].
1797
1799
///
1798
1800
/// ```
1799
1801
/// # use lightning::events::{Event, EventsProvider};
@@ -2127,8 +2129,10 @@ where
2127
2129
/// [`list_recent_payments`]: Self::list_recent_payments
2128
2130
/// [`abandon_payment`]: Self::abandon_payment
2129
2131
/// [`lightning-invoice`]: https://docs.rs/lightning_invoice/latest/lightning_invoice
2132
+ /// [`create_bolt11_invoice`]: Self::create_bolt11_invoice
2130
2133
/// [`create_inbound_payment`]: Self::create_inbound_payment
2131
2134
/// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
2135
+ /// [`bolt11_payment`]: crate::ln::bolt11_payment
2132
2136
/// [`claim_funds`]: Self::claim_funds
2133
2137
/// [`send_payment`]: Self::send_payment
2134
2138
/// [`offers`]: crate::offers
0 commit comments