@@ -14,23 +14,9 @@ use std::time::{SystemTime, UNIX_EPOCH};
1414pub fn is_valid_opening_fee_params (
1515 fee_params : & OpeningFeeParams , promise_secret : & [ u8 ; 32 ] ,
1616) -> 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 ;
3219 }
33-
3420 let mut hmac = HmacEngine :: < Sha256 > :: new ( promise_secret) ;
3521 hmac. input ( & fee_params. min_fee_msat . to_be_bytes ( ) ) ;
3622 hmac. input ( & fee_params. proportional . to_be_bytes ( ) ) ;
@@ -44,6 +30,28 @@ pub fn is_valid_opening_fee_params(
4430 promise == fee_params. promise
4531}
4632
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+
4755/// Computes the opening fee given a payment size and the fee parameters.
4856///
4957/// Returns [`Option::None`] when the computation overflows.
0 commit comments