pub struct Sequence(pub u32);
Expand description
Bitcoin transaction input sequence number.
Tuple Fields§
§0: u32
Implementations§
Source§impl Sequence
impl Sequence
Sourcepub const MAX: Self
pub const MAX: Self
The maximum allowable sequence number.
The sequence number that disables replace-by-fee, absolute lock time and relative lock time.
Sourcepub const ZERO: Self
pub const ZERO: Self
Zero value sequence.
This sequence number enables replace-by-fee and absolute lock time.
Sourcepub const FINAL: Self = Sequence::MAX
pub const FINAL: Self = Sequence::MAX
The sequence number that disables replace-by-fee, absolute lock time and relative lock time.
Sourcepub const ENABLE_LOCKTIME_NO_RBF: Self = Sequence::MIN_NO_RBF
pub const ENABLE_LOCKTIME_NO_RBF: Self = Sequence::MIN_NO_RBF
The sequence number that enables absolute lock time but disables replace-by-fee and relative lock time.
Sourcepub const ENABLE_RBF_NO_LOCKTIME: Self
👎Deprecating in a future version: use ENABLE_LOCKTIME_AND_RBF
instead
pub const ENABLE_RBF_NO_LOCKTIME: Self
ENABLE_LOCKTIME_AND_RBF
insteadThe sequence number that enables replace-by-fee and absolute lock time but disables relative lock time.
Sourcepub const ENABLE_LOCKTIME_AND_RBF: Self
pub const ENABLE_LOCKTIME_AND_RBF: Self
The maximum sequence number that enables replace-by-fee and absolute lock time but disables relative lock time.
This sequence number has no meaning other than to enable RBF and the absolute locktime.
Sourcepub const SIZE: usize = 4usize
pub const SIZE: usize = 4usize
The number of bytes that a sequence number contributes to the size of a transaction.
Sourcepub fn enables_absolute_lock_time(&self) -> bool
pub fn enables_absolute_lock_time(&self) -> bool
Returns true
if the sequence number enables absolute lock-time (Transaction::lock_time
).
Sourcepub fn is_final(&self) -> bool
pub fn is_final(&self) -> bool
Returns true
if the sequence number indicates that the transaction is finalized.
Instead of this method please consider using !enables_absolute_lock_time
because it
is equivalent and improves readability for those not steeped in Bitcoin folklore.
§Historical note
The term ‘final’ is an archaic Bitcoin term, it may have come about because the sequence
number in the original Bitcoin code was intended to be incremented in order to replace a
transaction, so once the sequence number got to u64::MAX
it could no longer be increased,
hence it was ‘final’.
Some other references to the term:
CTxIn::SEQUENCE_FINAL
in the Bitcoin Core code.- BIP-112: “BIP 68 prevents a non-final transaction from being selected for inclusion in a block until the corresponding input has reached the specified age”
Sourcepub fn is_rbf(&self) -> bool
pub fn is_rbf(&self) -> bool
Returns true if the transaction opted-in to BIP125 replace-by-fee.
Replace by fee is signaled by the sequence being less than 0xfffffffe which is checked by
this method. Note, this is the highest “non-final” value (see Sequence::is_final
).
Sourcepub fn is_relative_lock_time(&self) -> bool
pub fn is_relative_lock_time(&self) -> bool
Returns true
if the sequence has a relative lock-time.
Sourcepub fn is_height_locked(&self) -> bool
pub fn is_height_locked(&self) -> bool
Returns true
if the sequence number encodes a block based relative lock-time.
Sourcepub fn is_time_locked(&self) -> bool
pub fn is_time_locked(&self) -> bool
Returns true
if the sequence number encodes a time interval based relative lock-time.
Sourcepub fn from_hex(s: &str) -> Result<Self, PrefixedHexError>
Available on crate feature alloc
only.
pub fn from_hex(s: &str) -> Result<Self, PrefixedHexError>
alloc
only.Constructs a new Sequence
from a prefixed hex string.
Sourcepub fn from_unprefixed_hex(s: &str) -> Result<Self, UnprefixedHexError>
Available on crate feature alloc
only.
pub fn from_unprefixed_hex(s: &str) -> Result<Self, UnprefixedHexError>
alloc
only.Constructs a new Sequence
from an unprefixed hex string.
Sourcepub fn from_height(height: u16) -> Self
pub fn from_height(height: u16) -> Self
Constructs a new relative lock-time using block height.
Sourcepub fn from_512_second_intervals(intervals: u16) -> Self
pub fn from_512_second_intervals(intervals: u16) -> Self
Constructs a new relative lock-time using time intervals where each interval is equivalent to 512 seconds.
Encoding finer granularity of time for relative lock-times is not supported in Bitcoin
Sourcepub fn from_seconds_floor(seconds: u32) -> Result<Self, TimeOverflowError>
Available on crate feature alloc
only.
pub fn from_seconds_floor(seconds: u32) -> Result<Self, TimeOverflowError>
alloc
only.Constructs a new relative lock-time from seconds, converting the seconds into 512 second interval with floor division.
Will return an error if the input cannot be encoded in 16 bits.
Sourcepub fn from_seconds_ceil(seconds: u32) -> Result<Self, TimeOverflowError>
Available on crate feature alloc
only.
pub fn from_seconds_ceil(seconds: u32) -> Result<Self, TimeOverflowError>
alloc
only.Constructs a new relative lock-time from seconds, converting the seconds into 512 second interval with ceiling division.
Will return an error if the input cannot be encoded in 16 bits.
Sourcepub fn from_consensus(n: u32) -> Self
pub fn from_consensus(n: u32) -> Self
Constructs a new sequence from a u32 value.
Sourcepub fn to_consensus_u32(self) -> u32
pub fn to_consensus_u32(self) -> u32
Returns the inner 32bit integer value of Sequence.
Sourcepub fn to_relative_lock_time(&self) -> Option<LockTime>
Available on crate feature alloc
only.
pub fn to_relative_lock_time(&self) -> Option<LockTime>
alloc
only.Constructs a new relative::LockTime
from this Sequence
number.
Trait Implementations§
Source§impl<'a> Arbitrary<'a> for Sequence
Available on crate features arbitrary
and alloc
only.
impl<'a> Arbitrary<'a> for Sequence
arbitrary
and alloc
only.Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self
from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self
from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured
this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured
this type
needs to construct itself. Read more