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