Skip to content

Commit 13e2c31

Browse files
committed
Re-name function at_height -> at_lock_time
The function takes as a parameter that represents the argument from `OP_CLTV`, this is a height _or_ time. Improve the function name to reflect this.
1 parent 951b4f0 commit 13e2c31

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/policy/semantic.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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,12 @@ 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!(policy.clone().at_lock_time(500_000_001), Policy::Unsatisfiable);
779779
assert_eq!(policy.n_keys(), 0);
780780
assert_eq!(policy.minimum_n_keys(), Some(0));
781781

@@ -784,16 +784,16 @@ mod tests {
784784
assert_eq!(policy, Policy::After(500_000_010));
785785
assert_eq!(policy.absolute_timelocks(), vec![500_000_010]);
786786
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());
787+
// Pass a block height to at_lock_time while policy uses a UNIX timestapm.
788+
assert_eq!(policy.clone().at_lock_time(0), Policy::Unsatisfiable);
789+
assert_eq!(policy.clone().at_lock_time(999), Policy::Unsatisfiable);
790+
assert_eq!(policy.clone().at_lock_time(1000), Policy::Unsatisfiable);
791+
assert_eq!(policy.clone().at_lock_time(10000), Policy::Unsatisfiable);
792+
// And now pass a UNIX timestamp to at_lock_time while policy also uses a timestamp.
793+
assert_eq!(policy.clone().at_lock_time(500_000_000), Policy::Unsatisfiable);
794+
assert_eq!(policy.clone().at_lock_time(500_000_001), Policy::Unsatisfiable);
795+
assert_eq!(policy.clone().at_lock_time(500_000_010), policy.clone());
796+
assert_eq!(policy.clone().at_lock_time(500_000_012), policy.clone());
797797
assert_eq!(policy.n_keys(), 0);
798798
assert_eq!(policy.minimum_n_keys(), Some(0));
799799
}

0 commit comments

Comments
 (0)