Add push_* methods for lock times

Lock times are u32 and can necessitate encoding using 5 bytes. As such
they are "special".

Add methods `push_lock_time` and `push_sequence` for pushing absolute
lock times and sequence numbers. We do not push relative locktimes
because they are only 16 bits from the original sequence number.
This commit is contained in:
Tobin C. Harding 2023-02-07 16:31:02 +11:00
parent b6387db47f
commit 1e0e712bb0
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 12 additions and 0 deletions

View File

@ -7,8 +7,10 @@ use core::fmt;
use secp256k1::XOnlyPublicKey;
use crate::blockdata::locktime::absolute;
use crate::blockdata::opcodes::{self, all::*};
use crate::blockdata::script::{write_scriptint, opcode_to_verify, Script, ScriptBuf};
use crate::blockdata::transaction::Sequence;
use crate::key::PublicKey;
use crate::prelude::*;
@ -106,6 +108,16 @@ impl Builder {
}
}
/// Adds instructions to push an absolute lock time onto the stack.
pub fn push_lock_time(self, lock_time: absolute::LockTime) -> Builder {
self.push_int(lock_time.to_consensus_u32().into())
}
/// Adds instructions to push a sequence number onto the stack.
pub fn push_sequence(self, sequence: Sequence) -> Builder {
self.push_int(sequence.to_consensus_u32().into())
}
/// Converts the `Builder` into `ScriptBuf`.
pub fn into_script(self) -> ScriptBuf {
self.0