@@ -14,23 +14,9 @@ use std::time::{SystemTime, UNIX_EPOCH};
14
14
pub fn is_valid_opening_fee_params (
15
15
fee_params : & OpeningFeeParams , promise_secret : & [ u8 ; 32 ] ,
16
16
) -> bool {
17
- #[ cfg( feature = "std" ) ]
18
- {
19
- // TODO: We need to find a way to check expiry times in no-std builds.
20
- let seconds_since_epoch = SystemTime :: now ( )
21
- . duration_since ( UNIX_EPOCH )
22
- . expect ( "system clock to be ahead of the unix epoch" )
23
- . as_secs ( ) ;
24
- let valid_until_seconds_since_epoch = fee_params
25
- . valid_until
26
- . timestamp ( )
27
- . try_into ( )
28
- . expect ( "expiration to be ahead of unix epoch" ) ;
29
- if seconds_since_epoch > valid_until_seconds_since_epoch {
30
- return false ;
31
- }
17
+ if is_expired_opening_fee_params ( fee_params) {
18
+ return false ;
32
19
}
33
-
34
20
let mut hmac = HmacEngine :: < Sha256 > :: new ( promise_secret) ;
35
21
hmac. input ( & fee_params. min_fee_msat . to_be_bytes ( ) ) ;
36
22
hmac. input ( & fee_params. proportional . to_be_bytes ( ) ) ;
@@ -44,6 +30,28 @@ pub fn is_valid_opening_fee_params(
44
30
promise == fee_params. promise
45
31
}
46
32
33
+ /// Determines if the given parameters are expired, or still valid.
34
+ pub fn is_expired_opening_fee_params ( fee_params : & OpeningFeeParams ) -> bool {
35
+ #[ cfg( feature = "std" ) ]
36
+ {
37
+ let seconds_since_epoch = SystemTime :: now ( )
38
+ . duration_since ( UNIX_EPOCH )
39
+ . expect ( "system clock to be ahead of the unix epoch" )
40
+ . as_secs ( ) ;
41
+ let valid_until_seconds_since_epoch = fee_params
42
+ . valid_until
43
+ . timestamp ( )
44
+ . try_into ( )
45
+ . expect ( "expiration to be ahead of unix epoch" ) ;
46
+ seconds_since_epoch > valid_until_seconds_since_epoch
47
+ }
48
+ #[ cfg( not( feature = "std" ) ) ]
49
+ {
50
+ // TODO: We need to find a way to check expiry times in no-std builds.
51
+ false
52
+ }
53
+ }
54
+
47
55
/// Computes the opening fee given a payment size and the fee parameters.
48
56
///
49
57
/// Returns [`Option::None`] when the computation overflows.
0 commit comments