@@ -1213,6 +1213,12 @@ impl Invoice {
1213
1213
self . signed_invoice . recover_payee_pub_key ( ) . expect ( "was checked by constructor" ) . 0
1214
1214
}
1215
1215
1216
+ /// Returns the Duration since the Unix epoch at which the invoice expires.
1217
+ /// Returning None if overflow occurred.
1218
+ pub fn expires_at ( & self ) -> Option < Duration > {
1219
+ self . duration_since_epoch ( ) . checked_add ( self . expiry_time ( ) )
1220
+ }
1221
+
1216
1222
/// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
1217
1223
pub fn expiry_time ( & self ) -> Duration {
1218
1224
self . signed_invoice . expiry_time ( )
@@ -1235,6 +1241,21 @@ impl Invoice {
1235
1241
}
1236
1242
}
1237
1243
1244
+ /// Returns the Duration remaining until the invoice expires.
1245
+ #[ cfg( feature = "std" ) ]
1246
+ pub fn duration_until_expiry ( & self ) -> Duration {
1247
+ match self . timestamp ( ) . elapsed ( ) {
1248
+ Ok ( elapsed) => self . expiry_time ( ) . checked_sub ( elapsed) . unwrap_or ( Duration :: ZERO ) ,
1249
+ Err ( _) => Duration :: ZERO ,
1250
+ }
1251
+ }
1252
+
1253
+ /// Returns the Duration remaining until the invoice expires given the current time.
1254
+ /// `time` is the timestamp as a duration since the Unix epoch.
1255
+ pub fn expiration_remaining_from_epoch ( & self , time : Duration ) -> Duration {
1256
+ self . expires_at ( ) . map ( |x| x. checked_sub ( time) ) . flatten ( ) . unwrap_or ( Duration :: ZERO )
1257
+ }
1258
+
1238
1259
/// Returns whether the expiry time would pass at the given point in time.
1239
1260
/// `at_time` is the timestamp as a duration since the Unix epoch.
1240
1261
pub fn would_expire ( & self , at_time : Duration ) -> bool {
0 commit comments