@@ -540,20 +540,20 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
540
540
}
541
541
542
542
/// Filter a policy by eliminating absolute timelock constraints
543
- /// that are not satisfied at the given age .
544
- pub fn at_height ( mut self , time : u32 ) -> Policy < Pk > {
543
+ /// that are not satisfied at the given `n` (`n OP_CHECKLOCKTIMEVERIFY`) .
544
+ pub fn at_lock_time ( mut self , n : u32 ) -> Policy < Pk > {
545
545
self = match self {
546
546
Policy :: After ( t) => {
547
- if !timelock:: absolute_timelocks_are_same_unit ( t, time ) {
547
+ if !timelock:: absolute_timelocks_are_same_unit ( t, n ) {
548
548
Policy :: Unsatisfiable
549
- } else if t > time {
549
+ } else if t > n {
550
550
Policy :: Unsatisfiable
551
551
} else {
552
552
Policy :: After ( t)
553
553
}
554
554
}
555
555
Policy :: Threshold ( k, subs) => {
556
- Policy :: Threshold ( k, subs. into_iter ( ) . map ( |sub| sub. at_height ( time ) ) . collect ( ) )
556
+ Policy :: Threshold ( k, subs. into_iter ( ) . map ( |sub| sub. at_lock_time ( n ) ) . collect ( ) )
557
557
}
558
558
x => x,
559
559
} ;
@@ -770,12 +770,15 @@ mod tests {
770
770
assert_eq ! ( policy, Policy :: After ( 1000 ) ) ;
771
771
assert_eq ! ( policy. absolute_timelocks( ) , vec![ 1000 ] ) ;
772
772
assert_eq ! ( policy. relative_timelocks( ) , vec![ ] ) ;
773
- assert_eq ! ( policy. clone( ) . at_height( 0 ) , Policy :: Unsatisfiable ) ;
774
- assert_eq ! ( policy. clone( ) . at_height( 999 ) , Policy :: Unsatisfiable ) ;
775
- assert_eq ! ( policy. clone( ) . at_height( 1000 ) , policy. clone( ) ) ;
776
- assert_eq ! ( policy. clone( ) . at_height( 10000 ) , policy. clone( ) ) ;
777
- // Pass a UNIX timestamp to at_height while policy uses a block height.
778
- assert_eq ! ( policy. clone( ) . at_height( 500_000_001 ) , Policy :: Unsatisfiable ) ;
773
+ assert_eq ! ( policy. clone( ) . at_lock_time( 0 ) , Policy :: Unsatisfiable ) ;
774
+ assert_eq ! ( policy. clone( ) . at_lock_time( 999 ) , Policy :: Unsatisfiable ) ;
775
+ assert_eq ! ( policy. clone( ) . at_lock_time( 1000 ) , policy. clone( ) ) ;
776
+ assert_eq ! ( policy. clone( ) . at_lock_time( 10000 ) , policy. clone( ) ) ;
777
+ // Pass a UNIX timestamp to at_lock_time while policy uses a block height.
778
+ assert_eq ! (
779
+ policy. clone( ) . at_lock_time( 500_000_001 ) ,
780
+ Policy :: Unsatisfiable
781
+ ) ;
779
782
assert_eq ! ( policy. n_keys( ) , 0 ) ;
780
783
assert_eq ! ( policy. minimum_n_keys( ) , Some ( 0 ) ) ;
781
784
@@ -784,16 +787,22 @@ mod tests {
784
787
assert_eq ! ( policy, Policy :: After ( 500_000_010 ) ) ;
785
788
assert_eq ! ( policy. absolute_timelocks( ) , vec![ 500_000_010 ] ) ;
786
789
assert_eq ! ( policy. relative_timelocks( ) , vec![ ] ) ;
787
- // Pass a block height to at_height while policy uses a UNIX timestapm.
788
- assert_eq ! ( policy. clone( ) . at_height( 0 ) , Policy :: Unsatisfiable ) ;
789
- assert_eq ! ( policy. clone( ) . at_height( 999 ) , Policy :: Unsatisfiable ) ;
790
- assert_eq ! ( policy. clone( ) . at_height( 1000 ) , Policy :: Unsatisfiable ) ;
791
- assert_eq ! ( policy. clone( ) . at_height( 10000 ) , Policy :: Unsatisfiable ) ;
792
- // And now pass a UNIX timestamp to at_height while policy also uses a timestamp.
793
- assert_eq ! ( policy. clone( ) . at_height( 500_000_000 ) , Policy :: Unsatisfiable ) ;
794
- assert_eq ! ( policy. clone( ) . at_height( 500_000_001 ) , Policy :: Unsatisfiable ) ;
795
- assert_eq ! ( policy. clone( ) . at_height( 500_000_010 ) , policy. clone( ) ) ;
796
- assert_eq ! ( policy. clone( ) . at_height( 500_000_012 ) , policy. clone( ) ) ;
790
+ // Pass a block height to at_lock_time while policy uses a UNIX timestapm.
791
+ assert_eq ! ( policy. clone( ) . at_lock_time( 0 ) , Policy :: Unsatisfiable ) ;
792
+ assert_eq ! ( policy. clone( ) . at_lock_time( 999 ) , Policy :: Unsatisfiable ) ;
793
+ assert_eq ! ( policy. clone( ) . at_lock_time( 1000 ) , Policy :: Unsatisfiable ) ;
794
+ assert_eq ! ( policy. clone( ) . at_lock_time( 10000 ) , Policy :: Unsatisfiable ) ;
795
+ // And now pass a UNIX timestamp to at_lock_time while policy also uses a timestamp.
796
+ assert_eq ! (
797
+ policy. clone( ) . at_lock_time( 500_000_000 ) ,
798
+ Policy :: Unsatisfiable
799
+ ) ;
800
+ assert_eq ! (
801
+ policy. clone( ) . at_lock_time( 500_000_001 ) ,
802
+ Policy :: Unsatisfiable
803
+ ) ;
804
+ assert_eq ! ( policy. clone( ) . at_lock_time( 500_000_010 ) , policy. clone( ) ) ;
805
+ assert_eq ! ( policy. clone( ) . at_lock_time( 500_000_012 ) , policy. clone( ) ) ;
797
806
assert_eq ! ( policy. n_keys( ) , 0 ) ;
798
807
assert_eq ! ( policy. minimum_n_keys( ) , Some ( 0 ) ) ;
799
808
}
0 commit comments