getEpochAndSlotIndex method

List<u64> getEpochAndSlotIndex(
  1. u64 slot
)

Implementation

List<u64> getEpochAndSlotIndex(final u64 slot) {
  if (slot < firstNormalSlot) {
    final epoch =
        _trailingZeros(_nextPowerOfTwo(slot + minimumSlotPerEpoch + 1)) -
            _trailingZeros(minimumSlotPerEpoch) -
            1;
    final epochLen = getSlotsInEpoch(epoch);
    final slotIndex = slot - (epochLen - minimumSlotPerEpoch);
    return [epoch, slotIndex];
  } else {
    final normalSlotIndex = slot - firstNormalSlot;
    final normalEpochIndex = (normalSlotIndex / slotsPerEpoch).floor();
    final epoch = firstNormalEpoch + normalEpochIndex;
    final slotIndex = normalSlotIndex % slotsPerEpoch;
    return [epoch, slotIndex];
  }
}