import * as constants from "./Constants"; import { getBytes } from "./TransactionHelper"; export function getEraBytes(blockNumber: number): Buffer{ if(blockNumber == 0){ return Buffer.from([0x00]); } let period = constants.ERA_PERIOD; let phase = blockNumber; let quantizeFactor = Math.max(1, period / 4096); let lastBit = quantizeFactor << 63; let logOf2 = lastBit != 0 ? Math.log2(lastBit) : 64; let low = Math.min(15, Math.max(1, logOf2 - 1)); let high = (phase / quantizeFactor << 4); let encoded = low | high; return getBytes(encoded); }