From 270bc2e4c07f2891c8fbbc2339297565bf529050 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Mon, 14 Aug 2023 21:09:57 -0500 Subject: [PATCH] Move BOLT 12 offer method implementations --- lightning/src/offers/offer.rs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/lightning/src/offers/offer.rs b/lightning/src/offers/offer.rs index d801be9d2..a84c2ff43 100644 --- a/lightning/src/offers/offer.rs +++ b/lightning/src/offers/offer.rs @@ -398,14 +398,14 @@ impl Offer { /// Features pertaining to the offer. pub fn features(&self) -> &OfferFeatures { - &self.contents.features + &self.contents.features() } /// Duration since the Unix epoch when an invoice should no longer be requested. /// /// If `None`, the offer does not expire. pub fn absolute_expiry(&self) -> Option { - self.contents.absolute_expiry + self.contents.absolute_expiry() } /// Whether the offer has expired. @@ -417,13 +417,13 @@ impl Offer { /// The issuer of the offer, possibly beginning with `user@domain` or `domain`. Intended to be /// displayed to the user but with the caveat that it has not been verified in any way. pub fn issuer(&self) -> Option { - self.contents.issuer.as_ref().map(|issuer| PrintableString(issuer.as_str())) + self.contents.issuer() } /// Paths to the recipient originating from publicly reachable nodes. Blinded paths provide /// recipient privacy by obfuscating its node id. pub fn paths(&self) -> &[BlindedPath] { - self.contents.paths.as_ref().map(|paths| paths.as_slice()).unwrap_or(&[]) + self.contents.paths() } /// The quantity of items supported. @@ -551,10 +551,22 @@ impl OfferContents { self.metadata.as_ref().and_then(|metadata| metadata.as_bytes()) } + pub fn amount(&self) -> Option<&Amount> { + self.amount.as_ref() + } + pub fn description(&self) -> PrintableString { PrintableString(&self.description) } + pub fn features(&self) -> &OfferFeatures { + &self.features + } + + pub fn absolute_expiry(&self) -> Option { + self.absolute_expiry + } + #[cfg(feature = "std")] pub(super) fn is_expired(&self) -> bool { match self.absolute_expiry { @@ -566,8 +578,12 @@ impl OfferContents { } } - pub fn amount(&self) -> Option<&Amount> { - self.amount.as_ref() + pub fn issuer(&self) -> Option { + self.issuer.as_ref().map(|issuer| PrintableString(issuer.as_str())) + } + + pub fn paths(&self) -> &[BlindedPath] { + self.paths.as_ref().map(|paths| paths.as_slice()).unwrap_or(&[]) } pub(super) fn check_amount_msats_for_quantity( -- 2.39.5