Skip to content

Commit 7ea2c21

Browse files
committed
f Account for create_offer_builder not taking an expiry arg
1 parent f92de06 commit 7ea2c21

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/payment/bolt12.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,17 @@ impl Bolt12Payment {
275275
pub(crate) fn receive_inner(
276276
&self, amount_msat: u64, description: &str, expiry_secs: Option<u32>, quantity: Option<u64>,
277277
) -> Result<LdkOffer, Error> {
278-
let absolute_expiry = expiry_secs.map(|secs| {
279-
(SystemTime::now() + Duration::from_secs(secs as u64))
280-
.duration_since(UNIX_EPOCH)
281-
.unwrap()
282-
});
278+
let mut offer_builder = self.channel_manager.create_offer_builder().map_err(|e| {
279+
log_error!(self.logger, "Failed to create offer builder: {:?}", e);
280+
Error::OfferCreationFailed
281+
})?;
283282

284-
let offer_builder =
285-
self.channel_manager.create_offer_builder(absolute_expiry).map_err(|e| {
286-
log_error!(self.logger, "Failed to create offer builder: {:?}", e);
287-
Error::OfferCreationFailed
288-
})?;
283+
if let Some(expiry_secs) = expiry_secs {
284+
let absolute_expiry = (SystemTime::now() + Duration::from_secs(expiry_secs as u64))
285+
.duration_since(UNIX_EPOCH)
286+
.unwrap();
287+
offer_builder = offer_builder.absolute_expiry(absolute_expiry);
288+
}
289289

290290
let mut offer =
291291
offer_builder.amount_msats(amount_msat).description(description.to_string());
@@ -321,17 +321,18 @@ impl Bolt12Payment {
321321
pub fn receive_variable_amount(
322322
&self, description: &str, expiry_secs: Option<u32>,
323323
) -> Result<Offer, Error> {
324-
let absolute_expiry = expiry_secs.map(|secs| {
325-
(SystemTime::now() + Duration::from_secs(secs as u64))
324+
let mut offer_builder = self.channel_manager.create_offer_builder().map_err(|e| {
325+
log_error!(self.logger, "Failed to create offer builder: {:?}", e);
326+
Error::OfferCreationFailed
327+
})?;
328+
329+
if let Some(expiry_secs) = expiry_secs {
330+
let absolute_expiry = (SystemTime::now() + Duration::from_secs(expiry_secs as u64))
326331
.duration_since(UNIX_EPOCH)
327-
.unwrap()
328-
});
332+
.unwrap();
333+
offer_builder = offer_builder.absolute_expiry(absolute_expiry);
334+
}
329335

330-
let offer_builder =
331-
self.channel_manager.create_offer_builder(absolute_expiry).map_err(|e| {
332-
log_error!(self.logger, "Failed to create offer builder: {:?}", e);
333-
Error::OfferCreationFailed
334-
})?;
335336
let offer = offer_builder.description(description.to_string()).build().map_err(|e| {
336337
log_error!(self.logger, "Failed to create offer: {:?}", e);
337338
Error::OfferCreationFailed

0 commit comments

Comments
 (0)