@@ -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,29 @@ 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
+ #[ cfg_attr( not( feature = "std" ) , allow( unused_variables) ) ]
35
+ pub fn is_expired_opening_fee_params ( fee_params : & OpeningFeeParams ) -> bool {
36
+ #[ cfg( feature = "std" ) ]
37
+ {
38
+ let seconds_since_epoch = SystemTime :: now ( )
39
+ . duration_since ( UNIX_EPOCH )
40
+ . expect ( "system clock to be ahead of the unix epoch" )
41
+ . as_secs ( ) ;
42
+ let valid_until_seconds_since_epoch = fee_params
43
+ . valid_until
44
+ . timestamp ( )
45
+ . try_into ( )
46
+ . expect ( "expiration to be ahead of unix epoch" ) ;
47
+ seconds_since_epoch > valid_until_seconds_since_epoch
48
+ }
49
+ #[ cfg( not( feature = "std" ) ) ]
50
+ {
51
+ // TODO: We need to find a way to check expiry times in no-std builds.
52
+ false
53
+ }
54
+ }
55
+
47
56
/// Computes the opening fee given a payment size and the fee parameters.
48
57
///
49
58
/// Returns [`Option::None`] when the computation overflows.
0 commit comments