Skip to content

Commit b3e7aac

Browse files
authored
Merge pull request #2689 from benthecarman/no-std-offer-expire
Add `is_expired_no_std` to Offer
2 parents 8f308f9 + 5ddd8a7 commit b3e7aac

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lightning/src/offers/offer.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,11 @@ impl Offer {
468468
self.contents.is_expired()
469469
}
470470

471+
/// Whether the offer has expired given the duration since the Unix epoch.
472+
pub fn is_expired_no_std(&self, duration_since_epoch: Duration) -> bool {
473+
self.contents.is_expired_no_std(duration_since_epoch)
474+
}
475+
471476
/// Returns whether the given quantity is valid for the offer.
472477
pub fn is_valid_quantity(&self, quantity: u64) -> bool {
473478
self.contents.is_valid_quantity(quantity)
@@ -1192,13 +1197,15 @@ mod tests {
11921197
fn builds_offer_with_absolute_expiry() {
11931198
let future_expiry = Duration::from_secs(u64::max_value());
11941199
let past_expiry = Duration::from_secs(0);
1200+
let now = future_expiry - Duration::from_secs(1_000);
11951201

11961202
let offer = OfferBuilder::new("foo".into(), pubkey(42))
11971203
.absolute_expiry(future_expiry)
11981204
.build()
11991205
.unwrap();
12001206
#[cfg(feature = "std")]
12011207
assert!(!offer.is_expired());
1208+
assert!(!offer.is_expired_no_std(now));
12021209
assert_eq!(offer.absolute_expiry(), Some(future_expiry));
12031210
assert_eq!(offer.as_tlv_stream().absolute_expiry, Some(future_expiry.as_secs()));
12041211

@@ -1209,6 +1216,7 @@ mod tests {
12091216
.unwrap();
12101217
#[cfg(feature = "std")]
12111218
assert!(offer.is_expired());
1219+
assert!(offer.is_expired_no_std(now));
12121220
assert_eq!(offer.absolute_expiry(), Some(past_expiry));
12131221
assert_eq!(offer.as_tlv_stream().absolute_expiry, Some(past_expiry.as_secs()));
12141222
}

lightning/src/offers/refund.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,11 @@ impl Refund {
359359
self.contents.is_expired()
360360
}
361361

362+
/// Whether the refund has expired given the duration since the Unix epoch.
363+
pub fn is_expired_no_std(&self, duration_since_epoch: Duration) -> bool {
364+
self.contents.is_expired_no_std(duration_since_epoch)
365+
}
366+
362367
/// The issuer of the refund, possibly beginning with `user@domain` or `domain`. Intended to be
363368
/// displayed to the user but with the caveat that it has not been verified in any way.
364369
pub fn issuer(&self) -> Option<PrintableString> {
@@ -993,6 +998,7 @@ mod tests {
993998
fn builds_refund_with_absolute_expiry() {
994999
let future_expiry = Duration::from_secs(u64::max_value());
9951000
let past_expiry = Duration::from_secs(0);
1001+
let now = future_expiry - Duration::from_secs(1_000);
9961002

9971003
let refund = RefundBuilder::new("foo".into(), vec![1; 32], payer_pubkey(), 1000).unwrap()
9981004
.absolute_expiry(future_expiry)
@@ -1001,6 +1007,7 @@ mod tests {
10011007
let (_, tlv_stream, _) = refund.as_tlv_stream();
10021008
#[cfg(feature = "std")]
10031009
assert!(!refund.is_expired());
1010+
assert!(!refund.is_expired_no_std(now));
10041011
assert_eq!(refund.absolute_expiry(), Some(future_expiry));
10051012
assert_eq!(tlv_stream.absolute_expiry, Some(future_expiry.as_secs()));
10061013

@@ -1012,6 +1019,7 @@ mod tests {
10121019
let (_, tlv_stream, _) = refund.as_tlv_stream();
10131020
#[cfg(feature = "std")]
10141021
assert!(refund.is_expired());
1022+
assert!(refund.is_expired_no_std(now));
10151023
assert_eq!(refund.absolute_expiry(), Some(past_expiry));
10161024
assert_eq!(tlv_stream.absolute_expiry, Some(past_expiry.as_secs()));
10171025
}

0 commit comments

Comments
 (0)