From cbfa8cff4c140ccebeb2ce1cac7992c2731ac40a Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 16 Aug 2022 11:33:54 +1000 Subject: [PATCH] Improve lock time docs Bitcoin lock times are easy to get confused, add absolute/relative in various places to help clarify things. --- src/blockdata/locktime/absolute.rs | 5 +++-- src/blockdata/transaction.rs | 16 ++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/blockdata/locktime/absolute.rs b/src/blockdata/locktime/absolute.rs index f2fedb03..aaece729 100644 --- a/src/blockdata/locktime/absolute.rs +++ b/src/blockdata/locktime/absolute.rs @@ -141,7 +141,8 @@ impl fmt::UpperHex for PackedLockTime { } } -/// A lock time value, representing either a block height or a UNIX timestamp (seconds since epoch). +/// An absolute lock time value, representing either a block height or a UNIX timestamp (seconds +/// since epoch). /// /// Used for transaction lock time (`nLockTime` in Bitcoin Core and [`crate::Transaction::lock_time`] /// in this library) and also for the argument to opcode 'OP_CHECKLOCKTIMEVERIFY`. @@ -156,7 +157,7 @@ impl fmt::UpperHex for PackedLockTime { /// # use bitcoin::absolute::{LockTime, LockTime::*}; /// # let n = LockTime::from_consensus(100); // n OP_CHECKLOCKTIMEVERIFY /// # let lock_time = LockTime::from_consensus(100); // nLockTime -/// // To compare lock times there are various `is_satisfied_*` methods, you may also use: +/// // To compare absolute lock times there are various `is_satisfied_*` methods, you may also use: /// let is_satisfied = match (n, lock_time) { /// (Blocks(n), Blocks(lock_time)) => n <= lock_time, /// (Seconds(n), Seconds(lock_time)) => n <= lock_time, diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index 736a4234..f0fb57a5 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -262,17 +262,17 @@ pub enum RelativeLockTimeError { impl Sequence { /// The maximum allowable sequence number. /// - /// This sequence number disables lock-time and replace-by-fee. + /// This sequence number disables absolute lock time and replace-by-fee. pub const MAX: Self = Sequence(0xFFFFFFFF); /// Zero value sequence. /// - /// This sequence number enables replace-by-fee and lock-time. + /// This sequence number enables replace-by-fee and absolute lock time. pub const ZERO: Self = Sequence(0); - /// The sequence number that enables absolute lock-time but disables replace-by-fee - /// and relative lock-time. + /// The sequence number that enables absolute lock time but disables replace-by-fee + /// and relative lock time. pub const ENABLE_LOCKTIME_NO_RBF: Self = Sequence::MIN_NO_RBF; - /// The sequence number that enables replace-by-fee and absolute lock-time but - /// disables relative lock-time. + /// The sequence number that enables replace-by-fee and absolute lock time but + /// disables relative lock time. pub const ENABLE_RBF_NO_LOCKTIME: Self = Sequence(0xFFFFFFFD); /// The lowest sequence number that does not opt-in for replace-by-fee. @@ -283,9 +283,9 @@ impl Sequence { /// /// [BIP-125]: const MIN_NO_RBF: Self = Sequence(0xFFFFFFFE); - /// BIP-68 relative lock-time disable flag mask + /// BIP-68 relative lock time disable flag mask. const LOCK_TIME_DISABLE_FLAG_MASK: u32 = 0x80000000; - /// BIP-68 relative lock-time type flag mask + /// BIP-68 relative lock time type flag mask. const LOCK_TYPE_MASK: u32 = 0x00400000; /// Retuns `true` if the sequence number indicates that the transaction is finalised.