Construct a new Epoch instance.
Whole epoch units (Num/bigint)
Fractional numerator (Num).
Fractional denominator (Num).
ReadonlyintegerWhole epoch units (Num/bigint)
ReadonlynumeratorFractional numerator (Num).
ReadonlydenominatorFractional denominator (Num).
Static OptionalbyteThe bytes length of the entity, if it is fixed, otherwise undefined
StaticGenesisReturn the genesis epoch.
Note: for historical reasons the genesis epoch is represented with all-zero fields, no other epoch instance should use a zero denominator.
Epoch with integer = 0, numerator = 0, denominator = 0.
StaticOneReturn an Epoch representing one Nervos DAO cycle (180 epochs exactly).
Epoch equal to 180 with denominator set to 1 to represent an exact whole unit.
Normalize simpler base invariants:
This is a minimal correction used before arithmetic or canonical normalization.
New Epoch with denominator corrected (but fraction not reduced).
Perform full canonical normalization of the epoch value.
Steps:
Canonicalized Epoch with a non-negative, reduced fractional part and integer adjusted accordingly.
Convert this Epoch into its RPC-style packed numeric representation (Num).
Packing layout (little-endian style fields):
Throws if any component is negative since packed representation assumes non-negative components.
Packed numeric representation (Num) suitable for RPC packing.
Convert epoch to hex string representation of the RPC-style packed numeric form.
Returns the same representation used by CKB RPC responses where the packed numeric bytes may be trimmed of leading zeros, see numToHex
Hex string corresponding to the packed epoch.
StaticfromStaticfromCreate an Epoch from an EpochLike value.
Accepts:
All numeric-like inputs are converted with numFrom() to produce internal Num values.
Value convertible to Epoch
Epoch instance
Compare this epoch to another EpochLike.
The comparison computes scaled integer values so fractions are compared without precision loss: scaled = (integer * denominator + numerator) * other.denominator
Special-case: identical object references return equality immediately.
Epoch-like value to compare against.
1 if this > other, 0 if equal, -1 if this < other.
Check whether this epoch is less than another EpochLike.
EpochLike to compare against.
true if this < other.
Check whether this epoch is less than or equal to another EpochLike.
EpochLike to compare against.
true if this <= other.
Check whether this epoch equals another EpochLike.
EpochLike to compare against.
true if equal.
Check whether this epoch is greater than or equal to another EpochLike.
EpochLike to compare against.
true if this >= other.
Check whether this epoch is greater than another EpochLike.
EpochLike to compare against.
true if this > other.
Add another EpochLike to this epoch and return the normalized result.
Rules and edge-cases:
Epoch-like value to add.
Normalized Epoch representing the sum.
Subtract an EpochLike from this epoch and return the normalized result.
Implementation notes:
Epoch-like value to subtract.
Normalized Epoch representing this - other.
Convert this epoch to an estimated Unix timestamp in milliseconds using a reference header.
Note: This is an estimation that assumes a constant epoch duration.
Object providing epoch (Epoch) and timestamp (Num) fields, such as a ClientBlockHeader.
Duration of a single epoch in milliseconds. Defaults to 4 hours.
Estimated Unix timestamp in milliseconds as bigint.
StaticencodeStaticdecodeStaticfromCalculate the hash of the entity
The hash of the entity
Convert the entity to a full-byte untrimmed Hex representation
The entity full-byte untrimmed hexadecimal representation
Epoch
Represents a blockchain epoch consisting of a whole integer part and an optional fractional part represented as numerator/denominator.
Behavior highlights:
Example
Remarks
This class is primarily a thin value-object; operations return new Epoch instances.