Skip to content

Commit

Permalink
Use the new relative::LockTime module
Browse files Browse the repository at this point in the history
Implement `check_older` using the new `relative::LockTime` API.

This code seems upside down, I'm not sure I have the naming correct,
i.e., I don't know which (`self` or arg) is doing the satisfying and
which is satisfied?

I believe the `<=` are going the correct direction, its the naming and
which sequence value to call the 'lock' that I'm struggling with.
  • Loading branch information
tcharding committed Aug 16, 2022
1 parent 4a0a87b commit 7a7282a
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/miniscript/satisfy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,12 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for Sequence {
return false;
}

// We need a relative lock time type in rust-bitcoin to clean this up.

/* If nSequence encodes a relative lock-time, this mask is
* applied to extract that lock-time from the sequence field. */
const SEQUENCE_LOCKTIME_MASK: u32 = 0x0000ffff;
const SEQUENCE_LOCKTIME_TYPE_FLAG: u32 = 0x00400000;

let mask = SEQUENCE_LOCKTIME_MASK | SEQUENCE_LOCKTIME_TYPE_FLAG;
let masked_n = n.to_consensus_u32() & mask;
let masked_seq = self.to_consensus_u32() & mask;
if masked_n < SEQUENCE_LOCKTIME_TYPE_FLAG && masked_seq >= SEQUENCE_LOCKTIME_TYPE_FLAG {
false
} else {
masked_n <= masked_seq
}
let lock = match n.to_relative_lock_time() {
Some(lock) => lock,
None => return false,
};

lock.is_satisfied_by(self)
}
}

Expand Down

0 comments on commit 7a7282a

Please sign in to comment.