Struct ckb_types::core::EpochNumberWithFraction
source · pub struct EpochNumberWithFraction(/* private fields */);
Expand description
Represents an epoch number with a fraction unit, it can be used to accurately represent the position for a block within an epoch.
Implementations§
source§impl EpochNumberWithFraction
impl EpochNumberWithFraction
sourcepub const NUMBER_OFFSET: usize = 0usize
pub const NUMBER_OFFSET: usize = 0usize
TODO(doc): @quake
sourcepub const NUMBER_BITS: usize = 24usize
pub const NUMBER_BITS: usize = 24usize
TODO(doc): @quake
sourcepub const NUMBER_MAXIMUM_VALUE: u64 = 16_777_216u64
pub const NUMBER_MAXIMUM_VALUE: u64 = 16_777_216u64
TODO(doc): @quake
sourcepub const NUMBER_MASK: u64 = 16_777_215u64
pub const NUMBER_MASK: u64 = 16_777_215u64
TODO(doc): @quake
sourcepub const INDEX_OFFSET: usize = 24usize
pub const INDEX_OFFSET: usize = 24usize
TODO(doc): @quake
sourcepub const INDEX_BITS: usize = 16usize
pub const INDEX_BITS: usize = 16usize
TODO(doc): @quake
sourcepub const INDEX_MAXIMUM_VALUE: u64 = 65_536u64
pub const INDEX_MAXIMUM_VALUE: u64 = 65_536u64
TODO(doc): @quake
sourcepub const INDEX_MASK: u64 = 65_535u64
pub const INDEX_MASK: u64 = 65_535u64
TODO(doc): @quake
sourcepub const LENGTH_OFFSET: usize = 40usize
pub const LENGTH_OFFSET: usize = 40usize
TODO(doc): @quake
sourcepub const LENGTH_BITS: usize = 16usize
pub const LENGTH_BITS: usize = 16usize
TODO(doc): @quake
sourcepub const LENGTH_MAXIMUM_VALUE: u64 = 65_536u64
pub const LENGTH_MAXIMUM_VALUE: u64 = 65_536u64
TODO(doc): @quake
sourcepub const LENGTH_MASK: u64 = 65_535u64
pub const LENGTH_MASK: u64 = 65_535u64
TODO(doc): @quake
sourcepub const fn new_unchecked(number: u64, index: u64, length: u64) -> Self
pub const fn new_unchecked(number: u64, index: u64, length: u64) -> Self
TODO(doc): @quake
sourcepub fn number(self) -> EpochNumber
pub fn number(self) -> EpochNumber
TODO(doc): @quake
sourcepub const fn full_value(self) -> u64
pub const fn full_value(self) -> u64
TODO(doc): @quake
sourcepub fn minimum_epoch_number_after_n_blocks(self, n: BlockNumber) -> EpochNumber
pub fn minimum_epoch_number_after_n_blocks(self, n: BlockNumber) -> EpochNumber
Estimate the floor limit of epoch number after N blocks.
Since we couldn’t know the length of next epoch before reach the next epoch,
this function could only return self.number()
or self.number()+1
.
sourcepub fn from_full_value(value: u64) -> Self
pub fn from_full_value(value: u64) -> Self
TODO(doc): @quake
sourcepub fn from_full_value_unchecked(value: u64) -> Self
pub fn from_full_value_unchecked(value: u64) -> Self
Converts from an unsigned 64 bits number without checks.
Notice
The EpochNumberWithFraction
constructed by this method has a potential risk that when
call self.to_rational()
may lead to a panic if the user specifies a zero epoch length.
sourcepub fn normalize(self) -> Self
pub fn normalize(self) -> Self
Prevents leading to a panic if the EpochNumberWithFraction
is constructed without checks.
sourcepub fn to_rational(self) -> RationalU256
pub fn to_rational(self) -> RationalU256
Converts the epoch to an unsigned 256 bits rational.
Panics
Only genesis epoch’s length could be zero, otherwise causes a division-by-zero panic.
sourcepub fn is_genesis(&self) -> bool
pub fn is_genesis(&self) -> bool
Check if current value is the genesis block.
sourcepub fn is_successor_of(self, predecessor: Self) -> bool
pub fn is_successor_of(self, predecessor: Self) -> bool
Check if current value is another value’s successor.
sourcepub fn is_well_formed(self) -> bool
pub fn is_well_formed(self) -> bool
Check the data format.
The epoch length should be greater than zero. The epoch index should be less than the epoch length.
sourcepub fn is_well_formed_increment(self) -> bool
pub fn is_well_formed_increment(self) -> bool
Check the data format as an increment.
The epoch index should be less than the epoch length or both of them are zero.
Trait Implementations§
source§impl Clone for EpochNumberWithFraction
impl Clone for EpochNumberWithFraction
source§fn clone(&self) -> EpochNumberWithFraction
fn clone(&self) -> EpochNumberWithFraction
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for EpochNumberWithFraction
impl Debug for EpochNumberWithFraction
source§impl Display for EpochNumberWithFraction
impl Display for EpochNumberWithFraction
source§impl FromStr for EpochNumberWithFraction
impl FromStr for EpochNumberWithFraction
source§impl Hash for EpochNumberWithFraction
impl Hash for EpochNumberWithFraction
source§impl Ord for EpochNumberWithFraction
impl Ord for EpochNumberWithFraction
source§fn cmp(&self, other: &EpochNumberWithFraction) -> Ordering
fn cmp(&self, other: &EpochNumberWithFraction) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl Pack<Uint64> for EpochNumberWithFraction
impl Pack<Uint64> for EpochNumberWithFraction
source§impl PartialEq for EpochNumberWithFraction
impl PartialEq for EpochNumberWithFraction
source§fn eq(&self, other: &EpochNumberWithFraction) -> bool
fn eq(&self, other: &EpochNumberWithFraction) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for EpochNumberWithFraction
impl PartialOrd for EpochNumberWithFraction
source§fn partial_cmp(&self, other: &EpochNumberWithFraction) -> Option<Ordering>
fn partial_cmp(&self, other: &EpochNumberWithFraction) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more