Skip to content

Commit

Permalink
WIP: Add timelock related methods on Transaction
Browse files Browse the repository at this point in the history
Now we have the two `timelock` types we can implement a few methods on
`Transaction` that may be useful to users of the library.
  • Loading branch information
tcharding committed May 16, 2022
1 parent b4353d2 commit f908845
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/blockdata/transaction.rs
Expand Up @@ -40,7 +40,7 @@ use blockdata::witness::Witness;
use consensus::{encode, Decodable, Encodable};
use consensus::encode::MAX_VEC_SIZE;
use hash_types::{Sighash, Txid, Wtxid};
use VarInt;
use {timelock, VarInt};

#[cfg(doc)]
use util::sighash::SchnorrSighashType;
Expand Down Expand Up @@ -609,6 +609,24 @@ impl Transaction {
pub fn is_explicitly_rbf(&self) -> bool {
self.input.iter().any(|input| input.sequence < (0xffffffff - 1))
}

/// Returns the nLockTime as an absolute timelock.
pub fn absolute_lock_time(&self) -> timelock::Abs {
timelock::Abs::from(self.lock_time)
}

/// Return the nSequence for `input_index` as a relative timelock.
pub fn relative_lock_time(&self, input_index: usize) -> timelock::Rel {
timelock::Rel::from(self.input[input_index].sequence)
}

/// Returns `true` if this transactions nLockTime should be ignored.
pub fn ignore_lock_time(&self) -> bool {
if self.lock_time == 0 {
return true;
}
self.input.iter().all(|input| input.sequence == 0xffffffff)
}
}

impl_consensus_encoding!(TxOut, value, script_pubkey);
Expand Down

0 comments on commit f908845

Please sign in to comment.