@@ -540,20 +540,20 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
540540 }
541541
542542 /// 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 > {
545545 self = match self {
546546 Policy :: After ( t) => {
547- if !timelock:: absolute_timelocks_are_same_unit ( t, time ) {
547+ if !timelock:: absolute_timelocks_are_same_unit ( t, n ) {
548548 Policy :: Unsatisfiable
549- } else if t > time {
549+ } else if t > n {
550550 Policy :: Unsatisfiable
551551 } else {
552552 Policy :: After ( t)
553553 }
554554 }
555555 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 ( ) )
557557 }
558558 x => x,
559559 } ;
@@ -770,12 +770,15 @@ mod tests {
770770 assert_eq ! ( policy, Policy :: After ( 1000 ) ) ;
771771 assert_eq ! ( policy. absolute_timelocks( ) , vec![ 1000 ] ) ;
772772 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+ ) ;
779782 assert_eq ! ( policy. n_keys( ) , 0 ) ;
780783 assert_eq ! ( policy. minimum_n_keys( ) , Some ( 0 ) ) ;
781784
@@ -784,16 +787,22 @@ mod tests {
784787 assert_eq ! ( policy, Policy :: After ( 500_000_010 ) ) ;
785788 assert_eq ! ( policy. absolute_timelocks( ) , vec![ 500_000_010 ] ) ;
786789 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( ) ) ;
797806 assert_eq ! ( policy. n_keys( ) , 0 ) ;
798807 assert_eq ! ( policy. minimum_n_keys( ) , Some ( 0 ) ) ;
799808 }
0 commit comments