Skip to content

Commit 5cf3585

Browse files
Add API to retrieve cached async receive offer
Over the past several commits we've implemented interactively building an async receive offer with a static invoice server that will service invoice requests on our behalf as an async recipient. Here we add an API to retrieve this resulting offer so we can receive payments when we're offline.
1 parent cd62d3a commit 5cf3585

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

lightning/src/ln/channelmanager.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -10317,9 +10317,23 @@ where
1031710317
#[cfg(c_bindings)]
1031810318
create_refund_builder!(self, RefundMaybeWithDerivedMetadataBuilder);
1031910319

10320+
/// Retrieve our cached [`Offer`] for receiving async payments as an often-offline recipient. Will
10321+
/// only be set if [`UserConfig::paths_to_static_invoice_server`] is set and we succeeded in
10322+
/// interactively building a [`StaticInvoice`] with the static invoice server, erroring otherwise.
10323+
#[cfg(async_payments)]
10324+
pub fn get_cached_async_receive_offer(&self) -> Result<Offer, ()> {
10325+
let mut offer_cache = self.async_receive_offer_cache.lock().unwrap();
10326+
offer_cache.check_expire_offer(self.duration_since_epoch());
10327+
10328+
offer_cache.offer.clone().ok_or(())
10329+
}
10330+
1032010331
/// Create an offer for receiving async payments as an often-offline recipient.
1032110332
///
10322-
/// Because we may be offline when the payer attempts to request an invoice, you MUST:
10333+
/// Instead of using this method, prefer to set [`UserConfig::paths_to_static_invoice_server`] and
10334+
/// retrieve the automatically built offer via [`Self::get_cached_async_receive_offer`].
10335+
///
10336+
/// If you want to build the [`StaticInvoice`] manually using this method instead, you MUST:
1032310337
/// 1. Provide at least 1 [`BlindedMessagePath`] terminating at an always-online node that will
1032410338
/// serve the [`StaticInvoice`] created from this offer on our behalf.
1032510339
/// 2. Use [`Self::create_static_invoice_builder`] to create a [`StaticInvoice`] from this
@@ -10353,6 +10367,10 @@ where
1035310367
/// Creates a [`StaticInvoiceBuilder`] from the corresponding [`Offer`] and [`Nonce`] that were
1035410368
/// created via [`Self::create_async_receive_offer_builder`]. If `relative_expiry` is unset, the
1035510369
/// invoice's expiry will default to [`STATIC_INVOICE_DEFAULT_RELATIVE_EXPIRY`].
10370+
///
10371+
/// Instead of using this method to manually build the invoice, prefer to set
10372+
/// [`UserConfig::paths_to_static_invoice_server`] and retrieve the automatically built offer via
10373+
/// [`Self::get_cached_async_receive_offer`].
1035610374
#[cfg(async_payments)]
1035710375
pub fn create_static_invoice_builder<'a>(
1035810376
&self, offer: &'a Offer, offer_nonce: Nonce, relative_expiry: Option<Duration>

0 commit comments

Comments
 (0)