Invoice request message interface and data format
[rust-lightning] / lightning / src / offers / offer.rs
index c31ca9bb9c5ac5ee4a7d8debff728309957e9b4a..1ac8b0bdebf26377d4cb9440f208595b1f4d2c83 100644 (file)
@@ -224,7 +224,7 @@ impl OfferBuilder {
 
 /// An `Offer` is a potentially long-lived proposal for payment of a good or service.
 ///
-/// An offer is a precursor to an `InvoiceRequest`. A merchant publishes an offer from which a
+/// An offer is a precursor to an [`InvoiceRequest`]. A merchant publishes an offer from which a
 /// customer may request an `Invoice` for a specific quantity and using an amount sufficient to
 /// cover that quantity (i.e., at least `quantity * amount`). See [`Offer::amount`].
 ///
@@ -232,6 +232,8 @@ impl OfferBuilder {
 /// latter.
 ///
 /// Through the use of [`BlindedPath`]s, offers provide recipient privacy.
+///
+/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
 #[derive(Clone, Debug)]
 pub struct Offer {
        // The serialized offer. Needed when creating an `InvoiceRequest` if the offer contains unknown
@@ -240,7 +242,9 @@ pub struct Offer {
        contents: OfferContents,
 }
 
-/// The contents of an [`Offer`], which may be shared with an `InvoiceRequest` or an `Invoice`.
+/// The contents of an [`Offer`], which may be shared with an [`InvoiceRequest`] or an `Invoice`.
+///
+/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
 #[derive(Clone, Debug)]
 pub(super) struct OfferContents {
        chains: Option<Vec<ChainHash>>,
@@ -263,10 +267,7 @@ impl Offer {
        /// Payments must be denominated in units of the minimal lightning-payable unit (e.g., msats)
        /// for the selected chain.
        pub fn chains(&self) -> Vec<ChainHash> {
-               self.contents.chains
-                       .as_ref()
-                       .cloned()
-                       .unwrap_or_else(|| vec![self.contents.implied_chain()])
+               self.contents.chains()
        }
 
        // TODO: Link to corresponding method in `InvoiceRequest`.
@@ -346,6 +347,10 @@ impl AsRef<[u8]> for Offer {
 }
 
 impl OfferContents {
+       pub fn chains(&self) -> Vec<ChainHash> {
+               self.chains.as_ref().cloned().unwrap_or_else(|| vec![self.implied_chain()])
+       }
+
        pub fn implied_chain(&self) -> ChainHash {
                ChainHash::using_genesis_block(Network::Bitcoin)
        }